Schedule modes
by John Pritchett · in Torque Game Builder · 05/09/2005 (10:32 am) · 3 replies
Let me know if there's already something like this in the engine, but I didn't see anything in the docs.
Schedule appears to function as a one-shot timer event, but more often, I use it as a periodic event. Yeah, it's easy to just reschedule during each event, but I wonder if it would be slightly more efficient if the engine recognized schedule events as being either one-shot or periodic. One-shot events would work as always, but periodic ones would be automatically rescheduled by the scheduler on the defined period, and then I'd only need to call the scheduler to remove my event from the queue once rather than re-add it on every call.
Thanks!
Schedule appears to function as a one-shot timer event, but more often, I use it as a periodic event. Yeah, it's easy to just reschedule during each event, but I wonder if it would be slightly more efficient if the engine recognized schedule events as being either one-shot or periodic. One-shot events would work as always, but periodic ones would be automatically rescheduled by the scheduler on the defined period, and then I'd only need to call the scheduler to remove my event from the queue once rather than re-add it on every call.
Thanks!
About the author
Indie developer since 1994, games include TradeWars 2002 (named 10th best PC game of all time by PCWorld magazine), TW: Dark Millennium/Exarch/Dungeon Runners, and Rocketbowl 360. Have worked for Martech Software, 21-6, EIS and Black Squirrel Studios.
#2
actually gives you a lot of control...
if you told it to automatically reschedule itself then you'd have to pass a sentry value with the schedule function for it to do internal checks, unless you just want something to schedule infinitely :)
EDIT: I can see scheduling something for a period of time, though one thing to keep in consideration is the exact time isn't always "exact"... so for me I often find its much better to work off of sentry values vs a specified time.
05/09/2005 (11:08 am)
Doing it the basic wayfunction fxSceneObject2D::checkDest()
{
if(%this.getPosition() $= %this.dest)
{
} else
{
%this.schedule(100, checkDest);
}
}actually gives you a lot of control...
if you told it to automatically reschedule itself then you'd have to pass a sentry value with the schedule function for it to do internal checks, unless you just want something to schedule infinitely :)
EDIT: I can see scheduling something for a period of time, though one thing to keep in consideration is the exact time isn't always "exact"... so for me I often find its much better to work off of sentry values vs a specified time.
#3
@Matthew: You're right, it's not that difficult to do it this way and when you use timeouts more than timer ticks, it would be the preferred approach. I just like my periodic timers ;)
05/09/2005 (12:21 pm)
@Stephen: Thanks. I probably should have checked the code before proposing it. Certainly no need to redesign the scheduler for so small a gain. I personally have used a priority heap for schedulers I've designed, so rescheduling an event object is just a matter of incrementing the trigger time by the period and stuffing it back onto the heap. But now that I've checked the code, I see the event queue is linear, so the overhead I save on creating and destroying objects would be overshadowed by the process of placing the object onto the queue in most cases.@Matthew: You're right, it's not that difficult to do it this way and when you use timeouts more than timer ticks, it would be the preferred approach. I just like my periodic timers ;)
Torque 3D Owner Stephen Zepp
Without a re-write of how the system works, the "re-scheduling" would have to happen in any case, so refactoring it down lower would only save a few method calls at most--the rest of the work would still need to be done.