Efficient Spawning
pHghost
London, UKMember Posts: 2,342
I have a spawner (combined with a timer) spewing out tons of instances of an actor, one every 0.15 seconds. The instances are spawned offscreen and then shoot across the scene quite rapidly. I was wondering whether it would be more resource efficient to reduce the frequency of spawning, but spawn several at once, and space them out so that they still speed by in 0.15s intervals.
So, instead of:
every 0.15s
[
spawn actor, position (x) 0, relative to actor
]
it would be:
every 0.6s
[
spawn actor, position (x) 0, relative to actor
spawn actor, position (x) -100, relative to actor
spawn actor, position (x) -200, relative to actor
spawn actor, position (x) -300, relative to actor
]
Does it make any sense? Would it reduce the computing load? Or not much and isn't worth it?
Thanks!
So, instead of:
every 0.15s
[
spawn actor, position (x) 0, relative to actor
]
it would be:
every 0.6s
[
spawn actor, position (x) 0, relative to actor
spawn actor, position (x) -100, relative to actor
spawn actor, position (x) -200, relative to actor
spawn actor, position (x) -300, relative to actor
]
Does it make any sense? Would it reduce the computing load? Or not much and isn't worth it?
Thanks!
Comments
Darren.
That might be your path too. I just wanted to test gameplay and then think after that - performance!
You can get performance gains using the game clock and recycling. There's heaps on these forums about that stuff too
Cheers, M@
I've run long tests, projects that have run for hours spawning and destroying hundreds of thousands of actors, with absolutely no impact on performance, frame rate or memory usage.
I think this used to be an issue for GameSalad, destroyed actors would not free up their memory, but this was dealt with years ago and now the 'recycle' myth, having entered GameSalad culture, persists. Of course I could be wrong (perhaps the issue has been reintroduced in a recent update ?), so if anyone has a project that shows recycling to be advantageous (or spawn/destroy to be problematic) I'd love to take a look at it.
"this is a myth !" How dare you thay that… I am a mithter.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Ha! :-$
(I do like a good drop of port as it happens, and it's true I'll be having plenty of port over Christmas as we're spending Christmas and into the New Year in Portugal with my nephew and his Portuguese wife… the Portuguese like a drop of port, you know…)
@pHghost Sorry for diverting your thread… :ar!
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
@sadida172
And which approach to spawning did you use, really small timer interval, or all at once and just changing the coordinates?
To be clear, I don't have an issue with performance yet, but it is possible I will need several such spawners in each scene, so the amount of spawned actors might go MUCH higher than 40. So I wanted to know if there could be a difference, before I finish setting it all up, just so that I don't have to go back later to change it all.
@DeepBlueApps
They do need to interact, though thanks for the tip, might come in handy for other elements.
Thanks everyone!
Also spawning multiple at once isn't much of an issue up to a certain point. (upwards of 25 at once is fine, 500 is not depending on the life of the actor).
My spacey game game was skipping frames as it's really quite full on with a lot of actors buzzing around firing off missiles mines and homing missiles and a ship that clones and fires bullets out at a rapid rate.
The project ran smooth as with a few actors, and lots of instances and spawning them and destroying them so there was heaps going on and it was just GS boxes - not artwork - my proof of concept was complete and running smooth as butter.
So then I started creating all the artwork and and putting in space effects and animations - a lot of unique sounds and wave formation delivery systems and buzzing patterns with cos sin equations.
Suddenly my game started to stutter - not everything - just the odd actor - and this is in the viewer and on my iPhone 5.
I had just done this with timers and spawns and destroys.
So I replaced the timers with clock based rules. This gave an improvement straight away but I was still not happy with some things still skipping frames.
I also recycled the aliens instead of spawning and destroying. Now perfect apart from one pesky creature.
Finally I refined the equations to remove one constrain attribute.
As a performance test what I like to do is run my games on my iPhone 3GS and 4 etc.
The original timers and spawners game concept with hardly any artwork, and aliens as GameSalad boxes, runs way worse than my latest full game with all the artwork, sounds and animations.
Simple prototype runs worse than full game? Wow.
I really would be interested to see what the key items of performance enhancement are.
Somebody could create a serious benchmarking tool
The game is still spawning lots of things - don't get me wrong - it's spawning like salmon.
But the thing that made the game run smooth was clock timers, recycling and equation refinements.
What are your thoughts on this?
Cheers, M@
Spawning actors means the images for the actors are being loaded in real time. So 50 unique imaged actors with 2048 textures are likely to cause a hiccup in fps.
Pre-loading (on scene from start) and recycling actors means the images are loaded in memory before the scene executes. So this adds to the load time, however once loaded it will be smoother while playing because of not needing to load those images during run time.
However in most cases recycling was done on actors that are similar or the same in nature and don't have unique images or rulesets and are generally small (bullets), and would cause very little in terms of real time performance, hence why spawning is generally a better system for the sake of easiness and load times.
But as you can see this isn't always the case and recycling has it's place too.
A good metric for "benchmarking" would be Xcode tools running core animations and memory usage. You can see the benefits of both systems as outlined above and create some test projects to see.
Also is your not destroying the actors fast enough, you will be getting a larger number of actors on the scene then if recycled and more actors=lower performance, so make sure the spawn and destroy are efficient.
Thanks for all this - will look in to the Xcode side.... cheers, M@