From 011868adc73e4ef77b1534b350e77571f2b94911 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 16 Jul 2021 01:14:51 +0100 Subject: [PATCH] mantis 8909: take number of npcs out of avatars limit check --- OpenSim/Region/Framework/Scenes/Scene.cs | 13 +++--- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 40 +++++++++++++++---- .../Region/Framework/Scenes/ScenePresence.cs | 4 +- .../OptionalModules/World/NPC/NPCModule.cs | 2 +- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index ac93ad4be1..a9d8408136 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -5202,9 +5202,9 @@ Label_GroupsDone: #region SceneGraph wrapper methods - public void SwapRootAgentCount(bool rootChildChildRootTF) + public void SwapRootAgentCount(bool rootChildChildRootTF, bool isnpc) { - m_sceneGraph.SwapRootChildAgent(rootChildChildRootTF); + m_sceneGraph.SwapRootChildAgent(rootChildChildRootTF, isnpc); } public void AddPhysicalPrim(int num) @@ -6167,9 +6167,7 @@ Environment.Exit(1); return false; } - // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. - // However, the long term fix is to make sure root agent count is always accurate. - m_sceneGraph.RecalculateStats(); + AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(agentID); // Fake AgentCircuitData to keep IAuthorizationModule smiling @@ -6222,7 +6220,12 @@ Environment.Exit(1); if(isManager) return true; + // FIXME: Root agent count is currently known to be inaccurate. This forces a recount before we check. + // However, the long term fix is to make sure root agent count is always accurate. + m_sceneGraph.RecalculateStats(); int num = m_sceneGraph.GetRootAgentCount(); + num -= m_sceneGraph.GetRootNPCCount(); + if (num >= RegionInfo.RegionSettings.AgentLimit) { reason = "The region is full"; diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index 586995020e..dd1a283f04 100755 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -79,10 +79,12 @@ namespace OpenSim.Region.Framework.Scenes private PhysicsScene _PhyScene; private int m_numRootAgents = 0; + private int m_numChildAgents = 0; + private int m_numRootNPC = 0; + private int m_numTotalPrim = 0; private int m_numPrim = 0; private int m_numMesh = 0; - private int m_numChildAgents = 0; private int m_physicalPrim = 0; private int m_activeScripts = 0; @@ -763,6 +765,14 @@ namespace OpenSim.Region.Framework.Scenes // Find the index in the list where the old ref was stored and remove the reference m_scenePresenceLocalIDMap.Remove(oldref.LocalId); m_scenePresenceList = null; + if(oldref.IsChildAgent) + --m_numChildAgents; + else + { + --m_numRootAgents; + if(oldref.IsNPC) + --m_numRootNPC; + } } else { @@ -776,17 +786,21 @@ namespace OpenSim.Region.Framework.Scenes } } - protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F) + protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F, bool isnpc = false) { if (direction_RC_CR_T_F) { - m_numRootAgents--; + --m_numRootAgents; + if(isnpc) + --m_numRootNPC; m_numChildAgents++; } else { - m_numChildAgents--; - m_numRootAgents++; + --m_numChildAgents; + ++m_numRootAgents; + if (isnpc) + ++m_numRootNPC; } } @@ -806,18 +820,25 @@ namespace OpenSim.Region.Framework.Scenes { int rootcount = 0; int childcount = 0; + int rootnpccount = 0; List presences = GetScenePresences(); for (int i = 0; i < presences.Count; ++i) { - if (presences[i].IsChildAgent) + ScenePresence sp = presences[i]; + if (sp.IsChildAgent) ++childcount; else + { ++rootcount; - }; + if(sp.IsNPC) + ++rootnpccount; + } + } m_numRootAgents = rootcount; m_numChildAgents = childcount; + m_numRootNPC = rootnpccount; } public int GetChildAgentCount() @@ -830,6 +851,11 @@ namespace OpenSim.Region.Framework.Scenes return m_numRootAgents; } + public int GetRootNPCCount() + { + return m_numRootNPC; + } + public int GetTotalObjectsCount() { return m_numTotalPrim; diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index f03ea943de..f3d5ce92eb 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1574,7 +1574,7 @@ namespace OpenSim.Region.Framework.Scenes } //m_log.DebugFormat("[MakeRootAgent] position and physical: {0}ms", Util.EnvironmentTickCountSubtract(ts)); - m_scene.SwapRootAgentCount(false); + m_scene.SwapRootAgentCount(false, IsNPC); // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will // stall on the border crossing since the existing child agent will still have the last movement @@ -1711,7 +1711,7 @@ namespace OpenSim.Region.Framework.Scenes //Velocity = new Vector3(0, 0, 0); IsChildAgent = true; - m_scene.SwapRootAgentCount(true); + m_scene.SwapRootAgentCount(true, IsNPC); RemoveFromPhysicalScene(); ParentID = 0; // Child agents can't be sitting diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 0122a201d9..e0f5103a53 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -48,7 +48,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private Dictionary m_avatars = new Dictionary(); + private readonly Dictionary m_avatars = new Dictionary(); private NPCOptionsFlags m_NPCOptionFlags; public NPCOptionsFlags NPCOptionFlags {get {return m_NPCOptionFlags;}}