From 15a514fcbc8f7447fc3a5997b6bbc2fe35974c9a Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 26 Aug 2011 23:06:41 +0100
Subject: refactor: simplify SOP.AttachedAvatar into SOG.AttachedAvatar

This does a tiny bit to reduce code complexity, memory requirement and the cpu time of pointlessly setting this field to the same value in every SOP
---
 .../CoreModules/Avatar/Attachments/AttachmentsModule.cs   | 15 +++++----------
 OpenSim/Region/Framework/Scenes/Prioritizer.cs            |  7 +++----
 OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs       | 12 ++++++++++--
 OpenSim/Region/Framework/Scenes/SceneObjectPart.cs        |  5 +----
 .../ScriptEngine/Shared/Api/Implementation/LSL_Api.cs     |  8 ++++----
 .../Shared/Api/Implementation/Plugins/SensorRepeat.cs     |  4 ++--
 .../Region/ScriptEngine/Shared/Instance/ScriptInstance.cs |  2 +-
 7 files changed, 26 insertions(+), 27 deletions(-)

(limited to 'OpenSim')

diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index 93920b0..3e1cb02 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -456,7 +456,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
             if (so == null)
                 return;
 
-            if (so.RootPart.AttachedAvatar != remoteClient.AgentId)
+            if (so.AttachedAvatar != remoteClient.AgentId)
                 return;
 
             UUID inventoryID = so.GetFromItemID();
@@ -498,7 +498,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
 
             rootPart.FromItemID = UUID.Zero;
             so.AbsolutePosition = sp.AbsolutePosition;
-            so.ForEachPart(part => part.AttachedAvatar = UUID.Zero);
+            so.AttachedAvatar = UUID.Zero;
             rootPart.SetParentLocalId(0);
             so.ClearPartAttachmentData();
             rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive, m_scene.m_physicalPrim);
@@ -534,11 +534,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
                         sp.RemoveAttachment(group);
 
                         // Prepare sog for storage
+                        group.AttachedAvatar = UUID.Zero;
+
                         group.ForEachPart(
                             delegate(SceneObjectPart part)
                             {
-                                part.AttachedAvatar = UUID.Zero;
-
                                 // If there are any scripts,
                                 // then always trigger a new object and state persistence in UpdateKnownItem()
                                 if (part.Inventory.ContainsScripts())
@@ -656,12 +656,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
             m_scene.DeleteFromStorage(so.UUID);
             m_scene.EventManager.TriggerParcelPrimCountTainted();
 
-            so.RootPart.AttachedAvatar = avatar.UUID;
-
-            //Anakin Lohner bug #3839 
-            SceneObjectPart[] parts = so.Parts;
-            for (int i = 0; i < parts.Length; i++)
-                parts[i].AttachedAvatar = avatar.UUID;
+            so.AttachedAvatar = avatar.UUID;
 
             if (so.RootPart.PhysActor != null)
             {
diff --git a/OpenSim/Region/Framework/Scenes/Prioritizer.cs b/OpenSim/Region/Framework/Scenes/Prioritizer.cs
index 4595a29..2a76755 100644
--- a/OpenSim/Region/Framework/Scenes/Prioritizer.cs
+++ b/OpenSim/Region/Framework/Scenes/Prioritizer.cs
@@ -116,14 +116,13 @@ namespace OpenSim.Region.Framework.Scenes
             return priority;
         }
 
-
         private uint GetPriorityByTime(IClientAPI client, ISceneEntity entity)
         {
             // And anything attached to this avatar gets top priority as well
             if (entity is SceneObjectPart)
             {
                 SceneObjectPart sop = (SceneObjectPart)entity;
-                if (sop.ParentGroup.RootPart.IsAttachment && client.AgentId == sop.ParentGroup.RootPart.AttachedAvatar)
+                if (sop.ParentGroup.RootPart.IsAttachment && client.AgentId == sop.ParentGroup.AttachedAvatar)
                     return 1;
             }
 
@@ -136,7 +135,7 @@ namespace OpenSim.Region.Framework.Scenes
             if (entity is SceneObjectPart)
             {
                 SceneObjectPart sop = (SceneObjectPart)entity;
-                if (sop.ParentGroup.RootPart.IsAttachment && client.AgentId == sop.ParentGroup.RootPart.AttachedAvatar)
+                if (sop.ParentGroup.RootPart.IsAttachment && client.AgentId == sop.ParentGroup.AttachedAvatar)
                     return 1;
             }
 
@@ -149,7 +148,7 @@ namespace OpenSim.Region.Framework.Scenes
             if (entity is SceneObjectPart)
             {
                 SceneObjectPart sop = (SceneObjectPart)entity;
-                if (sop.ParentGroup.RootPart.IsAttachment && client.AgentId == sop.ParentGroup.RootPart.AttachedAvatar)
+                if (sop.ParentGroup.RootPart.IsAttachment && client.AgentId == sop.ParentGroup.AttachedAvatar)
                     return 1;
             }
 
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index e3b8fc8..fada688 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -169,6 +169,14 @@ namespace OpenSim.Region.Framework.Scenes
         }
 
         /// <summary>
+        /// The avatar to which this scene object is attached.
+        /// </summary>
+        /// <remarks>
+        /// If we're not attached to an avatar then this is UUID.Zero
+        /// </remarks>
+        public UUID AttachedAvatar { get; set; }
+
+        /// <summary>
         /// Is this scene object phantom?
         /// </summary>
         /// <remarks>
@@ -1540,7 +1548,7 @@ namespace OpenSim.Region.Framework.Scenes
             {
                 if (IsAttachment)
                 {
-                    ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
+                    ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
                     if (avatar != null)
                     {
                         avatar.PushForce(impulse);
@@ -1622,7 +1630,7 @@ namespace OpenSim.Region.Framework.Scenes
             {
                 if (IsAttachment)
                 {
-                    ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
+                    ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
                     if (avatar != null)
                     {
                         avatar.MoveToTarget(target, false);
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index a0e87d0..e510611 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -221,9 +221,6 @@ namespace OpenSim.Region.Framework.Scenes
         public scriptEvents AggregateScriptEvents;
 
         
-        public UUID AttachedAvatar;
-
-        
         public Vector3 AttachedPos;
 
         
@@ -728,7 +725,7 @@ namespace OpenSim.Region.Framework.Scenes
 
                 if (IsAttachment)
                 {
-                    ScenePresence sp = m_parentGroup.Scene.GetScenePresence(AttachedAvatar);
+                    ScenePresence sp = m_parentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
                     if (sp != null)
                         return sp.AbsolutePosition;
                 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index a690e3b..81f1f38 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -2099,7 +2099,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
             {
                 if (part.ParentGroup.RootPart.AttachmentPoint != 0)
                 {
-                    ScenePresence avatar = World.GetScenePresence(part.AttachedAvatar);
+                    ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
                     if (avatar != null)
                     {
                         if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
@@ -2243,7 +2243,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
 
             if (m_host.IsAttachment)
             {
-                ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.AttachedAvatar);
+                ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
                 vel = avatar.Velocity;
             }
             else
@@ -3388,7 +3388,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
 
             m_host.AddScriptLPS(1);
 
-            if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.RootPart.AttachedAvatar)
+            if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
             {
                 // When attached, certain permissions are implicit if requested from owner
                 int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
@@ -7460,7 +7460,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
             Quaternion q;
             if (m_host.ParentGroup.RootPart.AttachmentPoint != 0)
             {
-                ScenePresence avatar = World.GetScenePresence(m_host.AttachedAvatar);
+                ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
                 if (avatar != null)
                     if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
                         q = avatar.CameraRotation; // Mouselook
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index e53a61a..bf74760 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -308,7 +308,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
                 // In attachments, the sensor cone always orients with the
                 // avatar rotation. This may include a nonzero elevation if
                 // in mouselook.
-                ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar);
+                ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
                 q = avatar.Rotation;
             }
             LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
@@ -428,7 +428,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
                 // In attachments, the sensor cone always orients with the
                 // avatar rotation. This may include a nonzero elevation if
                 // in mouselook.
-                ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar);
+                ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
                 q = avatar.Rotation;
             }
 
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 783791f..ef9b2ac 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -233,7 +233,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
             m_MaxScriptQueue = maxScriptQueue;
             m_stateSource = stateSource;
             m_postOnRez = postOnRez;
-            m_AttachedAvatar = part.AttachedAvatar;
+            m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
             m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
 
             if (part != null)
-- 
cgit v1.1