refactor: Move ScenePresence <-> AgentData attachments copying code into AttachmentsModule.

0.7.3-extended
Justin Clark-Casey (justincc) 2012-06-27 00:41:46 +01:00
parent 96191241be
commit ea9b0794e0
4 changed files with 74 additions and 37 deletions

View File

@ -102,6 +102,56 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
#region IAttachmentsModule
public void CopyAttachments(IScenePresence sp, AgentData ad)
{
lock (sp.AttachmentsSyncLock)
{
// Attachment objects
List<SceneObjectGroup> attachments = sp.GetAttachments();
if (attachments.Count > 0)
{
ad.AttachmentObjects = new List<ISceneObject>();
ad.AttachmentObjectStates = new List<string>();
// IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>();
sp.InTransitScriptStates.Clear();
foreach (SceneObjectGroup sog in attachments)
{
// We need to make a copy and pass that copy
// because of transfers withn the same sim
ISceneObject clone = sog.CloneForNewScene();
// Attachment module assumes that GroupPosition holds the offsets...!
((SceneObjectGroup)clone).RootPart.GroupPosition = sog.RootPart.AttachedPos;
((SceneObjectGroup)clone).IsAttachment = false;
ad.AttachmentObjects.Add(clone);
string state = sog.GetStateSnapshot();
ad.AttachmentObjectStates.Add(state);
sp.InTransitScriptStates.Add(state);
// Let's remove the scripts of the original object here
sog.RemoveScriptInstances(true);
}
}
}
}
public void CopyAttachments(AgentData ad, IScenePresence sp)
{
if (ad.AttachmentObjects != null && ad.AttachmentObjects.Count > 0)
{
lock (sp.AttachmentsSyncLock)
sp.ClearAttachments();
int i = 0;
foreach (ISceneObject so in ad.AttachmentObjects)
{
((SceneObjectGroup)so).LocalId = 0;
((SceneObjectGroup)so).RootPart.ClearUpdateSchedule();
so.SetState(ad.AttachmentObjectStates[i++], m_scene);
m_scene.IncomingCreateObject(Vector3.Zero, so);
}
}
}
/// <summary>
/// RezAttachments. This should only be called upon login on the first region.
/// Attachment rezzings on crossings and TPs are done in a different way.

View File

@ -35,6 +35,20 @@ namespace OpenSim.Region.Framework.Interfaces
{
public interface IAttachmentsModule
{
/// <summary>
/// Copy attachment data from a ScenePresence into the AgentData structure for transmission to another simulator
/// </summary>
/// <param name='sp'></param>
/// <param name='ad'></param>
void CopyAttachments(IScenePresence sp, AgentData ad);
/// <summary>
/// Copy attachment data from an AgentData structure into a ScenePresence.
/// </summary>
/// <param name='ad'></param>
/// <param name='sp'></param>
void CopyAttachments(AgentData ad, IScenePresence sp);
/// <summary>
/// RezAttachments. This should only be called upon login on the first region.
/// Attachment rezzings on crossings and TPs are done in a different way.

View File

@ -40,6 +40,12 @@ namespace OpenSim.Region.Framework.Interfaces
/// </remarks>
public interface IScenePresence : ISceneAgent
{
/// <summary>
/// Copy of the script states while the agent is in transit. This state may
/// need to be placed back in case of transfer fail.
/// </summary>
List<string> InTransitScriptStates { get; }
/// <summary>
/// The AttachmentsModule synchronizes on this to avoid race conditions between commands to add and remove attachments.
/// </summary>

View File

@ -3145,31 +3145,8 @@ namespace OpenSim.Region.Framework.Scenes
}
catch { }
// Attachment objects
List<SceneObjectGroup> attachments = GetAttachments();
if (attachments.Count > 0)
{
cAgent.AttachmentObjects = new List<ISceneObject>();
cAgent.AttachmentObjectStates = new List<string>();
// IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>();
InTransitScriptStates.Clear();
foreach (SceneObjectGroup sog in attachments)
{
// We need to make a copy and pass that copy
// because of transfers withn the same sim
ISceneObject clone = sog.CloneForNewScene();
// Attachment module assumes that GroupPosition holds the offsets...!
((SceneObjectGroup)clone).RootPart.GroupPosition = sog.RootPart.AttachedPos;
((SceneObjectGroup)clone).IsAttachment = false;
cAgent.AttachmentObjects.Add(clone);
string state = sog.GetStateSnapshot();
cAgent.AttachmentObjectStates.Add(state);
InTransitScriptStates.Add(state);
// Let's remove the scripts of the original object here
sog.RemoveScriptInstances(true);
}
}
if (Scene.AttachmentsModule != null)
Scene.AttachmentsModule.CopyAttachments(this, cAgent);
}
private void CopyFrom(AgentData cAgent)
@ -3239,18 +3216,8 @@ namespace OpenSim.Region.Framework.Scenes
if (cAgent.Anims != null)
Animator.Animations.FromArray(cAgent.Anims);
if (cAgent.AttachmentObjects != null && cAgent.AttachmentObjects.Count > 0)
{
m_attachments = new List<SceneObjectGroup>();
int i = 0;
foreach (ISceneObject so in cAgent.AttachmentObjects)
{
((SceneObjectGroup)so).LocalId = 0;
((SceneObjectGroup)so).RootPart.ClearUpdateSchedule();
so.SetState(cAgent.AttachmentObjectStates[i++], m_scene);
m_scene.IncomingCreateObject(Vector3.Zero, so);
}
}
if (Scene.AttachmentsModule != null)
Scene.AttachmentsModule.CopyAttachments(cAgent, this);
}
public bool CopyAgent(out IAgentData agent)