From e68a8f771048e47034626329e0be160038310430 Mon Sep 17 00:00:00 2001 From: "Huaiyu (Kitty) Liu" Date: Thu, 23 Dec 2010 15:42:05 -0800 Subject: [PATCH] Added handlers to SceneGraph.OnObjectCreate event in both ScenePersistenceSyncModule and ScriptEngineSyncModule, so that they can apply actor specific operations once an object is added to the local Scene. --- .../SymmetricSync/RegionSyncModule.cs | 12 ++++++------ .../ScenePersistenceSyncModule.cs | 17 +++++++++++++++++ .../SymmetricSync/ScriptEngineSyncModule.cs | 18 ++++++++++++++++++ .../SymmetricSync/SyncConnector.cs | 17 ++++++++++------- .../Region/Framework/Scenes/EventManager.cs | 1 - OpenSim/Region/Framework/Scenes/Scene.cs | 9 --------- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 16 +++------------- 7 files changed, 54 insertions(+), 36 deletions(-) diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs index e72fefa9ce..23417dbfba 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs @@ -272,6 +272,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_log.Warn("[REGION SYNC MODULE]: StatsTimerElapsed -- NOT yet implemented."); } + //NOTE: We proably don't need to do this, and there might not be a need for OnPostSceneCreation event to let RegionSyncModule + // and ActorSyncModules to gain some access to each other. We'll keep it here for a while, until we are sure it's not + // needed. + // Now the communication between RegionSyncModule and ActorSyncModules are through SceneGraph or Scene.EventManager events. public void OnPostSceneCreation(Scene createdScene) { //If this is the local scene the actor is working on, find out the actor type. @@ -282,7 +286,6 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule return; } m_actorType = m_scene.ActorSyncModule.ActorType; - m_log.Warn(LogHeader + " informed about ActorType: "+m_actorType); } } @@ -569,13 +572,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule private void HandleAddNewObject(SceneObjectGroup sog) { + //RegionSyncModule only add object to SceneGraph. Any actor specific actions will be implemented + //by each ActorSyncModule, which would be triggered its subcription to event SceneGraph.OnObjectCreate. bool attachToBackup = false; - //only need to persist the scene if this is the ScenePersistence - if (m_actorType == DSGActorTypes.ScenePersistence) - { - attachToBackup = true; - } if (m_scene.AddNewSceneObject(sog, attachToBackup)) { m_log.Debug(LogHeader + ": added obj " + sog.UUID); diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScenePersistenceSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScenePersistenceSyncModule.cs index ad0d6ba006..c8e165fb20 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScenePersistenceSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScenePersistenceSyncModule.cs @@ -73,6 +73,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //Register for the OnPostSceneCreation event //m_scene.EventManager.OnPostSceneCreation += OnPostSceneCreation; + + //Register for Scene/SceneGraph events + m_scene.SceneGraph.OnObjectCreate += new ObjectCreateDelegate(ScenePersistence_OnObjectCreate); } //Called after AddRegion() has been called for all region modules of the scene. @@ -137,6 +140,20 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule { } } + + /// + /// ScenePersistence's actions upon an object is added to the local scene. + /// + private void ScenePersistence_OnObjectCreate(EntityBase entity) + { + if (entity is SceneObjectGroup) + { + m_log.Warn(LogHeader + ": link to backup for " + entity.UUID); + SceneObjectGroup sog = (SceneObjectGroup)entity; + sog.AttachToBackup(); + } + } + #endregion //ScenePersistenceSyncModule } diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs index f80f8a7c95..cde08746d2 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs @@ -74,6 +74,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //Register for the OnPostSceneCreation event //m_scene.EventManager.OnPostSceneCreation += OnPostSceneCreation; + + //Register for Scene/SceneGraph events + m_scene.SceneGraph.OnObjectCreate += new ObjectCreateDelegate(ScriptEngine_OnObjectCreate); } //Called after AddRegion() has been called for all region modules of the scene. @@ -136,6 +139,21 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule { } } + + /// + /// Script Engine's action upon an object is added to the local scene + /// + private void ScriptEngine_OnObjectCreate(EntityBase entity) + { + if (entity is SceneObjectGroup) + { + m_log.Warn(LogHeader + ": start script for obj " + entity.UUID); + SceneObjectGroup sog = (SceneObjectGroup)entity; + sog.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, 0); + sog.ResumeScripts(); + } + } + #endregion //ScriptEngineSyncModule } diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SyncConnector.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SyncConnector.cs index 935d7db7b8..cf2f0654e6 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SyncConnector.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SyncConnector.cs @@ -117,20 +117,22 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule // Create a thread for the receive loop m_rcvLoop = new Thread(new ThreadStart(ReceiveLoop)); m_rcvLoop.Name = Description + " (ReceiveLoop)"; - m_log.WarnFormat("{0} Starting {1} thread", LogHeader, m_rcvLoop.Name); + m_log.WarnFormat("{0} Starting {1} thread", Description, m_rcvLoop.Name); m_rcvLoop.Start(); // Create a thread for the send loop m_send_loop = new Thread(new ThreadStart(delegate() { SendLoop(); })); m_send_loop.Name = Description + " (SendLoop)"; - m_log.WarnFormat("{0} Starting {1} thread", LogHeader, m_send_loop.Name); + m_log.WarnFormat("{0} Starting {1} thread", Description, m_send_loop.Name); m_send_loop.Start(); } public void Shutdown() { - // The remote scene will remove our avatars automatically when we disconnect - //m_rcvLoop.Abort(); + m_log.Warn(LogHeader + " shutdown connection"); + // Abort receive and send loop + m_rcvLoop.Abort(); + m_send_loop.Abort(); // Close the connection m_tcpConnection.Client.Close(); @@ -157,7 +159,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } catch (Exception e) { - m_log.ErrorFormat("{0} has disconnected: {1} (SendLoop)", LogHeader, e.Message); + m_log.ErrorFormat("{0} has disconnected: {1} (SendLoop)", Description, e.Message); } Shutdown(); } @@ -208,7 +210,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } catch (IOException) { - m_log.WarnFormat("{0}:{1} has disconnected.", LogHeader, m_connectorNum); + m_log.WarnFormat("{0}:{1} has disconnected.", Description, m_connectorNum); } } } @@ -232,6 +234,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule catch { //ShutdownClient(); + m_log.WarnFormat("{0}:{1} has disconnected.", Description, m_connectorNum); Shutdown(); return; } @@ -242,7 +245,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } catch (Exception e) { - m_log.WarnFormat("{0} Encountered an exception: {1} (MSGTYPE = {2})", LogHeader, e.Message, msg.ToString()); + m_log.WarnFormat("{0} Encountered an exception: {1} (MSGTYPE = {2})", Description, e.Message, msg.ToString()); } } } diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index a755d0347d..db1e27f336 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -2256,7 +2256,6 @@ namespace OpenSim.Region.Framework.Scenes { try { - m_log.Warn("TriggerOnPostSceneCreation"); d(createdScene); } catch (Exception e) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index fcc7ab09aa..7ca1980976 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1293,15 +1293,6 @@ namespace OpenSim.Region.Framework.Scenes //SYMMETRIC SYNC (KittyL: started 12/23/2010) ////////////////////////////////////////////////////////////////////// m_regionSyncModule = RequestModuleInterface(); - if (m_regionSyncModule == null) - { - m_log.Warn("Does not find a RegionSyncModule interface"); - } - else - { - m_log.Warn("SetModuleInterfaces: RegionSyncModule interface set."); - } - m_DSGActorSyncModule = RequestModuleInterface(); ////////////////////////////////////////////////////////////////////// diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index 8a410600d5..c91f205ee3 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -373,24 +373,14 @@ namespace OpenSim.Region.Framework.Scenes sceneObject.AttachToScene(m_parentScene); - //KittyL: edited to support script engine actor - //if (sendClientUpdates) - // sceneObject.ScheduleGroupForFullUpdate(); if (sendClientUpdates) - { sceneObject.ScheduleGroupForFullUpdate(); - } - + Entities.Add(sceneObject); - //KittyL: edited to support script engine actor - //if (attachToBackup) - // sceneObject.AttachToBackup(); - if (attachToBackup && m_parentScene.IsAuthoritativeScene()) - { + if (attachToBackup) sceneObject.AttachToBackup(); - } - + if (OnObjectCreate != null) OnObjectCreate(sceneObject);