move common code into AttachmentsModule.DeleteAttachmentsFromScene()

remove-scene-viewer
Justin Clark-Casey (justincc) 2011-08-31 17:53:58 +01:00
parent 3aa86d22d1
commit 7d58b5fa15
6 changed files with 37 additions and 25 deletions

View File

@ -147,6 +147,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
} }
} }
} }
public void DeleteAttachmentsFromScene(IScenePresence sp, bool silent)
{
foreach (SceneObjectGroup sop in sp.GetAttachments())
{
sop.Scene.DeleteSceneObject(sop, silent);
}
sp.ClearAttachments();
}
/// <summary> /// <summary>
/// Called by client /// Called by client

View File

@ -559,11 +559,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
protected virtual void AgentHasMovedAway(ScenePresence sp, bool logout) protected virtual void AgentHasMovedAway(ScenePresence sp, bool logout)
{ {
foreach (SceneObjectGroup sop in sp.GetAttachments()) sp.Scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, true);
{
sop.Scene.DeleteSceneObject(sop, true);
}
sp.ClearAttachments();
} }
protected void KillEntity(Scene scene, uint localID) protected void KillEntity(Scene scene, uint localID)

View File

@ -47,6 +47,15 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="sp"></param> /// <param name="sp"></param>
void SaveChangedAttachments(IScenePresence sp); void SaveChangedAttachments(IScenePresence sp);
/// <summary>
/// Delete all the presence's attachments from the scene
/// </summary>
/// <param name="sp">
/// This is done when a root agent leaves/is demoted to child (for instance, on logout, teleport or region cross).
/// </param>
/// <param name="silent"></param>
void DeleteAttachmentsFromScene(IScenePresence sp, bool silent);
/// <summary> /// <summary>
/// Attach an object to an avatar from the world. /// Attach an object to an avatar from the world.
/// </summary> /// </summary>

View File

@ -62,9 +62,22 @@ namespace OpenSim.Region.Framework.Interfaces
/// A copy of the list. /// A copy of the list.
/// </returns> /// </returns>
/// <remarks> /// <remarks>
/// Do not change this list directly - use methods such as /// Do not change this list directly - use the attachments module.
/// AddAttachment() and RemoveAttachment().
/// </remarks> /// </remarks>
List<SceneObjectGroup> GetAttachments(); List<SceneObjectGroup> GetAttachments();
/// <summary>
/// The scene objects attached to this avatar at a specific attachment point.
/// </summary>
/// <param name="attachmentPoint"></param>
/// <returns></returns>
List<SceneObjectGroup> GetAttachments(uint attachmentPoint);
bool HasAttachments();
// Don't use these methods directly. Instead, use the AttachmentsModule
void AddAttachment(SceneObjectGroup gobj);
void RemoveAttachment(SceneObjectGroup gobj);
void ClearAttachments();
} }
} }

View File

@ -3401,19 +3401,7 @@ namespace OpenSim.Region.Framework.Scenes
public void Close() public void Close()
{ {
lock (m_attachments) m_scene.AttachmentsModule.DeleteAttachmentsFromScene(this, false);
{
// Delete attachments from scene
// Don't try to save, as this thread won't live long
// enough to complete the save. This would cause no copy
// attachments to poof!
//
foreach (SceneObjectGroup grp in m_attachments)
{
m_scene.DeleteSceneObject(grp, false);
}
m_attachments.Clear();
}
lock (m_knownChildRegions) lock (m_knownChildRegions)
{ {

View File

@ -143,11 +143,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
if (!m_avatars.ContainsKey(agentId)) if (!m_avatars.ContainsKey(agentId))
return false; return false;
// FIXME: An extremely bad bit of code that reaches directly into the attachments list and manipulates it scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, false);
foreach (SceneObjectGroup att in sp.GetAttachments())
scene.DeleteSceneObject(att, false);
sp.ClearAttachments();
AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);
sp.Appearance = npcAppearance; sp.Appearance = npcAppearance;