diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index ed2445270f..a42dcc6f6c 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -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; diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 2e166637ef..2384143edb 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -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 m_lastColliders = new List(); + private List m_lastColliders = new List(); + 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 colliding = new List(); + 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 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); } + + EventManager eventmanager = ParentGroup.Scene.EventManager; - SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart); + SendCollisionEvent(scriptEvents.collision_start, startedColliders, eventmanager.TriggerScriptCollidingStart); if (!VolumeDetectActive) - SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding); - SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd); + SendCollisionEvent(scriptEvents.collision , m_lastColliders , eventmanager.TriggerScriptColliding); + SendCollisionEvent(scriptEvents.collision_end , endedColliders , eventmanager.TriggerScriptCollidingEnd); - 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); + 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; diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs index 005caee161..44e722c4d8 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs @@ -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) diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs index 5758e0a1a3..004ee7f31d 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs @@ -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; } /// @@ -1638,13 +1641,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde /// 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;