a few changes on check targets for lsl

0.9.1.1
UbitUmarov 2019-11-27 16:44:45 +00:00
parent b3db90db92
commit 5c5e4bd830
4 changed files with 119 additions and 130 deletions

View File

@ -410,7 +410,7 @@ namespace OpenSim.Region.Framework.Scenes
private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing private readonly Timer m_restartTimer = new Timer(15000); // Wait before firing
private volatile bool m_backingup; private volatile bool m_backingup;
private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>(); private Dictionary<UUID, ReturnInfo> m_returns = new Dictionary<UUID, ReturnInfo>();
private Dictionary<UUID, int> m_groupsWithTargets = new Dictionary<UUID, int>(); private HashSet<UUID> m_groupsWithTargets = new HashSet<UUID>();
private string m_defaultScriptEngine; private string m_defaultScriptEngine;
@ -837,7 +837,8 @@ namespace OpenSim.Region.Framework.Scenes
Random random = new Random(); 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_authenticateHandler = authen;
m_sceneGridService = new SceneCommunicationService(); m_sceneGridService = new SceneCommunicationService();
m_SimulationDataService = simDataService; m_SimulationDataService = simDataService;
@ -1633,7 +1634,7 @@ namespace OpenSim.Region.Framework.Scenes
// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); // 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 try
{ {
@ -1713,6 +1714,10 @@ namespace OpenSim.Region.Framework.Scenes
if (Frame % m_update_objects == 0) if (Frame % m_update_objects == 0)
m_sceneGraph.UpdateObjectGroups(); m_sceneGraph.UpdateObjectGroups();
tmpMS2 = Util.GetTimeStampMS();
otherMS = (float)(tmpMS2 - tmpMS);
tmpMS = tmpMS2;
// Run through all ScenePresences looking for updates // Run through all ScenePresences looking for updates
// Presence updates and queued object updates for each presence are sent to clients // Presence updates and queued object updates for each presence are sent to clients
if (Frame % m_update_presences == 0) if (Frame % m_update_presences == 0)
@ -1828,7 +1833,7 @@ namespace OpenSim.Region.Framework.Scenes
m_firstHeartbeat = false; m_firstHeartbeat = false;
Watchdog.UpdateThread(); Watchdog.UpdateThread();
otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS; otherMS += tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
tmpMS = Util.GetTimeStampMS(); tmpMS = Util.GetTimeStampMS();
@ -1912,7 +1917,7 @@ namespace OpenSim.Region.Framework.Scenes
public void AddGroupTarget(SceneObjectGroup grp) public void AddGroupTarget(SceneObjectGroup grp)
{ {
lock (m_groupsWithTargets) lock (m_groupsWithTargets)
m_groupsWithTargets[grp.UUID] = 0; m_groupsWithTargets.Add(grp.UUID);
} }
public void RemoveGroupTarget(SceneObjectGroup grp) public void RemoveGroupTarget(SceneObjectGroup grp)
@ -1928,13 +1933,14 @@ namespace OpenSim.Region.Framework.Scenes
lock (m_groupsWithTargets) lock (m_groupsWithTargets)
{ {
if (m_groupsWithTargets.Count != 0) if (m_groupsWithTargets.Count != 0)
objs = new List<UUID>(m_groupsWithTargets.Keys); objs = new List<UUID>(m_groupsWithTargets);
} }
if (objs != null) if (objs != null)
{ {
foreach (UUID entry in objs) for(int i = 0; i< objs.Count; ++i)
{ {
UUID entry = objs[i];
SceneObjectGroup grp = GetSceneObjectGroup(entry); SceneObjectGroup grp = GetSceneObjectGroup(entry);
if (grp == null) if (grp == null)
m_groupsWithTargets.Remove(entry); m_groupsWithTargets.Remove(entry);

View File

@ -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 /// The last allocated local prim id. When a new local id is requested, the next number in the sequence is
/// dispensed. /// dispensed.
/// </summary> /// </summary>
protected uint m_lastAllocatedLocalId = 720000; protected int m_lastAllocatedLocalId = 720000;
protected int m_lastAllocatedIntId = 7200;
private readonly Mutex _primAllocateMutex = new Mutex(false);
protected readonly ClientManager m_clientManager = new ClientManager(); protected readonly ClientManager m_clientManager = new ClientManager();
@ -299,15 +298,16 @@ namespace OpenSim.Region.Framework.Scenes
/// <returns>A brand new local ID</returns> /// <returns>A brand new local ID</returns>
public uint AllocateLocalId() public uint AllocateLocalId()
{ {
uint myID; return (uint)Interlocked.Increment(ref m_lastAllocatedLocalId);
_primAllocateMutex.WaitOne();
myID = ++m_lastAllocatedLocalId;
_primAllocateMutex.ReleaseMutex();
return myID;
} }
public int AllocateIntId()
{
return Interlocked.Increment(ref m_lastAllocatedLocalId);
}
#region Module Methods #region Module Methods
/// <summary> /// <summary>

View File

@ -87,14 +87,14 @@ namespace OpenSim.Region.Framework.Scenes
{ {
public Vector3 targetPos; public Vector3 targetPos;
public float tolerance; public float tolerance;
public uint handle; public int handle;
} }
public struct scriptRotTarget public struct scriptRotTarget
{ {
public Quaternion targetRot; public Quaternion targetRot;
public float tolerance; public float tolerance;
public uint handle; public int handle;
} }
public delegate void PrimCountTaintedDelegate(); public delegate void PrimCountTaintedDelegate();
@ -357,15 +357,15 @@ namespace OpenSim.Region.Framework.Scenes
protected SceneObjectPart m_rootPart; protected SceneObjectPart m_rootPart;
// private Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>(); // private Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>();
private SortedDictionary<uint, scriptPosTarget> m_targets = new SortedDictionary<uint, scriptPosTarget>(); private SortedDictionary<int, scriptPosTarget> m_targets = new SortedDictionary<int, scriptPosTarget>();
private SortedDictionary<uint, scriptRotTarget> m_rotTargets = new SortedDictionary<uint, scriptRotTarget>(); private SortedDictionary<int, scriptRotTarget> m_rotTargets = new SortedDictionary<int, scriptRotTarget>();
public SortedDictionary<uint, scriptPosTarget> AtTargets public SortedDictionary<int, scriptPosTarget> AtTargets
{ {
get { return m_targets; } get { return m_targets; }
} }
public SortedDictionary<uint, scriptRotTarget> RotTargets public SortedDictionary<int, scriptRotTarget> RotTargets
{ {
get { return m_rotTargets; } get { return m_rotTargets; }
} }
@ -2906,7 +2906,6 @@ namespace OpenSim.Region.Framework.Scenes
{ {
// if (IsAttachment) // if (IsAttachment)
// m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId); // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId);
checkAtTargets();
if (Scene.GetNumberOfClients() == 0) if (Scene.GetNumberOfClients() == 0)
return; return;
@ -2925,8 +2924,6 @@ namespace OpenSim.Region.Framework.Scenes
{ {
// if (IsAttachment) // if (IsAttachment)
// m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId); // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId);
checkAtTargets();
if (Scene.GetNumberOfClients() == 0) if (Scene.GetNumberOfClients() == 0)
return; return;
@ -4809,7 +4806,7 @@ namespace OpenSim.Region.Framework.Scenes
scriptRotTarget waypoint = new scriptRotTarget(); scriptRotTarget waypoint = new scriptRotTarget();
waypoint.targetRot = target; waypoint.targetRot = target;
waypoint.tolerance = tolerance; waypoint.tolerance = tolerance;
uint handle = m_scene.AllocateLocalId(); int handle = m_scene.AllocateIntId();
waypoint.handle = handle; waypoint.handle = handle;
lock (m_rotTargets) lock (m_rotTargets)
{ {
@ -4818,14 +4815,14 @@ namespace OpenSim.Region.Framework.Scenes
m_rotTargets.Add(handle, waypoint); m_rotTargets.Add(handle, waypoint);
} }
m_scene.AddGroupTarget(this); m_scene.AddGroupTarget(this);
return (int)handle; return handle;
} }
public void unregisterRotTargetWaypoint(int handle) public void unregisterRotTargetWaypoint(int handle)
{ {
lock (m_targets) lock (m_targets)
{ {
m_rotTargets.Remove((uint)handle); m_rotTargets.Remove(handle);
if (m_targets.Count == 0) if (m_targets.Count == 0)
m_scene.RemoveGroupTarget(this); m_scene.RemoveGroupTarget(this);
} }
@ -4836,7 +4833,7 @@ namespace OpenSim.Region.Framework.Scenes
scriptPosTarget waypoint = new scriptPosTarget(); scriptPosTarget waypoint = new scriptPosTarget();
waypoint.targetPos = target; waypoint.targetPos = target;
waypoint.tolerance = tolerance; waypoint.tolerance = tolerance;
uint handle = m_scene.AllocateLocalId(); int handle = m_scene.AllocateIntId();
waypoint.handle = handle; waypoint.handle = handle;
lock (m_targets) lock (m_targets)
{ {
@ -4852,7 +4849,7 @@ namespace OpenSim.Region.Framework.Scenes
{ {
lock (m_targets) lock (m_targets)
{ {
m_targets.Remove((uint)handle); m_targets.Remove(handle);
if (m_targets.Count == 0) if (m_targets.Count == 0)
m_scene.RemoveGroupTarget(this); m_scene.RemoveGroupTarget(this);
} }
@ -4860,141 +4857,127 @@ namespace OpenSim.Region.Framework.Scenes
public void checkAtTargets() 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<scriptPosTarget> atTargets = new List<scriptPosTarget>(m_targets.Count);
lock (m_targets)
{ {
bool at_target = false; if (m_scriptListens_atTarget)
//Vector3 targetPos;
//uint targetHandle;
Dictionary<uint, scriptPosTarget> atTargets = new Dictionary<uint, scriptPosTarget>();
lock (m_targets)
{ {
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) if (Vector3.DistanceSquared(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance * target.tolerance)
{ {
at_target = true; not_target = false;
atTargets.Add(target);
// 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);
}
} }
} }
} }
else
if (atTargets.Count > 0)
{ {
SceneObjectPart[] parts = m_parts.GetArray(); foreach (scriptPosTarget target in m_targets.Values)
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 (uint target in atTargets.Keys) if (Vector3.DistanceSquared(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance * target.tolerance)
{ {
scriptPosTarget att = atTargets[target]; not_target = false;
m_scene.EventManager.TriggerAtTargetEvent( break;
localids[ctr], att.handle, att.targetPos, m_rootPart.GroupPosition);
} }
} }
return;
}
if (m_scriptListens_notAtTarget && !at_target)
{
//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++)
{
m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
}
} }
} }
}
if (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget) if (atTargets.Count > 0)
{
if (m_rotTargets.Count > 0)
{ {
bool at_Rottarget = false; SceneObjectPart[] parts = m_parts.GetArray();
Dictionary<uint, scriptRotTarget> atRotTargets = new Dictionary<uint, scriptRotTarget>(); for (int ctr = 0; ctr < parts.Length; ++ctr)
lock (m_rotTargets)
{ {
foreach (uint idx in m_rotTargets.Keys) uint pid = parts[ctr].LocalId;
for(int target = 0; target < atTargets.Count; ++target)
{ {
scriptRotTarget target = m_rotTargets[idx]; scriptPosTarget att = atTargets[target];
double angle m_scene.EventManager.TriggerAtTargetEvent(
= Math.Acos( pid, (uint)att.handle, att.targetPos, m_rootPart.GroupPosition);
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 (not_target && m_scriptListens_notAtTarget)
if (angle < 0) angle = -angle; {
if (angle > Math.PI) angle = (Math.PI * 2 - angle); //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_rotTargets.Count > 0 && (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget))
{
bool not_Rottarget = true;
List<scriptRotTarget> atRotTargets = new List<scriptRotTarget>(m_rotTargets.Count);
lock (m_rotTargets)
{
if (m_scriptListens_atRotTarget)
{
foreach (scriptRotTarget target in m_rotTargets.Values)
{
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) if (angle <= target.tolerance)
{ {
// trigger at_rot_target // trigger at_rot_target
if (m_scriptListens_atRotTarget) not_Rottarget = false;
{ atRotTargets.Add(target);
at_Rottarget = true;
scriptRotTarget att = new scriptRotTarget();
att.targetRot = target.targetRot;
att.tolerance = target.tolerance;
att.handle = target.handle;
atRotTargets.Add(idx, att);
}
} }
} }
} }
else
if (atRotTargets.Count > 0)
{ {
SceneObjectPart[] parts = m_parts.GetArray(); foreach (scriptRotTarget target in m_rotTargets.Values)
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 (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]; not_Rottarget = false;
m_scene.EventManager.TriggerAtRotTargetEvent( break;
localids[ctr], att.handle, att.targetRot, m_rootPart.RotationOffset);
} }
} }
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 uint pid = parts[ctr].LocalId;
SceneObjectPart[] parts = m_parts.GetArray(); for (int target = 0; target < atRotTargets.Count; ++target)
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++)
{ {
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);
}
} }
} }

View File

@ -3344,7 +3344,7 @@ namespace OpenSim.Region.Framework.Scenes
private const float VELOCITY_TOLERANCE = 0.1f; private const float VELOCITY_TOLERANCE = 0.1f;
private const float ANGVELOCITY_TOLERANCE = 0.005f; 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 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) private Vector3 ClampVectorForTerseUpdate(Vector3 v, float max)
{ {