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,31 +4857,32 @@ 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;
{
bool at_target = false; List<scriptPosTarget> atTargets = new List<scriptPosTarget>(m_targets.Count);
//Vector3 targetPos;
//uint targetHandle;
Dictionary<uint, scriptPosTarget> atTargets = new Dictionary<uint, scriptPosTarget>();
lock (m_targets) lock (m_targets)
{ {
foreach (uint idx in m_targets.Keys)
{
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) if (m_scriptListens_atTarget)
{ {
scriptPosTarget att = new scriptPosTarget(); foreach (scriptPosTarget target in m_targets.Values)
att.targetPos = target.targetPos; {
att.tolerance = target.tolerance; if (Vector3.DistanceSquared(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance * target.tolerance)
att.handle = target.handle; {
atTargets.Add(idx, att); not_target = false;
atTargets.Add(target);
}
}
}
else
{
foreach (scriptPosTarget target in m_targets.Values)
{
if (Vector3.DistanceSquared(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance * target.tolerance)
{
not_target = false;
break;
} }
} }
} }
@ -4893,69 +4891,66 @@ namespace OpenSim.Region.Framework.Scenes
if (atTargets.Count > 0) if (atTargets.Count > 0)
{ {
SceneObjectPart[] parts = m_parts.GetArray(); SceneObjectPart[] parts = m_parts.GetArray();
uint[] localids = new uint[parts.Length]; for (int ctr = 0; ctr < parts.Length; ++ctr)
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) uint pid = parts[ctr].LocalId;
for(int target = 0; target < atTargets.Count; ++target)
{ {
scriptPosTarget att = atTargets[target]; scriptPosTarget att = atTargets[target];
m_scene.EventManager.TriggerAtTargetEvent( m_scene.EventManager.TriggerAtTargetEvent(
localids[ctr], att.handle, att.targetPos, m_rootPart.GroupPosition); pid, (uint)att.handle, att.targetPos, m_rootPart.GroupPosition);
}
} }
} }
return; if (not_target && m_scriptListens_notAtTarget)
}
if (m_scriptListens_notAtTarget && !at_target)
{ {
//trigger not_at_target //trigger not_at_target
SceneObjectPart[] parts = m_parts.GetArray(); SceneObjectPart[] parts = m_parts.GetArray();
uint[] localids = new uint[parts.Length]; for (int ctr = 0; ctr < parts.Length; ctr++)
for (int i = 0; i < parts.Length; i++) {
localids[i] = parts[i].LocalId; m_scene.EventManager.TriggerNotAtTargetEvent(parts[ctr].LocalId);
}
}
}
for (int ctr = 0; ctr < localids.Length; ctr++) if (m_rotTargets.Count > 0 && (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget))
{ {
m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); bool not_Rottarget = true;
}
} List<scriptRotTarget> atRotTargets = new List<scriptRotTarget>(m_rotTargets.Count);
}
}
if (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget)
{
if (m_rotTargets.Count > 0)
{
bool at_Rottarget = false;
Dictionary<uint, scriptRotTarget> atRotTargets = new Dictionary<uint, scriptRotTarget>();
lock (m_rotTargets) lock (m_rotTargets)
{ {
foreach (uint idx in m_rotTargets.Keys) if (m_scriptListens_atRotTarget)
{ {
scriptRotTarget target = m_rotTargets[idx]; foreach (scriptRotTarget target in m_rotTargets.Values)
double angle {
= Math.Acos( double angle = 2 * Math.Acos(Quaternion.Dot(target.targetRot, m_rootPart.RotationOffset));
target.targetRot.X * m_rootPart.RotationOffset.X if (angle < 0)
+ target.targetRot.Y * m_rootPart.RotationOffset.Y angle = -angle;
+ target.targetRot.Z * m_rootPart.RotationOffset.Z if (angle > Math.PI)
+ target.targetRot.W * m_rootPart.RotationOffset.W) angle = (2 * Math.PI - angle);
* 2;
if (angle < 0) angle = -angle;
if (angle > Math.PI) angle = (Math.PI * 2 - 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);
}
}
}
else
{ {
at_Rottarget = true; foreach (scriptRotTarget target in m_rotTargets.Values)
scriptRotTarget att = new scriptRotTarget(); {
att.targetRot = target.targetRot; double angle = 2 * Math.Acos(Quaternion.Dot(target.targetRot, m_rootPart.RotationOffset));
att.tolerance = target.tolerance; if (angle < 0)
att.handle = target.handle; angle = -angle;
atRotTargets.Add(idx, att); if (angle > Math.PI)
angle = (2 * Math.PI - angle);
if (angle <= target.tolerance)
{
not_Rottarget = false;
break;
} }
} }
} }
@ -4964,36 +4959,24 @@ namespace OpenSim.Region.Framework.Scenes
if (atRotTargets.Count > 0) if (atRotTargets.Count > 0)
{ {
SceneObjectPart[] parts = m_parts.GetArray(); SceneObjectPart[] parts = m_parts.GetArray();
uint[] localids = new uint[parts.Length]; for (int ctr = 0; ctr < parts.Length; ++ctr)
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) uint pid = parts[ctr].LocalId;
for (int target = 0; target < atRotTargets.Count; ++target)
{ {
scriptRotTarget att = atRotTargets[target]; scriptRotTarget att = atRotTargets[target];
m_scene.EventManager.TriggerAtRotTargetEvent( m_scene.EventManager.TriggerAtRotTargetEvent(
localids[ctr], att.handle, att.targetRot, m_rootPart.RotationOffset); pid, (uint)att.handle, att.targetRot, m_rootPart.RotationOffset);
}
} }
} }
return; if (not_Rottarget && m_scriptListens_notAtRotTarget)
}
if (m_scriptListens_notAtRotTarget && !at_Rottarget)
{ {
//trigger not_at_target //trigger not_at_target
SceneObjectPart[] parts = m_parts.GetArray(); SceneObjectPart[] parts = m_parts.GetArray();
uint[] localids = new uint[parts.Length]; for (int ctr = 0; ctr < parts.Length; ++ctr)
for (int i = 0; i < parts.Length; i++) m_scene.EventManager.TriggerNotAtRotTargetEvent(parts[ctr].LocalId);
localids[i] = parts[i].LocalId;
for (int ctr = 0; ctr < localids.Length; ctr++)
{
m_scene.EventManager.TriggerNotAtRotTargetEvent(localids[ctr]);
}
}
} }
} }
} }

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)
{ {