BulletSim: another attempt at computing physics FPS correctly.

connector_plugin
Robert Adams 2012-09-14 11:12:23 -07:00
parent dcb94b8a24
commit f35bd6eb7d
1 changed files with 6 additions and 23 deletions

View File

@ -110,11 +110,6 @@ public class BSScene : PhysicsScene, IPhysicsParameters
private long m_simulationStep = 0; private long m_simulationStep = 0;
public long SimulationStep { get { return m_simulationStep; } } public long SimulationStep { get { return m_simulationStep; } }
// The length of the last timestep we were asked to simulate.
// This is used by the vehicle code. Since the vehicle code is called
// once per simulation step, its constants need to be scaled by this.
public float LastSimulatedTimestep { get; private set; }
// A value of the time now so all the collision and update routines do not have to get their own // A value of the time now so all the collision and update routines do not have to get their own
// Set to 'now' just before all the prims and actors are called for collisions and updates // Set to 'now' just before all the prims and actors are called for collisions and updates
public int SimulationNowTime { get; private set; } public int SimulationNowTime { get; private set; }
@ -469,12 +464,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters
int collidersCount = 0; int collidersCount = 0;
IntPtr collidersPtr; IntPtr collidersPtr;
LastSimulatedTimestep = timeStep;
// prevent simulation until we've been initialized // prevent simulation until we've been initialized
if (!m_initialized) return 10.0f; if (!m_initialized) return 5.0f;
int simulateStartTime = Util.EnvironmentTickCount();
// update the prim states while we know the physics engine is not busy // update the prim states while we know the physics engine is not busy
int numTaints = _taintedObjects.Count; int numTaints = _taintedObjects.Count;
@ -514,7 +505,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
// This is a kludge to get avatar movement updates. // This is a kludge to get avatar movement updates.
// ODE sends collisions for avatars even if there are have been no collisions. This updates // ODE sends collisions for avatars even if there are have been no collisions. This updates
// avatar animations and stuff. // avatar animations and stuff.
// If you fix avatar animation updates, remove this overhead and let collisions happen. // If you fix avatar animation updates, remove this overhead and let normal collision processing happen.
m_objectsWithCollisions = new HashSet<BSPhysObject>(m_avatarsWithCollisions); m_objectsWithCollisions = new HashSet<BSPhysObject>(m_avatarsWithCollisions);
// If there were collisions, process them by sending the event to the prim. // If there were collisions, process them by sending the event to the prim.
@ -561,18 +552,10 @@ public class BSScene : PhysicsScene, IPhysicsParameters
} }
} }
// this is a waste since the outside routine also calcuates the physics simulation // The physics engine returns the number of milliseconds it simulated this call.
// period. TODO: There should be a way of computing physics frames from simulator computation. // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS.
// long simulateTotalTime = Util.EnvironmentTickCountSubtract(simulateStartTime); // Since Bullet normally does 5 or 6 substeps, this will normally sum to about 60 FPS.
// return (timeStep * (float)simulateTotalTime); return numSubSteps * m_fixedTimeStep;
// 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 // Something has collided