ubitODE - do own timing control (as chODE does) until heartbeat does it right

avinationmerge
UbitUmarov 2012-04-23 20:16:53 +01:00
parent e0f81e2400
commit 5a8fdc8a0b
2 changed files with 34 additions and 21 deletions

View File

@ -695,7 +695,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_PIDTau = 0; m_PIDTau = 0;
else else
{ {
float mint = (0.05f > _parent_scene.ODE_STEPSIZE ? 0.05f : _parent_scene.ODE_STEPSIZE); float mint = (0.05f > m_timeStep ? 0.05f : m_timeStep);
if (value < mint) if (value < mint)
m_PIDTau = mint; m_PIDTau = mint;
else else
@ -723,7 +723,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_PIDHoverTau = 0; m_PIDHoverTau = 0;
else else
{ {
float mint = (0.05f > _parent_scene.ODE_STEPSIZE ? 0.05f : _parent_scene.ODE_STEPSIZE); float mint = (0.05f > m_timeStep ? 0.05f : m_timeStep);
if (value < mint) if (value < mint)
m_PIDHoverTau = mint; m_PIDHoverTau = mint;
else else
@ -801,7 +801,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
if (force.IsFinite()) if (force.IsFinite())
{ {
AddChange(changes.AddForce, force / _parent_scene.ODE_STEPSIZE); AddChange(changes.AddForce, force * m_invTimeStep);
} }
else else
{ {
@ -814,7 +814,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
if (force.IsFinite()) if (force.IsFinite())
{ {
AddChange(changes.AddAngForce, force / _parent_scene.ODE_STEPSIZE); AddChange(changes.AddAngForce, force * m_invTimeStep);
} }
else else
{ {

View File

@ -189,9 +189,12 @@ namespace OpenSim.Region.Physics.OdePlugin
private const uint m_regionHeight = Constants.RegionSize; private const uint m_regionHeight = Constants.RegionSize;
public float ODE_STEPSIZE = 0.020f; public float ODE_STEPSIZE = 0.020f;
public float HalfOdeStep = 0.01f;
private float metersInSpace = 25.6f; private float metersInSpace = 25.6f;
private float m_timeDilation = 1.0f; private float m_timeDilation = 1.0f;
DateTime m_lastframe;
public float gravityx = 0f; public float gravityx = 0f;
public float gravityy = 0f; public float gravityy = 0f;
public float gravityz = -9.8f; public float gravityz = -9.8f;
@ -485,6 +488,8 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
} }
HalfOdeStep = ODE_STEPSIZE * 0.5f;
ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf); ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf);
GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf); GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf);
@ -564,6 +569,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// let this now be real maximum values // let this now be real maximum values
spaceGridMaxX--; spaceGridMaxX--;
spaceGridMaxY--; spaceGridMaxY--;
m_lastframe = DateTime.UtcNow;
} }
internal void waitForSpaceUnlock(IntPtr space) internal void waitForSpaceUnlock(IntPtr space)
@ -1685,24 +1691,30 @@ namespace OpenSim.Region.Physics.OdePlugin
/// <returns></returns> /// <returns></returns>
public override float Simulate(float timeStep) public override float Simulate(float timeStep)
{ {
DateTime now = DateTime.UtcNow;
TimeSpan SinceLastFrame = now - m_lastframe;
m_lastframe = now;
timeStep = (float)SinceLastFrame.TotalSeconds;
// acumulate time so we can reduce error // acumulate time so we can reduce error
step_time += timeStep; step_time += timeStep;
if (step_time < ODE_STEPSIZE) if (step_time < HalfOdeStep)
return 0; return 0;
if (framecount >= int.MaxValue) if (framecount < 0)
framecount = 0; framecount = 0;
framecount++; framecount++;
int curphysiteractions = m_physicsiterations; int curphysiteractions;
if (step_time >= m_SkipFramesAtms)
{
// if in trouble reduce step resolution // if in trouble reduce step resolution
curphysiteractions /= 2; if (step_time >= m_SkipFramesAtms)
} curphysiteractions = m_physicsiterations / 2;
else
curphysiteractions = m_physicsiterations;
int nodeframes = 0; int nodeframes = 0;
@ -1722,8 +1734,7 @@ namespace OpenSim.Region.Physics.OdePlugin
base.TriggerPhysicsBasedRestart(); base.TriggerPhysicsBasedRestart();
} }
while (step_time >= HalfOdeStep && nodeframes < 10) //limit number of steps so we don't say here for ever
while (step_time >= ODE_STEPSIZE && nodeframes < 10) //limit number of steps so we don't say here for ever
{ {
try try
{ {
@ -1905,14 +1916,16 @@ namespace OpenSim.Region.Physics.OdePlugin
d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
} }
// think time dilation is not a physics issue alone.. but ok let's fake something // think time dilation as to do with dinamic step size that we dont' have
if (step_time < ODE_STEPSIZE) // we did the required loops // even so tell something to world
if (nodeframes < 10) // we did the requested loops
m_timeDilation = 1.0f; m_timeDilation = 1.0f;
else else if (step_time > 0)
{ // we didn't forget the lost ones and let user know something {
m_timeDilation = 1 - step_time / timeStep; m_timeDilation = timeStep / step_time;
if (m_timeDilation < 0) if (m_timeDilation > 1)
m_timeDilation = 0; m_timeDilation = 1;
if (step_time > m_SkipFramesAtms)
step_time = 0; step_time = 0;
} }
} }