aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-11-05 01:38:42 +0000
committerJustin Clark-Casey (justincc)2011-11-05 01:38:42 +0000
commit28c4dc9be490a3beedccb17bc1b411e45cced846 (patch)
treea399c6faf3f08e53f20ae4aba546aff9cfdd083e /OpenSim
parentAdd comment for experimental effect of removing the Thread.Sleep(20) in ODEPr... (diff)
downloadopensim-SC_OLD-28c4dc9be490a3beedccb17bc1b411e45cced846.zip
opensim-SC_OLD-28c4dc9be490a3beedccb17bc1b411e45cced846.tar.gz
opensim-SC_OLD-28c4dc9be490a3beedccb17bc1b411e45cced846.tar.bz2
opensim-SC_OLD-28c4dc9be490a3beedccb17bc1b411e45cced846.tar.xz
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.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs12
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs20
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs2
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs41
4 files changed, 61 insertions, 14 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index b77f1b6..4071159 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -1096,13 +1096,21 @@ namespace OpenSim.Region.Framework.Scenes
1096 public Quaternion SitTargetOrientation 1096 public Quaternion SitTargetOrientation
1097 { 1097 {
1098 get { return m_sitTargetOrientation; } 1098 get { return m_sitTargetOrientation; }
1099 set { m_sitTargetOrientation = value; } 1099 set
1100 {
1101 m_sitTargetOrientation = value;
1102// m_log.DebugFormat("[SCENE OBJECT PART]: Set sit target orientation {0} for {1} {2}", m_sitTargetOrientation, Name, LocalId);
1103 }
1100 } 1104 }
1101 1105
1102 public Vector3 SitTargetPosition 1106 public Vector3 SitTargetPosition
1103 { 1107 {
1104 get { return m_sitTargetPosition; } 1108 get { return m_sitTargetPosition; }
1105 set { m_sitTargetPosition = value; } 1109 set
1110 {
1111 m_sitTargetPosition = value;
1112// m_log.DebugFormat("[SCENE OBJECT PART]: Set sit target position to {0} for {1} {2}", m_sitTargetPosition, Name, LocalId);
1113 }
1106 } 1114 }
1107 1115
1108 // This sort of sucks, but I'm adding these in to make some of 1116 // This sort of sucks, but I'm adding these in to make some of
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 89e511f..4156f21 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -89,7 +89,7 @@ namespace OpenSim.Region.Framework.Scenes
89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
90 /// issue #1716 90 /// issue #1716
91 /// </summary> 91 /// </summary>
92 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 92 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
93 93
94 /// <summary> 94 /// <summary>
95 /// Movement updates for agents in neighboring regions are sent directly to clients. 95 /// Movement updates for agents in neighboring regions are sent directly to clients.
@@ -1873,7 +1873,7 @@ namespace OpenSim.Region.Framework.Scenes
1873 AddToPhysicalScene(false); 1873 AddToPhysicalScene(false);
1874 } 1874 }
1875 1875
1876 m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1876 m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
1877 ParentPosition = Vector3.Zero; 1877 ParentPosition = Vector3.Zero;
1878 1878
1879 ParentID = 0; 1879 ParentID = 0;
@@ -2283,6 +2283,10 @@ namespace OpenSim.Region.Framework.Scenes
2283 Vector3 sitTargetPos = part.SitTargetPosition; 2283 Vector3 sitTargetPos = part.SitTargetPosition;
2284 Quaternion sitTargetOrient = part.SitTargetOrientation; 2284 Quaternion sitTargetOrient = part.SitTargetOrientation;
2285 2285
2286// m_log.DebugFormat(
2287// "[SCENE PRESENCE]: Sitting {0} at sit target {1}, {2} on {3} {4}",
2288// Name, sitTargetPos, sitTargetOrient, part.Name, part.LocalId);
2289
2286 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0); 2290 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2287 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w); 2291 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2288 2292
@@ -2291,15 +2295,17 @@ namespace OpenSim.Region.Framework.Scenes
2291 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2295 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2292 m_pos += SIT_TARGET_ADJUSTMENT; 2296 m_pos += SIT_TARGET_ADJUSTMENT;
2293 Rotation = sitTargetOrient; 2297 Rotation = sitTargetOrient;
2294 //Rotation = sitTargetOrient;
2295 ParentPosition = part.AbsolutePosition; 2298 ParentPosition = part.AbsolutePosition;
2296
2297 //SendTerseUpdateToAllClients();
2298 } 2299 }
2299 else 2300 else
2300 { 2301 {
2301 m_pos -= part.AbsolutePosition; 2302 m_pos -= part.AbsolutePosition;
2303
2302 ParentPosition = part.AbsolutePosition; 2304 ParentPosition = part.AbsolutePosition;
2305
2306// m_log.DebugFormat(
2307// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
2308// Name, part.AbsolutePosition, m_pos, ParentPosition, part.Name, part.LocalId);
2303 } 2309 }
2304 } 2310 }
2305 else 2311 else
@@ -2314,10 +2320,6 @@ namespace OpenSim.Region.Framework.Scenes
2314 2320
2315 Animator.TrySetMovementAnimation(sitAnimation); 2321 Animator.TrySetMovementAnimation(sitAnimation);
2316 SendAvatarDataToAllAgents(); 2322 SendAvatarDataToAllAgents();
2317 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2318 // So we're also sending a terse update (which has avatar rotation)
2319 // [Update] We do now.
2320 //SendTerseUpdateToAllClients();
2321 } 2323 }
2322 2324
2323 /// <summary> 2325 /// <summary>
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 10181aa..56ff367 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -208,7 +208,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
208 ScenePresence sp; 208 ScenePresence sp;
209 scene.TryGetScenePresence(agentID, out sp); 209 scene.TryGetScenePresence(agentID, out sp);
210 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero); 210 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero);
211 sp.HandleAgentSit(m_avatars[agentID], agentID); 211// sp.HandleAgentSit(m_avatars[agentID], agentID);
212 212
213 return true; 213 return true;
214 } 214 }
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
index 174d74c..d2b79f7 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
@@ -231,7 +231,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
231 } 231 }
232 232
233 [Test] 233 [Test]
234 public void TestSitAndStand() 234 public void TestSitAndStandWithSitTarget()
235 { 235 {
236 TestHelpers.InMethod(); 236 TestHelpers.InMethod();
237// log4net.Config.XmlConfigurator.Configure(); 237// log4net.Config.XmlConfigurator.Configure();
@@ -245,12 +245,49 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
245 ScenePresence npc = scene.GetScenePresence(npcId); 245 ScenePresence npc = scene.GetScenePresence(npcId);
246 SceneObjectPart part = SceneHelpers.AddSceneObject(scene); 246 SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
247 247
248 // We must have a non Vector3.Zero sit target position otherwise part.SitTargetAvatar doesn't get set!
249 part.SitTargetPosition = new Vector3(0, 0, 1); 248 part.SitTargetPosition = new Vector3(0, 0, 1);
250 npcModule.Sit(npc.UUID, part.UUID, scene); 249 npcModule.Sit(npc.UUID, part.UUID, scene);
251 250
252 Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId)); 251 Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId));
253 Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); 252 Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
253 Assert.That(
254 npc.AbsolutePosition,
255 Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT));
256
257 npcModule.Stand(npc.UUID, scene);
258
259 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
260 Assert.That(npc.ParentID, Is.EqualTo(0));
261 }
262
263 [Test]
264 public void TestSitAndStandWithNoSitTarget()
265 {
266 TestHelpers.InMethod();
267// log4net.Config.XmlConfigurator.Configure();
268
269 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
270
271 // FIXME: To get this to work for now, we are going to place the npc right next to the target so that
272 // the autopilot doesn't trigger
273 Vector3 startPos = new Vector3(1, 1, 1);
274
275 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
276 UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance);
277
278 ScenePresence npc = scene.GetScenePresence(npcId);
279 SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
280
281 npcModule.Sit(npc.UUID, part.UUID, scene);
282
283 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
284 Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
285
286 // FIXME: This is different for live avatars - z position is adjusted. This is half the height of the
287 // default avatar.
288 Assert.That(
289 npc.AbsolutePosition,
290 Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.8857438f)));
254 291
255 npcModule.Stand(npc.UUID, scene); 292 npcModule.Stand(npc.UUID, scene);
256 293