Fix NPC sitting for prims without a sit target.
This is to partially address http://opensimulator.org/mantis/view.php?id=5769 We don't need to call SP.HandleAgentSit() again if we are within 10m since the autopilot won't trigger. By calling it twice, the position of the sitting NPC was wrongly adjusted, ending up near <0,0,0>. However, this change does mean that NPCs further than 10m away will not attempt to autopilot to the prim, though this code was broken anyway (is actually a different mechanism to normal NPC movmeent). Hopefully this can be addressed soon.remove-scene-viewer
parent
f7b8c54c24
commit
28c4dc9be4
|
@ -1096,13 +1096,21 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
public Quaternion SitTargetOrientation
|
||||
{
|
||||
get { return m_sitTargetOrientation; }
|
||||
set { m_sitTargetOrientation = value; }
|
||||
set
|
||||
{
|
||||
m_sitTargetOrientation = value;
|
||||
// m_log.DebugFormat("[SCENE OBJECT PART]: Set sit target orientation {0} for {1} {2}", m_sitTargetOrientation, Name, LocalId);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 SitTargetPosition
|
||||
{
|
||||
get { return m_sitTargetPosition; }
|
||||
set { m_sitTargetPosition = value; }
|
||||
set
|
||||
{
|
||||
m_sitTargetPosition = value;
|
||||
// m_log.DebugFormat("[SCENE OBJECT PART]: Set sit target position to {0} for {1} {2}", m_sitTargetPosition, Name, LocalId);
|
||||
}
|
||||
}
|
||||
|
||||
// This sort of sucks, but I'm adding these in to make some of
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
/// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
|
||||
/// issue #1716
|
||||
/// </summary>
|
||||
private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
|
||||
public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
|
||||
|
||||
/// <summary>
|
||||
/// Movement updates for agents in neighboring regions are sent directly to clients.
|
||||
|
@ -1873,7 +1873,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
AddToPhysicalScene(false);
|
||||
}
|
||||
|
||||
m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight);
|
||||
m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
|
||||
ParentPosition = Vector3.Zero;
|
||||
|
||||
ParentID = 0;
|
||||
|
@ -2283,6 +2283,10 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
Vector3 sitTargetPos = part.SitTargetPosition;
|
||||
Quaternion sitTargetOrient = part.SitTargetOrientation;
|
||||
|
||||
// m_log.DebugFormat(
|
||||
// "[SCENE PRESENCE]: Sitting {0} at sit target {1}, {2} on {3} {4}",
|
||||
// Name, sitTargetPos, sitTargetOrient, part.Name, part.LocalId);
|
||||
|
||||
//Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
|
||||
//Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
|
||||
|
||||
|
@ -2291,15 +2295,17 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
|
||||
m_pos += SIT_TARGET_ADJUSTMENT;
|
||||
Rotation = sitTargetOrient;
|
||||
//Rotation = sitTargetOrient;
|
||||
ParentPosition = part.AbsolutePosition;
|
||||
|
||||
//SendTerseUpdateToAllClients();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pos -= part.AbsolutePosition;
|
||||
|
||||
ParentPosition = part.AbsolutePosition;
|
||||
|
||||
// m_log.DebugFormat(
|
||||
// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
|
||||
// Name, part.AbsolutePosition, m_pos, ParentPosition, part.Name, part.LocalId);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -2314,10 +2320,6 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
|
||||
Animator.TrySetMovementAnimation(sitAnimation);
|
||||
SendAvatarDataToAllAgents();
|
||||
// This may seem stupid, but Our Full updates don't send avatar rotation :P
|
||||
// So we're also sending a terse update (which has avatar rotation)
|
||||
// [Update] We do now.
|
||||
//SendTerseUpdateToAllClients();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -208,7 +208,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
|||
ScenePresence sp;
|
||||
scene.TryGetScenePresence(agentID, out sp);
|
||||
sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero);
|
||||
sp.HandleAgentSit(m_avatars[agentID], agentID);
|
||||
// sp.HandleAgentSit(m_avatars[agentID], agentID);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -231,7 +231,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void TestSitAndStand()
|
||||
public void TestSitAndStandWithSitTarget()
|
||||
{
|
||||
TestHelpers.InMethod();
|
||||
// log4net.Config.XmlConfigurator.Configure();
|
||||
|
@ -245,12 +245,49 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
|||
ScenePresence npc = scene.GetScenePresence(npcId);
|
||||
SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
|
||||
|
||||
// We must have a non Vector3.Zero sit target position otherwise part.SitTargetAvatar doesn't get set!
|
||||
part.SitTargetPosition = new Vector3(0, 0, 1);
|
||||
npcModule.Sit(npc.UUID, part.UUID, scene);
|
||||
|
||||
Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId));
|
||||
Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
|
||||
Assert.That(
|
||||
npc.AbsolutePosition,
|
||||
Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT));
|
||||
|
||||
npcModule.Stand(npc.UUID, scene);
|
||||
|
||||
Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
|
||||
Assert.That(npc.ParentID, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSitAndStandWithNoSitTarget()
|
||||
{
|
||||
TestHelpers.InMethod();
|
||||
// log4net.Config.XmlConfigurator.Configure();
|
||||
|
||||
ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
|
||||
|
||||
// FIXME: To get this to work for now, we are going to place the npc right next to the target so that
|
||||
// the autopilot doesn't trigger
|
||||
Vector3 startPos = new Vector3(1, 1, 1);
|
||||
|
||||
INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
|
||||
UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance);
|
||||
|
||||
ScenePresence npc = scene.GetScenePresence(npcId);
|
||||
SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
|
||||
|
||||
npcModule.Sit(npc.UUID, part.UUID, scene);
|
||||
|
||||
Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
|
||||
Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
|
||||
|
||||
// FIXME: This is different for live avatars - z position is adjusted. This is half the height of the
|
||||
// default avatar.
|
||||
Assert.That(
|
||||
npc.AbsolutePosition,
|
||||
Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.8857438f)));
|
||||
|
||||
npcModule.Stand(npc.UUID, scene);
|
||||
|
||||
|
|
Loading…
Reference in New Issue