GetRealTime() vs. getSimTime() - drift
by Orion Elenzil · in Torque Game Engine · 11/13/2008 (4:37 pm) · 2 replies
We just noticed some surprising results comparing getSimTime() getRealTime().
check out this example code entered into the console.
(
here's the source for mSubS32,
but you get similar results w/ the stock tge 1.4 demo and just dividing all the times by 1000.
check out this example code entered into the console.
(
function calibrate() { $dTime = mSubS32(getRealTime(), getSimTime()); }
function printDrift() { %predictedTime = mSubS32(getRealTime(), $dTime); %drift = mSubS32(%predictedTime, getSimTime()); echo("drift =" SPC %drift); }
[11/13/2008 16:19:30][Inf][General] ==>calibrate();
[11/13/2008 16:19:40][Inf][General] ==>printDrift();
[11/13/2008 16:19:40][Inf][General] drift = 1124here's the source for mSubS32,
but you get similar results w/ the stock tge 1.4 demo and just dividing all the times by 1000.
// based on code by Peter Simard
ConsoleFunction( mSubS32, const char*, 3, 3, "Subtract 2 large numbers" )
{
S32 v1 = dAtoi(argv[1]);
S32 v2 = dAtoi(argv[2]);
S32 res = v1 - v2;
char* ret = Con::getReturnBuffer(64);
dSprintf(ret, 64, "%i", res);
return ret;
}About the author
#2
although honestly i'm not quite sure how to explain the drift within the drift,
why it starts out extreme and then gravitates back towards unity.
.. that would make sense if my test code introduced a constant offset when it zero'd itself out, but it don't.
here's some numbers, measuring every thirty seconds for three minutes:
and here's the code which generated them
11/13/2008 (6:41 pm)
The variance seems to be drifting between about 0.85 and 0.97, so it's probably fine.although honestly i'm not quite sure how to explain the drift within the drift,
why it starts out extreme and then gravitates back towards unity.
.. that would make sense if my test code introduced a constant offset when it zero'd itself out, but it don't.
here's some numbers, measuring every thirty seconds for three minutes:
[11/13/2008 18:29:15][Inf][General] ==>timeTest_tare(); [11/13/2008 18:29:18][Inf][General] ==>timeTest_measure(); [11/13/2008 18:29:18][Inf][General] driftSim is 0.329 [11/13/2008 18:29:18][Inf][General] elapsed real seconds = 2.516 [11/13/2008 18:29:18][Inf][General] elapsed sim seconds = 2.187 [11/13/2008 18:29:18][Inf][General] driftSim /elapsedReal = 0.130763 [11/13/2008 18:29:18][Inf][General] elapsedSim/elapsedReal = 0.869237 [11/13/2008 18:29:45][Inf][General] ==>timeTest_measure(); [11/13/2008 18:29:45][Inf][General] driftSim is 1.163 [11/13/2008 18:29:45][Inf][General] elapsed real seconds = 29.657 [11/13/2008 18:29:45][Inf][General] elapsed sim seconds = 28.494 [11/13/2008 18:29:45][Inf][General] driftSim /elapsedReal = 0.039215 [11/13/2008 18:29:45][Inf][General] elapsedSim/elapsedReal = 0.960785 [11/13/2008 18:30:15][Inf][General] ==>timeTest_measure(); [11/13/2008 18:30:15][Inf][General] driftSim is 1.833 [11/13/2008 18:30:15][Inf][General] elapsed real seconds = 60.203 [11/13/2008 18:30:15][Inf][General] elapsed sim seconds = 58.37 [11/13/2008 18:30:15][Inf][General] driftSim /elapsedReal = 0.030447 [11/13/2008 18:30:15][Inf][General] elapsedSim/elapsedReal = 0.969553 [11/13/2008 18:30:45][Inf][General] ==>timeTest_measure(); [11/13/2008 18:30:45][Inf][General] driftSim is 2.47 [11/13/2008 18:30:45][Inf][General] elapsed real seconds = 90.188 [11/13/2008 18:30:45][Inf][General] elapsed sim seconds = 87.718 [11/13/2008 18:30:45][Inf][General] driftSim /elapsedReal = 0.0273872 [11/13/2008 18:30:45][Inf][General] elapsedSim/elapsedReal = 0.972613 [11/13/2008 18:31:15][Inf][General] ==>timeTest_measure(); [11/13/2008 18:31:15][Inf][General] driftSim is 3.075 [11/13/2008 18:31:15][Inf][General] elapsed real seconds = 119.813 [11/13/2008 18:31:15][Inf][General] elapsed sim seconds = 116.738 [11/13/2008 18:31:15][Inf][General] driftSim /elapsedReal = 0.025665 [11/13/2008 18:31:15][Inf][General] elapsedSim/elapsedReal = 0.974335 [11/13/2008 18:31:45][Inf][General] ==>timeTest_measure(); [11/13/2008 18:31:45][Inf][General] driftSim is 4.976 [11/13/2008 18:31:45][Inf][General] elapsed real seconds = 150.172 [11/13/2008 18:31:45][Inf][General] elapsed sim seconds = 145.196 [11/13/2008 18:31:45][Inf][General] driftSim /elapsedReal = 0.0331353 [11/13/2008 18:31:45][Inf][General] elapsedSim/elapsedReal = 0.966865 [11/13/2008 18:32:15][Inf][General] ==>timeTest_measure(); [11/13/2008 18:32:15][Inf][General] driftSim is 5.947 [11/13/2008 18:32:15][Inf][General] elapsed real seconds = 179.75 [11/13/2008 18:32:15][Inf][General] elapsed sim seconds = 173.803 [11/13/2008 18:32:15][Inf][General] driftSim /elapsedReal = 0.0330848 [11/13/2008 18:32:15][Inf][General] elapsedSim/elapsedReal = 0.966915
and here's the code which generated them
function timeTest_tare()
{
$gTimeTest_StartTimeReal = getRealTime();
$gTimeTest_StartTimeSim = getSimTime ();
$gTimeTest_dRealToSim = mSubS32($gTimeTest_StartTimeSim, $gTimeTest_StartTimeReal);
}
function timeTest_measure()
{
%timeReal = getRealTime();
%timeSim = getSimTime ();
%elapsedReal = mSubS32(%timeReal, $gTimeTest_StartTimeReal);
%elapsedSim = mSubS32(%timeSim , $gTimeTest_StartTimeSim );
%expectedTimeSim = mAddS32(%timeReal, $gTimeTest_dRealToSim);
%driftSim = mSubS32(%expectedTimeSim, %timeSim );
echo("driftSim is" SPC %driftSim * 0.001 );
echo("elapsed real seconds =" SPC %elapsedReal * 0.001 );
echo("elapsed sim seconds =" SPC %elapsedSim * 0.001 );
echo("driftSim /elapsedReal =" SPC %driftSim / %elapsedReal);
echo("elapsedSim/elapsedReal =" SPC %elapsedSim / %elapsedReal);
}
Associate Kyle Carter