From 56d894ae2428955ca0a86d5c4e1dfe024e548141 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 10 Jul 2012 23:50:04 +0100 Subject: [PATCH] refactor: move management of SOP.SitTargetAvatar into SOP.AddSittingAvatar() and SOP.RemoveSittingAvatar() --- .../Framework/Scenes/SceneObjectPart.cs | 6 +++ .../Region/Framework/Scenes/ScenePresence.cs | 51 +++++++------------ 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index f32350248f..acc25a2b67 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -4835,6 +4835,9 @@ namespace OpenSim.Region.Framework.Scenes /// protected internal bool AddSittingAvatar(UUID avatarId) { + if (IsSitTargetSet && SitTargetAvatar == UUID.Zero) + SitTargetAvatar = avatarId; + HashSet sittingAvatars = m_sittingAvatars; if (sittingAvatars == null) @@ -4857,6 +4860,9 @@ namespace OpenSim.Region.Framework.Scenes /// protected internal bool RemoveSittingAvatar(UUID avatarId) { + if (SitTargetAvatar == avatarId) + SitTargetAvatar = UUID.Zero; + HashSet sittingAvatars = m_sittingAvatars; // This can occur under a race condition where another thread diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 3885cb4d44..0f49fefc5c 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -519,19 +519,12 @@ namespace OpenSim.Region.Framework.Scenes // in the sim unless the avatar is on a sit target. While // on a sit target, m_pos will contain the desired offset // without the parent rotation applied. - if (ParentID != 0) - { - SceneObjectPart part = m_scene.GetSceneObjectPart(ParentID); - if (part != null) - { - return part.AbsolutePosition + (m_pos * part.GetWorldRotation()); - } - else - { - return ParentPosition + m_pos; - } - } + SceneObjectPart sitPart = ParentPart; + + if (sitPart != null) + return sitPart.AbsolutePosition + (m_pos * sitPart.GetWorldRotation()); } + return m_pos; } set @@ -1846,36 +1839,30 @@ namespace OpenSim.Region.Framework.Scenes if (ParentID != 0) { - SceneObjectPart part = m_scene.GetSceneObjectPart(ParentID); - if (part != null) + SceneObjectPart part = ParentPart; + TaskInventoryDictionary taskIDict = part.TaskInventory; + if (taskIDict != null) { - TaskInventoryDictionary taskIDict = part.TaskInventory; - if (taskIDict != null) + lock (taskIDict) { - lock (taskIDict) + foreach (UUID taskID in taskIDict.Keys) { - foreach (UUID taskID in taskIDict.Keys) - { - UnRegisterControlEventsToScript(LocalId, taskID); - taskIDict[taskID].PermsMask &= ~( - 2048 | //PERMISSION_CONTROL_CAMERA - 4); // PERMISSION_TAKE_CONTROLS - } + UnRegisterControlEventsToScript(LocalId, taskID); + taskIDict[taskID].PermsMask &= ~( + 2048 | //PERMISSION_CONTROL_CAMERA + 4); // PERMISSION_TAKE_CONTROLS } } - - // Reset sit target. - if (part.SitTargetAvatar == UUID) - part.SitTargetAvatar = UUID.Zero; - - ParentPosition = part.GetWorldPosition(); - ControllingClient.SendClearFollowCamProperties(part.ParentUUID); } + ParentPosition = part.GetWorldPosition(); + ControllingClient.SendClearFollowCamProperties(part.ParentUUID); + m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight); ParentPosition = Vector3.Zero; ParentID = 0; + ParentPart = null; SendAvatarDataToAllAgents(); m_requestedSitTargetID = 0; @@ -1949,7 +1936,6 @@ namespace OpenSim.Region.Framework.Scenes // "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is set and unoccupied", // Name, part.Name, part.LocalId); - part.SitTargetAvatar = UUID; offset = part.SitTargetPosition; sitOrientation = part.SitTargetOrientation; canSit = true; @@ -2299,6 +2285,7 @@ namespace OpenSim.Region.Framework.Scenes return; } + ParentPart = m_scene.GetSceneObjectPart(m_requestedSitTargetID); ParentID = m_requestedSitTargetID; Velocity = Vector3.Zero;