From 11a4b9ec1d4f93cfd0600d090efbf257c9ea9a1b Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 14 Aug 2012 16:20:07 -0700 Subject: [PATCH] BulletSim: rework physics FPS calculation to make a more realistic number. --- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index beaea1f32c..f63ad95b6d 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -413,7 +413,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters // prevent simulation until we've been initialized if (!m_initialized) return 10.0f; - long simulateStartTime = Util.EnvironmentTickCount(); + int simulateStartTime = Util.EnvironmentTickCount(); // update the prim states while we know the physics engine is not busy ProcessTaints(); @@ -511,8 +511,13 @@ public class BSScene : PhysicsScene, IPhysicsParameters // long simulateTotalTime = Util.EnvironmentTickCountSubtract(simulateStartTime); // return (timeStep * (float)simulateTotalTime); - // TODO: FIX THIS: fps calculation wrong. This calculation always returns about 1 in normal operation. - return timeStep / (numSubSteps * m_fixedTimeStep) * 1000f; + // TODO: FIX THIS: fps calculation possibly wrong. + // This calculation says 1/timeStep is the ideal frame rate. Any time added to + // that by the physics simulation gives a slower frame rate. + long totalSimulationTime = Util.EnvironmentTickCountSubtract(simulateStartTime); + if (totalSimulationTime >= timeStep) + return 0; + return 1f / (timeStep + totalSimulationTime); } // Something has collided