From ebd9f22b29bfbe0cfb0689405984f856e0413405 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 7 Nov 2008 18:46:11 +0000 Subject: * refactor: allocate local ids to prims only when an object is attached to a scene --- .../Archiver/ArchiveWriteRequestPreparation.cs | 2 +- .../Modules/World/Serialiser/SceneXmlLoader.cs | 2 +- .../Region/Environment/Scenes/Scene.Inventory.cs | 8 +++-- OpenSim/Region/Environment/Scenes/Scene.cs | 2 +- .../Region/Environment/Scenes/SceneObjectGroup.cs | 42 +++++++++++++++------- 5 files changed, 37 insertions(+), 19 deletions(-) (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs index 1fbc20f..0202841 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs @@ -176,7 +176,7 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver if (null != objectAsset) { string xml = Utils.BytesToString(objectAsset.Data); - SceneObjectGroup sog = new SceneObjectGroup(m_scene, m_scene.RegionInfo.RegionHandle, xml); + SceneObjectGroup sog = new SceneObjectGroup(xml, true); GetSceneObjectAssetUuids(sog, assetUuids); } } diff --git a/OpenSim/Region/Environment/Modules/World/Serialiser/SceneXmlLoader.cs b/OpenSim/Region/Environment/Modules/World/Serialiser/SceneXmlLoader.cs index af69707..a069ac3 100644 --- a/OpenSim/Region/Environment/Modules/World/Serialiser/SceneXmlLoader.cs +++ b/OpenSim/Region/Environment/Modules/World/Serialiser/SceneXmlLoader.cs @@ -58,7 +58,7 @@ namespace OpenSim.Region.Environment.Scenes rootNode = doc.FirstChild; foreach (XmlNode aPrimNode in rootNode.ChildNodes) { - SceneObjectGroup obj = new SceneObjectGroup(scene, scene.RegionInfo.RegionHandle, aPrimNode.OuterXml); + SceneObjectGroup obj = new SceneObjectGroup(aPrimNode.OuterXml, true); if (newIDS) { diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs index c59fffc..4e93551 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs @@ -1953,8 +1953,10 @@ namespace OpenSim.Region.Environment.Scenes if (rezAsset != null) { string xmlData = Utils.BytesToString(rezAsset.Data); - SceneObjectGroup group = new SceneObjectGroup(this, m_regionHandle, xmlData); - if (!ExternalChecks.ExternalChecksCanRezObject(group.Children.Count, remoteClient.AgentId, pos) && !attachment) + SceneObjectGroup group = new SceneObjectGroup(xmlData, true); + if (!ExternalChecks.ExternalChecksCanRezObject( + group.Children.Count, remoteClient.AgentId, pos) + && !attachment) { return null; } @@ -2091,7 +2093,7 @@ namespace OpenSim.Region.Environment.Scenes if (rezAsset != null) { string xmlData = Utils.BytesToString(rezAsset.Data); - SceneObjectGroup group = new SceneObjectGroup(this, m_regionHandle, xmlData); + SceneObjectGroup group = new SceneObjectGroup(xmlData, true); if (!ExternalChecks.ExternalChecksCanRezObject(group.Children.Count, ownerID, pos)) { diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 40f8605..95d9f2a 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -1890,7 +1890,7 @@ namespace OpenSim.Region.Environment.Scenes public void LoadPrimsFromXml(string fileName, bool newIdsFlag, Vector3 loadOffset) { - m_log.InfoFormat("[SCENE]: Loading prims in xml format to region {0} from {1}", RegionInfo.RegionName); + m_log.InfoFormat("[SCENE]: Loading prims in xml format to region {0} from {1}", RegionInfo.RegionName, fileName); m_serialiser.LoadPrimsFromXml(this, fileName, newIdsFlag, loadOffset); } diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs index a19564f..5926445 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs @@ -381,10 +381,16 @@ namespace OpenSim.Region.Environment.Scenes /// /// Create an object using serialized data in OpenSim's original xml format. /// - public SceneObjectGroup(Scene scene, ulong regionHandle, string xmlData) - { - m_scene = scene; - m_regionHandle = regionHandle; + /// + /// + /// This parameter only exists to separate the two different xml constructors. In the future, versions should + /// be specified within the xml itself. + /// + public SceneObjectGroup(string xmlData, bool isOriginalXmlFormat) + { + if (!isOriginalXmlFormat) + throw new Exception("This constructor must specify the xml is in OpenSim's original format"); + // libomv.types changes UUID to Guid xmlData = xmlData.Replace("", ""); xmlData = xmlData.Replace("", ""); @@ -416,16 +422,15 @@ namespace OpenSim.Region.Environment.Scenes { reader.Read(); SceneObjectPart part = SceneObjectPart.FromXml(reader); - part.LocalId = m_scene.PrimIDAllocate(); linkNum = part.LinkNum; AddPart(part); part.LinkNum = linkNum; - part.RegionHandle = m_regionHandle; part.TrimPermissions(); part.StoreUndoState(); } break; + case XmlNodeType.EndElement: break; } @@ -440,11 +445,6 @@ namespace OpenSim.Region.Environment.Scenes reader.Close(); sr.Close(); - - m_rootPart.LocalId = m_scene.PrimIDAllocate(); - m_rootPart.ParentID = 0; - m_rootPart.RegionHandle = m_regionHandle; - UpdateParentIDs(); } /// @@ -570,8 +570,24 @@ namespace OpenSim.Region.Environment.Scenes /// public void AttachToScene(Scene scene) { - m_scene = scene; - RegionHandle = scene.RegionInfo.RegionHandle; + m_scene = scene; + RegionHandle = m_scene.RegionInfo.RegionHandle; + + m_rootPart.ParentID = 0; + m_rootPart.LocalId = m_scene.PrimIDAllocate(); + + //UpdateParentIDs(); + + // No need to lock here since part isn't yet in a scene + foreach (SceneObjectPart part in m_parts.Values) + { + if (Object.ReferenceEquals(part, m_rootPart)) + continue; + + part.LocalId = m_scene.PrimIDAllocate(); + part.ParentID = m_rootPart.LocalId; + m_log.DebugFormat("[SCENE]: Given local id {0} to part {1}, linknum {2}, parent {3} {4}", part.LocalId, part.UUID, part.LinkNum, part.ParentID, part.ParentUUID); + } ApplyPhysics(m_scene.m_physicalPrim); -- cgit v1.1