aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-04-29 19:29:16 +0100
committerJustin Clark-Casey (justincc)2014-04-29 19:29:16 +0100
commit2dbc18054e354a17519f84c0b3294094fae3b5b2 (patch)
tree83cc0d4f25e711464fad07ae28da56dfe278c498 /OpenSim/Region
parentImproved HTTP logging (diff)
downloadopensim-SC_OLD-2dbc18054e354a17519f84c0b3294094fae3b5b2.zip
opensim-SC_OLD-2dbc18054e354a17519f84c0b3294094fae3b5b2.tar.gz
opensim-SC_OLD-2dbc18054e354a17519f84c0b3294094fae3b5b2.tar.bz2
opensim-SC_OLD-2dbc18054e354a17519f84c0b3294094fae3b5b2.tar.xz
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).
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs77
-rw-r--r--OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs17
2 files changed, 84 insertions, 10 deletions
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
71 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; 71 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
72 } 72 }
73 73
74 [SetUp] 74 public void SetUpScene()
75 public void Init()
76 { 75 {
77 base.SetUp(); 76 SetUpScene(256, 256);
77 }
78 78
79 public void SetUpScene(uint sizeX, uint sizeY)
80 {
79 IConfigSource config = new IniConfigSource(); 81 IConfigSource config = new IniConfigSource();
80 config.AddConfig("NPC"); 82 config.AddConfig("NPC");
81 config.Configs["NPC"].Set("Enabled", "true"); 83 config.Configs["NPC"].Set("Enabled", "true");
@@ -87,7 +89,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
87 m_attMod = new AttachmentsModule(); 89 m_attMod = new AttachmentsModule();
88 m_npcMod = new NPCModule(); 90 m_npcMod = new NPCModule();
89 91
90 m_scene = new SceneHelpers().SetupScene(); 92 m_scene = new SceneHelpers().SetupScene("test scene", UUID.Random(), 1000, 1000, sizeX, sizeY, config);
91 SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule()); 93 SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule());
92 } 94 }
93 95
@@ -97,6 +99,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
97 TestHelpers.InMethod(); 99 TestHelpers.InMethod();
98// log4net.Config.XmlConfigurator.Configure(); 100// log4net.Config.XmlConfigurator.Configure();
99 101
102 SetUpScene();
103
100 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); 104 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
101// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); 105// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
102 106
@@ -133,6 +137,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
133 TestHelpers.InMethod(); 137 TestHelpers.InMethod();
134// log4net.Config.XmlConfigurator.Configure(); 138// log4net.Config.XmlConfigurator.Configure();
135 139
140 SetUpScene();
141
136 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); 142 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
137// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); 143// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
138 144
@@ -157,6 +163,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
157 TestHelpers.InMethod(); 163 TestHelpers.InMethod();
158// TestHelpers.EnableLogging(); 164// TestHelpers.EnableLogging();
159 165
166 SetUpScene();
167
160 UUID userId = TestHelpers.ParseTail(0x1); 168 UUID userId = TestHelpers.ParseTail(0x1);
161 UserAccountHelpers.CreateUserWithInventory(m_scene, userId); 169 UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
162 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); 170 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
@@ -196,6 +204,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
196 TestHelpers.InMethod(); 204 TestHelpers.InMethod();
197// log4net.Config.XmlConfigurator.Configure(); 205// log4net.Config.XmlConfigurator.Configure();
198 206
207 SetUpScene();
208
199 UUID userId = TestHelpers.ParseTail(0x1); 209 UUID userId = TestHelpers.ParseTail(0x1);
200 UserAccountHelpers.CreateUserWithInventory(m_scene, userId); 210 UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
201 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); 211 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
@@ -239,6 +249,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
239 TestHelpers.InMethod(); 249 TestHelpers.InMethod();
240// log4net.Config.XmlConfigurator.Configure(); 250// log4net.Config.XmlConfigurator.Configure();
241 251
252 SetUpScene();
253
242 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); 254 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
243// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); 255// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
244 256
@@ -303,11 +315,64 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
303 } 315 }
304 316
305 [Test] 317 [Test]
318 public void TestMoveInVarRegion()
319 {
320 TestHelpers.InMethod();
321// TestHelpers.EnableLogging();
322
323 SetUpScene(512, 512);
324
325 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
326// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
327
328 Vector3 startPos = new Vector3(128, 246, 30);
329 UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance);
330
331 ScenePresence npc = m_scene.GetScenePresence(npcId);
332 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
333
334 // For now, we'll make the scene presence fly to simplify this test, but this needs to change.
335 npc.Flying = true;
336
337 m_scene.Update(1);
338 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
339
340 Vector3 targetPos = startPos + new Vector3(0, 20, 0);
341 m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false);
342
343 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
344 //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f)));
345 Assert.That(
346 npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001));
347
348 m_scene.Update(1);
349
350 // We should really check the exact figure.
351 Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X));
352 Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y));
353 Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
354 Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X));
355
356 for (int i = 0; i < 20; i++)
357 {
358 m_scene.Update(1);
359// Console.WriteLine("pos: {0}", npc.AbsolutePosition);
360 }
361
362 double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
363 Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move");
364 Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
365 Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));
366 }
367
368 [Test]
306 public void TestSitAndStandWithSitTarget() 369 public void TestSitAndStandWithSitTarget()
307 { 370 {
308 TestHelpers.InMethod(); 371 TestHelpers.InMethod();
309// log4net.Config.XmlConfigurator.Configure(); 372// log4net.Config.XmlConfigurator.Configure();
310 373
374 SetUpScene();
375
311 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); 376 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
312 377
313 Vector3 startPos = new Vector3(128, 128, 30); 378 Vector3 startPos = new Vector3(128, 128, 30);
@@ -337,6 +402,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
337 TestHelpers.InMethod(); 402 TestHelpers.InMethod();
338// TestHelpers.EnableLogging(); 403// TestHelpers.EnableLogging();
339 404
405 SetUpScene();
406
340 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); 407 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
341 408
342 // FIXME: To get this to work for now, we are going to place the npc right next to the target so that 409 // 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
365 Assert.That(npc.ParentID, Is.EqualTo(0)); 432 Assert.That(npc.ParentID, Is.EqualTo(0));
366 } 433 }
367 } 434 }
368} 435} \ 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
46 private List<BasicActor> _actors = new List<BasicActor>(); 46 private List<BasicActor> _actors = new List<BasicActor>();
47 private List<BasicPhysicsPrim> _prims = new List<BasicPhysicsPrim>(); 47 private List<BasicPhysicsPrim> _prims = new List<BasicPhysicsPrim>();
48 private float[] _heightMap; 48 private float[] _heightMap;
49 private Vector3 m_regionExtent;
49 50
50 //protected internal string sceneIdentifier; 51 //protected internal string sceneIdentifier;
51 52
@@ -58,6 +59,12 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
58 59
59 public override void Initialise(IMesher meshmerizer, IConfigSource config) 60 public override void Initialise(IMesher meshmerizer, IConfigSource config)
60 { 61 {
62 throw new Exception("Should not be called.");
63 }
64
65 public override void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent)
66 {
67 m_regionExtent = regionExtent;
61 } 68 }
62 69
63 public override void Dispose() {} 70 public override void Dispose() {}
@@ -121,23 +128,23 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
121 { 128 {
122 actorPosition.Y = 0.1F; 129 actorPosition.Y = 0.1F;
123 } 130 }
124 else if (actor.Position.Y >= Constants.RegionSize) 131 else if (actor.Position.Y >= m_regionExtent.Y)
125 { 132 {
126 actorPosition.Y = ((int)Constants.RegionSize - 0.1f); 133 actorPosition.Y = (m_regionExtent.Y - 0.1f);
127 } 134 }
128 135
129 if (actor.Position.X < 0) 136 if (actor.Position.X < 0)
130 { 137 {
131 actorPosition.X = 0.1F; 138 actorPosition.X = 0.1F;
132 } 139 }
133 else if (actor.Position.X >= Constants.RegionSize) 140 else if (actor.Position.X >= m_regionExtent.X)
134 { 141 {
135 actorPosition.X = ((int)Constants.RegionSize - 0.1f); 142 actorPosition.X = (m_regionExtent.X - 0.1f);
136 } 143 }
137 144
138 float terrainHeight = 0; 145 float terrainHeight = 0;
139 if (_heightMap != null) 146 if (_heightMap != null)
140 terrainHeight = _heightMap[(int)actor.Position.Y * Constants.RegionSize + (int)actor.Position.X]; 147 terrainHeight = _heightMap[(int)actor.Position.Y * (int)m_regionExtent.Y + (int)actor.Position.X];
141 148
142 float height = terrainHeight + actor.Size.Z; 149 float height = terrainHeight + actor.Size.Z;
143 150