/// <summary>
/// Synchronously delete the given object from the scene.
/// </summary>
/// <param name="group">Object Id</param>
/// <param name="DeleteScripts">Remove the scripts from the ScriptEngine as well</param>
/// <param name="removeFromDatabase">Remove from the database?</param>
protected bool DeleteSceneObject(SceneObjectGroup group, bool DeleteScripts, bool removeFromDatabase)
{
//m_log.DebugFormat("[Backup]: Deleting scene object {0} {1}", group.Name, group.UUID);
lock (group.RootPart.SitTargetAvatar)
{
if (group.RootPart.SitTargetAvatar.Count != 0)
{
UUID[] ids = new UUID[group.RootPart.SitTargetAvatar.Count];
group.RootPart.SitTargetAvatar.CopyTo(ids);
foreach (UUID avID in ids)
{
IScenePresence SP = m_scene.GetScenePresence(avID);
if (SP != null)
SP.StandUp();
}
}
}
// Serialise calls to RemoveScriptInstances to avoid
// deadlocking on m_parts inside SceneObjectGroup
if (DeleteScripts)
{
group.RemoveScriptInstances(true);
}
foreach (SceneObjectPart part in group.ChildrenList)
{
if (part.IsJoint() && ((part.Flags & PrimFlags.Physics) != 0))
{
m_scene.PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed?
}
else if (part.PhysActor != null)
{
m_scene.PhysicsScene.RemovePrim(part.PhysActor);
part.PhysActor = null;
}
}
if (m_scene.SceneGraph.DeleteEntity(group))
{
if(removeFromDatabase)
DeleteFromStorage(group.UUID);
// We need to keep track of this state in case this group is still queued for backup.
group.IsDeleted = true;
//Clear the update schedule HERE so that IsDeleted will not have to fire as well
lock (group.ChildrenListLock)
{
foreach (SceneObjectPart part in group.ChildrenList)
{
//Make sure it isn't going to be updated again
part.ClearUpdateSchedule();
}
}
m_scene.EventManager.TriggerObjectBeingRemovedFromScene(group);
return true;
}
//m_log.DebugFormat("[SCENE]: Exit DeleteSceneObject() for {0} {1}", group.Name, group.UUID);
return false;
}