Timers and FPS - Can timers be useful?
KiwiLee
Member Posts: 181
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.
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
-
RThurman Posts: 2,881Yes, 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
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'.
@RThurman
Best Regards.
Lee.