Page 1 of 1
Question about internal timestepping
Posted: Sun Dec 16, 2012 1:48 am
by Telanor
What happens when the physics engine is not able to keep up and it hits the maximum timesteps per frame? Does it somehow skip over those timesteps and try to catch up, or does it simply leave them for the next frame in the hope that it will be able to eventually catch up?
If it skips them, how does it do that and is there any event that will notify me of such? Or if it doesn't skip, wouldn't that just put the simulation increasingly further behind in a situation where the computer isn't fast enough to run a single timestep in the specified time?
Re: Question about internal timestepping
Posted: Sun Dec 16, 2012 2:39 am
by Norbo
The logic for internal time stepping is pretty simple; here's the relevant code from the Space.Update(float dt) method:
Code: Select all
TimeStepSettings.AccumulatedTime += dt;
for (int i = 0; i < TimeStepSettings.MaximumTimeStepsPerFrame; i++)
{
if (TimeStepSettings.AccumulatedTime >= TimeStepSettings.TimeStepDuration)
{
TimeStepSettings.AccumulatedTime -= TimeStepSettings.TimeStepDuration;
DoTimeStep();
}
else
{
break;
}
}
So:
Does it somehow skip over those timesteps and try to catch up, or does it simply leave them for the next frame in the hope that it will be able to eventually catch up?
Accumulated time is never 'deleted,' just deferred, so it will keep piling up.
Or if it doesn't skip, wouldn't that just put the simulation increasingly further behind in a situation where the computer isn't fast enough to run a single timestep in the specified time?
Correct.
The purpose of internal time stepping is to update the simulation every TimeStepSettings.TimeStepDuration in real time. It will do extra work when the simulation falls behind (up to the maximum), but it expects any such deficit to be temporary so that the number of frames where it has do extra timesteps is finite. In other words, it requires that the simulation can actually be run in real time.
Re: Question about internal timestepping
Posted: Sun Dec 16, 2012 9:12 am
by Telanor
Alright, thanks for the answer