TIP: Visibility OFF (Optimization)

JGary321JGary321 Member Posts: 1,246
edited November -1 in Working with GS (Mac)
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.
«1

Comments

  • JCFordJCFord Member Posts: 785
    nice find well done.
  • BeyondtheTechBeyondtheTech Member Posts: 809
    Very good to know. Every little bit helps, especially on the older devices. Thank you.
  • ZillaZilla Member Posts: 157
    `turning off VISIBILITY. You CAN edit it by change attribute.`

    Can you? I thought that it's not possible to change this boolean flag in-game?
  • JGary321JGary321 Member Posts: 1,246
    You are right my friend. I didn't complete the check all the way. It DOES let you 'turn it off' it just doesn't do anything I'm afraid. Bummer. This would have helped big time.
  • design219design219 Member Posts: 2,273
    Good research, thanks.

    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.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    alright I'm confused. Jgary seems to be saying that turning off visibility helps performace, others seem to say it doesn't really get turned off. Huh?
  • JGary321JGary321 Member Posts: 1,246
    1. It DOES help. With 12 actors (albeit they have probably 25+ rules on them) it cut my FPS by 4-5.

    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.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    SO I can't use magnitude to have things become visible just before they come on screen?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @sciTunes, No, you'll need to use the Actor's alpha for that - if you want to CHANGE the visibility of an Actor.

    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.
  • JGary321JGary321 Member Posts: 1,246
    I also tested turning alpha to 0 & making the actor size to 1 x 1 from (25 x 23).

    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.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    What if, if an object goes off screen you change image to a 1x1 pixel image then change back when on screen, could it work in theory and would it increase fps. You can change images for actors in game. Just an idea.
  • JGary321JGary321 Member Posts: 1,246
    Nice idea, I'll try it. I'll report back my findings soon.
  • JGary321JGary321 Member Posts: 1,246
    Gained a minor FPS upgrade of 1.5 - 2 FPS. Anyone with any other ideas?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I sure you know this, but make sure none of your ALL Rules have more than one condition.
    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!"
  • JGary321JGary321 Member Posts: 1,246
    Firemaple I've never heard of that? Why would it be more efficient? I would this that it would be more efficient to use them with more than one condition. Care to explain more? I know you have a history in dev, so I would love to hear your thought.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Really? Ok, well, every condition that is exposed needs to be checked by the game - a million zillion times a second

    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
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    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!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @scitunes: aw shucks! Well, I hope it helps! I don't know the inner workings of GS, but I believe what I stated above to be true.

    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.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Do you mean testing magnitude or vector versus just having a screen sized invisible actor constrained to the camera-controlling actor?

    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.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Yes, that is key. Especially on the iPhone. Do things, check things, ONLY when necessary...
  • micahmicah Member Posts: 85
    Similarly to what firemaplegames is saying, it's also more efficient to to use Otherwise in rules. Take this example: http://img51.imageshack.us/img51/2641/screenshot20100122at504.png

    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...
  • JGary321JGary321 Member Posts: 1,246
    That makes a LOT of sense. And I will actually start doing this from now on in order to squeeze every bit out of the engine. However, I am sad to report that I noticed almost no FPS increase redoing all my actors this way =(

    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 =)
  • firemaplegamesfiremaplegames Member Posts: 3,211
    rats, I was hoping that would help you out.

    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?
  • JGary321JGary321 Member Posts: 1,246
    Hey FMG,

    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.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    A Timer is always counting I believe. It only fires at the interval you tell it, but it is always running.

    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
  • JGary321JGary321 Member Posts: 1,246
    I don't keep track on the Creeps X/Y. No need. Instead of HP bars I have their alpha contrain to HP, so the more invisible they get the less HP they have... Neat 'trick'. The spells shoot only 1 path. They don't track, so again no need to constrain X/Y's of Creeps.

    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.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I'm not sure about the Timer...
    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...
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Ha! hopefully 0.8 will fix your performance issues!
  • JGary321JGary321 Member Posts: 1,246
    FMG: I am sitting above 30 FPS with everything going! No changes made, Yea, it was a Dramatic improvement for me. I *might* still optimize a little more, but maybe I'll just do that in an update. We'll see =)

    But for now everything is good.
Sign In or Register to comment.