Timers and FPS - Can timers be useful?

KiwiLeeKiwiLee Member Posts: 181
edited September 2012 in Working with GS (Mac)
I know there has been lots of debate about timers and self.time and that is not the purpose of the thread.

My latest (first :-) ) game had hit a few walls with FPS and I have a few ideas so I'll explain my scenario and hopefully you ace pro's will confirm my theory.

I have code that positions and sizes an actor at the scene load. If have a flag called self.first time? and if true executes the code, the actors can appear in a different area of the screen depending on the gameplay option. I naturally then set this to self.first time? = false

Am I right in saying that GS executes the rule check of self.first time? every pass i.e. 60 times per second if I have a good frame rate.

I'm not fussed about 0.01 :-) seconds to initialise and the start so a small delay of say or 0.2 is perfectly acceptable........

SO............

If I wrap the case statement in a TIMER (or SELF.TIME loop - not sure if this would be any better as it's a check) of say every 0.2 seconds does that reduce my burden on the engine i.e. freeing up valuable cycles on the frame rate? i.e. is timer seperate thread more efficient than a rule check every cycle.

Or perhaps there are other ways that people handle actor initialisation code OR this is just a necessary hit.

Best Regards.
Lee.

Best Answer

  • RThurmanRThurman Posts: 2,881
    edited September 2012 Accepted Answer
    Yes, everything has its price. The currency here is fps!

    In general I stick with these ideas:
    If it executes once, use 'Change Attribute'
    If it executes constantly, use 'Constrain Attribute'
    If it executes every x seconds (or after x seconds), use 'Timer'
    If it needs to ask, "Now?" use 'Rule'

    In your example:
    You don't need to ask "Now?" because you already know the answer is yes.
    You don't need to execute the initialization every x seconds or even after x seconds. The answer is already "Now!"
    You don't need it to execute constantly since it only does it once, "Now!" and never again.
    Therefore, all that is left is 'Change Attribute'

    There is something else about "if it ain't broke - don't fix it" but I often forget that one!

Answers

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    If I understand your question right, the answer is yes. If you slow down the number of times a rule is checked, it will save fps.

    However, I wouldn't suggest using a rule when initializing actors (or their attributes) at the start of a scene. Instead, set things up with some 'Change Attribute' behaviors at the beginning of the scene and be done with it. If they are outside of any timers or rules, 'Change Attribute' behaviors only fire once, and then there is no more worry about checking if its 'the first time'.
  • KiwiLeeKiwiLee Member Posts: 181
    My business programming background coming back to haunt me again :-).

  • KiwiLeeKiwiLee Member Posts: 181
    edited September 2012
    Okay. So that means I was actually adding to my FPS by putting the initialization code into a rule in the first instance.........

    @RThurman
  • KiwiLeeKiwiLee Member Posts: 181
    edited September 2012
    @RThurman Thanks again. Whilst it ain't broke I want to get my frame rate up as it was dropping to 35 in places. I guess every little helps in these circumstances especially as I was talking about 20 actors needlessly checking for self.first time? every frame cycle.

    Best Regards.
    Lee.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    You are welcome. Hope it sparked an idea or two!
Sign In or Register to comment.