From d604cd284efc61af4616506830ff17ee52ff6e48 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Wed, 29 Apr 2009 15:54:16 +0000 Subject: Again, completely revamp the unlink code to finally allow unlinking arbitrary combinations of root and child prims from one or multiple link sets. Please test throughly and consider things UNSTABLE until this is proven out. --- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 160 +++++++++++---------- .../Region/Framework/Scenes/SceneObjectGroup.cs | 95 ++++++------ 2 files changed, 131 insertions(+), 124 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index 1e6955a..4b4461f 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -1588,106 +1588,108 @@ namespace OpenSim.Region.Framework.Scenes protected internal void DelinkObjects(List primIds, bool sendEvents) { - SceneObjectGroup parentPrim = null; - // Find the root prim among the prim ids we've been given - for (int i = 0; i < primIds.Count; i++) + List childParts = new List(); + List rootParts = new List(); + List affectedGroups = new List(); + // Look them all up in one go, since that is comparatively expensive + // + foreach (uint primID in primIds) { - // Get the group for this prim and check that it is the parent - parentPrim = GetGroupByPrim(primIds[i]); - if (parentPrim != null && parentPrim.LocalId == primIds[i]) + SceneObjectPart part = m_parentScene.GetSceneObjectPart(primID); + if (part != null) { - primIds.RemoveAt(i); - break; + if (part.LinkNum < 2) // Root or single + rootParts.Add(part); + else + childParts.Add(part); + + SceneObjectGroup group = part.ParentGroup; + if (!affectedGroups.Contains(group)) + affectedGroups.Add(group); + } + else + { + m_log.ErrorFormat("Viewer requested unlink of nonexistent part {0}", primID); } } - if (parentPrim != null) + foreach (SceneObjectPart child in childParts) { - foreach (uint childPrimId in primIds) - { - parentPrim.DelinkFromGroup(childPrimId, sendEvents); - } + // Unlink all child parts from their groups + // + child.ParentGroup.DelinkFromGroup(child, sendEvents); + } - if (parentPrim.Children.Count == 1) - { - // The link set has been completely torn down - // This is the case if you select a link set and delink - // - parentPrim.RootPart.LinkNum = 0; - if (sendEvents) - parentPrim.TriggerScriptChangedEvent(Changed.LINK); - } - else + foreach (SceneObjectPart root in rootParts) + { + // In most cases, this will run only one time, and the prim + // will be a solo prim + // However, editing linked parts and unlinking may be different + // + SceneObjectGroup group = root.ParentGroup; + List newSet = new List(group.Children.Values); + int numChildren = group.Children.Count; + + // If there are prims left in a link set, but the root is + // slated for unlink, we need to do this + // + if (numChildren != 1) { - // The link set has prims remaining. This path is taken - // when a subset of a link set's prims are selected - // and the root prim is part of that selection + // Unlink the remaining set // - List parts = new List(parentPrim.Children.Values); + bool sendEventsToRemainder = true; + if (numChildren > 1) + sendEventsToRemainder = false; - List unlink_ids = new List(); - foreach (SceneObjectPart unlink_part in parts) - unlink_ids.Add(unlink_part.LocalId); + foreach (SceneObjectPart p in newSet) + { + if (p != group.RootPart) + group.DelinkFromGroup(p, sendEventsToRemainder); + } - // Tear down the remaining link set + // If there is more than one prim remaining, we + // need to re-link // - if (unlink_ids.Count == 2) + if (numChildren > 2) { - DelinkObjects(unlink_ids, true); - return; - } + // Remove old root + // + if (newSet.Contains(root)) + newSet.Remove(root); + + // Preserve link ordering + // + newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b) + { + return a.LinkNum.CompareTo(b.LinkNum); + }); - DelinkObjects(unlink_ids, false); + // Determine new root + // + SceneObjectPart newRoot = newSet[0]; + newSet.RemoveAt(0); - // Send event to root prim, then we're done with it - parentPrim.TriggerScriptChangedEvent(Changed.LINK); + List linkIDs = new List(); - unlink_ids.Remove(parentPrim.RootPart.LocalId); + foreach (SceneObjectPart newChild in newSet) + { + newChild.UpdateFlag = 0; + linkIDs.Add(newChild.LocalId); + } - foreach (uint localId in unlink_ids) - { - SceneObjectPart nr = GetSceneObjectPart(localId); - nr.UpdateFlag = 0; + LinkObjects(null, newRoot.LocalId, linkIDs); + if (!affectedGroups.Contains(newRoot.ParentGroup)) + affectedGroups.Add(newRoot.ParentGroup); } - - uint newRoot = unlink_ids[0]; - unlink_ids.Remove(newRoot); - - LinkObjects(null, newRoot, unlink_ids); } } - else - { - // The selected prims were all child prims. Edit linked parts - // without the root prim selected will get us here - // - List parentGroups = new List(); - // If the first scan failed, we need to do a /deep/ scan of the linkages. This is /really/ slow - // We know that this is not the root prim now essentially, so we don't have to worry about remapping - // which one is the root prim - bool delinkedSomething = false; - for (int i = 0; i < primIds.Count; i++) - { - SceneObjectGroup parent = GetGroupByPrim(primIds[i]); - parent.DelinkFromGroup(primIds[i]); - delinkedSomething = true; - if (!parentGroups.Contains(parent)) - parentGroups.Add(parent); - } - if (!delinkedSomething) - { - m_log.InfoFormat("[SCENE]: " + - "DelinkObjects(): Could not find a root prim out of {0} as given to a delink request!", - primIds); - } - else - { - foreach (SceneObjectGroup g in parentGroups) - { - g.TriggerScriptChangedEvent(Changed.LINK); - } - } + // Finally, trigger events in the roots + // + foreach (SceneObjectGroup g in affectedGroups) + { + g.TriggerScriptChangedEvent(Changed.LINK); + g.ScheduleGroupForFullUpdate(); } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index f8b4483..6dc331b 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -2237,71 +2237,76 @@ namespace OpenSim.Region.Framework.Scenes { SceneObjectPart linkPart = GetChildPart(partID); - if (null != linkPart) + if (linkPart != null) { - linkPart.ClearUndoState(); + DelinkFromGroup(linkPart, sendEvents); + } + else + { + m_log.InfoFormat("[SCENE OBJECT GROUP]: " + + "DelinkFromGroup(): Child prim {0} not found in object {1}, {2}", + partID, LocalId, UUID); + } + } + + public void DelinkFromGroup(SceneObjectPart linkPart, bool sendEvents) + { + linkPart.ClearUndoState(); // m_log.DebugFormat( // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}", // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID); - Quaternion worldRot = linkPart.GetWorldRotation(); + Quaternion worldRot = linkPart.GetWorldRotation(); - // Remove the part from this object - lock (m_parts) - { - m_parts.Remove(linkPart.UUID); - } + // Remove the part from this object + lock (m_parts) + { + m_parts.Remove(linkPart.UUID); + } - if (m_parts.Count == 1 && RootPart != null) //Single prim is left - RootPart.LinkNum = 0; - else + if (m_parts.Count == 1 && RootPart != null) //Single prim is left + RootPart.LinkNum = 0; + else + { + foreach (SceneObjectPart p in m_parts.Values) { - foreach (SceneObjectPart p in m_parts.Values) - { - if (p.LinkNum > linkPart.LinkNum) - p.LinkNum--; - } + if (p.LinkNum > linkPart.LinkNum) + p.LinkNum--; } + } - linkPart.ParentID = 0; - linkPart.LinkNum = 0; + linkPart.ParentID = 0; + linkPart.LinkNum = 0; - if (linkPart.PhysActor != null) - { - m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); - } + if (linkPart.PhysActor != null) + { + m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); + } - // We need to reset the child part's position - // ready for life as a separate object after being a part of another object - Quaternion parentRot = m_rootPart.RotationOffset; + // We need to reset the child part's position + // ready for life as a separate object after being a part of another object + Quaternion parentRot = m_rootPart.RotationOffset; - Vector3 axPos = linkPart.OffsetPosition; + Vector3 axPos = linkPart.OffsetPosition; - axPos *= parentRot; - linkPart.OffsetPosition = new Vector3(axPos.X, axPos.Y, axPos.Z); - linkPart.GroupPosition = AbsolutePosition + linkPart.OffsetPosition; - linkPart.OffsetPosition = new Vector3(0, 0, 0); + axPos *= parentRot; + linkPart.OffsetPosition = new Vector3(axPos.X, axPos.Y, axPos.Z); + linkPart.GroupPosition = AbsolutePosition + linkPart.OffsetPosition; + linkPart.OffsetPosition = new Vector3(0, 0, 0); - linkPart.RotationOffset = worldRot; + linkPart.RotationOffset = worldRot; - SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart); + SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart); - m_scene.AddNewSceneObject(objectGroup, true); + m_scene.AddNewSceneObject(objectGroup, true); - if (sendEvents) - linkPart.TriggerScriptChangedEvent(Changed.LINK); + if (sendEvents) + linkPart.TriggerScriptChangedEvent(Changed.LINK); - linkPart.Rezzed = RootPart.Rezzed; + linkPart.Rezzed = RootPart.Rezzed; - HasGroupChanged = true; - ScheduleGroupForFullUpdate(); - } - else - { - m_log.InfoFormat("[SCENE OBJECT GROUP]: " + - "DelinkFromGroup(): Child prim {0} not found in object {1}, {2}", - partID, LocalId, UUID); - } + HasGroupChanged = true; + ScheduleGroupForFullUpdate(); } /// -- cgit v1.1