From ca2abc43ad440a99f17b43d32de89e77fdeef00e Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Tue, 8 Jun 2010 16:30:51 -0700 Subject: Refactor SendCoarseLocations for better performance. Instead of computing list of all locations fresh for every scene presence on every frame, we will instead compute the list once every 50 frames and send to all connected presences at that time. Also, we only add 60 items to the list when there are more than 60 presences in the scene. For 1000 users, this change yields a 99.8% reduction in list processing and a 98% reduction in network bandwidth for coarse locations. --- OpenSim/Region/Framework/Scenes/Scene.cs | 24 +++++----- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 37 ++++++++++++++++ OpenSim/Region/Framework/Scenes/ScenePresence.cs | 56 +++--------------------- 3 files changed, 55 insertions(+), 62 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 4e90d09..9a3b0c9 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -348,6 +348,7 @@ namespace OpenSim.Region.Framework.Scenes private int m_update_backup = 200; private int m_update_terrain = 50; private int m_update_land = 1; + private int m_update_coarse_locations = 50; private int frameMS; private int physicsMS2; @@ -1417,6 +1418,18 @@ namespace OpenSim.Region.Framework.Scenes if (m_frame % m_update_presences == 0) m_sceneGraph.UpdatePresences(); + if (m_frame % m_update_coarse_locations == 0) + { + List coarseLocations; + List avatarUUIDs; + SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60); + // Send coarse locations to clients + ForEachScenePresence(delegate(ScenePresence presence) + { + presence.SendCoarseLocations(coarseLocations, avatarUUIDs); + }); + } + int tmpPhysicsMS2 = Util.EnvironmentTickCount(); if ((m_frame % m_update_physics == 0) && m_physics_enabled) m_sceneGraph.UpdatePreparePhysics(); @@ -3301,9 +3314,6 @@ namespace OpenSim.Region.Framework.Scenes catch (NullReferenceException) { } }); - ForEachScenePresence( - delegate(ScenePresence presence) { presence.CoarseLocationChange(); }); - IAgentAssetTransactions agentTransactions = this.RequestModuleInterface(); if (agentTransactions != null) { @@ -3355,14 +3365,6 @@ namespace OpenSim.Region.Framework.Scenes } } - /// - /// Inform all other ScenePresences on this Scene that someone else has changed position on the minimap. - /// - public void NotifyMyCoarseLocationChange() - { - ForEachScenePresence(delegate(ScenePresence presence) { presence.CoarseLocationChange(); }); - } - #endregion #region Entities diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index 5902080..673674d 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -206,6 +206,43 @@ namespace OpenSim.Region.Framework.Scenes }); } + public void GetCoarseLocations(out List coarseLocations, out List avatarUUIDs, uint maxLocations) + { + coarseLocations = new List(); + avatarUUIDs = new List(); + + List presences = GetScenePresences(); + for (int i = 0; i < Math.Min(presences.Count, maxLocations); ++i) + { + ScenePresence sp = presences[i]; + // If this presence is a child agent, we don't want its coarse locations + if (sp.IsChildAgent) + return; + + if (sp.ParentID != 0) + { + // sitting avatar + SceneObjectPart sop = m_parentScene.GetSceneObjectPart(sp.ParentID); + if (sop != null) + { + coarseLocations.Add(sop.AbsolutePosition + sp.AbsolutePosition); + avatarUUIDs.Add(sp.UUID); + } + else + { + // we can't find the parent.. ! arg! + coarseLocations.Add(sp.AbsolutePosition); + avatarUUIDs.Add(sp.UUID); + } + } + else + { + coarseLocations.Add(sp.AbsolutePosition); + avatarUUIDs.Add(sp.UUID); + } + } + } + #endregion #region Entity Methods diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 45375b0..15b9446 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -65,7 +65,7 @@ namespace OpenSim.Region.Framework.Scenes public ScriptControlled eventControls; } - public delegate void SendCourseLocationsMethod(UUID scene, ScenePresence presence); + public delegate void SendCourseLocationsMethod(UUID scene, ScenePresence presence, List coarseLocations, List avatarUUIDs); public class ScenePresence : EntityBase, ISceneEntity { @@ -173,8 +173,6 @@ namespace OpenSim.Region.Framework.Scenes public string JID = String.Empty; - // Agent moves with a PID controller causing a force to be exerted. - private bool m_newCoarseLocations = true; private float m_health = 100f; // Default AV Height @@ -2296,12 +2294,6 @@ namespace OpenSim.Region.Framework.Scenes SendPrimUpdates(); - if (m_newCoarseLocations) - { - SendCoarseLocations(); - m_newCoarseLocations = false; - } - if (m_isChildAgent == false) { // PhysicsActor actor = m_physicsActor; @@ -2375,12 +2367,12 @@ namespace OpenSim.Region.Framework.Scenes m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); } - public void SendCoarseLocations() + public void SendCoarseLocations(List coarseLocations, List avatarUUIDs) { SendCourseLocationsMethod d = m_sendCourseLocationsMethod; if (d != null) { - d.Invoke(m_scene.RegionInfo.originRegionID, this); + d.Invoke(m_scene.RegionInfo.originRegionID, this, coarseLocations, avatarUUIDs); } } @@ -2390,50 +2382,13 @@ namespace OpenSim.Region.Framework.Scenes m_sendCourseLocationsMethod = d; } - public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p) + public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p, List coarseLocations, List avatarUUIDs) { m_perfMonMS = Util.EnvironmentTickCount(); - - List CoarseLocations = new List(); - List AvatarUUIDs = new List(); - m_scene.ForEachScenePresence(delegate(ScenePresence sp) - { - if (sp.IsChildAgent) - return; - - if (sp.ParentID != 0) - { - // sitting avatar - SceneObjectPart sop = m_scene.GetSceneObjectPart(sp.ParentID); - if (sop != null) - { - CoarseLocations.Add(sop.AbsolutePosition + sp.m_pos); - AvatarUUIDs.Add(sp.UUID); - } - else - { - // we can't find the parent.. ! arg! - CoarseLocations.Add(sp.m_pos); - AvatarUUIDs.Add(sp.UUID); - } - } - else - { - CoarseLocations.Add(sp.m_pos); - AvatarUUIDs.Add(sp.UUID); - } - }); - - m_controllingClient.SendCoarseLocationUpdate(AvatarUUIDs, CoarseLocations); - + m_controllingClient.SendCoarseLocationUpdate(avatarUUIDs, coarseLocations); m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); } - public void CoarseLocationChange() - { - m_newCoarseLocations = true; - } - /// /// Tell other client about this avatar (The client previously didn't know or had outdated details about this avatar) /// @@ -2668,7 +2623,6 @@ namespace OpenSim.Region.Framework.Scenes { posLastSignificantMove = AbsolutePosition; m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient); - m_scene.NotifyMyCoarseLocationChange(); } // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m -- cgit v1.1