Page 1 of 1

useInternalTimeStepping bug?

Posted: Thu Aug 05, 2010 11:19 am
by multox
Is it possible that useInternalTimeStepping is bugged? I've gone up and down my code and can't figure out what I might be doing to break it. It seems that timeStepDuration is inversely proportional to the effective timeScale. Setting timeStepDuration to 1 results in a super-speed simulation, and setting it low makes the simulation go very slowly. Shouldn't the actual speed of the objects remain the same regardless of the timeStepDuration?

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);
                }
            }

Re: useInternalTimeStepping bug?

Posted: Thu Aug 05, 2010 7:33 pm
by Norbo
Setting timeStepDuration to 1 results in a super-speed simulation, and setting it low makes the simulation go very slowly. Shouldn't the actual speed of the objects remain the same regardless of the timeStepDuration?
Within the limits of the computation, yes.

Right now it looks like the code is updating using milliseconds as opposed to seconds, which would make it run 1000x too fast. It probably just can't keep up with that speed when the timeStepDuration is lowered, resulting in slower execution.

Re: useInternalTimeStepping bug?

Posted: Thu Aug 05, 2010 8:28 pm
by multox
You're right! I was stuck on thinking in terms of milliseconds. Now the InternalTimeStepping works awesomely.

Thanks!