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.
mb-throttle-test
Justin Clark-Casey (justincc) 2014-09-26 20:56:22 +01:00
parent 7bababaab6
commit 8d72145112
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 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 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
{