Game Development Community

OnUpdate vs. recursive schedule

by PeterB · in Torque Game Builder · 08/21/2007 (3:28 pm) · 6 replies

I assume using onUpdate is better practice than say:

function myMainLoop()
{
    // do stuff
    schedule(33, 0, myMainLoop);

But what if you really only need the function every 50 or 100 milliseconds? 200? Do you get less of a processing hit with a recursive schedule at 50 milliseconds than onUpdate for example?
Or maybe I'm wrong and a recursive schedule is just as good as onUpdate.

#1
08/21/2007 (3:37 pm)
Well I'm not sure which one takes less of a hit, but Scheduled calls are not garenteed to be completely accurate. I'm sure what its doing internally is updating all the schedules each tick, so the closest precision you can get is 33 or so ms. Adding behaviors and onUpdate is still relatively new so lots of games have been made using recursive schedules you can be sure. Ok I don't really know the answer to your question, but I'm betting the only difference is in one case the logic for "is it my time to execute" is done within the schedule and in the other it is done inside your onUpdate function, the schedule code is in c++ so it could actually be faster and might look cleaner in your script.
#2
08/22/2007 (1:46 pm)
I always use recursive schedule for things that only need calls every 50 (or+) milliseconds. It just seems like the less you do EVERY frame (onUpdate) the better.
Don't have hard evidence to back this up, but that's my feeling on it.
#3
08/22/2007 (2:28 pm)
I agree with Spider, less is more.

onUpdate is called every 32ms, so if you dont need your function called that frequently, use something adjustable.
#4
08/26/2007 (1:10 am)
Hmmm, i do like this discussion though on which spares more system memory though...

im pretty much up in the air on which saves more but i will give my own specific example, maybe someone can shine light down on me

ok lets say i have a bullet pattern(think modern-day shmup). and i have a projectile moving in the shape of a helix (sin wave) the only way to make the movement look smooth is to either use onUpdate(32ms) or schedule(32ms).... there both technically the same thing but is one better than the other for saving system memory?
#5
08/27/2007 (10:13 am)
Rendering actually happens faster than every tick I believe, so for it to move smoothly you would have to to this in a different way than just setposition every tick. Eg. paths.
#6
09/01/2007 (9:33 am)
There is also the setTimer() and onTimer() functions which can be used in place of recurring schedules.