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.

This commit is contained in:
Dan Lake
2011-10-27 00:42:21 -07:00
parent 40bee97015
commit b98613091c
14 changed files with 78 additions and 87 deletions

View File

@@ -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());
ForEachRootScenePresence(delegate(ScenePresence agent)
{
//agent.ControllingClient.new
//this.CommsManager.InterRegion.InformRegionOfChildAgent(otherRegion.RegionHandle, agent.ControllingClient.RequestClientInfo());
List<ulong> old = new List<ulong>();
old.Add(otherRegion.RegionHandle);
agent.DropOldNeighbours(old);
if (m_teleportModule != null)
m_teleportModule.EnableChildAgent(agent, otherRegion);
}
}
);
List<ulong> old = new List<ulong>();
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
/// <param name="stats">Stats on the Simulator's performance</param>
private void SendSimStatsPackets(SimStats stats)
{
ForEachScenePresence(
ForEachRootScenePresence(
delegate(ScenePresence agent)
{
if (!agent.IsChildAgent)
agent.ControllingClient.SendSimStats(stats);
agent.ControllingClient.SendSimStats(stats);
}
);
}
@@ -4289,6 +4278,19 @@ namespace OpenSim.Region.Framework.Scenes
return cp.IsChildAgent;
}
/// <summary>
/// Performs action on all ROOT (not child) scene presences.
/// This is just a shortcut function since frequently actions only appy to root SPs
/// </summary>
/// <param name="action"></param>
public void ForEachRootScenePresence(Action<ScenePresence> action)
{
if(m_sceneGraph != null)
{
m_sceneGraph.ForEachRootScenePresence(action);
}
}
/// <summary>
/// Performs action on all scene presences.
/// </summary>

View File

@@ -1190,7 +1190,21 @@ namespace OpenSim.Region.Framework.Scenes
}
}
}
/// <summary>
/// Performs action on all ROOT (not child) scene presences.
/// This is just a shortcut function since frequently actions only appy to root SPs
/// </summary>
/// <param name="action"></param>
public void ForEachRootScenePresence(Action<ScenePresence> action)
{
ForEachScenePresence(delegate(ScenePresence sp)
{
if (!sp.IsChildAgent)
action(sp);
});
}
/// <summary>
/// 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

View File

@@ -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);
});
}
);