From 859bc717a4fe4cd5810ad9889cfb9b1e7f5c2046 Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Fri, 19 Mar 2010 05:51:16 -0700 Subject: Cleaned up access to scenepresences in scenegraph. GetScenePresences and GetAvatars have been removed to consolidate locking and iteration within SceneGraph. All callers which used these to then iterate over presences have been refactored to instead pass their delegates to Scene.ForEachScenePresence(Action). --- .../Shared/Api/Implementation/LSL_Api.cs | 38 +++++---- .../Shared/Api/Implementation/OSSL_Api.cs | 20 ++--- .../Api/Implementation/Plugins/SensorRepeat.cs | 93 +++++++++------------- 3 files changed, 68 insertions(+), 83 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index b040ca77..3ccbb3a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -5092,7 +5092,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Integer llGetRegionAgentCount() { m_host.AddScriptLPS(1); - return new LSL_Integer(World.GetAvatars().Count); + return new LSL_Integer(World.GetRootAgentCount()); } public LSL_Vector llGetRegionCorner() @@ -8771,17 +8771,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api landObject.SetMediaUrl(url); // now send to all (non-child) agents - List agents = World.GetAvatars(); - foreach (ScenePresence agent in agents) + World.ForEachScenePresence(delegate(ScenePresence sp) { - agent.ControllingClient.SendParcelMediaUpdate(landData.MediaURL, - landData.MediaID, - landData.MediaAutoScale, - mediaType, - description, - width, height, - loop); - } + if (!sp.IsChildAgent) + { + sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL, + landData.MediaID, + landData.MediaAutoScale, + mediaType, + description, + width, height, + loop); + } + }); } else if (!presence.IsChildAgent) { @@ -8802,13 +8804,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (presence == null) { // send to all (non-child) agents - List agents = World.GetAvatars(); - foreach (ScenePresence agent in agents) + World.ForEachScenePresence(delegate(ScenePresence sp) { - agent.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this? - (ParcelMediaCommandEnum)commandToSend, - time); - } + if (!sp.IsChildAgent) + { + sp.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this? + (ParcelMediaCommandEnum)commandToSend, + time); + } + }); } else if (!presence.IsChildAgent) { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 85ee29d..7e68cc7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -697,10 +697,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api CheckThreatLevel(ThreatLevel.None, "osGetAgents"); LSL_List result = new LSL_List(); - foreach (ScenePresence avatar in World.GetAvatars()) + World.ForEachScenePresence(delegate(ScenePresence sp) { - result.Add(avatar.Name); - } + if (!sp.IsChildAgent) + result.Add(sp.Name); + }); return result; } @@ -1985,19 +1986,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) { - foreach (ScenePresence presence in World.GetAvatars()) + World.ForEachScenePresence(delegate(ScenePresence sp) { - if ((presence.Firstname == FirstName) && - presence.Lastname == SurName) + if (!sp.IsChildAgent && + sp.Firstname == FirstName && + sp.Lastname == SurName) { // kick client... if (alert != null) - presence.ControllingClient.Kick(alert); + sp.ControllingClient.Kick(alert); // ...and close on our side - presence.Scene.IncomingCloseAgent(presence.UUID); + sp.Scene.IncomingCloseAgent(sp.UUID); } - } + }); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 829fbb7..6cbf260 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs @@ -404,70 +404,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins private List doAgentSensor(SenseRepeatClass ts) { - List presences; List sensedEntities = new List(); - // If this is an avatar sense by key try to get them directly - // rather than getting a list to scan through - if (ts.keyID != UUID.Zero) - { - ScenePresence p = m_CmdManager.m_ScriptEngine.World.GetScenePresence(ts.keyID); - if (p == null) - return sensedEntities; - presences = new List(); - presences.Add(p); - } - else - { - presences = new List(m_CmdManager.m_ScriptEngine.World.GetScenePresences()); - } - // If nobody about quit fast - if (presences.Count == 0) + if(m_CmdManager.m_ScriptEngine.World.GetRootAgentCount() == 0) return sensedEntities; SceneObjectPart SensePoint = ts.host; - Vector3 fromRegionPos = SensePoint.AbsolutePosition; - Quaternion q = SensePoint.RotationOffset; LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); - bool attached = (SensePoint.AttachmentPoint != 0); - bool nameSearch = (ts.name != null && ts.name != ""); Vector3 toRegionPos; double dis; - for (int i = 0; i < presences.Count; i++) + Action senseEntity = new Action(delegate(ScenePresence presence) { - ScenePresence presence = presences[i]; - bool keep = true; + if (presence.IsDeleted || presence.IsChildAgent || presence.GodLevel > 0.0) + return; + + // if the object the script is in is attached and the avatar is the owner + // then this one is not wanted + if (attached && presence.UUID == SensePoint.OwnerID) + return; - if (presence.IsDeleted) - continue; - - if (presence.IsChildAgent) - keep = false; toRegionPos = presence.AbsolutePosition; - dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos)); // are they in range - if (keep && dis <= ts.range) + if (dis <= ts.range) { - // if the object the script is in is attached and the avatar is the owner - // then this one is not wanted - if (attached && presence.UUID == SensePoint.OwnerID) - keep = false; - - // check the name if needed - if (keep && nameSearch && ts.name != presence.Name) - keep = false; - // Are they in the required angle of view - if (keep && ts.arc < Math.PI) + if (ts.arc < Math.PI) { // not omni-directional. Can you see it ? // vec forward_dir = llRot2Fwd(llGetRot()) @@ -488,26 +458,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins catch { } - if (ang_obj > ts.arc) keep = false; + if (ang_obj <= ts.arc) + { + sensedEntities.Add(new SensedEntity(dis, presence.UUID)); + } } } - else - { - keep = false; - } + }); - // Do not report gods, not even minor ones - if (keep && presence.GodLevel > 0.0) - keep = false; - - if (keep) // add to list with distance - { - sensedEntities.Add(new SensedEntity(dis, presence.UUID)); - } - - // If this is a search by name and we have just found it then no more to do - if (nameSearch && ts.name == presence.Name) + // If this is an avatar sense by key try to get them directly + // rather than getting a list to scan through + if (ts.keyID != UUID.Zero) + { + ScenePresence sp; + // Try direct lookup by UUID + if(!m_CmdManager.m_ScriptEngine.World.TryGetAvatar(ts.keyID, out sp)) return sensedEntities; + senseEntity(sp); + } + else if (ts.name != null && ts.name != "") + { + ScenePresence sp; + // Try lookup by name will return if/when found + if (!m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out sp)) + return sensedEntities; + senseEntity(sp); + } + else + { + m_CmdManager.m_ScriptEngine.World.ForEachScenePresence(senseEntity); } return sensedEntities; } -- cgit v1.1