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 double TimeStampClockPeriodMS;
public static double TimeStampClockPeriod;
static Util()
{
LogThreadPool = 0;
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));
}
@ -3016,6 +3018,11 @@ namespace OpenSim.Framework
// returns a timestamp in ms as double
// using the time resolution avaiable to StopWatch
public static double GetTimeStamp()
{
return (double)Stopwatch.GetTimestamp() * TimeStampClockPeriod;
}
public static double GetTimeStampMS()
{
return (double)Stopwatch.GetTimestamp() * TimeStampClockPeriodMS;

View File

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

View File

@ -1240,7 +1240,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
SentEmptyCollisionsEvent = true;
// _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;
CollisionEventsThisFrame.Clear();
@ -3595,7 +3595,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
_zeroFlag = true;
d.BodySetAutoDisableSteps(Body, 1);
d.BodyEnable(Body);
m_bodydisablecontrol = -4;
m_bodydisablecontrol = -3;
}
if(m_bodydisablecontrol < 0)

View File

@ -203,8 +203,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
private float metersInSpace = 25.6f;
private float m_timeDilation = 1.0f;
private DateTime m_lastframe;
private DateTime m_lastMeshExpire;
private double m_lastframe;
private double m_lastMeshExpire;
public float gravityx = 0f;
public float gravityy = 0f;
@ -629,8 +629,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
staticPrimspaceOffRegion[i] = newspace;
}
m_lastframe = DateTime.UtcNow;
m_lastframe = Util.GetTimeStamp();
m_lastMeshExpire = m_lastframe;
step_time = -1;
}
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_lastframe = Util.GetTimeStamp() + 0.5;
step_time = -0.5f;
}
/// <summary>
@ -1638,13 +1641,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
/// <returns></returns>
public override float Simulate(float reqTimeStep)
{
DateTime now = DateTime.UtcNow;
TimeSpan timedif = now - m_lastframe;
float timeStep = (float)timedif.TotalSeconds;
double now = Util.GetTimeStamp();
double timeStep = now - m_lastframe;
m_lastframe = now;
// acumulate time so we can reduce error
step_time += timeStep;
step_time += (float)timeStep;
if (step_time < HalfOdeStep)
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
/*
int ntopactivegeoms = d.SpaceGetNumGeoms(ActiveSpace);
@ -1940,7 +1934,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
// if we lag too much skip frames
m_timeDilation = 0.0f;
step_time = 0;
m_lastframe = DateTime.UtcNow; // skip also the time lost
m_lastframe = Util.GetTimeStamp(); // skip also the time lost
}
else
{
@ -1948,6 +1942,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
if (m_timeDilation > 1)
m_timeDilation = 1;
}
if (m_timeDilation == 1 && now - m_lastMeshExpire > 30)
{
mesher.ExpireReleaseMeshs();
m_lastMeshExpire = now;
}
}
return fps;