Question about internal timestepping

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Telanor
Posts: 57
Joined: Sun May 06, 2012 10:49 pm

Question about internal timestepping

Post 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?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Question about internal timestepping

Post 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.
Telanor
Posts: 57
Joined: Sun May 06, 2012 10:49 pm

Re: Question about internal timestepping

Post by Telanor »

Alright, thanks for the answer
Post Reply