From fcecfc81bbd6ee8ebfa2dc0585d92ebf899358c1 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 18 Mar 2013 22:56:03 +0000 Subject: Multiattach, part 1 Conflicts: OpenSim/Framework/AvatarAppearance.cs OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs OpenSim/Region/Framework/Scenes/Scene.cs OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs --- .../Avatar/Attachments/AttachmentsModule.cs | 58 +++++++++++----------- .../Attachments/Tests/AttachmentsModuleTests.cs | 6 +-- .../Framework/Interfaces/IAttachmentsModule.cs | 2 +- OpenSim/Region/Framework/Scenes/Scene.cs | 2 +- .../Avatar/Attachments/TempAttachmentsModule.cs | 2 +- .../Shared/Api/Implementation/LSL_Api.cs | 4 +- OpenSim/Services/Interfaces/IAvatarService.cs | 9 +++- 7 files changed, 44 insertions(+), 39 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 8a3eeaa..f8fc483 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -221,9 +221,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // If we're an NPC then skip all the item checks and manipulations since we don't have an // inventory right now. if (sp.PresenceType == PresenceType.Npc) - RezSingleAttachmentFromInventoryInternal(sp, UUID.Zero, attach.AssetID, p); + RezSingleAttachmentFromInventoryInternal(sp, UUID.Zero, attach.AssetID, p, true); else - RezSingleAttachmentFromInventory(sp, attach.ItemID, p); + RezSingleAttachmentFromInventory(sp, attach.ItemID, p | (uint)0x80); } catch (Exception e) { @@ -268,13 +268,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments sp.ClearAttachments(); } - - public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool temp) + + public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool temp, bool append) { if (!Enabled) return false; - if (AttachObjectInternal(sp, group, attachmentPt, silent, temp)) + if (AttachObjectInternal(sp, group, attachmentPt, silent, temp, append)) { m_scene.EventManager.TriggerOnAttach(group.LocalId, group.FromItemID, sp.UUID); return true; @@ -283,7 +283,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments return false; } - private bool AttachObjectInternal(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool temp) + private bool AttachObjectInternal(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool temp, bool append) { lock (sp.AttachmentsSyncLock) { @@ -311,10 +311,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments Vector3 attachPos = group.AbsolutePosition; - // 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; - // 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. @@ -342,7 +338,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments group.AbsolutePosition = attachPos; if (sp.PresenceType != PresenceType.Npc) - UpdateUserInventoryWithAttachment(sp, group, attachmentPt, temp); + UpdateUserInventoryWithAttachment(sp, group, attachmentPt, temp, append); AttachToAgent(sp, group, attachmentPt, attachPos, silent); } @@ -350,21 +346,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments return true; } - private void UpdateUserInventoryWithAttachment(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool temp) + private void UpdateUserInventoryWithAttachment(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool temp, bool append) { // Remove any previous attachments List attachments = sp.GetAttachments(attachmentPt); // At the moment we can only deal with a single attachment - if (attachments.Count != 0) + if (attachments.Count != 0 && !append) { if (attachments[0].FromItemID != UUID.Zero) DetachSingleAttachmentToInvInternal(sp, attachments[0]); - // Error logging commented because UUID.Zero now means temp attachment -// else -// m_log.WarnFormat( -// "[ATTACHMENTS MODULE]: When detaching existing attachment {0} {1} at point {2} to make way for {3} {4} for {5}, couldn't find the associated item ID to adjust inventory attachment record!", -// attachments[0].Name, attachments[0].LocalId, attachmentPt, group.Name, group.LocalId, sp.Name); } // Add the new attachment to inventory if we don't already have it. @@ -374,7 +365,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments if (newAttachmentItemID == UUID.Zero) newAttachmentItemID = AddSceneObjectAsNewAttachmentInInv(sp, group).ID; - ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group); + ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group, append); } } @@ -387,8 +378,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // "[ATTACHMENTS MODULE]: RezSingleAttachmentFromInventory to point {0} from item {1} for {2}", // (AttachmentPoint)AttachmentPt, itemID, sp.Name); - // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should - // be removed when that functionality is implemented in opensim + bool append = (AttachmentPt & 0x80) != 0; AttachmentPt &= 0x7f; // Viewer 2/3 sometimes asks to re-wear items that are already worn (and show up in it's inventory as such). @@ -417,7 +407,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments return null; } - return RezSingleAttachmentFromInventoryInternal(sp, itemID, UUID.Zero, AttachmentPt); + return RezSingleAttachmentFromInventoryInternal(sp, itemID, UUID.Zero, AttachmentPt, append); } public void RezMultipleAttachmentsFromInventory(IScenePresence sp, List> rezlist) @@ -803,8 +793,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments UpdateDetachedObject(sp, so); } - private SceneObjectGroup RezSingleAttachmentFromInventoryInternal( - IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt) + protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal( + IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt, bool append) { if (m_invAccessModule == null) return null; @@ -842,7 +832,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // This will throw if the attachment fails try { - AttachObjectInternal(sp, objatt, attachmentPt, false, false); + AttachObjectInternal(sp, objatt, attachmentPt, false, false, append); } catch (Exception e) { @@ -887,7 +877,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments /// /// /// - private void ShowAttachInUserInventory(IScenePresence sp, uint AttachmentPt, UUID itemID, SceneObjectGroup att) + private void ShowAttachInUserInventory(IScenePresence sp, uint AttachmentPt, UUID itemID, SceneObjectGroup att, bool append) { // m_log.DebugFormat( // "[USER INVENTORY]: Updating attachment {0} for {1} at {2} using item ID {3}", @@ -910,7 +900,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments if (item == null) return; - bool changed = sp.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID); + int attFlag = append ? 0x80 : 0; + bool changed = sp.Appearance.SetAttachment((int)AttachmentPt | attFlag, itemID, item.AssetID); if (changed && m_scene.AvatarFactory != null) { // m_log.DebugFormat( @@ -994,12 +985,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments return; } - // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should - // be removed when that functionality is implemented in opensim + bool append = (AttachmentPt & 0x80) != 0; AttachmentPt &= 0x7f; // Calls attach with a Zero position - AttachObject(sp, part.ParentGroup, AttachmentPt, false, false); + if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, false, append)) + { +// m_log.Debug( +// "[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId +// + ", AttachmentPoint: " + AttachmentPt); + + // Save avatar attachment information + m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.FromItemID, remoteClient.AgentId); + } } catch (Exception e) { diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs index 0ee01c7..f48bb6f 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs @@ -197,7 +197,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName, sp.UUID); m_numberOfAttachEventsFired = 0; - scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, false); + scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, false, false); // Check status on scene presence Assert.That(sp.HasAttachments(), Is.True); @@ -254,7 +254,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests sp2.AbsolutePosition = new Vector3(0, 0, 0); sp2.HandleAgentRequestSit(sp2.ControllingClient, sp2.UUID, so.UUID, Vector3.Zero); - scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, false); + scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, false, false); Assert.That(sp.HasAttachments(), Is.False); Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); @@ -663,4 +663,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0)); } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs index 620ec22..46daab3 100644 --- a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs @@ -83,7 +83,7 @@ namespace OpenSim.Region.Framework.Interfaces /// /// /// true if the object was successfully attached, false otherwise - bool AttachObject(IScenePresence sp, SceneObjectGroup grp, uint AttachmentPt, bool silent, bool temp); + bool AttachObject(IScenePresence sp, SceneObjectGroup grp, uint AttachmentPt, bool silent, bool temp, bool append); /// /// Rez an attachment from user inventory and change inventory status to match. diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 14dac7a..3c91c5b 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2741,7 +2741,7 @@ namespace OpenSim.Region.Framework.Scenes RootPrim.RemFlag(PrimFlags.TemporaryOnRez); if (AttachmentsModule != null) - AttachmentsModule.AttachObject(sp, grp, 0, false, false); + AttachmentsModule.AttachObject(sp, grp, 0, false, false, true); } else { diff --git a/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs b/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs index 1e7bc02..e9ddbbe 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs @@ -183,7 +183,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Attachments hostPart.ParentGroup.RootPart.ScheduleFullUpdate(); } - return attachmentsModule.AttachObject(target, hostPart.ParentGroup, (uint)attachmentPoint, false, true) ? 1 : 0; + return attachmentsModule.AttachObject(target, hostPart.ParentGroup, (uint)attachmentPoint, false, true, true) ? 1 : 0; } } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index ab087af..cf6f13e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -2985,7 +2985,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; if (attachmentsModule != null) - return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, false); + return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true); else return false; } @@ -11787,4 +11787,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } } -} \ No newline at end of file +} diff --git a/OpenSim/Services/Interfaces/IAvatarService.cs b/OpenSim/Services/Interfaces/IAvatarService.cs index 863fd93..606e82c 100644 --- a/OpenSim/Services/Interfaces/IAvatarService.cs +++ b/OpenSim/Services/Interfaces/IAvatarService.cs @@ -174,11 +174,18 @@ namespace OpenSim.Services.Interfaces // Attachments List attachments = appearance.GetAttachments(); + Dictionary> atts = new Dictionary>(); foreach (AvatarAttachment attach in attachments) { if (attach.ItemID != UUID.Zero) - Data["_ap_" + attach.AttachPoint] = attach.ItemID.ToString(); + { + if (!atts.ContainsKey(attach.AttachPoint)) + atts[attach.AttachPoint] = new List(); + atts[attach.AttachPoint].Add(attach.ItemID.ToString()); + } } + foreach (KeyValuePair> kvp in atts) + Data["_ap_" + kvp.Key] = string.Join(",", kvp.Value.ToArray()); } public AvatarAppearance ToAvatarAppearance() -- cgit v1.1