Game Development Community

Problem regarding schedule's and scene time

by Oliver Rendelmann - DerR · in Torque Game Builder · 12/15/2005 (12:06 pm) · 3 replies

Heya folks,

I think I found a bug regarding scene timing in the EA release of T2D. I tried to schedule an entity spawn at 20,000ms after program creation, i.e. I am calling schedule in setupT2DScene(). Using the debug banner I found out that the entity already spawns after 19 seconds. I also measured the time delta between calling of schedule and function call manually using ::getSceneTime() and it gave me ~18.970, so the whole thing seems to be off by about 1s.

I have to add that I don't own TGE so I couldn't find out if that problem is only T2D related or if it's "derived" by TGE.

Yours sincerely,
Oliver Rendelmann

#1
12/15/2005 (1:54 pm)
Schedule calls use sim time, not scene time. This is unfortunate because it causes all kinds of trouble and makes using schedules much less reliable and useful. Maybe Melv will find it in his heart to change this some day. :)
#2
12/15/2005 (10:38 pm)
Oh, that's too bad. But in how far differ sim time and scene time? I experienced a "lag" of one second but is that the same on every machine? If yes it should be pretty easy to compensate...
#3
12/16/2005 (3:30 am)
Well scene time depends on framerate whereas sim time uses the CPU clock, so it can vary. Also if you created the schedule call while things are still loading, that might affect the accuracy. The best solution is to create your own time manager that is scheduled to update every 20 milliseconds or so and calculates a time delta to hand off to anyone that needs it. Code off the top of my head:
function timeMan::onAdd( %this )
{
    %this.now = 0;
    %this.delta = 0;
    %this.lastUpdate = 0;
}

function timeMan::onUpdate( %this )
{
    %this.now = GetSimTime();
    %this.delta = %this.now - %this.lastUpdate;
    %this.lastUpdate = %this.now;
    %this.nextUpdate = %this.schedule( 20, onUpdate );
}

function timeMan::getDelta( %this )
{
    return %this.delta;
}

// ...etc...

$timeMan = new ScriptObject( timeMan );
$timeMan.schedule( 20, onUpdate ); // get started updating
Or something like that. Alternately (and better), you could use scene time instead (%scenegraph.getSceneTime()), but you'd need an instance of a time manager for each scene.