From ca48bf4117751778c5a8842df87889db3dd9b05b Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 26 Feb 2020 03:18:22 +0000 Subject: [PATCH] those events are per script not per part --- .../CoreModules/Avatar/Chat/ChatModule.cs | 2 + .../Region/Framework/Scenes/EventManager.cs | 24 +++--- .../Framework/Scenes/SceneObjectGroup.cs | 74 +++++++++++++++---- .../Framework/Scenes/SceneObjectPart.cs | 19 +++-- .../Shared/Api/Implementation/LSL_Api.cs | 4 +- .../ScriptEngine/XEngine/EventManager.cs | 16 ++-- .../Region/ScriptEngine/YEngine/XMREvents.cs | 23 +++--- 7 files changed, 105 insertions(+), 57 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs index c8a2cb6813..5d194db566 100644 --- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs @@ -365,6 +365,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat } else if (c.SenderUUID != UUID.Zero) { + if(c.SenderObject == null) + return; fromID = c.SenderUUID; ownerID = ((SceneObjectPart)c.SenderObject).OwnerID; } diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index edc8886fbf..2c231b1b13 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -569,7 +569,7 @@ namespace OpenSim.Region.Framework.Scenes /// public event ScriptMovingEndEvent OnScriptMovingEndEvent; - public delegate void ScriptAtTargetEvent(uint localID, uint handle, Vector3 targetpos, Vector3 atpos); + public delegate void ScriptAtTargetEvent(UUID scriptID, uint handle, Vector3 targetpos, Vector3 atpos); /// /// Triggered when an object has arrived within a tolerance distance @@ -583,7 +583,7 @@ namespace OpenSim.Region.Framework.Scenes /// public event ScriptAtTargetEvent OnScriptAtTargetEvent; - public delegate void ScriptNotAtTargetEvent(uint localID); + public delegate void ScriptNotAtTargetEvent(UUID scriptID); /// /// Triggered when an object has a motion target but has not arrived @@ -597,7 +597,7 @@ namespace OpenSim.Region.Framework.Scenes /// public event ScriptNotAtTargetEvent OnScriptNotAtTargetEvent; - public delegate void ScriptAtRotTargetEvent(uint localID, uint handle, Quaternion targetrot, Quaternion atrot); + public delegate void ScriptAtRotTargetEvent(UUID scriptID, uint handle, Quaternion targetrot, Quaternion atrot); /// /// Triggered when an object has arrived within a tolerance rotation @@ -611,7 +611,7 @@ namespace OpenSim.Region.Framework.Scenes /// public event ScriptAtRotTargetEvent OnScriptAtRotTargetEvent; - public delegate void ScriptNotAtRotTargetEvent(uint localID); + public delegate void ScriptNotAtRotTargetEvent(UUID scriptID); /// /// Triggered when an object has a rotation target but has not arrived @@ -2325,7 +2325,7 @@ namespace OpenSim.Region.Framework.Scenes } } - public void TriggerAtTargetEvent(uint localID, uint handle, Vector3 targetpos, Vector3 currentpos) + public void TriggerAtTargetEvent(UUID scriptID, uint handle, Vector3 targetpos, Vector3 currentpos) { ScriptAtTargetEvent handlerScriptAtTargetEvent = OnScriptAtTargetEvent; if (handlerScriptAtTargetEvent != null) @@ -2334,7 +2334,7 @@ namespace OpenSim.Region.Framework.Scenes { try { - d(localID, handle, targetpos, currentpos); + d(scriptID, handle, targetpos, currentpos); } catch (Exception e) { @@ -2346,7 +2346,7 @@ namespace OpenSim.Region.Framework.Scenes } } - public void TriggerNotAtTargetEvent(uint localID) + public void TriggerNotAtTargetEvent(UUID scriptID) { ScriptNotAtTargetEvent handlerScriptNotAtTargetEvent = OnScriptNotAtTargetEvent; if (handlerScriptNotAtTargetEvent != null) @@ -2355,7 +2355,7 @@ namespace OpenSim.Region.Framework.Scenes { try { - d(localID); + d(scriptID); } catch (Exception e) { @@ -2367,7 +2367,7 @@ namespace OpenSim.Region.Framework.Scenes } } - public void TriggerAtRotTargetEvent(uint localID, uint handle, Quaternion targetrot, Quaternion currentrot) + public void TriggerAtRotTargetEvent(UUID scriptID, uint handle, Quaternion targetrot, Quaternion currentrot) { ScriptAtRotTargetEvent handlerScriptAtRotTargetEvent = OnScriptAtRotTargetEvent; if (handlerScriptAtRotTargetEvent != null) @@ -2376,7 +2376,7 @@ namespace OpenSim.Region.Framework.Scenes { try { - d(localID, handle, targetrot, currentrot); + d(scriptID, handle, targetrot, currentrot); } catch (Exception e) { @@ -2388,7 +2388,7 @@ namespace OpenSim.Region.Framework.Scenes } } - public void TriggerNotAtRotTargetEvent(uint localID) + public void TriggerNotAtRotTargetEvent(UUID scriptID) { ScriptNotAtRotTargetEvent handlerScriptNotAtRotTargetEvent = OnScriptNotAtRotTargetEvent; if (handlerScriptNotAtRotTargetEvent != null) @@ -2397,7 +2397,7 @@ namespace OpenSim.Region.Framework.Scenes { try { - d(localID); + d(scriptID); } catch (Exception e) { diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index d208675aa9..6c71c7184a 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -88,7 +88,7 @@ namespace OpenSim.Region.Framework.Scenes public Vector3 targetPos; public float tolerance; public int handle; - public uint partLocalID; + public UUID scriptID; } public struct scriptRotTarget @@ -96,7 +96,7 @@ namespace OpenSim.Region.Framework.Scenes public Quaternion targetRot; public float tolerance; public int handle; - public uint partLocalID; + public UUID scriptID; } public delegate void PrimCountTaintedDelegate(); @@ -4802,12 +4802,12 @@ namespace OpenSim.Region.Framework.Scenes return 0; } - public int registerRotTargetWaypoint(uint partLocalID, Quaternion target, float tolerance) + public int registerRotTargetWaypoint(UUID scriptID, Quaternion target, float tolerance) { scriptRotTarget waypoint = new scriptRotTarget(); waypoint.targetRot = target; waypoint.tolerance = tolerance; - waypoint.partLocalID = partLocalID; + waypoint.scriptID = scriptID; int handle = m_scene.AllocateIntId(); waypoint.handle = handle; lock (m_rotTargets) @@ -4830,15 +4830,14 @@ namespace OpenSim.Region.Framework.Scenes } } - public int registerTargetWaypoint(uint partLocalID, Vector3 target, float tolerance) + public int registerTargetWaypoint(UUID scriptID, Vector3 target, float tolerance) { - int handle = m_scene.AllocateIntId(); scriptPosTarget waypoint = new scriptPosTarget(); waypoint.targetPos = target; waypoint.tolerance = tolerance * tolerance; - waypoint.partLocalID = partLocalID; + waypoint.scriptID = scriptID; waypoint.handle = handle; lock (m_targets) @@ -4861,12 +4860,46 @@ namespace OpenSim.Region.Framework.Scenes } } + public void RemoveScriptTargets(UUID scriptID) + { + List toremove = new List(); + lock (m_targets) + { + foreach (KeyValuePair kvp in m_targets) + { + if (kvp.Value.scriptID == scriptID) + toremove.Add(kvp.Key); + } + if (toremove.Count > 0) + { + for (int i = 0; i < toremove.Count; ++i) + m_targets.Remove(toremove[i]); + toremove.Clear(); + } + } + + lock (m_rotTargets) + { + foreach (KeyValuePair kvp in m_rotTargets) + { + if (kvp.Value.scriptID == scriptID) + toremove.Add(kvp.Key); + } + if (toremove.Count > 0) + { + for (int i = 0; i < toremove.Count; ++i) + m_targets.Remove(toremove[i]); + } + + } + } + public void checkAtTargets() { int targetsCount = m_targets.Count; if (targetsCount > 0 && (m_scriptListens_atTarget || m_scriptListens_notAtTarget)) { - List atTargets = new List(targetsCount); + List atTargets = new List(); List notatTargets = new List(targetsCount); Vector3 pos = m_rootPart.GroupPosition; lock (m_targets) @@ -4886,21 +4919,26 @@ namespace OpenSim.Region.Framework.Scenes } } + bool hasnot = notatTargets.Count > 0; + HashSet excludes = new HashSet(); if (atTargets.Count > 0) { for (int target = 0; target < atTargets.Count; ++target) { scriptPosTarget att = atTargets[target]; - m_scene.EventManager.TriggerAtTargetEvent( - att.partLocalID, (uint)att.handle, att.targetPos, pos); + m_scene.EventManager.TriggerAtTargetEvent(att.scriptID, (uint)att.handle, att.targetPos, pos); + if(hasnot) + excludes.Add(att.scriptID); } } - if (notatTargets.Count > 0) + if (hasnot) { for (int target = 0; target < notatTargets.Count; ++target) { - m_scene.EventManager.TriggerNotAtTargetEvent(notatTargets[target].partLocalID); + UUID id = notatTargets[target].scriptID; + if(!excludes.Contains(id)) + m_scene.EventManager.TriggerNotAtTargetEvent(id); } } } @@ -4933,13 +4971,17 @@ namespace OpenSim.Region.Framework.Scenes } } + bool hasnot = notatRotTargets.Count > 0; + HashSet excludes = new HashSet(); + if (atRotTargets.Count > 0) { for (int target = 0; target < atRotTargets.Count; ++target) { scriptRotTarget att = atRotTargets[target]; - m_scene.EventManager.TriggerAtRotTargetEvent( - att.partLocalID, (uint)att.handle, att.targetRot, rot); + m_scene.EventManager.TriggerAtRotTargetEvent(att.scriptID, (uint)att.handle, att.targetRot, rot); + if(hasnot) + excludes.Add(att.scriptID); } } @@ -4947,7 +4989,9 @@ namespace OpenSim.Region.Framework.Scenes { for (int target = 0; target < notatRotTargets.Count; ++target) { - m_scene.EventManager.TriggerNotAtRotTargetEvent(notatRotTargets[target].partLocalID); + UUID id = notatRotTargets[target].scriptID; + if(!excludes.Contains(id)) + m_scene.EventManager.TriggerNotAtRotTargetEvent(id); } } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index ed1b97264b..f7bbc513f8 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -3013,8 +3013,11 @@ namespace OpenSim.Region.Framework.Scenes { lock (m_scriptEvents) { - if (m_scriptEvents.ContainsKey(scriptid)) + if (m_scriptEvents.TryGetValue(scriptid, out scriptEvents ev)) { + if (((ev & (scriptEvents.at_target | scriptEvents.at_rot_target)) != 0) && ParentGroup != null) + ParentGroup.RemoveScriptTargets(scriptid); + m_scriptEvents.Remove(scriptid); aggregateScriptEvents(); } @@ -3993,15 +3996,19 @@ namespace OpenSim.Region.Framework.Scenes /// public void SetScriptEvents(UUID scriptid, int events) { -// m_log.DebugFormat( -// "[SCENE OBJECT PART]: Set script events for script with id {0} on {1}/{2} to {3} in {4}", -// scriptid, Name, ParentGroup.Name, events, ParentGroup.Scene.Name); - + // m_log.DebugFormat( + // "[SCENE OBJECT PART]: Set script events for script with id {0} on {1}/{2} to {3} in {4}", + // scriptid, Name, ParentGroup.Name, events, ParentGroup.Scene.Name); // scriptEvents oldparts; lock (m_scriptEvents) { - if (m_scriptEvents.ContainsKey(scriptid) && m_scriptEvents[scriptid] == (scriptEvents) events) + if (m_scriptEvents.TryGetValue(scriptid, out scriptEvents ev)) + { + if (((ev & (scriptEvents.at_target | scriptEvents.at_rot_target)) != 0) && ParentGroup != null) + ParentGroup.RemoveScriptTargets(scriptid); + if (ev == (scriptEvents)events) return; + } m_scriptEvents[scriptid] = (scriptEvents) events; } aggregateScriptEvents(); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index c00efa9a94..fb9c719630 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3035,7 +3035,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Integer llTarget(LSL_Vector position, double range) { m_host.AddScriptLPS(1); - return m_host.ParentGroup.registerTargetWaypoint(m_host.LocalId, position, (float)range); + return m_host.ParentGroup.registerTargetWaypoint(m_item.ItemID, position, (float)range); } public void llTargetRemove(int number) @@ -3047,7 +3047,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Integer llRotTarget(LSL_Rotation rot, double error) { m_host.AddScriptLPS(1); - return m_host.ParentGroup.registerRotTargetWaypoint(m_host.LocalId, rot, (float)error); + return m_host.ParentGroup.registerRotTargetWaypoint(m_item.ItemID, rot, (float)error); } public void llRotTargetRemove(int number) diff --git a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs index 50a95a90ee..3963b5ee02 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs @@ -380,10 +380,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine new DetectParams[0])); } - public void at_target(uint localID, uint handle, Vector3 targetpos, + public void at_target(UUID itemID, uint handle, Vector3 targetpos, Vector3 atpos) { - myScriptEngine.PostObjectEvent(localID, new EventParams( + myScriptEngine.PostScriptEvent(itemID, new EventParams( "at_target", new object[] { new LSL_Types.LSLInteger(handle), new LSL_Types.Vector3(targetpos), @@ -391,17 +391,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine new DetectParams[0])); } - public void not_at_target(uint localID) + public void not_at_target(UUID itemID) { - myScriptEngine.PostObjectEvent(localID, new EventParams( + myScriptEngine.PostScriptEvent(itemID, new EventParams( "not_at_target",new object[0], new DetectParams[0])); } - public void at_rot_target(uint localID, uint handle, Quaternion targetrot, + public void at_rot_target(UUID itemID, uint handle, Quaternion targetrot, Quaternion atrot) { - myScriptEngine.PostObjectEvent(localID, new EventParams( + myScriptEngine.PostScriptEvent(itemID, new EventParams( "at_rot_target", new object[] { new LSL_Types.LSLInteger(handle), new LSL_Types.Quaternion(targetrot), @@ -409,9 +409,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine new DetectParams[0])); } - public void not_at_rot_target(uint localID) + public void not_at_rot_target(UUID itemID) { - myScriptEngine.PostObjectEvent(localID, new EventParams( + myScriptEngine.PostScriptEvent(itemID, new EventParams( "not_at_rot_target",new object[0], new DetectParams[0])); } diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMREvents.cs b/OpenSim/Region/ScriptEngine/YEngine/XMREvents.cs index 65a8aed88b..80d5f3767f 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMREvents.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMREvents.cs @@ -309,10 +309,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine zeroDetectParams)); } - public void at_target(uint localID, uint handle, Vector3 targetpos, - Vector3 atpos) + public void at_target(UUID scriptID, uint handle, Vector3 targetpos, Vector3 atpos) { - this.PostObjectEvent(localID, new EventParams( + PostScriptEvent(scriptID, new EventParams( "at_target", new object[] { (int)handle, new LSL_Vector(targetpos.X,targetpos.Y,targetpos.Z), @@ -320,32 +319,28 @@ namespace OpenSim.Region.ScriptEngine.Yengine zeroDetectParams)); } - public void not_at_target(uint localID) + public void not_at_target(UUID scriptID) { - this.PostObjectEvent(localID, new EventParams( + PostScriptEvent(scriptID, new EventParams( "not_at_target", zeroObjectArray, zeroDetectParams)); } - public void at_rot_target(uint localID, uint handle, OpenMetaverse.Quaternion targetrot, OpenMetaverse.Quaternion atrot) + public void at_rot_target(UUID scriptID, uint handle, OpenMetaverse.Quaternion targetrot, OpenMetaverse.Quaternion atrot) { - this.PostObjectEvent( - localID, - new EventParams( + PostScriptEvent(scriptID, new EventParams( "at_rot_target", new object[] { new LSL_Integer(handle), new LSL_Rotation(targetrot.X, targetrot.Y, targetrot.Z, targetrot.W), new LSL_Rotation(atrot.X, atrot.Y, atrot.Z, atrot.W) }, - zeroDetectParams - ) - ); + zeroDetectParams)); } - public void not_at_rot_target(uint localID) + public void not_at_rot_target(UUID scriptID) { - this.PostObjectEvent(localID, new EventParams( + PostScriptEvent(scriptID, new EventParams( "not_at_rot_target", zeroObjectArray, zeroDetectParams)); }