From 2dbc18054e354a17519f84c0b3294094fae3b5b2 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 29 Apr 2014 19:29:16 +0100 Subject: 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). --- .../World/NPC/Tests/NPCModuleTests.cs | 77 ++++++++++++++++++++-- .../BasicPhysicsPlugin/BasicPhysicsScene.cs | 17 +++-- 2 files changed, 84 insertions(+), 10 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index c65794e..ddd4525 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -71,11 +71,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; } - [SetUp] - public void Init() + public void SetUpScene() { - base.SetUp(); + SetUpScene(256, 256); + } + public void SetUpScene(uint sizeX, uint sizeY) + { IConfigSource config = new IniConfigSource(); config.AddConfig("NPC"); config.Configs["NPC"].Set("Enabled", "true"); @@ -87,7 +89,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests m_attMod = new AttachmentsModule(); 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()); } @@ -97,6 +99,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); + SetUpScene(); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); @@ -133,6 +137,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); + SetUpScene(); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); @@ -157,6 +163,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // TestHelpers.EnableLogging(); + SetUpScene(); + UUID userId = TestHelpers.ParseTail(0x1); UserAccountHelpers.CreateUserWithInventory(m_scene, userId); ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); @@ -196,6 +204,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); + SetUpScene(); + UUID userId = TestHelpers.ParseTail(0x1); UserAccountHelpers.CreateUserWithInventory(m_scene, userId); ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); @@ -239,6 +249,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); + SetUpScene(); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); @@ -303,11 +315,64 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests } [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] public void TestSitAndStandWithSitTarget() { TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); + SetUpScene(); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); Vector3 startPos = new Vector3(128, 128, 30); @@ -337,6 +402,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // TestHelpers.EnableLogging(); + SetUpScene(); + 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 @@ -365,4 +432,4 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Assert.That(npc.ParentID, Is.EqualTo(0)); } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs index 0816b7b..8e40561 100644 --- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs @@ -46,6 +46,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin private List _actors = new List(); private List _prims = new List(); private float[] _heightMap; + private Vector3 m_regionExtent; //protected internal string sceneIdentifier; @@ -58,6 +59,12 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin 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() {} @@ -121,23 +128,23 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin { 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) { 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; 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; -- cgit v1.1