Add regression test for NPC movement on a variable region.
Extends basic physics to allow av movement on a varregion (basic physics is only really useful for regression test purposes).0.8.0.3
parent
88f7a833dc
commit
2dbc18054e
|
@ -71,11 +71,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||||
Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
|
Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
[SetUp]
|
public void SetUpScene()
|
||||||
public void Init()
|
|
||||||
{
|
{
|
||||||
base.SetUp();
|
SetUpScene(256, 256);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetUpScene(uint sizeX, uint sizeY)
|
||||||
|
{
|
||||||
IConfigSource config = new IniConfigSource();
|
IConfigSource config = new IniConfigSource();
|
||||||
config.AddConfig("NPC");
|
config.AddConfig("NPC");
|
||||||
config.Configs["NPC"].Set("Enabled", "true");
|
config.Configs["NPC"].Set("Enabled", "true");
|
||||||
|
@ -87,7 +89,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||||
m_attMod = new AttachmentsModule();
|
m_attMod = new AttachmentsModule();
|
||||||
m_npcMod = new NPCModule();
|
m_npcMod = new NPCModule();
|
||||||
|
|
||||||
m_scene = new SceneHelpers().SetupScene();
|
m_scene = new SceneHelpers().SetupScene("test scene", UUID.Random(), 1000, 1000, sizeX, sizeY, config);
|
||||||
SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule());
|
SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +99,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||||
TestHelpers.InMethod();
|
TestHelpers.InMethod();
|
||||||
// log4net.Config.XmlConfigurator.Configure();
|
// log4net.Config.XmlConfigurator.Configure();
|
||||||
|
|
||||||
|
SetUpScene();
|
||||||
|
|
||||||
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
|
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
|
||||||
// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
|
// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
|
||||||
|
|
||||||
|
@ -133,6 +137,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||||
TestHelpers.InMethod();
|
TestHelpers.InMethod();
|
||||||
// log4net.Config.XmlConfigurator.Configure();
|
// log4net.Config.XmlConfigurator.Configure();
|
||||||
|
|
||||||
|
SetUpScene();
|
||||||
|
|
||||||
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
|
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
|
||||||
// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
|
// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
|
||||||
|
|
||||||
|
@ -157,6 +163,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||||
TestHelpers.InMethod();
|
TestHelpers.InMethod();
|
||||||
// TestHelpers.EnableLogging();
|
// TestHelpers.EnableLogging();
|
||||||
|
|
||||||
|
SetUpScene();
|
||||||
|
|
||||||
UUID userId = TestHelpers.ParseTail(0x1);
|
UUID userId = TestHelpers.ParseTail(0x1);
|
||||||
UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
|
UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
|
||||||
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
|
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
|
||||||
|
@ -196,6 +204,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||||
TestHelpers.InMethod();
|
TestHelpers.InMethod();
|
||||||
// log4net.Config.XmlConfigurator.Configure();
|
// log4net.Config.XmlConfigurator.Configure();
|
||||||
|
|
||||||
|
SetUpScene();
|
||||||
|
|
||||||
UUID userId = TestHelpers.ParseTail(0x1);
|
UUID userId = TestHelpers.ParseTail(0x1);
|
||||||
UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
|
UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
|
||||||
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
|
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
|
||||||
|
@ -239,6 +249,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||||
TestHelpers.InMethod();
|
TestHelpers.InMethod();
|
||||||
// log4net.Config.XmlConfigurator.Configure();
|
// log4net.Config.XmlConfigurator.Configure();
|
||||||
|
|
||||||
|
SetUpScene();
|
||||||
|
|
||||||
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
|
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
|
||||||
// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
|
// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
|
||||||
|
|
||||||
|
@ -302,12 +314,65 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||||
Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
|
Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMoveInVarRegion()
|
||||||
|
{
|
||||||
|
TestHelpers.InMethod();
|
||||||
|
// TestHelpers.EnableLogging();
|
||||||
|
|
||||||
|
SetUpScene(512, 512);
|
||||||
|
|
||||||
|
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
|
||||||
|
// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
|
||||||
|
|
||||||
|
Vector3 startPos = new Vector3(128, 246, 30);
|
||||||
|
UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance);
|
||||||
|
|
||||||
|
ScenePresence npc = m_scene.GetScenePresence(npcId);
|
||||||
|
Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
|
||||||
|
|
||||||
|
// For now, we'll make the scene presence fly to simplify this test, but this needs to change.
|
||||||
|
npc.Flying = true;
|
||||||
|
|
||||||
|
m_scene.Update(1);
|
||||||
|
Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
|
||||||
|
|
||||||
|
Vector3 targetPos = startPos + new Vector3(0, 20, 0);
|
||||||
|
m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false);
|
||||||
|
|
||||||
|
Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
|
||||||
|
//Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f)));
|
||||||
|
Assert.That(
|
||||||
|
npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001));
|
||||||
|
|
||||||
|
m_scene.Update(1);
|
||||||
|
|
||||||
|
// We should really check the exact figure.
|
||||||
|
Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X));
|
||||||
|
Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y));
|
||||||
|
Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
|
||||||
|
Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X));
|
||||||
|
|
||||||
|
for (int i = 0; i < 20; i++)
|
||||||
|
{
|
||||||
|
m_scene.Update(1);
|
||||||
|
// Console.WriteLine("pos: {0}", npc.AbsolutePosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
|
||||||
|
Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move");
|
||||||
|
Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
|
||||||
|
Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSitAndStandWithSitTarget()
|
public void TestSitAndStandWithSitTarget()
|
||||||
{
|
{
|
||||||
TestHelpers.InMethod();
|
TestHelpers.InMethod();
|
||||||
// log4net.Config.XmlConfigurator.Configure();
|
// log4net.Config.XmlConfigurator.Configure();
|
||||||
|
|
||||||
|
SetUpScene();
|
||||||
|
|
||||||
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
|
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
|
||||||
|
|
||||||
Vector3 startPos = new Vector3(128, 128, 30);
|
Vector3 startPos = new Vector3(128, 128, 30);
|
||||||
|
@ -337,6 +402,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||||
TestHelpers.InMethod();
|
TestHelpers.InMethod();
|
||||||
// TestHelpers.EnableLogging();
|
// TestHelpers.EnableLogging();
|
||||||
|
|
||||||
|
SetUpScene();
|
||||||
|
|
||||||
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
|
ScenePresence sp = SceneHelpers.AddScenePresence(m_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
|
// FIXME: To get this to work for now, we are going to place the npc right next to the target so that
|
||||||
|
@ -365,4 +432,4 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||||
Assert.That(npc.ParentID, Is.EqualTo(0));
|
Assert.That(npc.ParentID, Is.EqualTo(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -46,6 +46,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
|
||||||
private List<BasicActor> _actors = new List<BasicActor>();
|
private List<BasicActor> _actors = new List<BasicActor>();
|
||||||
private List<BasicPhysicsPrim> _prims = new List<BasicPhysicsPrim>();
|
private List<BasicPhysicsPrim> _prims = new List<BasicPhysicsPrim>();
|
||||||
private float[] _heightMap;
|
private float[] _heightMap;
|
||||||
|
private Vector3 m_regionExtent;
|
||||||
|
|
||||||
//protected internal string sceneIdentifier;
|
//protected internal string sceneIdentifier;
|
||||||
|
|
||||||
|
@ -58,6 +59,12 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
|
||||||
|
|
||||||
public override void Initialise(IMesher meshmerizer, IConfigSource config)
|
public override void Initialise(IMesher meshmerizer, IConfigSource config)
|
||||||
{
|
{
|
||||||
|
throw new Exception("Should not be called.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent)
|
||||||
|
{
|
||||||
|
m_regionExtent = regionExtent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose() {}
|
public override void Dispose() {}
|
||||||
|
@ -121,23 +128,23 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
|
||||||
{
|
{
|
||||||
actorPosition.Y = 0.1F;
|
actorPosition.Y = 0.1F;
|
||||||
}
|
}
|
||||||
else if (actor.Position.Y >= Constants.RegionSize)
|
else if (actor.Position.Y >= m_regionExtent.Y)
|
||||||
{
|
{
|
||||||
actorPosition.Y = ((int)Constants.RegionSize - 0.1f);
|
actorPosition.Y = (m_regionExtent.Y - 0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actor.Position.X < 0)
|
if (actor.Position.X < 0)
|
||||||
{
|
{
|
||||||
actorPosition.X = 0.1F;
|
actorPosition.X = 0.1F;
|
||||||
}
|
}
|
||||||
else if (actor.Position.X >= Constants.RegionSize)
|
else if (actor.Position.X >= m_regionExtent.X)
|
||||||
{
|
{
|
||||||
actorPosition.X = ((int)Constants.RegionSize - 0.1f);
|
actorPosition.X = (m_regionExtent.X - 0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float terrainHeight = 0;
|
float terrainHeight = 0;
|
||||||
if (_heightMap != null)
|
if (_heightMap != null)
|
||||||
terrainHeight = _heightMap[(int)actor.Position.Y * Constants.RegionSize + (int)actor.Position.X];
|
terrainHeight = _heightMap[(int)actor.Position.Y * (int)m_regionExtent.Y + (int)actor.Position.X];
|
||||||
|
|
||||||
float height = terrainHeight + actor.Size.Z;
|
float height = terrainHeight + actor.Size.Z;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue