From b98613091cd6dc2f914fb5ab38ca33cdff21fc24 Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Thu, 27 Oct 2011 00:42:21 -0700 Subject: Added new ForEachRootScenePresence to Scene since almost every delegate passed to ForEachScenePresence checks for !IsChildAgent first. It consolidates child and root handling for coming refactors. --- .../Region/CoreModules/Avatar/Chat/ChatModule.cs | 7 +-- .../Region/CoreModules/Avatar/Gods/GodsModule.cs | 4 +- .../World/Estate/EstateManagementModule.cs | 13 ++--- .../Region/CoreModules/World/Land/LandObject.cs | 5 +- .../Region/CoreModules/World/Sound/SoundModule.cs | 10 +--- OpenSim/Region/CoreModules/World/Sun/SunModule.cs | 5 +- .../Region/CoreModules/World/Wind/WindModule.cs | 5 +- .../CoreModules/World/WorldMap/WorldMapModule.cs | 4 +- OpenSim/Region/Framework/Scenes/Scene.cs | 60 +++++++++++----------- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 16 +++++- OpenSim/Region/Framework/Scenes/SceneManager.cs | 9 ++-- .../Avatar/Concierge/ConciergeModule.cs | 5 +- .../RegionCombinerModule/RegionCombinerModule.cs | 4 +- .../Shared/Api/Implementation/LSL_Api.cs | 20 ++++---- 14 files changed, 79 insertions(+), 88 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs index 4359c01..2cd71c4 100644 --- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs @@ -279,12 +279,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat HashSet receiverIDs = new HashSet(); - ((Scene)c.Scene).ForEachScenePresence( + ((Scene)c.Scene).ForEachRootScenePresence( delegate(ScenePresence presence) - { - // ignore chat from child agents - if (presence.IsChildAgent) return; - + { IClientAPI client = presence.ControllingClient; // don't forward SayOwner chat from objects to diff --git a/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs b/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs index 5ec64d5..562c3b1 100644 --- a/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs @@ -140,10 +140,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods // This is a bit crude. It seems the client will be null before it actually stops the thread // The thread will kill itself eventually :/ // Is there another way to make sure *all* clients get this 'inter region' message? - m_scene.ForEachScenePresence( + m_scene.ForEachRootScenePresence( delegate(ScenePresence p) { - if (p.UUID != godID && !p.IsChildAgent) + if (p.UUID != godID) { // Possibly this should really be p.Close() though that method doesn't send a close // to the client diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs index c199a77..5427b68 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs @@ -658,17 +658,15 @@ namespace OpenSim.Region.CoreModules.World.Estate if (!Scene.Permissions.CanIssueEstateCommand(remover_client.AgentId, false)) return; - Scene.ForEachScenePresence(delegate(ScenePresence sp) + Scene.ForEachRootScenePresence(delegate(ScenePresence sp) { if (sp.UUID != senderID) { - ScenePresence p = Scene.GetScenePresence(sp.UUID); // make sure they are still there, we could be working down a long list // Also make sure they are actually in the region - if (p != null && !p.IsChildAgent) - { + ScenePresence p; + if(Scene.TryGetScenePresence(sp.UUID, out p)) Scene.TeleportClientHome(p.UUID, p.ControllingClient); - } } }); } @@ -929,10 +927,9 @@ namespace OpenSim.Region.CoreModules.World.Estate public void sendRegionInfoPacketToAll() { - Scene.ForEachScenePresence(delegate(ScenePresence sp) + Scene.ForEachRootScenePresence(delegate(ScenePresence sp) { - if (!sp.IsChildAgent) - HandleRegionInfoRequest(sp.ControllingClient); + HandleRegionInfoRequest(sp.ControllingClient); }); } diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs index 8c40171..0da0de3 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs @@ -476,11 +476,8 @@ namespace OpenSim.Region.CoreModules.World.Land public void SendLandUpdateToAvatarsOverMe(bool snap_selection) { - m_scene.ForEachScenePresence(delegate(ScenePresence avatar) + m_scene.ForEachRootScenePresence(delegate(ScenePresence avatar) { - if (avatar.IsChildAgent) - return; - ILandObject over = null; try { diff --git a/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs b/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs index 22ffcd6..93b1005 100644 --- a/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs +++ b/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs @@ -70,11 +70,8 @@ namespace OpenSim.Region.CoreModules.World.Sound SceneObjectGroup grp = part.ParentGroup; - m_scene.ForEachScenePresence(delegate(ScenePresence sp) + m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) { - if (sp.IsChildAgent) - return; - double dis = Util.GetDistanceTo(sp.AbsolutePosition, position); if (dis > 100.0) // Max audio distance return; @@ -122,11 +119,8 @@ namespace OpenSim.Region.CoreModules.World.Sound } } - m_scene.ForEachScenePresence(delegate(ScenePresence sp) + m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) { - if (sp.IsChildAgent) - return; - double dis = Util.GetDistanceTo(sp.AbsolutePosition, position); if (dis > 100.0) // Max audio distance return; diff --git a/OpenSim/Region/CoreModules/World/Sun/SunModule.cs b/OpenSim/Region/CoreModules/World/Sun/SunModule.cs index 4e14c73..d2c1289 100644 --- a/OpenSim/Region/CoreModules/World/Sun/SunModule.cs +++ b/OpenSim/Region/CoreModules/World/Sun/SunModule.cs @@ -488,12 +488,9 @@ namespace OpenSim.Region.CoreModules private void SunUpdateToAllClients() { - m_scene.ForEachScenePresence(delegate(ScenePresence sp) + m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) { - if (!sp.IsChildAgent) - { SunToClient(sp.ControllingClient); - } }); } diff --git a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs index 6bac555..bea5db1 100644 --- a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs +++ b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs @@ -435,10 +435,9 @@ namespace OpenSim.Region.CoreModules m_frameLastUpdateClientArray = m_frame; } - m_scene.ForEachScenePresence(delegate(ScenePresence sp) + m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) { - if (!sp.IsChildAgent) - sp.ControllingClient.SendWindData(windSpeeds); + sp.ControllingClient.SendWindData(windSpeeds); }); } } diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index 857079c..509c0d8 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs @@ -401,10 +401,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap } else { - m_scene.ForEachScenePresence(delegate(ScenePresence sp) + m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) { // Don't send a green dot for yourself - if (!sp.IsChildAgent && sp.UUID != remoteClient.AgentId) + if (sp.UUID != remoteClient.AgentId) { mapitem = new mapItemReply(); mapitem.x = (uint)(xstart + sp.AbsolutePosition.X); diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index e43185d..302103a 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -893,22 +893,17 @@ namespace OpenSim.Region.Framework.Scenes try { - ForEachScenePresence(delegate(ScenePresence agent) - { - // If agent is a root agent. - if (!agent.IsChildAgent) - { - //agent.ControllingClient.new - //this.CommsManager.InterRegion.InformRegionOfChildAgent(otherRegion.RegionHandle, agent.ControllingClient.RequestClientInfo()); - - List old = new List(); - old.Add(otherRegion.RegionHandle); - agent.DropOldNeighbours(old); - if (m_teleportModule != null) - m_teleportModule.EnableChildAgent(agent, otherRegion); - } - } - ); + ForEachRootScenePresence(delegate(ScenePresence agent) + { + //agent.ControllingClient.new + //this.CommsManager.InterRegion.InformRegionOfChildAgent(otherRegion.RegionHandle, agent.ControllingClient.RequestClientInfo()); + + List old = new List(); + old.Add(otherRegion.RegionHandle); + agent.DropOldNeighbours(old); + if (m_teleportModule != null) + m_teleportModule.EnableChildAgent(agent, otherRegion); + }); } catch (NullReferenceException) { @@ -1043,16 +1038,11 @@ namespace OpenSim.Region.Framework.Scenes GridRegion r = new GridRegion(region); try { - ForEachScenePresence(delegate(ScenePresence agent) - { - // If agent is a root agent. - if (!agent.IsChildAgent) - { - if (m_teleportModule != null) - m_teleportModule.EnableChildAgent(agent, r); - } - } - ); + ForEachRootScenePresence(delegate(ScenePresence agent) + { + if (m_teleportModule != null) + m_teleportModule.EnableChildAgent(agent, r); + }); } catch (NullReferenceException) { @@ -1456,11 +1446,10 @@ namespace OpenSim.Region.Framework.Scenes /// Stats on the Simulator's performance private void SendSimStatsPackets(SimStats stats) { - ForEachScenePresence( + ForEachRootScenePresence( delegate(ScenePresence agent) { - if (!agent.IsChildAgent) - agent.ControllingClient.SendSimStats(stats); + agent.ControllingClient.SendSimStats(stats); } ); } @@ -4290,6 +4279,19 @@ namespace OpenSim.Region.Framework.Scenes } /// + /// Performs action on all ROOT (not child) scene presences. + /// This is just a shortcut function since frequently actions only appy to root SPs + /// + /// + public void ForEachRootScenePresence(Action action) + { + if(m_sceneGraph != null) + { + m_sceneGraph.ForEachRootScenePresence(action); + } + } + + /// /// Performs action on all scene presences. /// /// diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index caec704..542bd51 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -1190,7 +1190,21 @@ namespace OpenSim.Region.Framework.Scenes } } } - + + /// + /// Performs action on all ROOT (not child) scene presences. + /// This is just a shortcut function since frequently actions only appy to root SPs + /// + /// + public void ForEachRootScenePresence(Action action) + { + ForEachScenePresence(delegate(ScenePresence sp) + { + if (!sp.IsChildAgent) + action(sp); + }); + } + /// /// Performs action on all scene presences. This can ultimately run the actions in parallel but /// any delegates passed in will need to implement their own locking on data they reference and diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs index a58b87d..3bfd866 100644 --- a/OpenSim/Region/Framework/Scenes/SceneManager.cs +++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs @@ -458,9 +458,9 @@ namespace OpenSim.Region.Framework.Scenes ForEachCurrentScene( delegate(Scene scene) { - scene.ForEachScenePresence(delegate(ScenePresence scenePresence) + scene.ForEachRootScenePresence(delegate(ScenePresence scenePresence) { - if (!scenePresence.IsChildAgent && (name == null || scenePresence.Name == name)) + if (name == null || scenePresence.Name == name) { m_log.DebugFormat("Packet debug for {0} {1} set to {2}", scenePresence.Firstname, @@ -481,10 +481,9 @@ namespace OpenSim.Region.Framework.Scenes ForEachCurrentScene( delegate(Scene scene) { - scene.ForEachScenePresence(delegate(ScenePresence scenePresence) + scene.ForEachRootScenePresence(delegate(ScenePresence scenePresence) { - if (!scenePresence.IsChildAgent) - avatars.Add(scenePresence); + avatars.Add(scenePresence); }); } ); diff --git a/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs b/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs index 0d6313a..e22618d 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs @@ -373,13 +373,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.Concierge scene.GetRootAgentCount(), scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, DateTime.UtcNow.ToString("s"))); - scene.ForEachScenePresence(delegate(ScenePresence sp) + scene.ForEachRootScenePresence(delegate(ScenePresence sp) { - if (!sp.IsChildAgent) - { list.Append(String.Format(" \n", sp.Name, sp.UUID)); list.Append(""); - } }); string payload = list.ToString(); diff --git a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs index 4a24c7d..92cbbc6 100644 --- a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs +++ b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs @@ -711,10 +711,8 @@ namespace OpenSim.Region.RegionCombinerModule List CoarseLocations = new List(); List AvatarUUIDs = new List(); - connectiondata.RegionScene.ForEachScenePresence(delegate(ScenePresence sp) + connectiondata.RegionScene.ForEachRootScenePresence(delegate(ScenePresence sp) { - if (sp.IsChildAgent) - return; if (sp.UUID != presence.UUID) { if (sp.ParentID != 0) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 82701ce..83c3b78 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3723,9 +3723,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); List keytable = new List(); // parse for sitting avatare-uuids - World.ForEachScenePresence(delegate(ScenePresence presence) + World.ForEachRootScenePresence(delegate(ScenePresence presence) { - if (!presence.IsChildAgent && presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID)) + if (presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID)) keytable.Add(presence.UUID); }); @@ -3785,9 +3785,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); // parse for sitting avatare-names List nametable = new List(); - World.ForEachScenePresence(delegate(ScenePresence presence) + World.ForEachRootScenePresence(delegate(ScenePresence presence) { - if (!presence.IsChildAgent && presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID)) + if (presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID)) nametable.Add(presence.ControllingClient.Name); }); @@ -7568,9 +7568,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); int avatarCount = 0; - World.ForEachScenePresence(delegate(ScenePresence presence) + World.ForEachRootScenePresence(delegate(ScenePresence presence) { - if (!presence.IsChildAgent && presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID)) + if (presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID)) avatarCount++; }); @@ -9336,9 +9336,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api landObject.SetMediaUrl(url); // now send to all (non-child) agents in the parcel - World.ForEachScenePresence(delegate(ScenePresence sp) + World.ForEachRootScenePresence(delegate(ScenePresence sp) { - if (!sp.IsChildAgent && (sp.currentParcelUUID == landData.GlobalID)) + if (sp.currentParcelUUID == landData.GlobalID) { sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL, landData.MediaID, @@ -9369,9 +9369,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (presence == null) { // send to all (non-child) agents in the parcel - World.ForEachScenePresence(delegate(ScenePresence sp) + World.ForEachRootScenePresence(delegate(ScenePresence sp) { - if (!sp.IsChildAgent && (sp.currentParcelUUID == landData.GlobalID)) + if (sp.currentParcelUUID == landData.GlobalID) { sp.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this? (ParcelMediaCommandEnum)commandToSend, -- cgit v1.1