From 5c5e4bd8304dbb607a4008ec41ecacf716cfd0db Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 27 Nov 2019 16:44:45 +0000 Subject: a few changes on check targets for lsl --- OpenSim/Region/Framework/Scenes/Scene.cs | 20 ++- OpenSim/Region/Framework/Scenes/SceneBase.cs | 18 +- .../Region/Framework/Scenes/SceneObjectGroup.cs | 193 ++++++++++----------- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 2 +- 4 files changed, 111 insertions(+), 122 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index a0a2882..0c5007a 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -410,7 +410,7 @@ namespace OpenSim.Region.Framework.Scenes private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing private volatile bool m_backingup; private Dictionary m_returns = new Dictionary(); - private Dictionary m_groupsWithTargets = new Dictionary(); + private HashSet m_groupsWithTargets = new HashSet(); private string m_defaultScriptEngine; @@ -837,7 +837,8 @@ namespace OpenSim.Region.Framework.Scenes Random random = new Random(); - m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue / 2)) + (uint)(uint.MaxValue / 4); + m_lastAllocatedLocalId = (int)(random.NextDouble() * (uint.MaxValue / 4)); + m_lastAllocatedIntId = (int)(random.NextDouble() * (int.MaxValue / 4)); m_authenticateHandler = authen; m_sceneGridService = new SceneCommunicationService(); m_SimulationDataService = simDataService; @@ -1633,7 +1634,7 @@ namespace OpenSim.Region.Framework.Scenes // m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); - agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0f; + otherMS = agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0f; try { @@ -1713,6 +1714,10 @@ namespace OpenSim.Region.Framework.Scenes if (Frame % m_update_objects == 0) m_sceneGraph.UpdateObjectGroups(); + tmpMS2 = Util.GetTimeStampMS(); + otherMS = (float)(tmpMS2 - tmpMS); + tmpMS = tmpMS2; + // Run through all ScenePresences looking for updates // Presence updates and queued object updates for each presence are sent to clients if (Frame % m_update_presences == 0) @@ -1828,7 +1833,7 @@ namespace OpenSim.Region.Framework.Scenes m_firstHeartbeat = false; Watchdog.UpdateThread(); - otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS; + otherMS += tempOnRezMS + eventMS + backupMS + terrainMS + landMS; tmpMS = Util.GetTimeStampMS(); @@ -1912,7 +1917,7 @@ namespace OpenSim.Region.Framework.Scenes public void AddGroupTarget(SceneObjectGroup grp) { lock (m_groupsWithTargets) - m_groupsWithTargets[grp.UUID] = 0; + m_groupsWithTargets.Add(grp.UUID); } public void RemoveGroupTarget(SceneObjectGroup grp) @@ -1928,13 +1933,14 @@ namespace OpenSim.Region.Framework.Scenes lock (m_groupsWithTargets) { if (m_groupsWithTargets.Count != 0) - objs = new List(m_groupsWithTargets.Keys); + objs = new List(m_groupsWithTargets); } if (objs != null) { - foreach (UUID entry in objs) + for(int i = 0; i< objs.Count; ++i) { + UUID entry = objs[i]; SceneObjectGroup grp = GetSceneObjectGroup(entry); if (grp == null) m_groupsWithTargets.Remove(entry); diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs index e3e54e2..a3c8112 100644 --- a/OpenSim/Region/Framework/Scenes/SceneBase.cs +++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs @@ -105,9 +105,8 @@ namespace OpenSim.Region.Framework.Scenes /// The last allocated local prim id. When a new local id is requested, the next number in the sequence is /// dispensed. /// - protected uint m_lastAllocatedLocalId = 720000; - - private readonly Mutex _primAllocateMutex = new Mutex(false); + protected int m_lastAllocatedLocalId = 720000; + protected int m_lastAllocatedIntId = 7200; protected readonly ClientManager m_clientManager = new ClientManager(); @@ -299,15 +298,16 @@ namespace OpenSim.Region.Framework.Scenes /// A brand new local ID public uint AllocateLocalId() { - uint myID; - - _primAllocateMutex.WaitOne(); - myID = ++m_lastAllocatedLocalId; - _primAllocateMutex.ReleaseMutex(); + return (uint)Interlocked.Increment(ref m_lastAllocatedLocalId); + } - return myID; + public int AllocateIntId() + { + return Interlocked.Increment(ref m_lastAllocatedLocalId); } + + #region Module Methods /// diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 199aa92..ca37d08 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -87,14 +87,14 @@ namespace OpenSim.Region.Framework.Scenes { public Vector3 targetPos; public float tolerance; - public uint handle; + public int handle; } public struct scriptRotTarget { public Quaternion targetRot; public float tolerance; - public uint handle; + public int handle; } public delegate void PrimCountTaintedDelegate(); @@ -357,15 +357,15 @@ namespace OpenSim.Region.Framework.Scenes protected SceneObjectPart m_rootPart; // private Dictionary m_scriptEvents = new Dictionary(); - private SortedDictionary m_targets = new SortedDictionary(); - private SortedDictionary m_rotTargets = new SortedDictionary(); + private SortedDictionary m_targets = new SortedDictionary(); + private SortedDictionary m_rotTargets = new SortedDictionary(); - public SortedDictionary AtTargets + public SortedDictionary AtTargets { get { return m_targets; } } - public SortedDictionary RotTargets + public SortedDictionary RotTargets { get { return m_rotTargets; } } @@ -2906,7 +2906,6 @@ namespace OpenSim.Region.Framework.Scenes { // if (IsAttachment) // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId); - checkAtTargets(); if (Scene.GetNumberOfClients() == 0) return; @@ -2925,8 +2924,6 @@ namespace OpenSim.Region.Framework.Scenes { // if (IsAttachment) // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId); - checkAtTargets(); - if (Scene.GetNumberOfClients() == 0) return; @@ -4809,7 +4806,7 @@ namespace OpenSim.Region.Framework.Scenes scriptRotTarget waypoint = new scriptRotTarget(); waypoint.targetRot = target; waypoint.tolerance = tolerance; - uint handle = m_scene.AllocateLocalId(); + int handle = m_scene.AllocateIntId(); waypoint.handle = handle; lock (m_rotTargets) { @@ -4818,14 +4815,14 @@ namespace OpenSim.Region.Framework.Scenes m_rotTargets.Add(handle, waypoint); } m_scene.AddGroupTarget(this); - return (int)handle; + return handle; } public void unregisterRotTargetWaypoint(int handle) { lock (m_targets) { - m_rotTargets.Remove((uint)handle); + m_rotTargets.Remove(handle); if (m_targets.Count == 0) m_scene.RemoveGroupTarget(this); } @@ -4836,7 +4833,7 @@ namespace OpenSim.Region.Framework.Scenes scriptPosTarget waypoint = new scriptPosTarget(); waypoint.targetPos = target; waypoint.tolerance = tolerance; - uint handle = m_scene.AllocateLocalId(); + int handle = m_scene.AllocateIntId(); waypoint.handle = handle; lock (m_targets) { @@ -4852,7 +4849,7 @@ namespace OpenSim.Region.Framework.Scenes { lock (m_targets) { - m_targets.Remove((uint)handle); + m_targets.Remove(handle); if (m_targets.Count == 0) m_scene.RemoveGroupTarget(this); } @@ -4860,141 +4857,127 @@ namespace OpenSim.Region.Framework.Scenes public void checkAtTargets() { - if (m_scriptListens_atTarget || m_scriptListens_notAtTarget) + if (m_targets.Count > 0 && (m_scriptListens_atTarget || m_scriptListens_notAtTarget)) { - if (m_targets.Count > 0) + bool not_target = true; + + List atTargets = new List(m_targets.Count); + lock (m_targets) { - bool at_target = false; - //Vector3 targetPos; - //uint targetHandle; - Dictionary atTargets = new Dictionary(); - lock (m_targets) + if (m_scriptListens_atTarget) { - foreach (uint idx in m_targets.Keys) + foreach (scriptPosTarget target in m_targets.Values) { - scriptPosTarget target = m_targets[idx]; if (Vector3.DistanceSquared(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance * target.tolerance) { - at_target = true; - - // trigger at_target - if (m_scriptListens_atTarget) - { - scriptPosTarget att = new scriptPosTarget(); - att.targetPos = target.targetPos; - att.tolerance = target.tolerance; - att.handle = target.handle; - atTargets.Add(idx, att); - } + not_target = false; + atTargets.Add(target); } } } - - if (atTargets.Count > 0) + else { - SceneObjectPart[] parts = m_parts.GetArray(); - uint[] localids = new uint[parts.Length]; - for (int i = 0; i < parts.Length; i++) - localids[i] = parts[i].LocalId; - - for (int ctr = 0; ctr < localids.Length; ctr++) + foreach (scriptPosTarget target in m_targets.Values) { - foreach (uint target in atTargets.Keys) + if (Vector3.DistanceSquared(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance * target.tolerance) { - scriptPosTarget att = atTargets[target]; - m_scene.EventManager.TriggerAtTargetEvent( - localids[ctr], att.handle, att.targetPos, m_rootPart.GroupPosition); + not_target = false; + break; } } - - return; } + } - if (m_scriptListens_notAtTarget && !at_target) + if (atTargets.Count > 0) + { + SceneObjectPart[] parts = m_parts.GetArray(); + for (int ctr = 0; ctr < parts.Length; ++ctr) { - //trigger not_at_target - SceneObjectPart[] parts = m_parts.GetArray(); - uint[] localids = new uint[parts.Length]; - for (int i = 0; i < parts.Length; i++) - localids[i] = parts[i].LocalId; - - for (int ctr = 0; ctr < localids.Length; ctr++) + uint pid = parts[ctr].LocalId; + for(int target = 0; target < atTargets.Count; ++target) { - m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); + scriptPosTarget att = atTargets[target]; + m_scene.EventManager.TriggerAtTargetEvent( + pid, (uint)att.handle, att.targetPos, m_rootPart.GroupPosition); } } } + + if (not_target && m_scriptListens_notAtTarget) + { + //trigger not_at_target + SceneObjectPart[] parts = m_parts.GetArray(); + for (int ctr = 0; ctr < parts.Length; ctr++) + { + m_scene.EventManager.TriggerNotAtTargetEvent(parts[ctr].LocalId); + } + } } - if (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget) + + if (m_rotTargets.Count > 0 && (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget)) { - if (m_rotTargets.Count > 0) + bool not_Rottarget = true; + + List atRotTargets = new List(m_rotTargets.Count); + lock (m_rotTargets) { - bool at_Rottarget = false; - Dictionary atRotTargets = new Dictionary(); - lock (m_rotTargets) + if (m_scriptListens_atRotTarget) { - foreach (uint idx in m_rotTargets.Keys) + foreach (scriptRotTarget target in m_rotTargets.Values) { - scriptRotTarget target = m_rotTargets[idx]; - double angle - = Math.Acos( - target.targetRot.X * m_rootPart.RotationOffset.X - + target.targetRot.Y * m_rootPart.RotationOffset.Y - + target.targetRot.Z * m_rootPart.RotationOffset.Z - + target.targetRot.W * m_rootPart.RotationOffset.W) - * 2; - if (angle < 0) angle = -angle; - if (angle > Math.PI) angle = (Math.PI * 2 - angle); + double angle = 2 * Math.Acos(Quaternion.Dot(target.targetRot, m_rootPart.RotationOffset)); + if (angle < 0) + angle = -angle; + if (angle > Math.PI) + angle = (2 * Math.PI - angle); if (angle <= target.tolerance) { // trigger at_rot_target - if (m_scriptListens_atRotTarget) - { - at_Rottarget = true; - scriptRotTarget att = new scriptRotTarget(); - att.targetRot = target.targetRot; - att.tolerance = target.tolerance; - att.handle = target.handle; - atRotTargets.Add(idx, att); - } + not_Rottarget = false; + atRotTargets.Add(target); } } } - - if (atRotTargets.Count > 0) + else { - SceneObjectPart[] parts = m_parts.GetArray(); - uint[] localids = new uint[parts.Length]; - for (int i = 0; i < parts.Length; i++) - localids[i] = parts[i].LocalId; - - for (int ctr = 0; ctr < localids.Length; ctr++) + foreach (scriptRotTarget target in m_rotTargets.Values) { - foreach (uint target in atRotTargets.Keys) + double angle = 2 * Math.Acos(Quaternion.Dot(target.targetRot, m_rootPart.RotationOffset)); + if (angle < 0) + angle = -angle; + if (angle > Math.PI) + angle = (2 * Math.PI - angle); + if (angle <= target.tolerance) { - scriptRotTarget att = atRotTargets[target]; - m_scene.EventManager.TriggerAtRotTargetEvent( - localids[ctr], att.handle, att.targetRot, m_rootPart.RotationOffset); + not_Rottarget = false; + break; } } - - return; } + } - if (m_scriptListens_notAtRotTarget && !at_Rottarget) + if (atRotTargets.Count > 0) + { + SceneObjectPart[] parts = m_parts.GetArray(); + for (int ctr = 0; ctr < parts.Length; ++ctr) { - //trigger not_at_target - SceneObjectPart[] parts = m_parts.GetArray(); - uint[] localids = new uint[parts.Length]; - for (int i = 0; i < parts.Length; i++) - localids[i] = parts[i].LocalId; - - for (int ctr = 0; ctr < localids.Length; ctr++) + uint pid = parts[ctr].LocalId; + for (int target = 0; target < atRotTargets.Count; ++target) { - m_scene.EventManager.TriggerNotAtRotTargetEvent(localids[ctr]); + scriptRotTarget att = atRotTargets[target]; + m_scene.EventManager.TriggerAtRotTargetEvent( + pid, (uint)att.handle, att.targetRot, m_rootPart.RotationOffset); } } } + + if (not_Rottarget && m_scriptListens_notAtRotTarget) + { + //trigger not_at_target + SceneObjectPart[] parts = m_parts.GetArray(); + for (int ctr = 0; ctr < parts.Length; ++ctr) + m_scene.EventManager.TriggerNotAtRotTargetEvent(parts[ctr].LocalId); + } } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index ec58b97..6cbdc43 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -3344,7 +3344,7 @@ namespace OpenSim.Region.Framework.Scenes private const float VELOCITY_TOLERANCE = 0.1f; private const float ANGVELOCITY_TOLERANCE = 0.005f; private const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary - private const double TIME_MS_TOLERANCE = 200.0; //llSetPos has a 200ms delay. This should NOT be 3 seconds. + private const double TIME_MS_TOLERANCE = 250.0; //llSetPos has a 200ms delay. This should NOT be 3 seconds. private Vector3 ClampVectorForTerseUpdate(Vector3 v, float max) { -- cgit v1.1