diff options
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Scene.cs | 68 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs | 135 | ||||
-rw-r--r-- | OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | 2 |
3 files changed, 203 insertions, 2 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 7897564..fc89b2a 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs | |||
@@ -896,6 +896,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
896 | 896 | ||
897 | if (dm != null) | 897 | if (dm != null) |
898 | m_eventManager.OnPermissionError += dm.SendAlertToUser; | 898 | m_eventManager.OnPermissionError += dm.SendAlertToUser; |
899 | |||
900 | m_eventManager.OnSignificantClientMovement += HandleOnSignificantClientMovement; | ||
899 | } | 901 | } |
900 | 902 | ||
901 | public override string GetSimulatorVersion() | 903 | public override string GetSimulatorVersion() |
@@ -5396,7 +5398,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
5396 | return true; | 5398 | return true; |
5397 | } | 5399 | } |
5398 | 5400 | ||
5399 | public void StartTimerWatchdog() | 5401 | public void StartTimerWatchdog() |
5400 | { | 5402 | { |
5401 | m_timerWatchdog.Interval = 1000; | 5403 | m_timerWatchdog.Interval = 1000; |
5402 | m_timerWatchdog.Elapsed += TimerWatchdog; | 5404 | m_timerWatchdog.Elapsed += TimerWatchdog; |
@@ -5407,6 +5409,70 @@ namespace OpenSim.Region.Framework.Scenes | |||
5407 | public void TimerWatchdog(object sender, ElapsedEventArgs e) | 5409 | public void TimerWatchdog(object sender, ElapsedEventArgs e) |
5408 | { | 5410 | { |
5409 | CheckHeartbeat(); | 5411 | CheckHeartbeat(); |
5412 | } | ||
5413 | |||
5414 | /// This method deals with movement when an avatar is automatically moving (but this is distinct from the | ||
5415 | /// autopilot that moves an avatar to a sit target!. | ||
5416 | /// </summary> | ||
5417 | /// <remarks> | ||
5418 | /// This is not intended as a permament location for this method. | ||
5419 | /// </remarks> | ||
5420 | /// <param name="presence"></param> | ||
5421 | private void HandleOnSignificantClientMovement(ScenePresence presence) | ||
5422 | { | ||
5423 | if (presence.MovingToTarget) | ||
5424 | { | ||
5425 | double distanceToTarget = Util.GetDistanceTo(presence.AbsolutePosition, presence.MoveToPositionTarget); | ||
5426 | // m_log.DebugFormat( | ||
5427 | // "[SCENE]: Abs pos of {0} is {1}, target {2}, distance {3}", | ||
5428 | // presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget, distanceToTarget); | ||
5429 | |||
5430 | // Check the error term of the current position in relation to the target position | ||
5431 | if (distanceToTarget <= ScenePresence.SIGNIFICANT_MOVEMENT) | ||
5432 | { | ||
5433 | // We are close enough to the target | ||
5434 | // m_log.DebugFormat("[SCENEE]: Stopping autopilot of {0}", presence.Name); | ||
5435 | |||
5436 | presence.Velocity = Vector3.Zero; | ||
5437 | presence.AbsolutePosition = presence.MoveToPositionTarget; | ||
5438 | presence.ResetMoveToTarget(); | ||
5439 | |||
5440 | if (presence.PhysicsActor.Flying) | ||
5441 | { | ||
5442 | // A horrible hack to stop the avatar dead in its tracks rather than having them overshoot | ||
5443 | // the target if flying. | ||
5444 | // We really need to be more subtle (slow the avatar as it approaches the target) or at | ||
5445 | // least be able to set collision status once, rather than 5 times to give it enough | ||
5446 | // weighting so that that PhysicsActor thinks it really is colliding. | ||
5447 | for (int i = 0; i < 5; i++) | ||
5448 | presence.PhysicsActor.IsColliding = true; | ||
5449 | |||
5450 | // Vector3 targetPos = presence.MoveToPositionTarget; | ||
5451 | // if (m_avatars[presence.UUID].LandAtTarget) | ||
5452 | // presence.PhysicsActor.Flying = false; | ||
5453 | |||
5454 | // float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y]; | ||
5455 | // if (targetPos.Z - terrainHeight < 0.2) | ||
5456 | // { | ||
5457 | // presence.PhysicsActor.Flying = false; | ||
5458 | // } | ||
5459 | } | ||
5460 | |||
5461 | // m_log.DebugFormat( | ||
5462 | // "[SCENE]: AgentControlFlags {0}, MovementFlag {1} for {2}", | ||
5463 | // presence.AgentControlFlags, presence.MovementFlag, presence.Name); | ||
5464 | } | ||
5465 | else | ||
5466 | { | ||
5467 | // m_log.DebugFormat( | ||
5468 | // "[SCENE]: Updating npc {0} at {1} for next movement to {2}", | ||
5469 | // presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget); | ||
5470 | |||
5471 | Vector3 agent_control_v3 = new Vector3(); | ||
5472 | presence.HandleMoveToTargetUpdate(ref agent_control_v3); | ||
5473 | presence.AddNewMovement(agent_control_v3); | ||
5474 | } | ||
5475 | } | ||
5410 | } | 5476 | } |
5411 | } | 5477 | } |
5412 | } | 5478 | } |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs new file mode 100644 index 0000000..5a85d7f --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using NUnit.Framework; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Communications; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Tests.Common; | ||
40 | using OpenSim.Tests.Common.Mock; | ||
41 | |||
42 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
43 | { | ||
44 | [TestFixture] | ||
45 | public class ScenePresenceAutopilotTests | ||
46 | { | ||
47 | private TestScene m_scene; | ||
48 | |||
49 | [TestFixtureSetUp] | ||
50 | public void FixtureInit() | ||
51 | { | ||
52 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
53 | Util.FireAndForgetMethod = FireAndForgetMethod.None; | ||
54 | } | ||
55 | |||
56 | [TestFixtureTearDown] | ||
57 | public void TearDown() | ||
58 | { | ||
59 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
60 | // threads. Possibly, later tests should be rewritten not to worry about such things. | ||
61 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
62 | } | ||
63 | |||
64 | [SetUp] | ||
65 | public void Init() | ||
66 | { | ||
67 | m_scene = SceneHelpers.SetupScene(); | ||
68 | } | ||
69 | |||
70 | [Test] | ||
71 | public void TestMove() | ||
72 | { | ||
73 | TestHelpers.InMethod(); | ||
74 | // log4net.Config.XmlConfigurator.Configure(); | ||
75 | |||
76 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | ||
77 | |||
78 | Vector3 startPos = sp.AbsolutePosition; | ||
79 | // Vector3 startPos = new Vector3(128, 128, 30); | ||
80 | |||
81 | // For now, we'll make the scene presence fly to simplify this test, but this needs to change. | ||
82 | sp.PhysicsActor.Flying = true; | ||
83 | |||
84 | m_scene.Update(); | ||
85 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); | ||
86 | |||
87 | Vector3 targetPos = startPos + new Vector3(0, 10, 0); | ||
88 | sp.MoveToTarget(targetPos, false); | ||
89 | |||
90 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); | ||
91 | Assert.That( | ||
92 | sp.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001)); | ||
93 | |||
94 | m_scene.Update(); | ||
95 | |||
96 | // We should really check the exact figure. | ||
97 | Assert.That(sp.AbsolutePosition.X, Is.EqualTo(startPos.X)); | ||
98 | Assert.That(sp.AbsolutePosition.Y, Is.GreaterThan(startPos.Y)); | ||
99 | Assert.That(sp.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); | ||
100 | Assert.That(sp.AbsolutePosition.Z, Is.LessThan(targetPos.X)); | ||
101 | |||
102 | for (int i = 0; i < 10; i++) | ||
103 | m_scene.Update(); | ||
104 | |||
105 | double distanceToTarget = Util.GetDistanceTo(sp.AbsolutePosition, targetPos); | ||
106 | Assert.That(distanceToTarget, Is.LessThan(1), "Avatar not within 1 unit of target position on first move"); | ||
107 | Assert.That(sp.AbsolutePosition, Is.EqualTo(targetPos)); | ||
108 | Assert.That(sp.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE)); | ||
109 | |||
110 | // Try a second movement | ||
111 | startPos = sp.AbsolutePosition; | ||
112 | targetPos = startPos + new Vector3(10, 0, 0); | ||
113 | sp.MoveToTarget(targetPos, false); | ||
114 | |||
115 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); | ||
116 | Assert.That( | ||
117 | sp.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001)); | ||
118 | |||
119 | m_scene.Update(); | ||
120 | |||
121 | // We should really check the exact figure. | ||
122 | Assert.That(sp.AbsolutePosition.X, Is.GreaterThan(startPos.X)); | ||
123 | Assert.That(sp.AbsolutePosition.X, Is.LessThan(targetPos.X)); | ||
124 | Assert.That(sp.AbsolutePosition.Y, Is.EqualTo(startPos.Y)); | ||
125 | Assert.That(sp.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); | ||
126 | |||
127 | for (int i = 0; i < 10; i++) | ||
128 | m_scene.Update(); | ||
129 | |||
130 | distanceToTarget = Util.GetDistanceTo(sp.AbsolutePosition, targetPos); | ||
131 | Assert.That(distanceToTarget, Is.LessThan(1), "Avatar not within 1 unit of target position on second move"); | ||
132 | Assert.That(sp.AbsolutePosition, Is.EqualTo(targetPos)); | ||
133 | } | ||
134 | } | ||
135 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 2fdeeab..6282245 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -53,7 +53,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
53 | if (config != null && config.GetBoolean("Enabled", false)) | 53 | if (config != null && config.GetBoolean("Enabled", false)) |
54 | { | 54 | { |
55 | scene.RegisterModuleInterface<INPCModule>(this); | 55 | scene.RegisterModuleInterface<INPCModule>(this); |
56 | scene.EventManager.OnSignificantClientMovement += HandleOnSignificantClientMovement; | 56 | // scene.EventManager.OnSignificantClientMovement += HandleOnSignificantClientMovement; |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||