From e8347b70957273421ee567577e2d9a6139af0621 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 10 Jul 2012 23:19:52 +0100 Subject: [PATCH 1/6] Move common code to detect whether a part has a valid sit target into a SOP property rather than being repeated in SP. This also makes the detection in SP.FindNextAvailableSitTarget() and SendSitResponse() identical. Previously they varied slightly (SendSitResponse didn't check for an older type of invalid quaternion) but the practical effect is most probably zero. --- .../Framework/Scenes/SceneObjectPart.cs | 15 ++++++++ .../Region/Framework/Scenes/ScenePresence.cs | 35 +++---------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 6677daeb30..dcec7e9681 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -135,6 +135,21 @@ namespace OpenSim.Region.Framework.Scenes get { return ParentGroup.RootPart == this; } } + /// + /// Is an explicit sit target set for this part? + /// + public bool IsSitTargetSet + { + get + { + return + !(SitTargetPosition == Vector3.Zero + && (SitTargetOrientation == Quaternion.Identity // Valid Zero Rotation quaternion + || SitTargetOrientation.X == 0f && SitTargetOrientation.Y == 0f && SitTargetOrientation.Z == 1f && SitTargetOrientation.W == 0f // W-Z Mapping was invalid at one point + || SitTargetOrientation.X == 0f && SitTargetOrientation.Y == 0f && SitTargetOrientation.Z == 0f && SitTargetOrientation.W == 0f)); // Invalid Quaternion + } + } + #region Fields public bool AllowedDrop; diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index c71bae9bc1..c644ea5914 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1846,15 +1846,7 @@ namespace OpenSim.Region.Framework.Scenes //look for prims with explicit sit targets that are available foreach (SceneObjectPart part in partArray) { - // Is a sit target available? - Vector3 avSitOffset = part.SitTargetPosition; - Quaternion avSitOrientation = part.SitTargetOrientation; - UUID avOnTargetAlready = part.SitTargetAvatar; - - bool SitTargetUnOccupied = avOnTargetAlready == UUID.Zero; - bool SitTargetisSet = avSitOffset != Vector3.Zero || avSitOrientation != Quaternion.Identity; - - if (SitTargetisSet && SitTargetUnOccupied) + if (part.IsSitTargetSet && part.SitTargetAvatar == UUID.Zero) { //switch the target to this prim return part; @@ -1880,40 +1872,23 @@ namespace OpenSim.Region.Framework.Scenes // TODO: determine position to sit at based on scene geometry; don't trust offset from client // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it - // Is a sit target available? - Vector3 avSitOffSet = part.SitTargetPosition; - Quaternion avSitOrientation = part.SitTargetOrientation; - UUID avOnTargetAlready = part.SitTargetAvatar; - - bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); - bool SitTargetisSet = - (!(avSitOffSet == Vector3.Zero && - ( - avSitOrientation == Quaternion.Identity // Valid Zero Rotation quaternion - || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point - || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion - ) - )); - -// m_log.DebugFormat("[SCENE PRESENCE]: {0} {1}", SitTargetisSet, SitTargetUnOccupied); - if (PhysicsActor != null) m_sitAvatarHeight = PhysicsActor.Size.Z; bool canSit = false; pos = part.AbsolutePosition + offset; - if (SitTargetisSet) + if (part.IsSitTargetSet) { - if (SitTargetUnOccupied) + if (part.SitTargetAvatar == UUID.Zero) { // m_log.DebugFormat( // "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is set and unoccupied", // Name, part.Name, part.LocalId); part.SitTargetAvatar = UUID; - offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); - sitOrientation = avSitOrientation; + offset = part.SitTargetPosition; + sitOrientation = part.SitTargetOrientation; canSit = true; } } From 69a6f6e3cd5cf1146a2d11d1393df0851c051e67 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 10 Jul 2012 23:26:40 +0100 Subject: [PATCH 2/6] refactor: use sit orientation argument passed in to SP.SendSitResponse() rather than creating a new copy There are no issues with side-effects since this is a struct. --- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index c644ea5914..a8c98edbdc 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1857,10 +1857,8 @@ namespace OpenSim.Region.Framework.Scenes return targetPart; } - private void SendSitResponse(UUID targetID, Vector3 offset, Quaternion pSitOrientation) + private void SendSitResponse(UUID targetID, Vector3 offset, Quaternion sitOrientation) { - Vector3 pos = new Vector3(); - Quaternion sitOrientation = pSitOrientation; Vector3 cameraEyeOffset = Vector3.Zero; Vector3 cameraAtOffset = Vector3.Zero; bool forceMouselook = false; @@ -1876,7 +1874,7 @@ namespace OpenSim.Region.Framework.Scenes m_sitAvatarHeight = PhysicsActor.Size.Z; bool canSit = false; - pos = part.AbsolutePosition + offset; + Vector3 pos = part.AbsolutePosition + offset; if (part.IsSitTargetSet) { From c8f0d476d2f775ba4d7afca12eeff527b46bb8e2 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 10 Jul 2012 23:34:40 +0100 Subject: [PATCH 3/6] refactor: Add SOP.IsSitTargetOccupied to improve readability --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 7 ++++++- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index dcec7e9681..937f43e1e8 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -135,6 +135,11 @@ namespace OpenSim.Region.Framework.Scenes get { return ParentGroup.RootPart == this; } } + /// + /// Is the sit target of this part occupied? + /// + public bool IsSitTargetOccupied { get { return SitTargetAvatar != UUID.Zero; } } + /// /// Is an explicit sit target set for this part? /// @@ -736,7 +741,7 @@ namespace OpenSim.Region.Framework.Scenes } // TODO if we decide to do sitting in a more SL compatible way (multiple avatars per prim), this has to be fixed, too - if (SitTargetAvatar != UUID.Zero) + if (IsSitTargetOccupied) { ScenePresence avatar; if (ParentGroup.Scene.TryGetScenePresence(SitTargetAvatar, out avatar)) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index a8c98edbdc..c824e56796 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1846,7 +1846,7 @@ namespace OpenSim.Region.Framework.Scenes //look for prims with explicit sit targets that are available foreach (SceneObjectPart part in partArray) { - if (part.IsSitTargetSet && part.SitTargetAvatar == UUID.Zero) + if (part.IsSitTargetSet && !part.IsSitTargetOccupied) { //switch the target to this prim return part; @@ -1878,7 +1878,7 @@ namespace OpenSim.Region.Framework.Scenes if (part.IsSitTargetSet) { - if (part.SitTargetAvatar == UUID.Zero) + if (!part.IsSitTargetOccupied) { // m_log.DebugFormat( // "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is set and unoccupied", From 11e0ad6dc8663756154652465750c1ebaaf3124f Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 10 Jul 2012 23:39:05 +0100 Subject: [PATCH 4/6] Revert "refactor: Add SOP.IsSitTargetOccupied to improve readability" This reverts commit c8f0d476d2f775ba4d7afca12eeff527b46bb8e2. On reconsideration, I think this is less readable since immediately following code still sets SitTargetAvatar directly --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 7 +------ OpenSim/Region/Framework/Scenes/ScenePresence.cs | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 937f43e1e8..dcec7e9681 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -135,11 +135,6 @@ namespace OpenSim.Region.Framework.Scenes get { return ParentGroup.RootPart == this; } } - /// - /// Is the sit target of this part occupied? - /// - public bool IsSitTargetOccupied { get { return SitTargetAvatar != UUID.Zero; } } - /// /// Is an explicit sit target set for this part? /// @@ -741,7 +736,7 @@ namespace OpenSim.Region.Framework.Scenes } // TODO if we decide to do sitting in a more SL compatible way (multiple avatars per prim), this has to be fixed, too - if (IsSitTargetOccupied) + if (SitTargetAvatar != UUID.Zero) { ScenePresence avatar; if (ParentGroup.Scene.TryGetScenePresence(SitTargetAvatar, out avatar)) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index c824e56796..a8c98edbdc 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1846,7 +1846,7 @@ namespace OpenSim.Region.Framework.Scenes //look for prims with explicit sit targets that are available foreach (SceneObjectPart part in partArray) { - if (part.IsSitTargetSet && !part.IsSitTargetOccupied) + if (part.IsSitTargetSet && part.SitTargetAvatar == UUID.Zero) { //switch the target to this prim return part; @@ -1878,7 +1878,7 @@ namespace OpenSim.Region.Framework.Scenes if (part.IsSitTargetSet) { - if (!part.IsSitTargetOccupied) + if (part.SitTargetAvatar == UUID.Zero) { // m_log.DebugFormat( // "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is set and unoccupied", From cdea572d2ea0256423a4cd72f132346d88a93e92 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 10 Jul 2012 23:50:04 +0100 Subject: [PATCH 5/6] refactor: move management of SOP.SitTargetAvatar into SOP.AddSittingAvatar() and SOP.RemoveSittingAvatar() --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 6 ++++++ OpenSim/Region/Framework/Scenes/ScenePresence.cs | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index dcec7e9681..b3f11a756e 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -4525,6 +4525,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) @@ -4547,6 +4550,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 a8c98edbdc..514c314ec3 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1799,10 +1799,6 @@ namespace OpenSim.Region.Framework.Scenes } } - // Reset sit target. - if (part.SitTargetAvatar == UUID) - part.SitTargetAvatar = UUID.Zero; - ParentPosition = part.GetWorldPosition(); ControllingClient.SendClearFollowCamProperties(part.ParentUUID); @@ -1884,7 +1880,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; From 337ea019bd0fa617df00d7bee10b869e73a50075 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 10 Jul 2012 23:55:22 +0100 Subject: [PATCH 6/6] If a part has a sit target and an avatar is already sitting, allow another avatar to sit in the position given if no sit target was set. Previous behave was that the second avatar could not sit. This matches behaviour observed on the LL grid. --- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 514c314ec3..0e7f2e5dd6 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1872,18 +1872,15 @@ namespace OpenSim.Region.Framework.Scenes bool canSit = false; Vector3 pos = part.AbsolutePosition + offset; - if (part.IsSitTargetSet) + if (part.IsSitTargetSet && part.SitTargetAvatar == UUID.Zero) { - if (part.SitTargetAvatar == UUID.Zero) - { // m_log.DebugFormat( // "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is set and unoccupied", // Name, part.Name, part.LocalId); - offset = part.SitTargetPosition; - sitOrientation = part.SitTargetOrientation; - canSit = true; - } + offset = part.SitTargetPosition; + sitOrientation = part.SitTargetOrientation; + canSit = true; } else {