add Util.GetTimeStamp() that returns the stamp in seconds; use it on ubOde; separed land collsions dispatch from the others...

0.9.0-post-fixes
UbitUmarov 2017-07-13 20:21:18 +01:00
parent 4fe13ef639
commit 8b16131206
4 changed files with 104 additions and 47 deletions

View File

@ -156,12 +156,14 @@ namespace OpenSim.Framework
public static readonly int MAX_THREADPOOL_LEVEL = 3; public static readonly int MAX_THREADPOOL_LEVEL = 3;
public static double TimeStampClockPeriodMS; public static double TimeStampClockPeriodMS;
public static double TimeStampClockPeriod;
static Util() static Util()
{ {
LogThreadPool = 0; LogThreadPool = 0;
LogOverloads = true; LogOverloads = true;
TimeStampClockPeriodMS = 1000.0D / (double)Stopwatch.Frequency; TimeStampClockPeriod = 1.0D/ (double)Stopwatch.Frequency;
TimeStampClockPeriodMS = 1e3 * TimeStampClockPeriod;
m_log.InfoFormat("[UTIL] TimeStamp clock with period of {0}ms", Math.Round(TimeStampClockPeriodMS,6,MidpointRounding.AwayFromZero)); m_log.InfoFormat("[UTIL] TimeStamp clock with period of {0}ms", Math.Round(TimeStampClockPeriodMS,6,MidpointRounding.AwayFromZero));
} }
@ -3016,6 +3018,11 @@ namespace OpenSim.Framework
// returns a timestamp in ms as double // returns a timestamp in ms as double
// using the time resolution avaiable to StopWatch // using the time resolution avaiable to StopWatch
public static double GetTimeStamp()
{
return (double)Stopwatch.GetTimestamp() * TimeStampClockPeriod;
}
public static double GetTimeStampMS() public static double GetTimeStampMS()
{ {
return (double)Stopwatch.GetTimestamp() * TimeStampClockPeriodMS; return (double)Stopwatch.GetTimestamp() * TimeStampClockPeriodMS;

View File

@ -329,7 +329,8 @@ namespace OpenSim.Region.Framework.Scenes
private byte[] m_TextureAnimation; private byte[] m_TextureAnimation;
private byte m_clickAction; private byte m_clickAction;
private Color m_color = Color.Black; private Color m_color = Color.Black;
private readonly List<uint> m_lastColliders = new List<uint>(); private List<uint> m_lastColliders = new List<uint>();
private bool m_lastLandCollide;
private int m_linkNum; private int m_linkNum;
private int m_scriptAccessPin; private int m_scriptAccessPin;
@ -2789,12 +2790,13 @@ namespace OpenSim.Region.Framework.Scenes
{ {
ColliderArgs colliderArgs = new ColliderArgs(); ColliderArgs colliderArgs = new ColliderArgs();
List<DetectedObject> colliding = new List<DetectedObject>(); List<DetectedObject> colliding = new List<DetectedObject>();
Scene parentScene = ParentGroup.Scene;
foreach (uint localId in colliders) foreach (uint localId in colliders)
{ {
if (localId == 0) if (localId == 0)
continue; continue;
SceneObjectPart obj = ParentGroup.Scene.GetSceneObjectPart(localId); SceneObjectPart obj = parentScene.GetSceneObjectPart(localId);
if (obj != null) if (obj != null)
{ {
if (!dest.CollisionFilteredOut(obj.UUID, obj.Name)) if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
@ -2802,7 +2804,7 @@ namespace OpenSim.Region.Framework.Scenes
} }
else else
{ {
ScenePresence av = ParentGroup.Scene.GetScenePresence(localId); ScenePresence av = parentScene.GetScenePresence(localId);
if (av != null && (!av.IsChildAgent)) if (av != null && (!av.IsChildAgent))
{ {
if (!dest.CollisionFilteredOut(av.UUID, av.Name)) if (!dest.CollisionFilteredOut(av.UUID, av.Name))
@ -2879,6 +2881,9 @@ namespace OpenSim.Region.Framework.Scenes
return; return;
// this a thread from physics ( heartbeat ) // this a thread from physics ( heartbeat )
bool thisHitLand = false;
bool startLand = false;
bool endedLand = false;
CollisionEventUpdate a = (CollisionEventUpdate)e; CollisionEventUpdate a = (CollisionEventUpdate)e;
Dictionary<uint, ContactPoint> collissionswith = a.m_objCollisionList; Dictionary<uint, ContactPoint> collissionswith = a.m_objCollisionList;
@ -2888,13 +2893,17 @@ namespace OpenSim.Region.Framework.Scenes
if (collissionswith.Count == 0) if (collissionswith.Count == 0)
{ {
if (m_lastColliders.Count == 0) if (m_lastColliders.Count == 0 && !m_lastLandCollide)
return; // nothing to do return; // nothing to do
endedLand = m_lastLandCollide;
m_lastLandCollide = false;
foreach (uint localID in m_lastColliders) foreach (uint localID in m_lastColliders)
{ {
endedColliders.Add(localID); endedColliders.Add(localID);
} }
m_lastColliders.Clear(); m_lastColliders.Clear();
} }
else else
@ -2910,19 +2919,39 @@ namespace OpenSim.Region.Framework.Scenes
foreach (uint id in collissionswith.Keys) foreach (uint id in collissionswith.Keys)
{ {
thisHitColliders.Add(id); if(id == 0)
if (!m_lastColliders.Contains(id))
{ {
startedColliders.Add(id); thisHitLand = true;
if (!m_lastLandCollide)
curcontact = collissionswith[id];
if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
{ {
soundinfo = new CollisionForSoundInfo(); startLand = true;
soundinfo.colliderID = id; curcontact = collissionswith[id];
soundinfo.position = curcontact.Position; if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
soundinfo.relativeVel = curcontact.RelativeSpeed; {
soundinfolist.Add(soundinfo); soundinfo = new CollisionForSoundInfo();
soundinfo.colliderID = id;
soundinfo.position = curcontact.Position;
soundinfo.relativeVel = curcontact.RelativeSpeed;
soundinfolist.Add(soundinfo);
}
}
}
else
{
thisHitColliders.Add(id);
if (!m_lastColliders.Contains(id))
{
startedColliders.Add(id);
curcontact = collissionswith[id];
if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
{
soundinfo = new CollisionForSoundInfo();
soundinfo.colliderID = id;
soundinfo.position = curcontact.Position;
soundinfo.relativeVel = curcontact.RelativeSpeed;
soundinfolist.Add(soundinfo);
}
} }
} }
} }
@ -2931,9 +2960,18 @@ namespace OpenSim.Region.Framework.Scenes
{ {
foreach (uint id in collissionswith.Keys) foreach (uint id in collissionswith.Keys)
{ {
thisHitColliders.Add(id); if(id == 0)
if (!m_lastColliders.Contains(id)) {
startedColliders.Add(id); thisHitLand = true;
if (!m_lastLandCollide)
startLand = true;
}
else
{
thisHitColliders.Add(id);
if (!m_lastColliders.Contains(id))
startedColliders.Add(id);
}
} }
} }
@ -2952,22 +2990,32 @@ namespace OpenSim.Region.Framework.Scenes
foreach (uint localID in endedColliders) foreach (uint localID in endedColliders)
m_lastColliders.Remove(localID); m_lastColliders.Remove(localID);
if(m_lastLandCollide && !thisHitLand)
endedLand = true;
m_lastLandCollide = thisHitLand;
// play sounds. // play sounds.
if (soundinfolist.Count > 0) if (soundinfolist.Count > 0)
CollisionSounds.PartCollisionSound(this, soundinfolist); CollisionSounds.PartCollisionSound(this, soundinfolist);
} }
SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart); EventManager eventmanager = ParentGroup.Scene.EventManager;
if (!VolumeDetectActive)
SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding);
SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd);
if (startedColliders.Contains(0)) SendCollisionEvent(scriptEvents.collision_start, startedColliders, eventmanager.TriggerScriptCollidingStart);
SendLandCollisionEvent(scriptEvents.land_collision_start, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingStart); if (!VolumeDetectActive)
if (m_lastColliders.Contains(0)) SendCollisionEvent(scriptEvents.collision , m_lastColliders , eventmanager.TriggerScriptColliding);
SendLandCollisionEvent(scriptEvents.land_collision, ParentGroup.Scene.EventManager.TriggerScriptLandColliding); SendCollisionEvent(scriptEvents.collision_end , endedColliders , eventmanager.TriggerScriptCollidingEnd);
if (endedColliders.Contains(0))
SendLandCollisionEvent(scriptEvents.land_collision_end, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd); if (!VolumeDetectActive)
{
if (startLand)
SendLandCollisionEvent(scriptEvents.land_collision_start, eventmanager.TriggerScriptLandCollidingStart);
if (m_lastLandCollide)
SendLandCollisionEvent(scriptEvents.land_collision, eventmanager.TriggerScriptLandColliding);
if (endedLand)
SendLandCollisionEvent(scriptEvents.land_collision_end, eventmanager.TriggerScriptLandCollidingEnd);
}
} }
// The Collision sounds code calls this // The Collision sounds code calls this
@ -2986,7 +3034,7 @@ namespace OpenSim.Region.Framework.Scenes
volume = 0; volume = 0;
int now = Util.EnvironmentTickCount(); int now = Util.EnvironmentTickCount();
if(Util.EnvironmentTickCountSubtract(now,LastColSoundSentTime) <200) if(Util.EnvironmentTickCountSubtract(now, LastColSoundSentTime) < 200)
return; return;
LastColSoundSentTime = now; LastColSoundSentTime = now;

View File

@ -1240,7 +1240,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
SentEmptyCollisionsEvent = true; SentEmptyCollisionsEvent = true;
// _parent_scene.RemoveCollisionEventReporting(this); // _parent_scene.RemoveCollisionEventReporting(this);
} }
else if(Body == IntPtr.Zero || d.BodyIsEnabled(Body)) else if(Body == IntPtr.Zero || (d.BodyIsEnabled(Body) && m_bodydisablecontrol >= 0 ))
{ {
SentEmptyCollisionsEvent = false; SentEmptyCollisionsEvent = false;
CollisionEventsThisFrame.Clear(); CollisionEventsThisFrame.Clear();
@ -3595,7 +3595,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
_zeroFlag = true; _zeroFlag = true;
d.BodySetAutoDisableSteps(Body, 1); d.BodySetAutoDisableSteps(Body, 1);
d.BodyEnable(Body); d.BodyEnable(Body);
m_bodydisablecontrol = -4; m_bodydisablecontrol = -3;
} }
if(m_bodydisablecontrol < 0) if(m_bodydisablecontrol < 0)

View File

@ -203,8 +203,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
private float metersInSpace = 25.6f; private float metersInSpace = 25.6f;
private float m_timeDilation = 1.0f; private float m_timeDilation = 1.0f;
private DateTime m_lastframe; private double m_lastframe;
private DateTime m_lastMeshExpire; private double m_lastMeshExpire;
public float gravityx = 0f; public float gravityx = 0f;
public float gravityy = 0f; public float gravityy = 0f;
@ -629,8 +629,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
staticPrimspaceOffRegion[i] = newspace; staticPrimspaceOffRegion[i] = newspace;
} }
m_lastframe = DateTime.UtcNow; m_lastframe = Util.GetTimeStamp();
m_lastMeshExpire = m_lastframe; m_lastMeshExpire = m_lastframe;
step_time = -1;
} }
internal void waitForSpaceUnlock(IntPtr space) internal void waitForSpaceUnlock(IntPtr space)
@ -1625,6 +1626,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
} }
m_log.InfoFormat("[ubOde] {0} prim actors loaded",_prims.Count); m_log.InfoFormat("[ubOde] {0} prim actors loaded",_prims.Count);
} }
m_lastframe = Util.GetTimeStamp() + 0.5;
step_time = -0.5f;
} }
/// <summary> /// <summary>
@ -1638,13 +1641,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
/// <returns></returns> /// <returns></returns>
public override float Simulate(float reqTimeStep) public override float Simulate(float reqTimeStep)
{ {
DateTime now = DateTime.UtcNow; double now = Util.GetTimeStamp();
TimeSpan timedif = now - m_lastframe; double timeStep = now - m_lastframe;
float timeStep = (float)timedif.TotalSeconds;
m_lastframe = now; m_lastframe = now;
// acumulate time so we can reduce error // acumulate time so we can reduce error
step_time += timeStep; step_time += (float)timeStep;
if (step_time < HalfOdeStep) if (step_time < HalfOdeStep)
return 0; return 0;
@ -1853,14 +1855,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
} }
} }
timedif = now - m_lastMeshExpire;
if (timedif.Seconds > 10)
{
mesher.ExpireReleaseMeshs();
m_lastMeshExpire = now;
}
// information block for in debug breakpoint only // information block for in debug breakpoint only
/* /*
int ntopactivegeoms = d.SpaceGetNumGeoms(ActiveSpace); int ntopactivegeoms = d.SpaceGetNumGeoms(ActiveSpace);
@ -1940,7 +1934,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
// if we lag too much skip frames // if we lag too much skip frames
m_timeDilation = 0.0f; m_timeDilation = 0.0f;
step_time = 0; step_time = 0;
m_lastframe = DateTime.UtcNow; // skip also the time lost m_lastframe = Util.GetTimeStamp(); // skip also the time lost
} }
else else
{ {
@ -1948,6 +1942,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
if (m_timeDilation > 1) if (m_timeDilation > 1)
m_timeDilation = 1; m_timeDilation = 1;
} }
if (m_timeDilation == 1 && now - m_lastMeshExpire > 30)
{
mesher.ExpireReleaseMeshs();
m_lastMeshExpire = now;
}
} }
return fps; return fps;