TIP: Visibility OFF (Optimization)
JGary321
Member Posts: 1,246
Thanks Toby for getting my curiosity flowing..
(http://gamesalad.com/forums/topic.php?id=2937)
He mentioned that he has visibility OFF for anything not in the playing field. I do this with objects off screen that won't come on screen, but I did some testing....
Blank screen = 60FPS
12 HEAVILY Ruled actors NOT moving, but MOVEABLE OFF= 37 FPS
12 HEAVILY Ruled actors NOT moving, but MOVEABLE ON = 38.5 FPS
12 HEAVILY Ruled actors MOVING = 34 FPS
12 HEAVILY Ruled actors MOVING/VISIBILITY OFF = 38 FPS
12 HEAVILY Ruled actors NOT MOVING/VISIBILITY OFF = 42 FPS
As you can see from these tests I only got a 1.5 FPS increase by turning MOVEABLE off. So don't worry TOO much about this one.
However I got a good 4-5 FPS by turning off VISIBILITY. You CAN edit it by change attribute. So definitely worth it for anything not in your screens view.
Just thought I would release my findings.
Does anyone have any other Optimization Tips? If so please list them here.
(http://gamesalad.com/forums/topic.php?id=2937)
He mentioned that he has visibility OFF for anything not in the playing field. I do this with objects off screen that won't come on screen, but I did some testing....
Blank screen = 60FPS
12 HEAVILY Ruled actors NOT moving, but MOVEABLE OFF= 37 FPS
12 HEAVILY Ruled actors NOT moving, but MOVEABLE ON = 38.5 FPS
12 HEAVILY Ruled actors MOVING = 34 FPS
12 HEAVILY Ruled actors MOVING/VISIBILITY OFF = 38 FPS
12 HEAVILY Ruled actors NOT MOVING/VISIBILITY OFF = 42 FPS
As you can see from these tests I only got a 1.5 FPS increase by turning MOVEABLE off. So don't worry TOO much about this one.
However I got a good 4-5 FPS by turning off VISIBILITY. You CAN edit it by change attribute. So definitely worth it for anything not in your screens view.
Just thought I would release my findings.
Does anyone have any other Optimization Tips? If so please list them here.
Comments
Can you? I thought that it's not possible to change this boolean flag in-game?
I've been wondering about actors off stage. I have a few that are just "control" actors that do nothing but contain attribute rules. I've made them invisible, but at times if have to find them to edit and if it made no difference, I'd like to keep them visible.
2. You just can't turn it on mid game. SO you couldn't have visibility turned off when they are off screen & then turned on when on screen. It's either on or off.
EDIT: The confusing part was that I seen it was a changeable attribute, however after testing I found out that even though it lets you change it, it doesn't really change it.
The Visible Attribute is not able to be turned on/off at runtime. It should be turned off for any "scene controlling" actors that are placed off-stage. Also for invisible walls and such.
Guess what? Neither had ANY effects. If it did it was less than 1FPS combined. Don't go through the head ache of adjusting these 2 attributes.
i.e don't check for multiple conditions at a time. It's much more efficient to nest them.
Change this:
Rule
ALL
When Bob is a person
When Bob was born on January 28th
Display Text "Today is Bob's birthday!"
To This:
Rule
When Bob is a person
Rule
When Bob was born on January 28th
Display Text "Today is Bob's birthday!"
By nesting them, you can hide conditions from the game that aren't necessary to check.
i.e., in the above example, it makes no sense to check if Bob's birthday is January 28th - if Bob isn't even a person!
By nesting the second condition, the game won't check that condition, saving precious cycles.
It does seems counterintuitive to ADD more Rules to make the game more efficient, and while it does add more weight to the game, you should notice an increase in frame rate.
Nest as much as possible.
If a Rule is checking for ANY condition, you kind of do have to expose them all.
But look through your ALL Rules and see if you can nest.
Also make the outer conditions easier to check than the inside ones, like this:
Rule
When MOUSE is DOWN
Rule
When MOUSE is INSIDE
Rule
When game.myAngle = cos(abs(sin(9*45678-34)/(cos(45643))))
Display Text: "Wow, that is a crazy angle"
In that example, you wouldn't want to check the angle first. And you would only want to check it if it absolutely necessary.
Also, any Behavior that is sitting out in the open, i.e, not wrapped in a Rule, gets checked every time.
You might want to try to nest them as well.
For example, a Collide Rule is pretty processor intensive, and the less things that the game has to check for collisions the better.
You could wrap them in Rules as well, like this:
For example, in an enemy actor that's always on the right side of the screen, you could do this:
Rule
When PlayerX > 240
Collide with actors of type Player
As opposed to this:
Collide with actors of type Player
No sense checking for collisions if the player isn't even close to the enemy.
Hope this helps!
Joe
I think you ought to be doing the Stanford web lectures! I feel like I just left a stanford lecture every time you leave a post!
Thanks!
You mentioned that you used magnitude and vectorToAngle to determine whether to act in your space game... now magnitude and vectorToAngle use trigonometry to work - but i'm pretty sure that Collide does as well - trigonometry is processor intensive so in that case you just have to test the performance, and see which one is better.
Either way it was a real eye-opener for me to realise that I could use rules to make actors do relatively complex stuff ONLY when in view. Seems like a no-brainer now, but as a newb it never even crossed my mind.
Thanks, again.
I ended up doing this a different way in the end, but what I was doing was:
If Self.Level = 1 and game.Beat Level 1 is true
- - spawn a check
Otherwise:
- If Self.Level = 2 and game.Beat Level 2 is true
- - - spawn a check
- Otherwise:
- - If Self.Level = 3 and game.Beat Level 3 is true
- - - - spawn a check
... for 30 levels.
I could have done the exact same thing just without the otherwises. But since this will end up being 30 actors on the scene and trying to figure out how to spawn a check, it's much better to do it this way because each actor doesn't need to process all 30 rules this way.
For example, the level 1 actor will process the first rule, then stop running (never running the Otherwise code, because the condition was true). The level 2 actor will check the first rule, but it will be false, so then it will run the Otherwise code and check the second rule, which will be true, so it will spawn a check and stop running. And then the level 30 actor will check each rule until it gets to the end. But if I didn't do this all in nested Otherwises, each actor would have to check all 30 rules, instead of just the last.
And I suppose that it would have been even more efficient to do:
If Self.Level = 1:
- If game.Beat Level 1 is true
- - spawn a check
Otherwise:
- If Self.Level = 2
- - If game.Beat Level 2 is true
- - - spawn a check
- Otherwise:
- - If Self.Level = 3
- - - If game.Beat Level 3 is true
- - - - spawn a check
- - - Otherwise:
- - - - ...etc...
Which is a real bummer b/c I definitely need a boost in FPS somewhere
Anyone got any other tips?? Can't release this running at 18 FPS
hmmm....
I would check your Timers as well. They can be brutal on the engine.
You're making a tower defense game, right? How many creeps are in each wave?
If you make it be just one creep, does the frame rate shoot up? and start to go down as you keep adding them?
I would start eliminating things from the scene so you can find out who the real memory hog is, and find out where you need to optimize.
also, are you testing on a 3GS or 2nd gen iPod? Or on the older devices?
TD game yeppers.
The creeps are pre-spawned & that part works perfectly. 10 creeps. I keep spreadsheets to help with my work, so here are some statistics:
EDIT: When the scene starts it starts at 40FPS, this is without ANYTHING doing anything. I will try to figure out where I'm losing this 20 FPS.
FPS (3G)
23-24 10 Creeps, No Spells
29-30 05 Creeps, No Spells
37-38 01 Creeps, No Spells
17-20 10 Creeps, With Spells
20-22 05 Creeps, With Spells
25-27 01 Creeps, With Spells
28-28 00 Creeps, With Spells
The way the game works is the spells shoot in 1 way. They do not auto-target. They shoot only the way they are designed to.
Do timers only use memory when running? Or just having them in the scene will use memory? Also if I had 4 timers running. Each one saying anywhere from every 1-2 seconds, how bad would that be? Any idea? I don't have many timers, & there are only 4 'towers' on screen at once.
I am currently spawning the spells, don't really want to have to 'move' them, as that will definitely complicate things, however I may have no choice.
Definitely something to look atj
Are you able to possibly put everything into one timer, some sort of "tower master" Actor that controls all the towers?
Also, if you want to send me your game, I'll test it on my 3GS. You should see a marked improvement in the framerate.
Do you keep track of all of the creeps' X and Y positions? If so, you could also theoretically have a "Creep Controller" Actor that sits offscreen. Instead of each creep having a ton of Rules that deal with the spells, the creep controller could shoot out the spells based on the creeps' X and Y positions.
The creeps themselves would only care about their own movement.
Maybe something to think about?
Joe
The spells come from your 4 minions. They control the spells. The rules I have in the creeps, are:
Movement Rules:
*Initial move speed 1
*On collision movements: Invisible actors on field to tell where to move.
*Animations based on which direction
HP Rules:
*Set HP
*Constrain Alpha to HP
*Destroy rule
Damage Rules:
*Damage from spells (based off actor tags)
*Various effects like 'freeze' or 'stun' (only a few)
My Creep actor is 36kb (looked at the .xml file)
Unfortunately not much of a way to get that down. However, I have been doing A LOT of testing.
Here are a few numbers:
These are the FPS without ANYTHING running
FPS What I removed
39-40 Standard game
41-42 Destroy Enemy/Destroy Spell (invisible)
45-45 Buttons/Minion-Selector (off screen, moves on screen)
42-43 Mob Spawner (invisible)
41-42 Presets (invisible)
41-42 Power-Up Spawner (invisible)
I can easily (maybe not too easily) delete most of these & only have them spawn when necessary or get rid of some all together.
Removing it all at once put me at around 50 FPS. I had the enemies spawn & it seems to only get me maybe 2-3 once everything is running though. Strange huh? You would think it would have given me like 5-10FPS. I didn't make that change permanent yet, it will require quite a bit of redoing. I'll do that right before release. Also we may come up with more ideas.
About the timer, if it's coupled in a rule that says:
If game.Spell Active = true, Every 1 sec Spawn Spell
I would not think that would run if game.Spell Active = false, correct? Since it wouldn't bypass the check first.
I tried have 4 spells spawn at once & that made it worse, so I would have no clue as to how it would run off 1 timer.
PS: Thanks for the help. This should help everyone out as well.
you can easily do a test by using a Display Text Behavior:
Simply add a Display Text behavior behavior inside your Timer that is simply a big red exclamation point, or anything really. It should not display the text. Hopefully you'll only see it blink when the Timer fires...
If the actor is invisible, or offscreen, just move it onscreen and make it visible for the test...
But for now everything is good.