Don't try to save changed attachment states when an NPC with attachments is removed from the scene.

This is done by introducing a PresenceType enum into ScenePresence which currently has two values, User and Npc.
This seems better than a SaveAttachments flag in terms of code comprehension, though I'm still slightly uneasy about introducing these semantics to core objects
This commit is contained in:
Justin Clark-Casey (justincc)
2011-08-18 00:53:05 +01:00
parent d8f886ccdb
commit c1a34cd8da
14 changed files with 71 additions and 23 deletions

View File

@@ -2543,10 +2543,11 @@ namespace OpenSim.Region.Framework.Scenes
#region Add/Remove Avatar Methods
/// <summary>
/// Adding a New Client and Create a Presence for it.
/// Add a new client and create a child agent for it.
/// </summary>
/// <param name="client"></param>
public override void AddNewClient(IClientAPI client)
/// <param name="type">The type of agent to add.</param>
public override void AddNewClient(IClientAPI client, PresenceType type)
{
AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode);
bool vialogin = false;
@@ -2566,7 +2567,7 @@ namespace OpenSim.Region.Framework.Scenes
m_clientManager.Add(client);
SubscribeToClientEvents(client);
ScenePresence sp = m_sceneGraph.CreateAndAddChildScenePresence(client, aCircuit.Appearance);
ScenePresence sp = m_sceneGraph.CreateAndAddChildScenePresence(client, aCircuit.Appearance, type);
m_eventManager.TriggerOnNewPresence(sp);
sp.TeleportFlags = (TeleportFlags)aCircuit.teleportFlags;
@@ -3149,7 +3150,7 @@ namespace OpenSim.Region.Framework.Scenes
m_eventManager.TriggerOnRemovePresence(agentID);
if (avatar != null && (!avatar.IsChildAgent))
if (avatar != null && (!avatar.IsChildAgent) && avatar.PresenceType != PresenceType.Npc)
avatar.SaveChangedAttachments();
ForEachClient(

View File

@@ -175,7 +175,7 @@ namespace OpenSim.Region.Framework.Scenes
#region Add/Remove Agent/Avatar
public abstract void AddNewClient(IClientAPI client);
public abstract void AddNewClient(IClientAPI client, PresenceType type);
public abstract void RemoveClient(UUID agentID, bool closeChildAgents);
public bool TryGetScenePresence(UUID agentID, out object scenePresence)

View File

@@ -590,12 +590,13 @@ namespace OpenSim.Region.Framework.Scenes
}
}
protected internal ScenePresence CreateAndAddChildScenePresence(IClientAPI client, AvatarAppearance appearance)
protected internal ScenePresence CreateAndAddChildScenePresence(
IClientAPI client, AvatarAppearance appearance, PresenceType type)
{
ScenePresence newAvatar = null;
// ScenePresence always defaults to child agent
newAvatar = new ScenePresence(client, m_parentScene, m_regInfo, appearance);
newAvatar = new ScenePresence(client, m_parentScene, m_regInfo, appearance, type);
AddScenePresence(newAvatar);

View File

@@ -75,6 +75,11 @@ namespace OpenSim.Region.Framework.Scenes
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// What type of presence is this? User, NPC, etc.
/// </summary>
public PresenceType PresenceType { get; private set; }
// private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes();
private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags));
private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f);
@@ -715,8 +720,9 @@ namespace OpenSim.Region.Framework.Scenes
m_animator = new ScenePresenceAnimator(this);
}
private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, PresenceType type) : this()
{
PresenceType = type;
m_DrawDistance = world.DefaultDrawDistance;
m_rootRegionHandle = reginfo.RegionHandle;
m_controllingClient = client;
@@ -764,8 +770,8 @@ namespace OpenSim.Region.Framework.Scenes
SetDirectionVectors();
}
public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance)
: this(client, world, reginfo)
public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance, PresenceType type)
: this(client, world, reginfo, type)
{
m_appearance = appearance;
}

View File

@@ -207,7 +207,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
scene.NewUserConnection(acd1, 0, out reason);
if (testclient == null)
testclient = new TestClient(acd1, scene);
scene.AddNewClient(testclient);
scene.AddNewClient(testclient, PresenceType.User);
ScenePresence presence = scene.GetScenePresence(agent1);
presence.MakeRootAgent(new Vector3(90,90,90),false);
@@ -257,7 +257,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
// Adding child agent to region 1001
string reason;
scene2.NewUserConnection(acd1,0, out reason);
scene2.AddNewClient(testclient);
scene2.AddNewClient(testclient, PresenceType.User);
ScenePresence presence = scene.GetScenePresence(agent1);
presence.MakeRootAgent(new Vector3(0,unchecked(Constants.RegionSize-1),0), true);