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.
ghosts
Justin Clark-Casey (justincc) 2014-09-26 20:56:22 +01:00
parent 85e04198fe
commit cfc95afc3d
1 changed files with 9 additions and 2 deletions

View File

@ -130,6 +130,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
internal int m_maxUpdatesPerFrame; internal int m_maxUpdatesPerFrame;
internal EntityProperties[] m_updateArray; internal EntityProperties[] m_updateArray;
/// <summary>
/// Used to control physics simulation timing if Bullet is running on its own thread.
/// </summary>
private ManualResetEvent m_updateWaitEvent;
public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero
public const uint GROUNDPLANE_ID = 1; public const uint GROUNDPLANE_ID = 1;
public const uint CHILDTERRAIN_ID = 2; // Terrain allocated based on our mega-prim childre start here 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() public void BulletSPluginPhysicsThread()
{ {
Thread.CurrentThread.Priority = ThreadPriority.Highest; Thread.CurrentThread.Priority = ThreadPriority.Highest;
m_updateWaitEvent = new ManualResetEvent(false);
while (m_initialized) while (m_initialized)
{ {
@ -853,8 +859,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
if (simulationTimeVsRealtimeDifferenceMS > 0) if (simulationTimeVsRealtimeDifferenceMS > 0)
{ {
// The simulation of the time interval took less than realtime. // The simulation of the time interval took less than realtime.
// Do a sleep for the rest of realtime. // Do a wait for the rest of realtime.
Thread.Sleep(simulationTimeVsRealtimeDifferenceMS); m_updateWaitEvent.WaitOne(simulationTimeVsRealtimeDifferenceMS);
//Thread.Sleep(simulationTimeVsRealtimeDifferenceMS);
} }
else else
{ {