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.
dsg
Huaiyu (Kitty) Liu 2010-12-23 15:42:05 -08:00
parent d0b429c186
commit e68a8f7710
7 changed files with 54 additions and 36 deletions

View File

@ -272,6 +272,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
m_log.Warn("[REGION SYNC MODULE]: StatsTimerElapsed -- NOT yet implemented."); 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) public void OnPostSceneCreation(Scene createdScene)
{ {
//If this is the local scene the actor is working on, find out the actor type. //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; return;
} }
m_actorType = m_scene.ActorSyncModule.ActorType; 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) 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; 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)) if (m_scene.AddNewSceneObject(sog, attachToBackup))
{ {
m_log.Debug(LogHeader + ": added obj " + sog.UUID); m_log.Debug(LogHeader + ": added obj " + sog.UUID);

View File

@ -73,6 +73,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
//Register for the OnPostSceneCreation event //Register for the OnPostSceneCreation event
//m_scene.EventManager.OnPostSceneCreation += OnPostSceneCreation; //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. //Called after AddRegion() has been called for all region modules of the scene.
@ -137,6 +140,20 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
{ {
} }
} }
/// <summary>
/// ScenePersistence's actions upon an object is added to the local scene.
/// </summary>
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 #endregion //ScenePersistenceSyncModule
} }

View File

@ -74,6 +74,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
//Register for the OnPostSceneCreation event //Register for the OnPostSceneCreation event
//m_scene.EventManager.OnPostSceneCreation += OnPostSceneCreation; //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. //Called after AddRegion() has been called for all region modules of the scene.
@ -136,6 +139,21 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
{ {
} }
} }
/// <summary>
/// Script Engine's action upon an object is added to the local scene
/// </summary>
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 #endregion //ScriptEngineSyncModule
} }

View File

@ -117,20 +117,22 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
// Create a thread for the receive loop // Create a thread for the receive loop
m_rcvLoop = new Thread(new ThreadStart(ReceiveLoop)); m_rcvLoop = new Thread(new ThreadStart(ReceiveLoop));
m_rcvLoop.Name = Description + " (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(); m_rcvLoop.Start();
// Create a thread for the send loop // Create a thread for the send loop
m_send_loop = new Thread(new ThreadStart(delegate() { SendLoop(); })); m_send_loop = new Thread(new ThreadStart(delegate() { SendLoop(); }));
m_send_loop.Name = Description + " (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(); m_send_loop.Start();
} }
public void Shutdown() public void Shutdown()
{ {
// The remote scene will remove our avatars automatically when we disconnect m_log.Warn(LogHeader + " shutdown connection");
//m_rcvLoop.Abort(); // Abort receive and send loop
m_rcvLoop.Abort();
m_send_loop.Abort();
// Close the connection // Close the connection
m_tcpConnection.Client.Close(); m_tcpConnection.Client.Close();
@ -157,7 +159,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
} }
catch (Exception e) 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(); Shutdown();
} }
@ -208,7 +210,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
} }
catch (IOException) 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 catch
{ {
//ShutdownClient(); //ShutdownClient();
m_log.WarnFormat("{0}:{1} has disconnected.", Description, m_connectorNum);
Shutdown(); Shutdown();
return; return;
} }
@ -242,7 +245,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
} }
catch (Exception e) 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());
} }
} }
} }

View File

@ -2256,7 +2256,6 @@ namespace OpenSim.Region.Framework.Scenes
{ {
try try
{ {
m_log.Warn("TriggerOnPostSceneCreation");
d(createdScene); d(createdScene);
} }
catch (Exception e) catch (Exception e)

View File

@ -1293,15 +1293,6 @@ namespace OpenSim.Region.Framework.Scenes
//SYMMETRIC SYNC (KittyL: started 12/23/2010) //SYMMETRIC SYNC (KittyL: started 12/23/2010)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
m_regionSyncModule = RequestModuleInterface<IRegionSyncModule>(); m_regionSyncModule = RequestModuleInterface<IRegionSyncModule>();
if (m_regionSyncModule == null)
{
m_log.Warn("Does not find a RegionSyncModule interface");
}
else
{
m_log.Warn("SetModuleInterfaces: RegionSyncModule interface set.");
}
m_DSGActorSyncModule = RequestModuleInterface<IDSGActorSyncModule>(); m_DSGActorSyncModule = RequestModuleInterface<IDSGActorSyncModule>();
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

View File

@ -373,24 +373,14 @@ namespace OpenSim.Region.Framework.Scenes
sceneObject.AttachToScene(m_parentScene); sceneObject.AttachToScene(m_parentScene);
//KittyL: edited to support script engine actor
//if (sendClientUpdates)
// sceneObject.ScheduleGroupForFullUpdate();
if (sendClientUpdates) if (sendClientUpdates)
{
sceneObject.ScheduleGroupForFullUpdate(); sceneObject.ScheduleGroupForFullUpdate();
}
Entities.Add(sceneObject); Entities.Add(sceneObject);
//KittyL: edited to support script engine actor if (attachToBackup)
//if (attachToBackup)
// sceneObject.AttachToBackup();
if (attachToBackup && m_parentScene.IsAuthoritativeScene())
{
sceneObject.AttachToBackup(); sceneObject.AttachToBackup();
}
if (OnObjectCreate != null) if (OnObjectCreate != null)
OnObjectCreate(sceneObject); OnObjectCreate(sceneObject);