From 0ee69707ea8c0948b79aeba5dbe078fe28dc6482 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Sat, 24 May 2008 23:11:07 +0000 Subject: * Refactor: Collapse some multiple remove object paths * Push some delete functionality into InnerScene to match what's already there for adding objects --- .../World/TreePopulator/TreePopulatorModule.cs | 2 +- OpenSim/Region/Environment/Scenes/InnerScene.cs | 41 ++++++++++--- .../Region/Environment/Scenes/Scene.Inventory.cs | 8 +-- OpenSim/Region/Environment/Scenes/Scene.cs | 71 +++++++++------------- .../Region/Examples/SimpleModule/ComplexObject.cs | 2 +- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 2 +- 6 files changed, 68 insertions(+), 58 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs b/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs index c56ed08..fc3b9dd 100644 --- a/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs +++ b/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs @@ -179,7 +179,7 @@ namespace OpenSim.Region.Environment.Modules.World.TreePopulator if (Util.RandomClass.NextDouble() < killLikelyhood) { - m_scene.RemoveSceneObject(selectedTree.ParentGroup); + m_scene.DeleteSceneObject(selectedTree.ParentGroup); m_trees.Remove(selectedTree.ParentGroup.UUID); m_scene.ForEachClient(delegate(IClientAPI controller) diff --git a/OpenSim/Region/Environment/Scenes/InnerScene.cs b/OpenSim/Region/Environment/Scenes/InnerScene.cs index 63f7f17..b03ffe2 100644 --- a/OpenSim/Region/Environment/Scenes/InnerScene.cs +++ b/OpenSim/Region/Environment/Scenes/InnerScene.cs @@ -204,18 +204,45 @@ namespace OpenSim.Region.Environment.Scenes /// Add an object to the scene. /// /// - public void AddSceneObject(SceneObjectGroup sceneObject) + /// true if the object was added, false if an object with the same uuid was already in the scene + /// + public bool AddSceneObject(SceneObjectGroup sceneObject) { - if (!Entities.ContainsKey(sceneObject.UUID)) + lock (Entities) { - // QuadTree.AddSceneObject(sceneObject); - lock (Entities) + if (!Entities.ContainsKey(sceneObject.UUID)) { + // QuadTree.AddSceneObject(sceneObject); Entities.Add(sceneObject.UUID, sceneObject); + m_numPrim++; + + return true; } - m_numPrim++; + + return false; } } + + /// + /// Delete an object from the scene + /// + /// + /// true if the object was deleted, false if there was no object to delete + public bool DeleteSceneObject(LLUUID uuid) + { + lock (Entities) + { + if (Entities.ContainsKey(uuid)) + { + Entities.Remove(uuid); + m_numPrim--; + + return true; + } + } + + return false; + } /// /// Add an entity to the list of prims to process on the next update @@ -376,7 +403,6 @@ namespace OpenSim.Region.Environment.Scenes // To LocalId or LLUUID, *THAT* is the question. How now Brown LLUUID?? public void DetachSingleAttachmentToInv(LLUUID itemID, IClientAPI remoteClient) { - if (itemID == LLUUID.Zero) // If this happened, someone made a mistake.... return; @@ -392,11 +418,10 @@ namespace OpenSim.Region.Environment.Scenes group.DetachToInventoryPrep(); m_log.Debug("[DETACH]: Saving attachpoint: " + ((uint)group.GetAttachmentPoint()).ToString()); m_parentScene.updateKnownAsset(remoteClient, group, group.GetFromAssetID(),group.OwnerID); - m_parentScene.DeleteSceneObjectGroup(group); + m_parentScene.DeleteSceneObject(group); } } } - } public void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, LLQuaternion rot, LLVector3 attachPos) diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs index 816b01d..82e112f 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs @@ -1251,14 +1251,12 @@ namespace OpenSim.Region.Environment.Scenes } } - if (permissionToDelete) { - DeleteSceneObjectGroup(objectGroup); + DeleteSceneObject(objectGroup); } } - } - + } } public void updateKnownAsset(IClientAPI remoteClient, SceneObjectGroup grp, LLUUID assetID, LLUUID agentID) @@ -1790,7 +1788,7 @@ namespace OpenSim.Region.Environment.Scenes returnobjects[i] = null; - DeleteSceneObjectGroup(ObjectDeleting); + DeleteSceneObject(ObjectDeleting); ObjectDeleting = null; } else diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index bbe8bd9..e30813c 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -1335,22 +1335,40 @@ namespace OpenSim.Region.Environment.Scenes public void AddSceneObject(SceneObjectGroup sceneObject) { m_innerScene.AddSceneObject(sceneObject); - } + } /// - /// Remove an object from the scene + /// Delete this object from the scene. /// - /// - public void RemoveSceneObject(SceneObjectGroup sceneObject) + /// + public void DeleteSceneObject(SceneObjectGroup group) { - if (Entities.ContainsKey(sceneObject.UUID)) + SceneObjectPart rootPart = (group).GetChildPart(group.UUID); + if (rootPart.PhysActor != null) + { + PhysicsScene.RemovePrim(rootPart.PhysActor); + rootPart.PhysActor = null; + } + + m_storageManager.DataStore.RemoveObject(group.UUID, m_regInfo.RegionID); + group.DeleteGroup(); + + if (m_innerScene.DeleteSceneObject(group.UUID)) { - EventManager.TriggerObjectBeingRemovedFromScene(sceneObject); - Entities.Remove(sceneObject.UUID); + EventManager.TriggerObjectBeingRemovedFromScene(group); EventManager.TriggerParcelPrimCountTainted(); - m_innerScene.RemoveAPrimCount(); } - } + + group.DeleteParts(); + + // In case anybody else retains a reference to this group, signal deletion by changing the name + // to null. We can't zero out the UUID because this is taken from the root part, which has already + // been removed. + // FIXME: This is a really poor temporary solution, since it still leaves plenty of scope for race + // conditions where a user deletes an entity while it is being stored. Really, the update + // code needs a redesign. + group.Name = null; + } public void LoadPrimsFromXml(string fileName, bool newIdsFlag, LLVector3 loadOffset) { @@ -1411,7 +1429,7 @@ namespace OpenSim.Region.Environment.Scenes // We remove the object here try { - DeleteSceneObjectGroup(grp); + DeleteSceneObject(grp); } catch (Exception) { @@ -1473,7 +1491,7 @@ namespace OpenSim.Region.Environment.Scenes // We remove the object here try { - DeleteSceneObjectGroup(grp); + DeleteSceneObject(grp); } catch (Exception) { @@ -3142,37 +3160,6 @@ namespace OpenSim.Region.Environment.Scenes } /// - /// Delete this object from the scene. - /// - /// - public void DeleteSceneObjectGroup(SceneObjectGroup group) - { - SceneObjectPart rootPart = (group).GetChildPart(group.UUID); - if (rootPart.PhysActor != null) - { - PhysicsScene.RemovePrim(rootPart.PhysActor); - rootPart.PhysActor = null; - } - - m_storageManager.DataStore.RemoveObject(group.UUID, m_regInfo.RegionID); - group.DeleteGroup(); - - lock (Entities) - { - RemoveSceneObject(group); - } - group.DeleteParts(); - - // In case anybody else retains a reference to this group, signal deletion by changing the name - // to null. We can't zero out the UUID because this is taken from the root part, which has already - // been removed. - // FIXME: This is a really poor temporary solution, since it still leaves plenty of scope for race - // conditions where a user deletes an entity while it is being stored. Really, the update - // code needs a redesign. - group.Name = null; - } - - /// /// /// /// diff --git a/OpenSim/Region/Examples/SimpleModule/ComplexObject.cs b/OpenSim/Region/Examples/SimpleModule/ComplexObject.cs index 87a5ffc..d83bba6 100644 --- a/OpenSim/Region/Examples/SimpleModule/ComplexObject.cs +++ b/OpenSim/Region/Examples/SimpleModule/ComplexObject.cs @@ -126,7 +126,7 @@ namespace OpenSim.Region.Examples.SimpleModule if (m_parts.Count == 1) { m_parts.Remove(m_rootPart.UUID); - m_scene.RemoveSceneObject(this); + m_scene.DeleteSceneObject(this); remoteClient.SendKillObject(m_regionHandle, m_rootPart.LocalId); remoteClient.AddMoney(50); remoteClient.SendChatMessage("KABLAM!!!", 1, AbsolutePosition, "Groupie Groupie", LLUUID.Zero, (byte)ChatSourceType.Object, (byte)ChatAudibleLevel.Fully); diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index ab91424..3fa65f5 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -704,7 +704,7 @@ namespace OpenSim.Region.ScriptEngine.Common public void llDie() { m_host.AddScriptLPS(1); - World.DeleteSceneObjectGroup(m_host.ParentGroup); + World.DeleteSceneObject(m_host.ParentGroup); } public double llGround(LSL_Types.Vector3 offset) -- cgit v1.1