aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-08-03 04:19:19 +0100
committerJustin Clark-Casey (justincc)2011-08-03 04:19:19 +0100
commit6e4ec2972266ae250337867fe1ba1944131f212d (patch)
treedb0d334a9d0cc871bbdd83b86d703260befa25b5
parentImprove z axis move to/autopilot so the avatar does alternative crouch/huzzah... (diff)
downloadopensim-SC_OLD-6e4ec2972266ae250337867fe1ba1944131f212d.zip
opensim-SC_OLD-6e4ec2972266ae250337867fe1ba1944131f212d.tar.gz
opensim-SC_OLD-6e4ec2972266ae250337867fe1ba1944131f212d.tar.bz2
opensim-SC_OLD-6e4ec2972266ae250337867fe1ba1944131f212d.tar.xz
Do a partial fix/implementation of OSSL osNpcMoveTo()
Avatar moves and stops. However, will stop in mid stride. And if the move to position is in the air, avatar will continue to make vain and quite hilarious attempts to take off (but never doing so). Clearly more work is needed.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs69
-rw-r--r--OpenSim/Region/Framework/Scenes/EventManager.cs11
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs37
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs59
4 files changed, 109 insertions, 67 deletions
diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
index 63dec15..7554e12 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs
@@ -470,53 +470,48 @@ namespace OpenSim.Region.CoreModules.World.Land
470 SendLandUpdate(avatar, false); 470 SendLandUpdate(avatar, false);
471 } 471 }
472 472
473 public void EventManagerOnSignificantClientMovement(IClientAPI remote_client) 473 public void EventManagerOnSignificantClientMovement(ScenePresence clientAvatar)
474 { 474 {
475 ScenePresence clientAvatar = m_scene.GetScenePresence(remote_client.AgentId); 475 SendLandUpdate(clientAvatar);
476 476 SendOutNearestBanLine(clientAvatar.ControllingClient);
477 if (clientAvatar != null) 477 ILandObject parcel = GetLandObject(clientAvatar.AbsolutePosition.X, clientAvatar.AbsolutePosition.Y);
478 if (parcel != null)
478 { 479 {
479 SendLandUpdate(clientAvatar); 480 if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
480 SendOutNearestBanLine(remote_client); 481 clientAvatar.sentMessageAboutRestrictedParcelFlyingDown)
481 ILandObject parcel = GetLandObject(clientAvatar.AbsolutePosition.X, clientAvatar.AbsolutePosition.Y);
482 if (parcel != null)
483 { 482 {
484 if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT && 483 EventManagerOnAvatarEnteringNewParcel(clientAvatar, parcel.LandData.LocalID,
485 clientAvatar.sentMessageAboutRestrictedParcelFlyingDown) 484 m_scene.RegionInfo.RegionID);
485 //They are going under the safety line!
486 if (!parcel.IsBannedFromLand(clientAvatar.UUID))
486 { 487 {
487 EventManagerOnAvatarEnteringNewParcel(clientAvatar, parcel.LandData.LocalID, 488 clientAvatar.sentMessageAboutRestrictedParcelFlyingDown = false;
488 m_scene.RegionInfo.RegionID);
489 //They are going under the safety line!
490 if (!parcel.IsBannedFromLand(clientAvatar.UUID))
491 {
492 clientAvatar.sentMessageAboutRestrictedParcelFlyingDown = false;
493 }
494 } 489 }
495 else if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT && 490 }
496 parcel.IsBannedFromLand(clientAvatar.UUID)) 491 else if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
492 parcel.IsBannedFromLand(clientAvatar.UUID))
493 {
494 //once we've sent the message once, keep going toward the target until we are done
495 if (forcedPosition.ContainsKey(clientAvatar.ControllingClient.AgentId))
497 { 496 {
498 //once we've sent the message once, keep going toward the target until we are done 497 SendYouAreBannedNotice(clientAvatar);
499 if (forcedPosition.ContainsKey(clientAvatar.ControllingClient.AgentId)) 498 ForceAvatarToPosition(clientAvatar, m_scene.GetNearestAllowedPosition(clientAvatar));
500 {
501 SendYouAreBannedNotice(clientAvatar);
502 ForceAvatarToPosition(clientAvatar, m_scene.GetNearestAllowedPosition(clientAvatar));
503 }
504 } 499 }
505 else if (parcel.IsRestrictedFromLand(clientAvatar.UUID)) 500 }
506 { 501 else if (parcel.IsRestrictedFromLand(clientAvatar.UUID))
507 //once we've sent the message once, keep going toward the target until we are done 502 {
508 if (forcedPosition.ContainsKey(clientAvatar.ControllingClient.AgentId)) 503 //once we've sent the message once, keep going toward the target until we are done
509 { 504 if (forcedPosition.ContainsKey(clientAvatar.ControllingClient.AgentId))
510 SendYouAreRestrictedNotice(clientAvatar);
511 ForceAvatarToPosition(clientAvatar, m_scene.GetNearestAllowedPosition(clientAvatar));
512 }
513 }
514 else
515 { 505 {
516 //when we are finally in a safe place, lets release the forced position lock 506 SendYouAreRestrictedNotice(clientAvatar);
517 forcedPosition.Remove(clientAvatar.ControllingClient.AgentId); 507 ForceAvatarToPosition(clientAvatar, m_scene.GetNearestAllowedPosition(clientAvatar));
518 } 508 }
519 } 509 }
510 else
511 {
512 //when we are finally in a safe place, lets release the forced position lock
513 forcedPosition.Remove(clientAvatar.ControllingClient.AgentId);
514 }
520 } 515 }
521 } 516 }
522 517
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index b67937d..96da2c3 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -165,8 +165,7 @@ namespace OpenSim.Region.Framework.Scenes
165 public delegate void AvatarEnteringNewParcel(ScenePresence avatar, int localLandID, UUID regionID); 165 public delegate void AvatarEnteringNewParcel(ScenePresence avatar, int localLandID, UUID regionID);
166 public event AvatarEnteringNewParcel OnAvatarEnteringNewParcel; 166 public event AvatarEnteringNewParcel OnAvatarEnteringNewParcel;
167 167
168 public delegate void SignificantClientMovement(IClientAPI remote_client); 168 public event Action<ScenePresence> OnSignificantClientMovement;
169 public event SignificantClientMovement OnSignificantClientMovement;
170 169
171 public delegate void IncomingInstantMessage(GridInstantMessage message); 170 public delegate void IncomingInstantMessage(GridInstantMessage message);
172 public event IncomingInstantMessage OnIncomingInstantMessage; 171 public event IncomingInstantMessage OnIncomingInstantMessage;
@@ -1592,16 +1591,16 @@ namespace OpenSim.Region.Framework.Scenes
1592 } 1591 }
1593 } 1592 }
1594 1593
1595 public void TriggerSignificantClientMovement(IClientAPI client) 1594 public void TriggerSignificantClientMovement(ScenePresence presence)
1596 { 1595 {
1597 SignificantClientMovement handlerSignificantClientMovement = OnSignificantClientMovement; 1596 Action<ScenePresence> handlerSignificantClientMovement = OnSignificantClientMovement;
1598 if (handlerSignificantClientMovement != null) 1597 if (handlerSignificantClientMovement != null)
1599 { 1598 {
1600 foreach (SignificantClientMovement d in handlerSignificantClientMovement.GetInvocationList()) 1599 foreach (Action<ScenePresence> d in handlerSignificantClientMovement.GetInvocationList())
1601 { 1600 {
1602 try 1601 try
1603 { 1602 {
1604 d(client); 1603 d(presence);
1605 } 1604 }
1606 catch (Exception e) 1605 catch (Exception e)
1607 { 1606 {
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index a610b6b..9558258 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -211,7 +211,8 @@ namespace OpenSim.Region.Framework.Scenes
211 211
212 //PauPaw:Proper PID Controler for autopilot************ 212 //PauPaw:Proper PID Controler for autopilot************
213 private bool m_moveToPositionInProgress; 213 private bool m_moveToPositionInProgress;
214 private Vector3 m_moveToPositionTarget; 214
215 public Vector3 MoveToPositionTarget { get; private set; }
215 216
216 private bool m_followCamAuto; 217 private bool m_followCamAuto;
217 218
@@ -1385,7 +1386,7 @@ namespace OpenSim.Region.Framework.Scenes
1385 if (agentData.UseClientAgentPosition) 1386 if (agentData.UseClientAgentPosition)
1386 { 1387 {
1387 m_moveToPositionInProgress = (agentData.ClientAgentPosition - AbsolutePosition).Length() > 0.2f; 1388 m_moveToPositionInProgress = (agentData.ClientAgentPosition - AbsolutePosition).Length() > 0.2f;
1388 m_moveToPositionTarget = agentData.ClientAgentPosition; 1389 MoveToPositionTarget = agentData.ClientAgentPosition;
1389 } 1390 }
1390 1391
1391 int i = 0; 1392 int i = 0;
@@ -1543,16 +1544,17 @@ namespace OpenSim.Region.Framework.Scenes
1543 /// <param value="reset">If true, clear the move to position</param> 1544 /// <param value="reset">If true, clear the move to position</param>
1544 /// <param value="allowUpdate">If true, allow the update in principle.</param> 1545 /// <param value="allowUpdate">If true, allow the update in principle.</param>
1545 /// <returns>True if movement has been updated in some way. False otherwise.</returns> 1546 /// <returns>True if movement has been updated in some way. False otherwise.</returns>
1546 protected bool DoMoveToPositionUpdate( 1547 public bool DoMoveToPositionUpdate(
1547 ref Vector3 agent_control_v3, Quaternion bodyRotation, bool reset, bool allowUpdate) 1548 ref Vector3 agent_control_v3, Quaternion bodyRotation, bool reset, bool allowUpdate)
1548 { 1549 {
1550// m_log.DebugFormat("[SCENE PRESENCE]: Called DoMoveToPositionUpdate() for {0}", Name);
1551
1549 bool updated = false; 1552 bool updated = false;
1550 1553
1551 //Paupaw:Do Proper PID for Autopilot here 1554 //Paupaw:Do Proper PID for Autopilot here
1552 if (reset) 1555 if (reset)
1553 { 1556 {
1554 m_moveToPositionTarget = Vector3.Zero; 1557 ResetMoveToPosition();
1555 m_moveToPositionInProgress = false;
1556 updated = true; 1558 updated = true;
1557 } 1559 }
1558 1560
@@ -1562,16 +1564,16 @@ namespace OpenSim.Region.Framework.Scenes
1562 1564
1563 if (allowUpdate && (m_moveToPositionInProgress && !m_autopilotMoving)) 1565 if (allowUpdate && (m_moveToPositionInProgress && !m_autopilotMoving))
1564 { 1566 {
1565 double distanceToTarget = Util.GetDistanceTo(AbsolutePosition, m_moveToPositionTarget); 1567 double distanceToTarget = Util.GetDistanceTo(AbsolutePosition, MoveToPositionTarget);
1566// m_log.DebugFormat( 1568 m_log.DebugFormat(
1567// "[SCENE PRESENCE]: Abs pos of {0} is {1}, target {2}, distance {3}", 1569 "[SCENE PRESENCE]: Abs pos of {0} is {1}, target {2}, distance {3}",
1568// Name, AbsolutePosition, m_moveToPositionTarget, distanceToTarget); 1570 Name, AbsolutePosition, MoveToPositionTarget, distanceToTarget);
1569 1571
1570 // Check the error term of the current position in relation to the target position 1572 // Check the error term of the current position in relation to the target position
1571 if (distanceToTarget <= 1) 1573 if (distanceToTarget <= 1)
1572 { 1574 {
1573 // We are close enough to the target 1575 // We are close enough to the target
1574 m_moveToPositionTarget = Vector3.Zero; 1576 MoveToPositionTarget = Vector3.Zero;
1575 m_moveToPositionInProgress = false; 1577 m_moveToPositionInProgress = false;
1576 updated = true; 1578 updated = true;
1577 } 1579 }
@@ -1585,7 +1587,7 @@ namespace OpenSim.Region.Framework.Scenes
1585 // unknown forces are acting on the avatar and we need to adaptively respond 1587 // unknown forces are acting on the avatar and we need to adaptively respond
1586 // to such forces, but the following simple approach seems to works fine. 1588 // to such forces, but the following simple approach seems to works fine.
1587 Vector3 LocalVectorToTarget3D = 1589 Vector3 LocalVectorToTarget3D =
1588 (m_moveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords 1590 (MoveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords
1589 * Matrix4.CreateFromQuaternion(Quaternion.Inverse(bodyRotation)); // change to avatar coords 1591 * Matrix4.CreateFromQuaternion(Quaternion.Inverse(bodyRotation)); // change to avatar coords
1590 // Ignore z component of vector 1592 // Ignore z component of vector
1591// Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1593// Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
@@ -1718,13 +1720,22 @@ namespace OpenSim.Region.Framework.Scenes
1718 } 1720 }
1719 1721
1720 m_moveToPositionInProgress = true; 1722 m_moveToPositionInProgress = true;
1721 m_moveToPositionTarget = pos; 1723 MoveToPositionTarget = pos;
1722 1724
1723 Vector3 agent_control_v3 = new Vector3(); 1725 Vector3 agent_control_v3 = new Vector3();
1724 DoMoveToPositionUpdate(ref agent_control_v3, Rotation, false, true); 1726 DoMoveToPositionUpdate(ref agent_control_v3, Rotation, false, true);
1725 AddNewMovement(agent_control_v3, Rotation); 1727 AddNewMovement(agent_control_v3, Rotation);
1726 } 1728 }
1727 1729
1730 /// <summary>
1731 /// Reset the move to position.
1732 /// </summary>
1733 public void ResetMoveToPosition()
1734 {
1735 MoveToPositionTarget = Vector3.Zero;
1736 m_moveToPositionInProgress = false;
1737 }
1738
1728 private void CheckAtSitTarget() 1739 private void CheckAtSitTarget()
1729 { 1740 {
1730 //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString()); 1741 //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString());
@@ -2731,7 +2742,7 @@ namespace OpenSim.Region.Framework.Scenes
2731 if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > SIGNIFICANT_MOVEMENT) 2742 if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > SIGNIFICANT_MOVEMENT)
2732 { 2743 {
2733 posLastSignificantMove = AbsolutePosition; 2744 posLastSignificantMove = AbsolutePosition;
2734 m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient); 2745 m_scene.EventManager.TriggerSignificantClientMovement(this);
2735 } 2746 }
2736 2747
2737 // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m 2748 // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 8cb8318..fcfacc6 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -46,12 +46,54 @@ namespace OpenSim.Region.OptionalModules.World.NPC
46 46
47 // private const bool m_enabled = false; 47 // private const bool m_enabled = false;
48 48
49 private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); 49 private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>();
50 private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); 50 private Dictionary<UUID, AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>();
51 51
52 public void Initialise(Scene scene, IConfigSource source) 52 public void Initialise(Scene scene, IConfigSource source)
53 { 53 {
54 scene.RegisterModuleInterface<INPCModule>(this); 54 scene.RegisterModuleInterface<INPCModule>(this);
55 scene.EventManager.OnSignificantClientMovement += HandleOnSignificantClientMovement;
56 }
57
58 public void HandleOnSignificantClientMovement(ScenePresence presence)
59 {
60 lock (m_avatars)
61 {
62 if (m_avatars.ContainsKey(presence.UUID))
63 {
64 double distanceToTarget = Util.GetDistanceTo(presence.AbsolutePosition, presence.MoveToPositionTarget);
65// m_log.DebugFormat(
66// "[NPC MODULE]: Abs pos of {0} is {1}, target {2}, distance {3}",
67// presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget, distanceToTarget);
68
69 // Check the error term of the current position in relation to the target position
70 if (distanceToTarget <= 1)
71 {
72// m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0} {1}", presence.Name, presence.UUID);
73 // We are close enough to the target for now
74 presence.ResetMoveToPosition();
75 presence.Velocity = Vector3.Zero;
76
77 // FIXME: This doesn't work
78 if (presence.PhysicsActor.Flying)
79 presence.Animator.TrySetMovementAnimation("HOVER");
80 else
81 presence.Animator.TrySetMovementAnimation("STAND");
82 }
83 else
84 {
85 Vector3 agent_control_v3 = new Vector3();
86 presence.DoMoveToPositionUpdate(ref agent_control_v3, presence.Rotation, false, true);
87 presence.AddNewMovement(agent_control_v3, presence.Rotation);
88 }
89//
90//// presence.DoMoveToPositionUpdate((0, presence.MoveToPositionTarget, null);
91
92//
93//
94
95 }
96 }
55 } 97 }
56 98
57 private AvatarAppearance GetAppearance(UUID target, Scene scene) 99 private AvatarAppearance GetAppearance(UUID target, Scene scene)
@@ -141,15 +183,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
141 ScenePresence sp; 183 ScenePresence sp;
142 scene.TryGetScenePresence(agentID, out sp); 184 scene.TryGetScenePresence(agentID, out sp);
143 185
144// m_log.DebugFormat( 186 m_log.DebugFormat(
145// "[NPC MODULE]: Moving {0} to {1} in {2}", sp.Name, pos, scene.RegionInfo.RegionName); 187 "[NPC MODULE]: Moving {0} to {1} in {2}", sp.Name, pos, scene.RegionInfo.RegionName);
146// 188
147// List<string> targetArgs = new List<string>(); 189 sp.DoMoveToPosition(0, pos, m_avatars[agentID]);
148// targetArgs.Add(pos.X);
149// targetArgs.Add(pos.Y);
150// targetArgs.Add(pos.Z);
151// sp.DoMoveToPosition(null, "NPC", targetArgs);
152// sp.DoMoveToPosition(0, pos, m_avatars[agentID]);
153 } 190 }
154 } 191 }
155 } 192 }