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.
0.6.5-rc1
Melanie Thielker 2009-04-29 15:54:16 +00:00
parent 84701701ef
commit d604cd284e
2 changed files with 149 additions and 142 deletions

View File

@ -1588,106 +1588,108 @@ namespace OpenSim.Region.Framework.Scenes
protected internal void DelinkObjects(List<uint> 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++)
{
// Get the group for this prim and check that it is the parent
parentPrim = GetGroupByPrim(primIds[i]);
if (parentPrim != null && parentPrim.LocalId == primIds[i])
{
primIds.RemoveAt(i);
break;
}
}
if (parentPrim != null)
{
foreach (uint childPrimId in primIds)
{
parentPrim.DelinkFromGroup(childPrimId, 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
List<SceneObjectPart> childParts = new List<SceneObjectPart>();
List<SceneObjectPart> rootParts = new List<SceneObjectPart>();
List<SceneObjectGroup> affectedGroups = new List<SceneObjectGroup>();
// Look them all up in one go, since that is comparatively expensive
//
parentPrim.RootPart.LinkNum = 0;
if (sendEvents)
parentPrim.TriggerScriptChangedEvent(Changed.LINK);
foreach (uint primID in primIds)
{
SceneObjectPart part = m_parentScene.GetSceneObjectPart(primID);
if (part != null)
{
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
{
// 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
m_log.ErrorFormat("Viewer requested unlink of nonexistent part {0}", primID);
}
}
foreach (SceneObjectPart child in childParts)
{
// Unlink all child parts from their groups
//
List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values);
child.ParentGroup.DelinkFromGroup(child, sendEvents);
}
List<uint> unlink_ids = new List<uint>();
foreach (SceneObjectPart unlink_part in parts)
unlink_ids.Add(unlink_part.LocalId);
// Tear down the remaining link set
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
//
if (unlink_ids.Count == 2)
{
DelinkObjects(unlink_ids, true);
return;
}
SceneObjectGroup group = root.ParentGroup;
List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Children.Values);
int numChildren = group.Children.Count;
DelinkObjects(unlink_ids, false);
// Send event to root prim, then we're done with it
parentPrim.TriggerScriptChangedEvent(Changed.LINK);
unlink_ids.Remove(parentPrim.RootPart.LocalId);
foreach (uint localId in unlink_ids)
{
SceneObjectPart nr = GetSceneObjectPart(localId);
nr.UpdateFlag = 0;
}
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
// If there are prims left in a link set, but the root is
// slated for unlink, we need to do this
//
List<SceneObjectGroup> parentGroups = new List<SceneObjectGroup>();
if (numChildren != 1)
{
// Unlink the remaining set
//
bool sendEventsToRemainder = true;
if (numChildren > 1)
sendEventsToRemainder = false;
// 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++)
foreach (SceneObjectPart p in newSet)
{
SceneObjectGroup parent = GetGroupByPrim(primIds[i]);
parent.DelinkFromGroup(primIds[i]);
delinkedSomething = true;
if (!parentGroups.Contains(parent))
parentGroups.Add(parent);
if (p != group.RootPart)
group.DelinkFromGroup(p, sendEventsToRemainder);
}
if (!delinkedSomething)
// If there is more than one prim remaining, we
// need to re-link
//
if (numChildren > 2)
{
m_log.InfoFormat("[SCENE]: " +
"DelinkObjects(): Could not find a root prim out of {0} as given to a delink request!",
primIds);
// 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);
});
// Determine new root
//
SceneObjectPart newRoot = newSet[0];
newSet.RemoveAt(0);
List<uint> linkIDs = new List<uint>();
foreach (SceneObjectPart newChild in newSet)
{
newChild.UpdateFlag = 0;
linkIDs.Add(newChild.LocalId);
}
else
{
foreach (SceneObjectGroup g in parentGroups)
LinkObjects(null, newRoot.LocalId, linkIDs);
if (!affectedGroups.Contains(newRoot.ParentGroup))
affectedGroups.Add(newRoot.ParentGroup);
}
}
}
// Finally, trigger events in the roots
//
foreach (SceneObjectGroup g in affectedGroups)
{
g.TriggerScriptChangedEvent(Changed.LINK);
}
}
g.ScheduleGroupForFullUpdate();
}
}

View File

@ -2237,7 +2237,19 @@ namespace OpenSim.Region.Framework.Scenes
{
SceneObjectPart linkPart = GetChildPart(partID);
if (null != linkPart)
if (linkPart != null)
{
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(
@ -2296,13 +2308,6 @@ namespace OpenSim.Region.Framework.Scenes
HasGroupChanged = true;
ScheduleGroupForFullUpdate();
}
else
{
m_log.InfoFormat("[SCENE OBJECT GROUP]: " +
"DelinkFromGroup(): Child prim {0} not found in object {1}, {2}",
partID, LocalId, UUID);
}
}
/// <summary>
/// Stop this object from being persisted over server restarts.