From 31304c222df1e5a832afd0ebcf7d3ed403543e54 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 25 Jul 2012 21:00:59 +0100 Subject: Make SceneManager.OnRegionsReadyStatusChange event available. This is fired when all regions are ready or when at least one region becomes not ready. Recently added EventManager.OnRegionReady becomes OnRegionReadyStatusChange to match OnLoginsEnabledStatusChange --- OpenSim/Region/Framework/Scenes/EventManager.cs | 11 +++-- OpenSim/Region/Framework/Scenes/Scene.cs | 4 +- OpenSim/Region/Framework/Scenes/SceneBase.cs | 18 +++++++++ OpenSim/Region/Framework/Scenes/SceneManager.cs | 53 ++++++++++++++++++++++++- 4 files changed, 76 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index 620b605..6dea2f0 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -513,8 +513,7 @@ namespace OpenSim.Region.Framework.Scenes /// A region is considered ready when startup operations such as loading of scripts already on the region /// have been completed. /// - public event RegionReady OnRegionReady; - public delegate void RegionReady(IScene scene); + public event Action OnRegionReadyStatusChange; public delegate void PrimsLoaded(Scene s); public event PrimsLoaded OnPrimsLoaded; @@ -2508,13 +2507,13 @@ namespace OpenSim.Region.Framework.Scenes } } - public void TriggerRegionReady(IScene scene) + public void TriggerRegionReadyStatusChange(IScene scene) { - RegionReady handler = OnRegionReady; + Action handler = OnRegionReadyStatusChange; if (handler != null) { - foreach (RegionReady d in handler.GetInvocationList()) + foreach (Action d in handler.GetInvocationList()) { try { @@ -2522,7 +2521,7 @@ namespace OpenSim.Region.Framework.Scenes } catch (Exception e) { - m_log.ErrorFormat("[EVENT MANAGER]: Delegate for OnRegionReady failed - continuing {0} - {1}", + m_log.ErrorFormat("[EVENT MANAGER]: Delegate for OnRegionReadyStatusChange failed - continuing {0} - {1}", e.Message, e.StackTrace); } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index ee34338..20918bd 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1499,8 +1499,8 @@ namespace OpenSim.Region.Framework.Scenes m_sceneGridService.InformNeighborsThatRegionisUp( RequestModuleInterface(), RegionInfo); - // Region ready should always be triggered whether logins are immediately enabled or not. - EventManager.TriggerRegionReady(this); + // Region ready should always be set + Ready = true; } else { diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs index 282fc5e..b87a38a 100644 --- a/OpenSim/Region/Framework/Scenes/SceneBase.cs +++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs @@ -124,6 +124,24 @@ namespace OpenSim.Region.Framework.Scenes } private bool m_loginsEnabled; + public bool Ready + { + get + { + return m_ready; + } + + set + { + if (m_ready != value) + { + m_ready = value; + EventManager.TriggerRegionReadyStatusChange(this); + } + } + } + private bool m_ready; + public float TimeDilation { get { return 1.0f; } diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs index d73a959..c81b55d 100644 --- a/OpenSim/Region/Framework/Scenes/SceneManager.cs +++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs @@ -47,6 +47,48 @@ namespace OpenSim.Region.Framework.Scenes public event RestartSim OnRestartSim; + /// + /// Fired when either all regions are ready for use or at least one region has become unready for use where + /// previously all regions were ready. + /// + public event Action OnRegionsReadyStatusChange; + + /// + /// Are all regions ready for use? + /// + public bool AllRegionsReady + { + get + { + return m_allRegionsReady; + } + + private set + { + if (m_allRegionsReady != value) + { + m_allRegionsReady = value; + Action handler = OnRegionsReadyStatusChange; + if (handler != null) + { + foreach (Action d in handler.GetInvocationList()) + { + try + { + d(this); + } + catch (Exception e) + { + m_log.ErrorFormat("[SCENE MANAGER]: Delegate for OnRegionsReadyStatusChange failed - continuing {0} - {1}", + e.Message, e.StackTrace); + } + } + } + } + } + } + private bool m_allRegionsReady; + private static SceneManager m_instance = null; public static SceneManager Instance { @@ -141,10 +183,11 @@ namespace OpenSim.Region.Framework.Scenes public void Add(Scene scene) { - scene.OnRestart += HandleRestart; - lock (m_localScenes) m_localScenes.Add(scene); + + scene.OnRestart += HandleRestart; + scene.EventManager.OnRegionReadyStatusChange += HandleRegionReadyStatusChange; } public void HandleRestart(RegionInfo rdata) @@ -175,6 +218,12 @@ namespace OpenSim.Region.Framework.Scenes OnRestartSim(rdata); } + private void HandleRegionReadyStatusChange(IScene scene) + { + lock (m_localScenes) + AllRegionsReady = m_localScenes.TrueForAll(s => s.Ready); + } + public void SendSimOnlineNotification(ulong regionHandle) { RegionInfo Result = null; -- cgit v1.1