useInternalTimeStepping bug?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
multox
Posts: 8
Joined: Tue Jul 13, 2010 12:30 am

useInternalTimeStepping bug?

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

Re: useInternalTimeStepping bug?

Post 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.
multox
Posts: 8
Joined: Tue Jul 13, 2010 12:30 am

Re: useInternalTimeStepping bug?

Post by multox »

You're right! I was stuck on thinking in terms of milliseconds. Now the InternalTimeStepping works awesomely.

Thanks!
Post Reply