SceneGraph-time based scheduling for TGB
by Michael Woerister · 04/11/2006 (2:02 pm) · 4 comments
Download Code File
UPDATED TO v0.3 - with a minor bug fix.
This is an extension to T2D. It allows scheduling Events that are fired depending on a t2dSceneGraph's time, not on the Sim's time.
Just add the files SceneTimeScheduler.h and SceneTimeScheduler.cc to your project and recompile.
Use the ConsoleMethod t2dSceneGraph::initScheduler() before using any of the other commands.
Available methods:
- t2dSceneGraph::initScheduler()
- t2dSceneGraph::sceneSchedule()
- t2dSceneGraph::sceneEventPending()
- t2dSceneGraph::sceneForceEvent()
- t2dSceneGraph::sceneKillEvent()
- t2dSceneObject::sceneSchedule()
The names should speak for themselves. There also is a base class called "SceneTimeEvent". You can derive your own scene-time based events from it in C++.
Note that sceneSchedule() does not take milliseconds for the time-offset but seconds (for consistency with scene time that also is given in seconds). So you have to specify an offset of 0.5 where you formerly had 500.
Example of using this in script:
The %someObject.sceneSchedule("doThis"); method only works with t2dSceneObjects and derivates. If you want to schedule an event on other objects (like scriptObjects) you have to do it like this:
The first argument has to be the object itself again.
Tell me if you find any bugs.
-Michael
UPDATED TO v0.3 - with a minor bug fix.
This is an extension to T2D. It allows scheduling Events that are fired depending on a t2dSceneGraph's time, not on the Sim's time.
Just add the files SceneTimeScheduler.h and SceneTimeScheduler.cc to your project and recompile.
Use the ConsoleMethod t2dSceneGraph::initScheduler() before using any of the other commands.
Available methods:
- t2dSceneGraph::initScheduler()
- t2dSceneGraph::sceneSchedule()
- t2dSceneGraph::sceneEventPending()
- t2dSceneGraph::sceneForceEvent()
- t2dSceneGraph::sceneKillEvent()
- t2dSceneObject::sceneSchedule()
The names should speak for themselves. There also is a base class called "SceneTimeEvent". You can derive your own scene-time based events from it in C++.
Note that sceneSchedule() does not take milliseconds for the time-offset but seconds (for consistency with scene time that also is given in seconds). So you have to specify an offset of 0.5 where you formerly had 500.
Example of using this in script:
for(%i=0; %i < 100; %i++)
$eventId[%i] = someSceneGraph.sceneSchedule(%i, 0, "echo", %i SPC "seconds over your precious time are wasted watching this...");
someSceneGraph.sceneSchedule(60, 0, "echo", "One minute is enough.");
for(%i=60; %i <100; %i++)
someSceneGraph.sceneKillEvent($eventId[%i]);The %someObject.sceneSchedule("doThis"); method only works with t2dSceneObjects and derivates. If you want to schedule an event on other objects (like scriptObjects) you have to do it like this:
someSceneGraph.sceneSchedule(1.5, $yourScriptObject, "doThis", $yourScriptObject, "arg1", "arg2", "arg3");
The first argument has to be the object itself again.
Tell me if you find any bugs.
-Michael
About the author
#2
04/11/2006 (6:35 pm)
Dude! You rock!
#3
07/19/2006 (8:17 pm)
Suh-wheet. I had forgotten that you implemented this, but I'll be using it for sure. Pausing a game will be much easier with this modification. Nice work!
#4
07/09/2007 (2:08 pm)
Nice resource. To make it work in TGB (1.1.3 at least) you might want to apply this change to the .cpp:if( dStrcmp(field,"") != 0 )
{
SceneTimeScheduler* scheduler = dynamic_cast<SceneTimeScheduler*>( Sim::findObject( field ) );
if( scheduler )
{
- Con::warnf("t2dSceneGraph::initScheduler() - Warning! There already is a SceneTimeScheduler for this scenegraph!");
- return;
+ if( scheduler->getSceneGraph() == object )
+ {
+ Con::warnf("t2dSceneGraph::initScheduler() - Warning! There already is a SceneTimeScheduler for this scenegraph!");
+ return;
+ }
}
else 
Torque Owner Josh Moore