From cfc95afc3dfbed5f611860a6502a1b0d6e2cdd56 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 26 Sep 2014 20:56:22 +0100 Subject: [PATCH] If Bullet is running on its own thread, use a reset event to control timing rather than a sleep. In theory, there should be no difference between these mechanisms. However, on at least Mono 3.2.8 waiting via an event appears to be much more accurate. --- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 7d577510c3..46a13ab5c0 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -130,6 +130,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters internal int m_maxUpdatesPerFrame; internal EntityProperties[] m_updateArray; + /// + /// Used to control physics simulation timing if Bullet is running on its own thread. + /// + private ManualResetEvent m_updateWaitEvent; + public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero public const uint GROUNDPLANE_ID = 1; public const uint CHILDTERRAIN_ID = 2; // Terrain allocated based on our mega-prim childre start here @@ -839,6 +844,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters public void BulletSPluginPhysicsThread() { Thread.CurrentThread.Priority = ThreadPriority.Highest; + m_updateWaitEvent = new ManualResetEvent(false); while (m_initialized) { @@ -853,8 +859,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters if (simulationTimeVsRealtimeDifferenceMS > 0) { // The simulation of the time interval took less than realtime. - // Do a sleep for the rest of realtime. - Thread.Sleep(simulationTimeVsRealtimeDifferenceMS); + // Do a wait for the rest of realtime. + m_updateWaitEvent.WaitOne(simulationTimeVsRealtimeDifferenceMS); + //Thread.Sleep(simulationTimeVsRealtimeDifferenceMS); } else {