those events are per script not per part

This commit is contained in:
UbitUmarov
2020-02-26 03:18:22 +00:00
parent c9137912c9
commit ca48bf4117
7 changed files with 105 additions and 57 deletions

View File

@@ -569,7 +569,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary>
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);
/// <summary>
/// Triggered when an object has arrived within a tolerance distance
@@ -583,7 +583,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </remarks>
public event ScriptAtTargetEvent OnScriptAtTargetEvent;
public delegate void ScriptNotAtTargetEvent(uint localID);
public delegate void ScriptNotAtTargetEvent(UUID scriptID);
/// <summary>
/// Triggered when an object has a motion target but has not arrived
@@ -597,7 +597,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </remarks>
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);
/// <summary>
/// Triggered when an object has arrived within a tolerance rotation
@@ -611,7 +611,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </remarks>
public event ScriptAtRotTargetEvent OnScriptAtRotTargetEvent;
public delegate void ScriptNotAtRotTargetEvent(uint localID);
public delegate void ScriptNotAtRotTargetEvent(UUID scriptID);
/// <summary>
/// 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)
{

View File

@@ -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<int> toremove = new List<int>();
lock (m_targets)
{
foreach (KeyValuePair<int, scriptPosTarget> 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<int, scriptRotTarget> 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<scriptPosTarget> atTargets = new List<scriptPosTarget>(targetsCount);
List<scriptPosTarget> atTargets = new List<scriptPosTarget>();
List<scriptPosTarget> notatTargets = new List<scriptPosTarget>(targetsCount);
Vector3 pos = m_rootPart.GroupPosition;
lock (m_targets)
@@ -4886,21 +4919,26 @@ namespace OpenSim.Region.Framework.Scenes
}
}
bool hasnot = notatTargets.Count > 0;
HashSet<UUID> excludes = new HashSet<UUID>();
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<UUID> excludes = new HashSet<UUID>();
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);
}
}
}

View File

@@ -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
/// <param name="events"></param>
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();