From 1615e7d29fb6961a3ffe791fde4318f819c1a4b7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 27 Aug 2011 00:33:24 +0100 Subject: Eliminate duplicate AttachmentPoint properties by always using the one stored in the root part's state field. --- .../Avatar/Attachments/AttachmentsModule.cs | 42 +++++++++++----------- .../Attachments/Tests/AttachmentsModuleTests.cs | 3 -- .../Region/CoreModules/World/Sound/SoundModule.cs | 4 +-- .../Region/Framework/Scenes/SceneObjectGroup.cs | 36 +++++++++---------- 4 files changed, 41 insertions(+), 44 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index d9259b3..2d5eb18 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -167,13 +167,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments return AttachObject(sp, group, AttachmentPt, silent); } - private bool AttachObject(ScenePresence sp, SceneObjectGroup group, uint AttachmentPt, bool silent) + private bool AttachObject(ScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent) { // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})", // group.Name, group.LocalId, sp.Name, AttachmentPt, silent); - if (sp.GetAttachments(AttachmentPt).Contains(group)) + if (sp.GetAttachments(attachmentPt).Contains(group)) { // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached", @@ -186,39 +186,39 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should // be removed when that functionality is implemented in opensim - AttachmentPt &= 0x7f; + attachmentPt &= 0x7f; // If the attachment point isn't the same as the one previously used // set it's offset position = 0 so that it appears on the attachment point // and not in a weird location somewhere unknown. - if (AttachmentPt != 0 && AttachmentPt != (uint)group.GetAttachmentPoint()) + if (attachmentPt != 0 && attachmentPt != group.AttachmentPoint) { attachPos = Vector3.Zero; } // AttachmentPt 0 means the client chose to 'wear' the attachment. - if (AttachmentPt == 0) + if (attachmentPt == 0) { // Check object for stored attachment point - AttachmentPt = (uint)group.GetAttachmentPoint(); + attachmentPt = group.AttachmentPoint; } // if we still didn't find a suitable attachment point....... - if (AttachmentPt == 0) + if (attachmentPt == 0) { // Stick it on left hand with Zero Offset from the attachment point. - AttachmentPt = (uint)AttachmentPoint.LeftHand; + attachmentPt = (uint)AttachmentPoint.LeftHand; attachPos = Vector3.Zero; } - group.SetAttachmentPoint((byte)AttachmentPt); + group.AttachmentPoint = attachmentPt; group.AbsolutePosition = attachPos; // Remove any previous attachments UUID itemID = UUID.Zero; foreach (SceneObjectGroup grp in sp.Attachments) { - if (grp.GetAttachmentPoint() == (byte)AttachmentPt) + if (grp.AttachmentPoint == attachmentPt) { itemID = grp.GetFromItemID(); break; @@ -232,9 +232,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments if (itemID == UUID.Zero) itemID = AddSceneObjectAsAttachment(sp.ControllingClient, group).ID; - ShowAttachInUserInventory(sp, AttachmentPt, itemID, group); + ShowAttachInUserInventory(sp, attachmentPt, itemID, group); - AttachToAgent(sp, group, AttachmentPt, attachPos, silent); + AttachToAgent(sp, group, attachmentPt, attachPos, silent); return true; } @@ -293,7 +293,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments } private SceneObjectGroup RezSingleAttachmentFromInventoryInternal( - ScenePresence sp, UUID itemID, uint AttachmentPt) + ScenePresence sp, UUID itemID, uint attachmentPt) { IInventoryAccessModule invAccess = m_scene.RequestModuleInterface(); if (invAccess != null) @@ -313,13 +313,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // since scripts aren't running yet. So, clear it here. objatt.HasGroupChanged = false; bool tainted = false; - if (AttachmentPt != 0 && AttachmentPt != objatt.GetAttachmentPoint()) + if (attachmentPt != 0 && attachmentPt != objatt.AttachmentPoint) tainted = true; // This will throw if the attachment fails try { - AttachObject(sp, objatt, AttachmentPt, false); + AttachObject(sp, objatt, attachmentPt, false); } catch (Exception e) { @@ -348,7 +348,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments { m_log.WarnFormat( "[ATTACHMENTS MODULE]: Could not retrieve item {0} for attaching to avatar {1} at point {2}", - itemID, sp.Name, AttachmentPt); + itemID, sp.Name, attachmentPt); } return objatt; @@ -567,11 +567,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // attachment. This is necessary in order to correctly save // and retrieve GroupPosition information for the attachment. // Finally, we restore the object's attachment status. - byte attachmentPoint = sog.GetAttachmentPoint(); + uint attachmentPoint = sog.AttachmentPoint; sog.UpdateGroupPosition(pos); sog.IsAttachment = false; sog.AbsolutePosition = sog.RootPart.AttachedPos; - sog.SetAttachmentPoint(attachmentPoint); + sog.AttachmentPoint = attachmentPoint; sog.HasGroupChanged = true; } @@ -594,14 +594,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments { m_log.DebugFormat( "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}", - grp.UUID, grp.GetAttachmentPoint()); + grp.UUID, grp.AttachmentPoint); return; } m_log.DebugFormat( "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}", - grp.UUID, grp.GetAttachmentPoint()); + grp.UUID, grp.AttachmentPoint); string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp); @@ -668,7 +668,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments so.RootPart.AttachedPos = attachOffset; so.IsAttachment = true; so.RootPart.SetParentLocalId(avatar.LocalId); - so.SetAttachmentPoint(Convert.ToByte(attachmentpoint)); + so.AttachmentPoint = attachmentpoint; avatar.AddAttachment(so); diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs index 790a651..bb53601 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs @@ -111,7 +111,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(attName)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); - Assert.That(attSo.GetAttachmentPoint(), Is.EqualTo((byte)AttachmentPoint.Chest)); Assert.That(attSo.IsAttachment); Assert.That(attSo.UsesPhysics, Is.False); Assert.That(attSo.IsTemporary, Is.False); @@ -146,7 +145,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(attName)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); - Assert.That(attSo.GetAttachmentPoint(), Is.EqualTo((byte)AttachmentPoint.Chest)); Assert.That(attSo.IsAttachment); Assert.That(attSo.UsesPhysics, Is.False); Assert.That(attSo.IsTemporary, Is.False); @@ -242,7 +240,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(attName)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); - Assert.That(attSo.GetAttachmentPoint(), Is.EqualTo((byte)AttachmentPoint.Chest)); Assert.That(attSo.IsAttachment); Assert.That(attSo.UsesPhysics, Is.False); Assert.That(attSo.IsTemporary, Is.False); diff --git a/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs b/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs index 09c0ebb..22ffcd6 100644 --- a/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs +++ b/OpenSim/Region/CoreModules/World/Sound/SoundModule.cs @@ -81,7 +81,7 @@ namespace OpenSim.Region.CoreModules.World.Sound if (grp.IsAttachment) { - if (grp.GetAttachmentPoint() > 30) // HUD + if (grp.AttachmentPoint > 30) // HUD { if (sp.ControllingClient.AgentId != grp.OwnerID) return; @@ -115,7 +115,7 @@ namespace OpenSim.Region.CoreModules.World.Sound { SceneObjectGroup grp = part.ParentGroup; - if (grp.IsAttachment && grp.GetAttachmentPoint() > 30) + if (grp.IsAttachment && grp.AttachmentPoint > 30) { objectID = ownerID; parentID = ownerID; diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 34f484d..c453366 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -166,7 +166,24 @@ namespace OpenSim.Region.Framework.Scenes /// /// 0 if we're not attached to anything /// - public uint AttachmentPoint; + public uint AttachmentPoint + { + get + { + return m_rootPart.Shape.State; + } + + set + { + IsAttachment = value != 0; + m_rootPart.Shape.State = (byte)value; + } + } + + public void ClearPartAttachmentData() + { + AttachmentPoint = 0; + } /// /// Is this scene object phantom? @@ -976,23 +993,6 @@ namespace OpenSim.Region.Framework.Scenes } } - public byte GetAttachmentPoint() - { - return m_rootPart.Shape.State; - } - - public void SetAttachmentPoint(uint point) - { - AttachmentPoint = point; - IsAttachment = point != 0; - m_rootPart.Shape.State = (byte)point; - } - - public void ClearPartAttachmentData() - { - SetAttachmentPoint((Byte)0); - } - /// /// /// -- cgit v1.1