From d011896341d09ce6c10a801264e663b6a19f0b48 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Wed, 23 Mar 2011 21:50:56 +0000
Subject: Add generic EventManager.OnObjectAddedToScene and get PrimCountModule
to listen for that rather than EventManager.OnParcelPrimCountAdd
OnParcelPrimCountAdd had the wrong semantics for the PrimCountModule - it was invoked for every entity in the scene, not just new ones, which would screw up the untainted count.
Extend automated test for this scenario.
---
OpenSim/Region/Framework/Scenes/EventManager.cs | 30 +++++++++++++++++++++++++
OpenSim/Region/Framework/Scenes/Scene.cs | 18 ++++++++++++---
2 files changed, 45 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Region/Framework')
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index c321a15..fd62535 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -242,7 +242,15 @@ namespace OpenSim.Region.Framework.Scenes
public delegate void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID);
public event EstateToolsSunUpdate OnEstateToolsSunUpdate;
+
+ ///
+ /// Triggered when an object is added to the scene.
+ ///
+ public event Action OnObjectAddedToScene;
+ ///
+ /// Triggered when an object is removed from the scene.
+ ///
public delegate void ObjectBeingRemovedFromScene(SceneObjectGroup obj);
public event ObjectBeingRemovedFromScene OnObjectBeingRemovedFromScene;
@@ -345,6 +353,7 @@ namespace OpenSim.Region.Framework.Scenes
public delegate void Attach(uint localID, UUID itemID, UUID avatarID);
public event Attach OnAttach;
+
///
/// Called immediately after an object is loaded from storage.
///
@@ -800,6 +809,27 @@ namespace OpenSim.Region.Framework.Scenes
}
}
+ public void TriggerObjectAddedToScene(SceneObjectGroup obj)
+ {
+ Action handler = OnObjectAddedToScene;
+ if (handler != null)
+ {
+ foreach (Action d in handler.GetInvocationList())
+ {
+ try
+ {
+ d(obj);
+ }
+ catch (Exception e)
+ {
+ m_log.ErrorFormat(
+ "[EVENT MANAGER]: Delegate for TriggerObjectAddedToScene failed - continuing. {0} {1}",
+ e.Message, e.StackTrace);
+ }
+ }
+ }
+ }
+
public void TriggerObjectBeingRemovedFromScene(SceneObjectGroup obj)
{
ObjectBeingRemovedFromScene handlerObjectBeingRemovedFromScene = OnObjectBeingRemovedFromScene;
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 4d2519d..d407a6f 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -1956,8 +1956,14 @@ namespace OpenSim.Region.Framework.Scenes
/// If false, it is left to the caller to schedule the update
///
public bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates)
- {
- return m_sceneGraph.AddNewSceneObject(sceneObject, attachToBackup, sendClientUpdates);
+ {
+ if (m_sceneGraph.AddNewSceneObject(sceneObject, attachToBackup, sendClientUpdates))
+ {
+ EventManager.TriggerObjectAddedToScene(sceneObject);
+ return true;
+ }
+
+ return false;
}
///
@@ -1974,7 +1980,13 @@ namespace OpenSim.Region.Framework.Scenes
public bool AddNewSceneObject(
SceneObjectGroup sceneObject, bool attachToBackup, Vector3 pos, Quaternion rot, Vector3 vel)
{
- return m_sceneGraph.AddNewSceneObject(sceneObject, attachToBackup, pos, rot, vel);
+ if (m_sceneGraph.AddNewSceneObject(sceneObject, attachToBackup, pos, rot, vel))
+ {
+ EventManager.TriggerObjectAddedToScene(sceneObject);
+ return true;
+ }
+
+ return false;
}
///
--
cgit v1.1