From 9f6c0e7622165f5bb4e92fd2420eee854a56171d Mon Sep 17 00:00:00 2001 From: "Huaiyu (Kitty) Liu" Date: Tue, 10 May 2011 16:27:25 -0700 Subject: [PATCH] Added code to handle the case where attachement objects are received, but the avatar they attach to is not created locally yet. --- .../SymmetricSync/RegionSyncModule.cs | 87 ++++++++++++++----- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 8 +- .../Framework/Scenes/SceneObjectGroup.cs | 2 +- 3 files changed, 74 insertions(+), 23 deletions(-) diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs index b0af4a6488..841562c89d 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs @@ -132,6 +132,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_scene.EventManager.OnPostSceneCreation += OnPostSceneCreation; //m_scene.EventManager.OnObjectBeingRemovedFromScene += new EventManager.ObjectBeingRemovedFromScene(RegionSyncModule_OnObjectBeingRemovedFromScene); + m_scene.EventManager.OnNewPresence += OnNewPresence; + LogHeader += "-LocalRegion " + scene.RegionInfo.RegionName; m_syncID = GetSyncID(); @@ -1777,6 +1779,25 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule SyncStart(null); } + private void OnNewPresence(ScenePresence avatar) + { + //Go through the objects, if any of them are attachments of the + //new avatar, link them. + EntityBase[] entities = m_scene.GetEntities(); + foreach (EntityBase e in entities) + { + if (e is SceneObjectGroup) + { + SceneObjectGroup sog = (SceneObjectGroup)e; + if (sog.RootPart.AttachedAvatar == avatar.UUID) + { + sog.RootPart.SetParentLocalId(avatar.LocalId); + } + } + } + + } + private void StartLocalSyncListener() { RegionSyncListenerInfo localSyncListenerInfo = GetLocalSyncListenerInfo(); @@ -4911,23 +4932,28 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule private static HashSet PrimNonPhysActorProperties = SceneObjectPart.GetAllPrimNonPhysActorProperties(); private static HashSet GroupProperties = SceneObjectPart.GetGroupProperties(); + private PrimSyncInfoManager m_syncInfoManager; + #endregion //Members #region Constructors - public PrimSyncInfo(SceneObjectPart part, long initUpdateTimestamp, string syncID) + public PrimSyncInfo(SceneObjectPart part, long initUpdateTimestamp, string syncID, PrimSyncInfoManager manager) { m_UUID = part.UUID; + m_syncInfoManager = manager; InitPropertiesSyncInfo(part, initUpdateTimestamp, syncID); } - public PrimSyncInfo() + public PrimSyncInfo(PrimSyncInfoManager manager) { + m_syncInfoManager = manager; } - public PrimSyncInfo(UUID id, OSDMap primSyncInfoData) + public PrimSyncInfo(UUID id, OSDMap primSyncInfoData, PrimSyncInfoManager manager) { m_UUID = id; + m_syncInfoManager = manager; InitPropertiesSyncInfoFromOSDMap(primSyncInfoData); } @@ -4938,18 +4964,6 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_propertiesSyncInfo[property].UpdateSyncInfoByLocal(lastUpdateTS, syncID, pValue, pHashedValue); } - /* - public void UpdatePropertyByLocal(SceneObjectPartSyncProperties property, long lastUpdateTS, string syncID, Object pValue) - { - m_propertiesSyncInfo[property].UpdateSyncInfoByLocal(lastUpdateTS, syncID, pValue); - } - * */ - - //public void UpdatePropertySyncInfoBySync(SceneObjectPartSyncProperties property, long lastUpdateTS, string syncID, Object pValue, Object pHashedValue, long recvTS) - //{ - // m_propertiesSyncInfo[property].UpdateSyncInfoBySync(lastUpdateTS, syncID, recvTS, pValue); - //} - //Triggered when a set of local writes just happened, and ScheduleFullUpdate //or ScheduleTerseUpdate has been called. /// @@ -5231,6 +5245,11 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } } + private Scene GetLocalScene() + { + return m_syncInfoManager.GetLocalScene(); + } + /// /// Initialize the properties with the values in the given SOP. /// @@ -6723,11 +6742,32 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule case SceneObjectPartSyncProperties.AttachedAvatar: //part.AttachedAvatar = (UUID)pSyncInfo.LastUpdateValue; UUID attachedAvatar = (UUID)pSyncInfo.LastUpdateValue; - if (!part.AttachedAvatar.Equals(attachedAvatar) && part.ParentGroup !=null) + if (!part.AttachedAvatar.Equals(attachedAvatar)) { part.AttachedAvatar = attachedAvatar; - ScenePresence avatar = part.ParentGroup.Scene.GetScenePresence(attachedAvatar); - part.ParentGroup.RootPart.SetParentLocalId(avatar.LocalId); + Scene localScene = GetLocalScene(); + ScenePresence avatar = localScene.GetScenePresence(attachedAvatar); + //It is possible that the avatar has not been fully + //created locally when attachment objects are sync'ed. + //So we need to check if the avatar already exists. + //If not, handling of NewAvatar will evetually trigger + //calling of SetParentLocalId. + if (avatar != null) + { + if (part.ParentGroup != null) + { + part.ParentGroup.RootPart.SetParentLocalId(avatar.LocalId); + } + else + { + //If this SOP is not a part of group yet, record the + //avatar's localID for now. If this SOP is rootpart of + //the group, then the localID is the right setting; + //otherwise, this SOP will be linked to the SOG it belongs + //to later, and that will rewrite the parent localID. + part.SetParentLocalId(avatar.LocalId); + } + } } break; case SceneObjectPartSyncProperties.AttachedPos: @@ -7097,6 +7137,11 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule return m_primsInSync.ContainsKey(primUUID); } + public Scene GetLocalScene() + { + return m_regionSyncModule.LocalScene; + } + /// /// For each property in updatedProperties, (1) if the value in SOP's /// data is different than that in PrimSyncInfo, and what's in PrimSyncInfo @@ -7120,7 +7165,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //The SOP's SyncInfo is no longer in my record, may due to //TimeOut or something. Add it back. Assume the properties //were "AgeOut" seconds old. - PrimSyncInfo primSyncInfo = new PrimSyncInfo(part, currentTime, m_regionSyncModule.SyncID); + PrimSyncInfo primSyncInfo = new PrimSyncInfo(part, currentTime, m_regionSyncModule.SyncID, this); InsertPrimSyncInfo(part.UUID, primSyncInfo); return new HashSet(updatedProperties); @@ -7214,7 +7259,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule UUID primUUID = primData["primUUID"]; OSDMap propertyData = (OSDMap)primData["propertyData"]; - PrimSyncInfo primSynInfo = new PrimSyncInfo(primUUID, propertyData); + PrimSyncInfo primSynInfo = new PrimSyncInfo(primUUID, propertyData, this); return primSynInfo; } @@ -7259,7 +7304,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule { long lastUpdateTimeStamp = syncInfoInitTime - m_ageOutThreshold; - PrimSyncInfo primSyncInfo = new PrimSyncInfo(part, lastUpdateTimeStamp, syncID); + PrimSyncInfo primSyncInfo = new PrimSyncInfo(part, lastUpdateTimeStamp, syncID, this); lock (m_primsInSyncLock) { if (m_primsInSync.ContainsKey(part.UUID)) diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index 0a4c1900d2..f5f4c6ac41 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -2175,7 +2175,13 @@ namespace OpenSim.Region.Framework.Scenes if (sceneObject.IsAttachment) { ScenePresence avatar = m_parentScene.GetScenePresence(sceneObject.RootPart.AttachedAvatar); - sceneObject.RootPart.SetParentLocalId(avatar.LocalId); + //It is possible that the avatar has not been fully + //created locally when attachment objects are sync'ed. + //So we need to check if the avatar already exists. + //If not, handling of NewAvatar will evetually trigger + //calling of SetParentLocalId. + if(avatar!=null) + sceneObject.RootPart.SetParentLocalId(avatar.LocalId); } sceneObject.HasGroupChanged = true; diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index df462aac7c..5e398af2d8 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1061,7 +1061,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// - private void SetPartAsNonRoot(SceneObjectPart part) + public void SetPartAsNonRoot(SceneObjectPart part) { part.ParentID = m_rootPart.LocalId; part.ClearUndoState();