Best way to "destroy" and "spawn"?

DrGlickertDrGlickert Member Posts: 1,135
edited November -1 in Working with GS (Mac)
On the heels of JohnP's advice to avoid Spawning and destroying too many actors in my game he suggested that I simply move the actor outside the viewing area and then back to the viewing area when it's supposed to "spawn."

Whats the simplest way to do this when making a game like a bubble shooter game? I want the actor (bubble) to be destroyed when the ball hits it, then I guess it to "respawn" above all the other bubbles...

Off the top of my head I guess: When ball hits actor; set visible to false, set collisions to off, move to (random(x,y)), then set visible to true and turn collisions back on? Is this right? Or is there a simpler way to do this?

Comments

  • QbAnYtOQbAnYtO Member Posts: 523
    (john owes me $5)

    thats called recycling...

    i've never "recycled" before bcuz my games wouldn't work well with it, not yet anyways....

    but i think ur somewhat in the right direction...
  • DrGlickertDrGlickert Member Posts: 1,135
    That seems like it's excessive. Can GS just "recycle" the memory from spawning and destroying actors? That would make things incredibly simple for my game....
  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    Unfortunately, no, GS can't do the recycling. It's kinda like someone who puts Pepsi cans in the normal trash ;)

    Recycling actors manually is by far the best way to go.

    Ace
  • ORBZORBZ Member Posts: 1,304
    Recycling actors improves performance but with a HEAVY HEAVY cost in code complexity.

    I don't recycle except in the most mundane circumstances.

    If you are trying to get your game to run in GS on the older devices (iPhone 3G, iPod Touch 2nd Gen, etc) then with their limited amount of memory recycling is a good idea. However, if you are satisfied with Arm7 devices which have a baseline of 256MB of memory you are safe to not recycle your actors and keep your spawning / destroying logic in play.

    However, one word of caution. GS does not release memory very rapidly, so it will "ramp-up" allocated memory until it figures out a threshold of max memory usage and then begin to ramp-off slowly. Basically, it allocates as fast as it can until it doesn't need to allocate anymore. This memory is then "Held" for a while because it's the memory allocation step that slows the game down GS keeps the allocation around for a while. Think caching but not quite.

    So if you spawn a bunch of stuff real quick it will be slow and choppy, but if you let it keep doing that for a few cycles eventually the spawns will be smoother and the memory allocation will stabalize.

    Example, the game i'm working on starts off a little bit choppy (but tolerable) and allocates 26MB of memory, but it quickly ramps up to 48, then 52MB, it levels off around 52 to 58MB of memory fluctuating around that point. Speed improves once it's settled.

    However, my same game on a 3G is unplayable because the 3G doesn't have enough free memory so it has to go to swap space, constantly juggling free memory with the disk.

    Therefor, if you want to prevent allocation spikes you should use recycling. A better way to do this would be to let us define an expected memory usage parameter somewhere in the settings and have GS pre-allocate the amount of memory it will need. Alas, not so lucky :(

    I believe this is all due to the memory allocation behavior of Lua. Pure speculation.

    We need a "collect garbage" behavior
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    garbage collection would rock me in my boots ;)
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    So does using the behavior for resetting the scene or resetting the game help any of the memory release, or does that just open another can of worms?
  • DrGlickertDrGlickert Member Posts: 1,135
    SlickZero said:
    So does using the behavior for resetting the scene or resetting the game help any of the memory release, or does that just open another can of worms?

    Excellent question. I'd like to know the answer to this as well...Anyone?
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    So, anyone know if resetting the scene, or even changing scenes have any effect on the memory release, or does it only happen once you quit the game?
Sign In or Register to comment.