This is my main physics loop. I can't think of any other place that should affect the speed of the simulation.
Code: Select all
... extracted from setup ...
m_PhysicsSpace.simulationSettings.timeStep.timeStepDuration = 1 / Constants.PHYSICS_FRAMES_PER_SECOND;
m_PhysicsSpace.simulationSettings.timeStep.timeScale = 1;
m_PhysicsSpace.simulationSettings.timeStep.useInternalTimeStepping = true;
Code: Select all
void physicsLoop( )
{
Stopwatch totalTime = new Stopwatch();
Stopwatch physicsThinkTime = new Stopwatch();
totalTime.Start();
// Use lastFrameTime instead of turning on/off a stopwatch so that we
// don't lose any milliseconds or portions thereof.
float lastFrameTime = 0;
Debug.Assert(Stopwatch.IsHighResolution);
while ( true )
{
#region Shutdown
if (ShutdownRequested)
break;
#endregion
#region Pausing
if (m_PhysicsPaused)
{
Thread.Sleep(500);
lastFrameTime = totalTime.ElapsedMilliseconds;
continue;
}
#endregion
physicsThinkTime.Reset();
physicsThinkTime.Start();
{
updatePhysicsObjectList();
beforePhysics();
float newtime = totalTime.ElapsedMilliseconds;
m_PhysicsSpace.update( newtime - lastFrameTime );
lastFrameTime = newtime;
}
physicsThinkTime.Stop();
reportPhysicsStatistics(physicsThinkTime.ElapsedMilliseconds);
}
}