aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/ScenePresence.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs925
1 files changed, 440 insertions, 485 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 87fac0c..6c0d9f2 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -76,8 +76,18 @@ namespace OpenSim.Region.Framework.Scenes
76 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 76 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
77 77
78 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 78 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
79 79 private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes();
80 public static byte[] DefaultTexture; 80 private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags));
81 private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f);
82 /// <summary>
83 /// Experimentally determined "fudge factor" to make sit-target positions
84 /// the same as in SecondLife. Fudge factor was tested for 36 different
85 /// test cases including prims of type box, sphere, cylinder, and torus,
86 /// with varying parameters for sit target location, prim size, prim
87 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
88 /// issue #1716
89 /// </summary>
90 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
81 91
82 public UUID currentParcelUUID = UUID.Zero; 92 public UUID currentParcelUUID = UUID.Zero;
83 93
@@ -92,16 +102,18 @@ namespace OpenSim.Region.Framework.Scenes
92 //private SceneObjectPart proxyObjectPart = null; 102 //private SceneObjectPart proxyObjectPart = null;
93 public Vector3 lastKnownAllowedPosition; 103 public Vector3 lastKnownAllowedPosition;
94 public bool sentMessageAboutRestrictedParcelFlyingDown; 104 public bool sentMessageAboutRestrictedParcelFlyingDown;
105 public Vector4 CollisionPlane = Vector4.UnitW;
95 106
96 private Vector3 m_lastPosition; 107 private Vector3 m_lastPosition;
97 private Quaternion m_lastRotation; 108 private Quaternion m_lastRotation;
98 private Vector3 m_lastVelocity; 109 private Vector3 m_lastVelocity;
110 //private int m_lastTerseSent;
99 111
100 private bool m_updateflag; 112 private bool m_updateflag;
101 private byte m_movementflag; 113 private byte m_movementflag;
102 private readonly List<NewForce> m_forcesList = new List<NewForce>(); 114 private Vector3? m_forceToApply;
103 private uint m_requestedSitTargetID; 115 private uint m_requestedSitTargetID;
104 private UUID m_requestedSitTargetUUID = UUID.Zero; 116 private UUID m_requestedSitTargetUUID;
105 private SendCourseLocationsMethod m_sendCourseLocationsMethod; 117 private SendCourseLocationsMethod m_sendCourseLocationsMethod;
106 118
107 private bool m_startAnimationSet; 119 private bool m_startAnimationSet;
@@ -112,30 +124,24 @@ namespace OpenSim.Region.Framework.Scenes
112 124
113 private float m_sitAvatarHeight = 2.0f; 125 private float m_sitAvatarHeight = 2.0f;
114 126
115 // experimentally determined "fudge factor" to make sit-target positions
116 // the same as in SecondLife. Fudge factor was tested for 36 different
117 // test cases including prims of type box, sphere, cylinder, and torus,
118 // with varying parameters for sit target location, prim size, prim
119 // rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
120 // issue #1716
121 private static readonly Vector3 m_sitTargetCorrectionOffset = new Vector3(0.1f, 0.0f, 0.3f);
122 private float m_godlevel; 127 private float m_godlevel;
123 128
124 private bool m_invulnerable = true; 129 private bool m_invulnerable = true;
125 130
126 private Vector3 m_LastChildAgentUpdatePosition; 131 private Vector3 m_lastChildAgentUpdatePosition;
132 private Vector3 m_lastChildAgentUpdateCamPosition;
127 133
128 private int m_perfMonMS; 134 private int m_perfMonMS;
129 135
130 private bool m_setAlwaysRun; 136 private bool m_setAlwaysRun;
131 137
132 private string m_movementAnimation = "DEFAULT"; 138 private string m_movementAnimation = "DEFAULT";
133 private long m_animPersistUntil = 0; 139 private int m_animTickFall;
134 private bool m_allowFalling = false; 140 private int m_animTickJump;
135 private bool m_useFlySlow = false; 141 private bool m_useFlySlow;
136 private bool m_usePreJump = false; 142 private bool m_usePreJump;
137 private bool m_forceFly = false; 143 private bool m_forceFly;
138 private bool m_flyDisabled = false; 144 private bool m_flyDisabled;
139 145
140 private float m_speedModifier = 1.0f; 146 private float m_speedModifier = 1.0f;
141 147
@@ -143,7 +149,7 @@ namespace OpenSim.Region.Framework.Scenes
143 149
144 public bool IsRestrictedToRegion; 150 public bool IsRestrictedToRegion;
145 151
146 public string JID = string.Empty; 152 public string JID = String.Empty;
147 153
148 // Agent moves with a PID controller causing a force to be exerted. 154 // Agent moves with a PID controller causing a force to be exerted.
149 private bool m_newCoarseLocations = true; 155 private bool m_newCoarseLocations = true;
@@ -158,43 +164,43 @@ namespace OpenSim.Region.Framework.Scenes
158 private readonly Vector3[] Dir_Vectors = new Vector3[6]; 164 private readonly Vector3[] Dir_Vectors = new Vector3[6];
159 165
160 // Position of agent's camera in world (region cordinates) 166 // Position of agent's camera in world (region cordinates)
161 protected Vector3 m_CameraCenter = Vector3.Zero; 167 protected Vector3 m_CameraCenter;
162 protected Vector3 m_lastCameraCenter = Vector3.Zero; 168 protected Vector3 m_lastCameraCenter;
163 169
164 protected Timer m_reprioritization_timer; 170 protected Timer m_reprioritization_timer;
165 protected bool m_reprioritizing = false; 171 protected bool m_reprioritizing;
166 protected bool m_reprioritization_called = false; 172 protected bool m_reprioritization_called;
167 173
168 // Use these three vectors to figure out what the agent is looking at 174 // Use these three vectors to figure out what the agent is looking at
169 // Convert it to a Matrix and/or Quaternion 175 // Convert it to a Matrix and/or Quaternion
170 protected Vector3 m_CameraAtAxis = Vector3.Zero; 176 protected Vector3 m_CameraAtAxis;
171 protected Vector3 m_CameraLeftAxis = Vector3.Zero; 177 protected Vector3 m_CameraLeftAxis;
172 protected Vector3 m_CameraUpAxis = Vector3.Zero; 178 protected Vector3 m_CameraUpAxis;
173 private uint m_AgentControlFlags; 179 private AgentManager.ControlFlags m_AgentControlFlags;
174 private Quaternion m_headrotation = Quaternion.Identity; 180 private Quaternion m_headrotation = Quaternion.Identity;
175 private byte m_state; 181 private byte m_state;
176 182
177 //Reuse the Vector3 instead of creating a new one on the UpdateMovement method 183 //Reuse the Vector3 instead of creating a new one on the UpdateMovement method
178 private Vector3 movementvector = Vector3.Zero; 184 private Vector3 movementvector;
179 185
180 private bool m_autopilotMoving; 186 private bool m_autopilotMoving;
181 private Vector3 m_autoPilotTarget = Vector3.Zero; 187 private Vector3 m_autoPilotTarget;
182 private bool m_sitAtAutoTarget; 188 private bool m_sitAtAutoTarget;
183 189
184 private string m_nextSitAnimation = String.Empty; 190 private string m_nextSitAnimation = String.Empty;
185 191
186 //PauPaw:Proper PID Controler for autopilot************ 192 //PauPaw:Proper PID Controler for autopilot************
187 private bool m_moveToPositionInProgress; 193 private bool m_moveToPositionInProgress;
188 private Vector3 m_moveToPositionTarget = Vector3.Zero; 194 private Vector3 m_moveToPositionTarget;
189 195
190 private bool m_followCamAuto = false; 196 private bool m_followCamAuto;
191 197
192 private int m_movementUpdateCount = 0; 198 private int m_movementUpdateCount;
193 199
194 private const int NumMovementsBetweenRayCast = 5; 200 private const int NumMovementsBetweenRayCast = 5;
195 201
196 private bool CameraConstraintActive = false; 202 private bool CameraConstraintActive;
197 //private int m_moveToPositionStateStatus = 0; 203 //private int m_moveToPositionStateStatus;
198 //***************************************************** 204 //*****************************************************
199 205
200 // Agent's Draw distance. 206 // Agent's Draw distance.
@@ -268,11 +274,9 @@ namespace OpenSim.Region.Framework.Scenes
268 get { return m_godlevel; } 274 get { return m_godlevel; }
269 } 275 }
270 276
271 private readonly ulong m_regionHandle;
272
273 public ulong RegionHandle 277 public ulong RegionHandle
274 { 278 {
275 get { return m_regionHandle; } 279 get { return m_rootRegionHandle; }
276 } 280 }
277 281
278 public Vector3 CameraPosition 282 public Vector3 CameraPosition
@@ -379,8 +383,8 @@ namespace OpenSim.Region.Framework.Scenes
379 383
380 public uint AgentControlFlags 384 public uint AgentControlFlags
381 { 385 {
382 get { return m_AgentControlFlags; } 386 get { return (uint)m_AgentControlFlags; }
383 set { m_AgentControlFlags = value; } 387 set { m_AgentControlFlags = (AgentManager.ControlFlags)value; }
384 } 388 }
385 389
386 /// <summary> 390 /// <summary>
@@ -411,31 +415,27 @@ namespace OpenSim.Region.Framework.Scenes
411 } 415 }
412 416
413 /// <summary> 417 /// <summary>
414 /// Absolute position of this avatar in 'region cordinates' 418 /// Position of this avatar relative to the region the avatar is in
415 /// </summary> 419 /// </summary>
416 public override Vector3 AbsolutePosition 420 public override Vector3 AbsolutePosition
417 { 421 {
418 get 422 get
419 { 423 {
420 if (m_physicsActor != null) 424 PhysicsActor actor = m_physicsActor;
421 { 425 if (actor != null)
422 m_pos.X = m_physicsActor.Position.X; 426 m_pos = actor.Position;
423 m_pos.Y = m_physicsActor.Position.Y;
424 m_pos.Z = m_physicsActor.Position.Z;
425 }
426 427
427 return m_parentPosition + m_pos; 428 return m_parentPosition + m_pos;
428 } 429 }
429 set 430 set
430 { 431 {
431 if (m_physicsActor != null) 432 PhysicsActor actor = m_physicsActor;
433 if (actor != null)
432 { 434 {
433 try 435 try
434 { 436 {
435 lock (m_scene.SyncRoot) 437 lock (m_scene.SyncRoot)
436 {
437 m_physicsActor.Position = value; 438 m_physicsActor.Position = value;
438 }
439 } 439 }
440 catch (Exception e) 440 catch (Exception e)
441 { 441 {
@@ -444,7 +444,7 @@ namespace OpenSim.Region.Framework.Scenes
444 } 444 }
445 445
446 m_pos = value; 446 m_pos = value;
447 m_parentPosition = new Vector3(0, 0, 0); 447 m_parentPosition = Vector3.Zero;
448 } 448 }
449 } 449 }
450 450
@@ -455,27 +455,21 @@ namespace OpenSim.Region.Framework.Scenes
455 { 455 {
456 get 456 get
457 { 457 {
458 if (m_physicsActor != null) 458 PhysicsActor actor = m_physicsActor;
459 { 459 if (actor != null)
460 m_velocity.X = m_physicsActor.Velocity.X; 460 m_velocity = actor.Velocity;
461 m_velocity.Y = m_physicsActor.Velocity.Y;
462 m_velocity.Z = m_physicsActor.Velocity.Z;
463 }
464 461
465 return m_velocity; 462 return m_velocity;
466 } 463 }
467 set 464 set
468 { 465 {
469 //m_log.DebugFormat("In {0} setting velocity of {1} to {2}", m_scene.RegionInfo.RegionName, Name, value); 466 PhysicsActor actor = m_physicsActor;
470 467 if (actor != null)
471 if (m_physicsActor != null)
472 { 468 {
473 try 469 try
474 { 470 {
475 lock (m_scene.SyncRoot) 471 lock (m_scene.SyncRoot)
476 { 472 actor.Velocity = value;
477 m_physicsActor.Velocity = value;
478 }
479 } 473 }
480 catch (Exception e) 474 catch (Exception e)
481 { 475 {
@@ -627,7 +621,7 @@ namespace OpenSim.Region.Framework.Scenes
627 { 621 {
628 m_sendCourseLocationsMethod = SendCoarseLocationsDefault; 622 m_sendCourseLocationsMethod = SendCoarseLocationsDefault;
629 CreateSceneViewer(); 623 CreateSceneViewer();
630 m_regionHandle = reginfo.RegionHandle; 624 m_rootRegionHandle = reginfo.RegionHandle;
631 m_controllingClient = client; 625 m_controllingClient = client;
632 m_firstname = m_controllingClient.FirstName; 626 m_firstname = m_controllingClient.FirstName;
633 m_lastname = m_controllingClient.LastName; 627 m_lastname = m_controllingClient.LastName;
@@ -710,25 +704,25 @@ namespace OpenSim.Region.Framework.Scenes
710 704
711 private void SetDirectionVectors() 705 private void SetDirectionVectors()
712 { 706 {
713 Dir_Vectors[0] = new Vector3(1, 0, 0); //FORWARD 707 Dir_Vectors[0] = Vector3.UnitX; //FORWARD
714 Dir_Vectors[1] = new Vector3(-1, 0, 0); //BACK 708 Dir_Vectors[1] = -Vector3.UnitX; //BACK
715 Dir_Vectors[2] = new Vector3(0, 1, 0); //LEFT 709 Dir_Vectors[2] = Vector3.UnitY; //LEFT
716 Dir_Vectors[3] = new Vector3(0, -1, 0); //RIGHT 710 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
717 Dir_Vectors[4] = new Vector3(0, 0, 1); //UP 711 Dir_Vectors[4] = Vector3.UnitZ; //UP
718 Dir_Vectors[5] = new Vector3(0, 0, -1); //DOWN 712 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
719 Dir_Vectors[5] = new Vector3(0, 0, -0.5f); //DOWN_Nudge 713 Dir_Vectors[5] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
720 } 714 }
721 715
722 private Vector3[] GetWalkDirectionVectors() 716 private Vector3[] GetWalkDirectionVectors()
723 { 717 {
724 Vector3[] vector = new Vector3[6]; 718 Vector3[] vector = new Vector3[6];
725 vector[0] = new Vector3(m_CameraUpAxis.Z, 0, -m_CameraAtAxis.Z); //FORWARD 719 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
726 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0, m_CameraAtAxis.Z); //BACK 720 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
727 vector[2] = new Vector3(0, 1, 0); //LEFT 721 vector[2] = Vector3.UnitY; //LEFT
728 vector[3] = new Vector3(0, -1, 0); //RIGHT 722 vector[3] = -Vector3.UnitY; //RIGHT
729 vector[4] = new Vector3(m_CameraAtAxis.Z, 0, m_CameraUpAxis.Z); //UP 723 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
730 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0, -m_CameraUpAxis.Z); //DOWN 724 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
731 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0, -m_CameraUpAxis.Z); //DOWN_Nudge 725 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge
732 return vector; 726 return vector;
733 } 727 }
734 728
@@ -781,6 +775,8 @@ namespace OpenSim.Region.Framework.Scenes
781 if (gm != null) 775 if (gm != null)
782 m_grouptitle = gm.GetGroupTitle(m_uuid); 776 m_grouptitle = gm.GetGroupTitle(m_uuid);
783 777
778 m_rootRegionHandle = m_scene.RegionInfo.RegionHandle;
779
784 m_scene.SetRootAgentScene(m_uuid); 780 m_scene.SetRootAgentScene(m_uuid);
785 781
786 // Moved this from SendInitialData to ensure that m_appearance is initialized 782 // Moved this from SendInitialData to ensure that m_appearance is initialized
@@ -811,7 +807,6 @@ namespace OpenSim.Region.Framework.Scenes
811 pos = emergencyPos; 807 pos = emergencyPos;
812 } 808 }
813 809
814
815 float localAVHeight = 1.56f; 810 float localAVHeight = 1.56f;
816 if (m_avHeight != 127.0f) 811 if (m_avHeight != 127.0f)
817 { 812 {
@@ -906,6 +901,8 @@ namespace OpenSim.Region.Framework.Scenes
906 m_isChildAgent = true; 901 m_isChildAgent = true;
907 m_scene.SwapRootAgentCount(true); 902 m_scene.SwapRootAgentCount(true);
908 RemoveFromPhysicalScene(); 903 RemoveFromPhysicalScene();
904
905 // FIXME: Set m_rootRegionHandle to the region handle of the scene this agent is moving into
909 906
910 m_scene.EventManager.TriggerOnMakeChildAgent(this); 907 m_scene.EventManager.TriggerOnMakeChildAgent(this);
911 } 908 }
@@ -937,7 +934,7 @@ namespace OpenSim.Region.Framework.Scenes
937 isFlying = m_physicsActor.Flying; 934 isFlying = m_physicsActor.Flying;
938 935
939 RemoveFromPhysicalScene(); 936 RemoveFromPhysicalScene();
940 Velocity = new Vector3(0, 0, 0); 937 Velocity = Vector3.Zero;
941 AbsolutePosition = pos; 938 AbsolutePosition = pos;
942 AddToPhysicalScene(isFlying); 939 AddToPhysicalScene(isFlying);
943 if (m_appearance != null) 940 if (m_appearance != null)
@@ -985,12 +982,13 @@ namespace OpenSim.Region.Framework.Scenes
985 982
986 if (m_avHeight != 127.0f) 983 if (m_avHeight != 127.0f)
987 { 984 {
988 AbsolutePosition = AbsolutePosition + new Vector3(0, 0, (m_avHeight / 6f)); 985 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (m_avHeight / 6f));
989 } 986 }
990 else 987 else
991 { 988 {
992 AbsolutePosition = AbsolutePosition + new Vector3(0, 0, (1.56f / 6f)); 989 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f));
993 } 990 }
991
994 TrySetMovementAnimation("LAND"); 992 TrySetMovementAnimation("LAND");
995 SendFullUpdateToAllClients(); 993 SendFullUpdateToAllClients();
996 } 994 }
@@ -1076,7 +1074,7 @@ namespace OpenSim.Region.Framework.Scenes
1076 } 1074 }
1077 1075
1078 m_isChildAgent = false; 1076 m_isChildAgent = false;
1079 bool m_flying = ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1077 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1080 MakeRootAgent(AbsolutePosition, m_flying); 1078 MakeRootAgent(AbsolutePosition, m_flying);
1081 1079
1082 if ((m_callbackURI != null) && !m_callbackURI.Equals("")) 1080 if ((m_callbackURI != null) && !m_callbackURI.Equals(""))
@@ -1103,9 +1101,12 @@ namespace OpenSim.Region.Framework.Scenes
1103 /// <param name="distance"></param> 1101 /// <param name="distance"></param>
1104 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance) 1102 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance)
1105 { 1103 {
1104 const float POSITION_TOLERANCE = 0.02f;
1105 const float VELOCITY_TOLERANCE = 0.02f;
1106 const float ROTATION_TOLERANCE = 0.02f;
1107
1106 if (m_followCamAuto) 1108 if (m_followCamAuto)
1107 { 1109 {
1108
1109 if (hitYN) 1110 if (hitYN)
1110 { 1111 {
1111 CameraConstraintActive = true; 1112 CameraConstraintActive = true;
@@ -1114,11 +1115,11 @@ namespace OpenSim.Region.Framework.Scenes
1114 Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); 1115 Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint);
1115 ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); 1116 ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint)));
1116 } 1117 }
1117 else 1118 else
1118 { 1119 {
1119 if ((m_pos - m_lastPosition).Length() > 0.02f || 1120 if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
1120 (m_velocity - m_lastVelocity).Length() > 0.02f || 1121 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
1121 m_bodyRot != m_lastRotation) 1122 !m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE))
1122 { 1123 {
1123 if (CameraConstraintActive) 1124 if (CameraConstraintActive)
1124 { 1125 {
@@ -1127,13 +1128,11 @@ namespace OpenSim.Region.Framework.Scenes
1127 } 1128 }
1128 } 1129 }
1129 } 1130 }
1130 } 1131 }
1131 } 1132 }
1132 1133
1133 Array m_dirControlFlags = Enum.GetValues(typeof(Dir_ControlFlags));
1134
1135 /// <summary> 1134 /// <summary>
1136 /// This is the event handler for client movement. If a client is moving, this event is triggering. 1135 /// This is the event handler for client movement. If a client is moving, this event is triggering.
1137 /// </summary> 1136 /// </summary>
1138 public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData) 1137 public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
1139 { 1138 {
@@ -1149,15 +1148,13 @@ namespace OpenSim.Region.Framework.Scenes
1149 if (m_movementUpdateCount < 1) 1148 if (m_movementUpdateCount < 1)
1150 m_movementUpdateCount = 1; 1149 m_movementUpdateCount = 1;
1151 1150
1152 // Must check for standing up even when PhysicsActor is null, 1151 #region Sanity Checking
1153 // since sitting currently removes avatar from physical scene
1154 //m_log.Debug("agentPos:" + AbsolutePosition.ToString());
1155 1152
1156 // This is irritating. Really. 1153 // This is irritating. Really.
1157 if (!AbsolutePosition.IsFinite()) 1154 if (!AbsolutePosition.IsFinite())
1158 { 1155 {
1159 RemoveFromPhysicalScene(); 1156 RemoveFromPhysicalScene();
1160 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error# 9999902"); 1157 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1161 1158
1162 m_pos = m_LastFinitePos; 1159 m_pos = m_LastFinitePos;
1163 if (!m_pos.IsFinite()) 1160 if (!m_pos.IsFinite())
@@ -1165,7 +1162,7 @@ namespace OpenSim.Region.Framework.Scenes
1165 m_pos.X = 127f; 1162 m_pos.X = 127f;
1166 m_pos.Y = 127f; 1163 m_pos.Y = 127f;
1167 m_pos.Z = 127f; 1164 m_pos.Z = 127f;
1168 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error# 9999903"); 1165 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999903");
1169 } 1166 }
1170 1167
1171 AddToPhysicalScene(false); 1168 AddToPhysicalScene(false);
@@ -1175,18 +1172,11 @@ namespace OpenSim.Region.Framework.Scenes
1175 m_LastFinitePos = m_pos; 1172 m_LastFinitePos = m_pos;
1176 } 1173 }
1177 1174
1178 //m_physicsActor.AddForce(new PhysicsVector(999999999, 99999999, 999999999999999), true); 1175 #endregion Sanity Checking
1179 1176
1180 //ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y); 1177 #region Inputs
1181 //if (land != null)
1182 //{
1183 //if (land.landData.landingType == (byte)1 && land.landData.userLocation != Vector3.Zero)
1184 //{
1185 // agent.startpos = land.landData.userLocation;
1186 //}
1187 //}
1188 1178
1189 uint flags = agentData.ControlFlags; 1179 AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags;
1190 Quaternion bodyRotation = agentData.BodyRotation; 1180 Quaternion bodyRotation = agentData.BodyRotation;
1191 1181
1192 // Camera location in world. We'll need to raytrace 1182 // Camera location in world. We'll need to raytrace
@@ -1207,87 +1197,85 @@ namespace OpenSim.Region.Framework.Scenes
1207 // The Agent's Draw distance setting 1197 // The Agent's Draw distance setting
1208 m_DrawDistance = agentData.Far; 1198 m_DrawDistance = agentData.Far;
1209 1199
1210 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0)
1211 {
1212 StandUp();
1213 }
1214
1215 // Check if Client has camera in 'follow cam' or 'build' mode. 1200 // Check if Client has camera in 'follow cam' or 'build' mode.
1216 Vector3 camdif = (Vector3.One * m_bodyRot - Vector3.One * CameraRotation); 1201 Vector3 camdif = (Vector3.One * m_bodyRot - Vector3.One * CameraRotation);
1217 1202
1218 m_followCamAuto = ((m_CameraUpAxis.Z > 0.959f && m_CameraUpAxis.Z < 0.98f) 1203 m_followCamAuto = ((m_CameraUpAxis.Z > 0.959f && m_CameraUpAxis.Z < 0.98f)
1219 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; 1204 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false;
1220 1205
1206 m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0;
1207 m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0;
1208
1209 #endregion Inputs
1210
1211 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0)
1212 {
1213 StandUp();
1214 }
1215
1221 //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto); 1216 //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto);
1222 // Raycast from the avatar's head to the camera to see if there's anything blocking the view 1217 // Raycast from the avatar's head to the camera to see if there's anything blocking the view
1223 if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) 1218 if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast())
1224 { 1219 {
1225 if (m_followCamAuto) 1220 if (m_followCamAuto)
1226 { 1221 {
1227 Vector3 headadjustment = new Vector3(0, 0, 0.3f); 1222 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT;
1228 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - (m_pos + headadjustment)), Vector3.Distance(m_CameraCenter, (m_pos + headadjustment)) + 0.3f, RayCastCameraCallback); 1223 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1229 } 1224 }
1230 } 1225 }
1231 1226
1232 m_mouseLook = (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0;
1233 m_leftButtonDown = (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0;
1234
1235 lock (scriptedcontrols) 1227 lock (scriptedcontrols)
1236 { 1228 {
1237 if (scriptedcontrols.Count > 0) 1229 if (scriptedcontrols.Count > 0)
1238 { 1230 {
1239 SendControlToScripts(flags); 1231 SendControlToScripts((uint)flags);
1240 flags = RemoveIgnoredControls(flags, IgnoredControls); 1232 flags = RemoveIgnoredControls(flags, IgnoredControls);
1241 } 1233 }
1242 } 1234 }
1243 1235
1244 if (PhysicsActor == null)
1245 {
1246 return;
1247 }
1248
1249 if (m_autopilotMoving) 1236 if (m_autopilotMoving)
1250 CheckAtSitTarget(); 1237 CheckAtSitTarget();
1251 1238
1252 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1239 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1253 { 1240 {
1254 // TODO: This doesn't prevent the user from walking yet. 1241 // TODO: This doesn't prevent the user from walking yet.
1255 // Setting parent ID would fix this, if we knew what value 1242 // Setting parent ID would fix this, if we knew what value
1256 // to use. Or we could add a m_isSitting variable. 1243 // to use. Or we could add a m_isSitting variable.
1257
1258 TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); 1244 TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1259 } 1245 }
1246
1260 // In the future, these values might need to go global. 1247 // In the future, these values might need to go global.
1261 // Here's where you get them. 1248 // Here's where you get them.
1262
1263 m_AgentControlFlags = flags; 1249 m_AgentControlFlags = flags;
1264 m_headrotation = agentData.HeadRotation; 1250 m_headrotation = agentData.HeadRotation;
1265 m_state = agentData.State; 1251 m_state = agentData.State;
1266 1252
1253 PhysicsActor actor = PhysicsActor;
1254 if (actor == null)
1255 {
1256 return;
1257 }
1258
1267 if (m_allowMovement) 1259 if (m_allowMovement)
1268 { 1260 {
1269 int i = 0; 1261 int i = 0;
1270 bool update_movementflag = false; 1262 bool update_movementflag = false;
1271 bool update_rotation = false; 1263 bool update_rotation = false;
1272 bool DCFlagKeyPressed = false; 1264 bool DCFlagKeyPressed = false;
1273 Vector3 agent_control_v3 = new Vector3(0, 0, 0); 1265 Vector3 agent_control_v3 = Vector3.Zero;
1274 Quaternion q = bodyRotation; 1266 Quaternion q = bodyRotation;
1275 if (PhysicsActor != null)
1276 {
1277 bool oldflying = PhysicsActor.Flying;
1278 1267
1279 if (m_forceFly) 1268 bool oldflying = PhysicsActor.Flying;
1280 PhysicsActor.Flying = true;
1281 else if (m_flyDisabled)
1282 PhysicsActor.Flying = false;
1283 else
1284 PhysicsActor.Flying = ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1285 1269
1286 if (PhysicsActor.Flying != oldflying) 1270 if (m_forceFly)
1287 { 1271 actor.Flying = true;
1288 update_movementflag = true; 1272 else if (m_flyDisabled)
1289 } 1273 actor.Flying = false;
1290 } 1274 else
1275 actor.Flying = ((flags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1276
1277 if (actor.Flying != oldflying)
1278 update_movementflag = true;
1291 1279
1292 if (q != m_bodyRot) 1280 if (q != m_bodyRot)
1293 { 1281 {
@@ -1309,10 +1297,9 @@ namespace OpenSim.Region.Framework.Scenes
1309 else 1297 else
1310 dirVectors = Dir_Vectors; 1298 dirVectors = Dir_Vectors;
1311 1299
1312 1300 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1313 foreach (Dir_ControlFlags DCF in m_dirControlFlags)
1314 { 1301 {
1315 if ((flags & (uint)DCF) != 0) 1302 if (((uint)flags & (uint)DCF) != 0)
1316 { 1303 {
1317 bResetMoveToPosition = true; 1304 bResetMoveToPosition = true;
1318 DCFlagKeyPressed = true; 1305 DCFlagKeyPressed = true;
@@ -1358,7 +1345,7 @@ namespace OpenSim.Region.Framework.Scenes
1358 if (bAllowUpdateMoveToPosition && (m_moveToPositionInProgress && !m_autopilotMoving)) 1345 if (bAllowUpdateMoveToPosition && (m_moveToPositionInProgress && !m_autopilotMoving))
1359 { 1346 {
1360 //Check the error term of the current position in relation to the target position 1347 //Check the error term of the current position in relation to the target position
1361 if (Util.GetDistanceTo(AbsolutePosition, m_moveToPositionTarget) <= 1.5) 1348 if (Util.GetDistanceTo(AbsolutePosition, m_moveToPositionTarget) <= 1.5f)
1362 { 1349 {
1363 // we are close enough to the target 1350 // we are close enough to the target
1364 m_moveToPositionTarget = Vector3.Zero; 1351 m_moveToPositionTarget = Vector3.Zero;
@@ -1439,8 +1426,8 @@ namespace OpenSim.Region.Framework.Scenes
1439 if (m_physicsActor != null && m_physicsActor.Flying && !m_forceFly) 1426 if (m_physicsActor != null && m_physicsActor.Flying && !m_forceFly)
1440 { 1427 {
1441 // Are the landing controls requirements filled? 1428 // Are the landing controls requirements filled?
1442 bool controlland = (((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || 1429 bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) ||
1443 ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 1430 ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
1444 1431
1445 // Are the collision requirements fulfilled? 1432 // Are the collision requirements fulfilled?
1446 bool colliding = (m_physicsActor.IsColliding == true); 1433 bool colliding = (m_physicsActor.IsColliding == true);
@@ -1537,7 +1524,7 @@ namespace OpenSim.Region.Framework.Scenes
1537 if (part != null) 1524 if (part != null)
1538 { 1525 {
1539 AbsolutePosition = part.AbsolutePosition; 1526 AbsolutePosition = part.AbsolutePosition;
1540 Velocity = new Vector3(0, 0, 0); 1527 Velocity = Vector3.Zero;
1541 SendFullUpdateToAllClients(); 1528 SendFullUpdateToAllClients();
1542 1529
1543 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1530 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID);
@@ -1607,7 +1594,7 @@ namespace OpenSim.Region.Framework.Scenes
1607 } 1594 }
1608 1595
1609 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1596 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight);
1610 m_parentPosition = new Vector3(); 1597 m_parentPosition = Vector3.Zero;
1611 1598
1612 m_parentID = 0; 1599 m_parentID = 0;
1613 SendFullUpdateToAllClients(); 1600 SendFullUpdateToAllClients();
@@ -1834,7 +1821,7 @@ namespace OpenSim.Region.Framework.Scenes
1834 //Quaternion result = (sitTargetOrient * vq) * nq; 1821 //Quaternion result = (sitTargetOrient * vq) * nq;
1835 1822
1836 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 1823 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
1837 m_pos += m_sitTargetCorrectionOffset; 1824 m_pos += SIT_TARGET_ADJUSTMENT;
1838 m_bodyRot = sitTargetOrient; 1825 m_bodyRot = sitTargetOrient;
1839 //Rotation = sitTargetOrient; 1826 //Rotation = sitTargetOrient;
1840 m_parentPosition = part.AbsolutePosition; 1827 m_parentPosition = part.AbsolutePosition;
@@ -1854,7 +1841,7 @@ namespace OpenSim.Region.Framework.Scenes
1854 } 1841 }
1855 m_parentID = m_requestedSitTargetID; 1842 m_parentID = m_requestedSitTargetID;
1856 1843
1857 Velocity = new Vector3(0, 0, 0); 1844 Velocity = Vector3.Zero;
1858 RemoveFromPhysicalScene(); 1845 RemoveFromPhysicalScene();
1859 1846
1860 TrySetMovementAnimation(sitAnimation); 1847 TrySetMovementAnimation(sitAnimation);
@@ -2011,7 +1998,7 @@ namespace OpenSim.Region.Framework.Scenes
2011 protected void TrySetMovementAnimation(string anim) 1998 protected void TrySetMovementAnimation(string anim)
2012 { 1999 {
2013 //m_log.DebugFormat("Updating movement animation to {0}", anim); 2000 //m_log.DebugFormat("Updating movement animation to {0}", anim);
2014 2001
2015 if (!m_isChildAgent) 2002 if (!m_isChildAgent)
2016 { 2003 {
2017 if (m_animations.TrySetDefaultAnimation(anim, m_controllingClient.NextAnimationSequenceNumber, UUID.Zero)) 2004 if (m_animations.TrySetDefaultAnimation(anim, m_controllingClient.NextAnimationSequenceNumber, UUID.Zero))
@@ -2046,200 +2033,169 @@ namespace OpenSim.Region.Framework.Scenes
2046 /// </summary> 2033 /// </summary>
2047 public string GetMovementAnimation() 2034 public string GetMovementAnimation()
2048 { 2035 {
2049 if ((m_animPersistUntil > 0) && (m_animPersistUntil > DateTime.Now.Ticks)) 2036 const float FALL_DELAY = 0.33f;
2050 { 2037 const float PREJUMP_DELAY = 0.25f;
2051 //We don't want our existing state to end yet.
2052 return m_movementAnimation;
2053 2038
2054 } 2039 #region Inputs
2055 else if (m_movementflag != 0) 2040
2041 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_AgentControlFlags;
2042 PhysicsActor actor = m_physicsActor;
2043
2044 // Create forward and left vectors from the current avatar rotation
2045 Matrix4 rotMatrix = Matrix4.CreateFromQuaternion(m_bodyRot);
2046 Vector3 fwd = Vector3.Transform(Vector3.UnitX, rotMatrix);
2047 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix);
2048
2049 // Check control flags
2050 bool heldForward = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS;
2051 bool heldBack = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG;
2052 bool heldLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS;
2053 bool heldRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG;
2054 //bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT;
2055 //bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT;
2056 bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS;
2057 bool heldDown = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG;
2058 //bool flying = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) == AgentManager.ControlFlags.AGENT_CONTROL_FLY;
2059 //bool mouselook = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) == AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK;
2060
2061 // Direction in which the avatar is trying to move
2062 Vector3 move = Vector3.Zero;
2063 if (heldForward) { move.X += fwd.X; move.Y += fwd.Y; }
2064 if (heldBack) { move.X -= fwd.X; move.Y -= fwd.Y; }
2065 if (heldLeft) { move.X += left.X; move.Y += left.Y; }
2066 if (heldRight) { move.X -= left.X; move.Y -= left.Y; }
2067 if (heldUp) { move.Z += 1; }
2068 if (heldDown) { move.Z -= 1; }
2069
2070 // Is the avatar trying to move?
2071 bool moving = (move != Vector3.Zero);
2072 bool jumping = m_animTickJump != 0;
2073
2074 #endregion Inputs
2075
2076 #region Flying
2077
2078 if (actor != null && actor.Flying)
2056 { 2079 {
2057 //We're moving 2080 m_animTickFall = 0;
2058 m_allowFalling = true; 2081 m_animTickJump = 0;
2059 if (PhysicsActor != null && PhysicsActor.IsColliding) 2082
2083 if (move.X != 0f || move.Y != 0f)
2060 { 2084 {
2061 //And colliding. Can you guess what it is yet? 2085 return (m_useFlySlow ? "FLYSLOW" : "FLY");
2062 if ((m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) 2086 }
2063 { 2087 else if (move.Z > 0f)
2064 //Down key is being pressed. 2088 {
2065 if ((m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) + (m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0) 2089 return "HOVER_UP";
2066 { 2090 }
2067 return "CROUCHWALK"; 2091 else if (move.Z < 0f)
2068 } 2092 {
2069 else 2093 if (actor != null && actor.IsColliding)
2070 { 2094 return "LAND";
2071 return "CROUCH";
2072 }
2073 }
2074 else if (m_setAlwaysRun)
2075 {
2076 return "RUN";
2077 }
2078 else 2095 else
2079 { 2096 return "HOVER_DOWN";
2080 //If we're prejumping then inhibit this, it's a problem
2081 //caused by a false positive on IsColliding
2082 if (m_movementAnimation == "PREJUMP")
2083 {
2084 return "PREJUMP";
2085 }
2086 else
2087 {
2088 return "WALK";
2089 }
2090 }
2091
2092 } 2097 }
2093 else 2098 else
2094 { 2099 {
2095 //We're not colliding. Colliding isn't cool these days. 2100 return "HOVER";
2096 if (PhysicsActor != null && PhysicsActor.Flying) 2101 }
2097 { 2102 }
2098 //Are we moving forwards or backwards?
2099 if ((m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0)
2100 {
2101 //Then we really are flying
2102 if (m_setAlwaysRun)
2103 {
2104 return "FLY";
2105 }
2106 else
2107 {
2108 if (m_useFlySlow == false)
2109 {
2110 return "FLY";
2111 }
2112 else
2113 {
2114 return "FLYSLOW";
2115 }
2116 }
2117 }
2118 else
2119 {
2120 if ((m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0)
2121 {
2122 return "HOVER_UP";
2123 }
2124 else
2125 {
2126 return "HOVER_DOWN";
2127 }
2128 }
2129 2103
2130 } 2104 #endregion Flying
2131 else if (m_movementAnimation == "JUMP")
2132 {
2133 //If we were already jumping, continue to jump until we collide
2134 return "JUMP";
2135 2105
2136 } 2106 #region Falling/Floating/Landing
2137 else if (m_movementAnimation == "PREJUMP" && (m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == 0)
2138 {
2139 //If we were in a prejump, and the UP key is no longer being held down
2140 //then we're not going to fly, so we're jumping
2141 return "JUMP";
2142 2107
2143 } 2108 if (actor == null || !actor.IsColliding)
2144 else if ((m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0) 2109 {
2145 { 2110 float fallElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f;
2146 //They're pressing up, so we're either going to fly or jump 2111 float fallVelocity = (actor != null) ? actor.Velocity.Z : 0.0f;
2147 return "PREJUMP"; 2112
2148 } 2113 if (m_animTickFall == 0 || (fallElapsed > FALL_DELAY && fallVelocity >= 0.0f))
2149 else 2114 {
2150 { 2115 // Just started falling
2151 //If we're moving and not flying and not jumping and not colliding.. 2116 m_animTickFall = Environment.TickCount;
2152
2153 if (m_movementAnimation == "WALK" || m_movementAnimation == "RUN")
2154 {
2155 //Let's not enter a FALLDOWN state here, since we're probably
2156 //not colliding because we're going down hill.
2157 return m_movementAnimation;
2158 }
2159 //Record the time we enter this state so we know whether to "land" or not
2160 m_animPersistUntil = DateTime.Now.Ticks;
2161 return "FALLDOWN";
2162
2163 }
2164 } 2117 }
2118 else if (!jumping && fallElapsed > FALL_DELAY)
2119 {
2120 // Falling long enough to trigger the animation
2121 return "FALLDOWN";
2122 }
2123
2124 return m_movementAnimation;
2165 } 2125 }
2166 else 2126
2127 #endregion Falling/Floating/Landing
2128
2129 #region Ground Movement
2130
2131 if (m_movementAnimation == "FALLDOWN")
2167 { 2132 {
2168 //We're not moving. 2133 m_animTickFall = Environment.TickCount;
2169 if (PhysicsActor != null && PhysicsActor.IsColliding)
2170 {
2171 //But we are colliding.
2172 if (m_movementAnimation == "FALLDOWN")
2173 {
2174 //We're re-using the m_animPersistUntil value here to see how long we've been falling
2175 if ((DateTime.Now.Ticks - m_animPersistUntil) > TimeSpan.TicksPerSecond)
2176 {
2177 //Make sure we don't change state for a bit
2178 m_animPersistUntil = DateTime.Now.Ticks + TimeSpan.TicksPerSecond;
2179 return "LAND";
2180 }
2181 else
2182 {
2183 //We haven't been falling very long, we were probably just walking down hill
2184 return "STAND";
2185 }
2186 }
2187 else if (m_movementAnimation == "JUMP" || m_movementAnimation == "HOVER_DOWN")
2188 {
2189 //Make sure we don't change state for a bit
2190 m_animPersistUntil = DateTime.Now.Ticks + (1 * TimeSpan.TicksPerSecond);
2191 return "SOFT_LAND";
2192 2134
2193 } 2135 // TODO: SOFT_LAND support
2194 else if ((m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0) 2136 return "LAND";
2195 { 2137 }
2196 return "PREJUMP"; 2138 else if (m_movementAnimation == "LAND")
2197 } 2139 {
2198 else if (PhysicsActor != null && PhysicsActor.Flying) 2140 float landElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f;
2199 {
2200 m_allowFalling = true;
2201 if ((m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0)
2202 {
2203 return "HOVER_UP";
2204 }
2205 else if ((m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0)
2206 {
2207 return "HOVER_DOWN";
2208 }
2209 else
2210 {
2211 return "HOVER";
2212 }
2213 }
2214 else
2215 {
2216 return "STAND";
2217 }
2218 2141
2142 if (landElapsed <= FALL_DELAY)
2143 return "LAND";
2144 }
2145
2146 m_animTickFall = 0;
2147
2148 if (move.Z > 0f)
2149 {
2150 // Jumping
2151 if (!jumping)
2152 {
2153 // Begin prejump
2154 m_animTickJump = Environment.TickCount;
2155 return "PREJUMP";
2219 } 2156 }
2220 else 2157 else if (Environment.TickCount - m_animTickJump > PREJUMP_DELAY * 1000.0f)
2221 { 2158 {
2222 //We're not colliding. 2159 // Start actual jump
2223 if (PhysicsActor != null && PhysicsActor.Flying) 2160 if (m_animTickJump == -1)
2224 { 2161 {
2225 2162 // Already jumping! End the current jump
2226 return "HOVER"; 2163 m_animTickJump = 0;
2227 2164 return "JUMP";
2228 } 2165 }
2229 else if ((m_movementAnimation == "JUMP" || m_movementAnimation == "PREJUMP") && (m_movementflag & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == 0)
2230 {
2231 2166
2232 return "JUMP"; 2167 m_animTickJump = -1;
2168 return "JUMP";
2169 }
2170 }
2171 else
2172 {
2173 // Not jumping
2174 m_animTickJump = 0;
2233 2175
2234 } 2176 if (move.X != 0f || move.Y != 0f)
2177 {
2178 // Walking / crouchwalking / running
2179 if (move.Z < 0f)
2180 return "CROUCHWALK";
2181 else if (m_setAlwaysRun)
2182 return "RUN";
2235 else 2183 else
2236 { 2184 return "WALK";
2237 //Record the time we enter this state so we know whether to "land" or not 2185 }
2238 m_animPersistUntil = DateTime.Now.Ticks; 2186 else
2239 return "FALLDOWN"; // this falling animation is invoked too frequently when capsule tilt correction is used - why? 2187 {
2240 } 2188 // Not walking
2189 if (move.Z < 0f)
2190 return "CROUCH";
2191 else
2192 return "STAND";
2241 } 2193 }
2242 } 2194 }
2195
2196 #endregion Ground Movement
2197
2198 return m_movementAnimation;
2243 } 2199 }
2244 2200
2245 /// <summary> 2201 /// <summary>
@@ -2247,24 +2203,16 @@ namespace OpenSim.Region.Framework.Scenes
2247 /// </summary> 2203 /// </summary>
2248 protected void UpdateMovementAnimations() 2204 protected void UpdateMovementAnimations()
2249 { 2205 {
2250 string movementAnimation = GetMovementAnimation(); 2206 m_movementAnimation = GetMovementAnimation();
2251 2207
2252 if (movementAnimation == "FALLDOWN" && m_allowFalling == false) 2208 if (m_movementAnimation == "PREJUMP" && !m_usePreJump)
2253 {
2254 movementAnimation = m_movementAnimation;
2255 }
2256 else
2257 {
2258 m_movementAnimation = movementAnimation;
2259 }
2260 if (movementAnimation == "PREJUMP" && m_usePreJump == false)
2261 { 2209 {
2262 //This was the previous behavior before PREJUMP 2210 // This was the previous behavior before PREJUMP
2263 TrySetMovementAnimation("JUMP"); 2211 TrySetMovementAnimation("JUMP");
2264 } 2212 }
2265 else 2213 else
2266 { 2214 {
2267 TrySetMovementAnimation(movementAnimation); 2215 TrySetMovementAnimation(m_movementAnimation);
2268 } 2216 }
2269 } 2217 }
2270 2218
@@ -2277,7 +2225,7 @@ namespace OpenSim.Region.Framework.Scenes
2277 { 2225 {
2278 if (m_isChildAgent) 2226 if (m_isChildAgent)
2279 { 2227 {
2280 m_log.Debug("DEBUG: AddNewMovement: child agent, Making root agent!"); 2228 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!");
2281 2229
2282 // we have to reset the user's child agent connections. 2230 // we have to reset the user's child agent connections.
2283 // Likely, here they've lost the eventqueue for other regions so border 2231 // Likely, here they've lost the eventqueue for other regions so border
@@ -2286,7 +2234,7 @@ namespace OpenSim.Region.Framework.Scenes
2286 List<ulong> regions = new List<ulong>(KnownChildRegionHandles); 2234 List<ulong> regions = new List<ulong>(KnownChildRegionHandles);
2287 regions.Remove(m_scene.RegionInfo.RegionHandle); 2235 regions.Remove(m_scene.RegionInfo.RegionHandle);
2288 2236
2289 MakeRootAgent(new Vector3(127, 127, 127), true); 2237 MakeRootAgent(new Vector3(127f, 127f, 127f), true);
2290 2238
2291 // Async command 2239 // Async command
2292 if (m_scene.SceneGridService != null) 2240 if (m_scene.SceneGridService != null)
@@ -2298,47 +2246,45 @@ namespace OpenSim.Region.Framework.Scenes
2298 System.Threading.Thread.Sleep(500); 2246 System.Threading.Thread.Sleep(500);
2299 } 2247 }
2300 2248
2301
2302 if (m_scene.SceneGridService != null) 2249 if (m_scene.SceneGridService != null)
2303 { 2250 {
2304 m_scene.SceneGridService.EnableNeighbourChildAgents(this, new List<RegionInfo>()); 2251 m_scene.SceneGridService.EnableNeighbourChildAgents(this, new List<RegionInfo>());
2305 } 2252 }
2306 2253
2307
2308
2309 return; 2254 return;
2310 } 2255 }
2311 2256
2312 m_perfMonMS = Environment.TickCount; 2257 m_perfMonMS = Environment.TickCount;
2313 2258
2314 m_rotation = rotation; 2259 m_rotation = rotation;
2315 NewForce newVelocity = new NewForce();
2316 Vector3 direc = vec * rotation; 2260 Vector3 direc = vec * rotation;
2317 direc.Normalize(); 2261 direc.Normalize();
2318 2262
2319 direc *= 0.03f * 128f * m_speedModifier; 2263 direc *= 0.03f * 128f * m_speedModifier;
2320 if (m_physicsActor.Flying) 2264
2321 { 2265 PhysicsActor actor = m_physicsActor;
2322 direc *= 4; 2266 if (actor != null)
2323 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
2324 //bool colliding = (m_physicsActor.IsColliding==true);
2325 //if (controlland)
2326 // m_log.Info("[AGENT]: landCommand");
2327 //if (colliding)
2328 // m_log.Info("[AGENT]: colliding");
2329 //if (m_physicsActor.Flying && colliding && controlland)
2330 //{
2331 // StopFlying();
2332 // m_log.Info("[AGENT]: Stop FLying");
2333 //}
2334 }
2335 else
2336 { 2267 {
2337 if (!m_physicsActor.Flying && m_physicsActor.IsColliding) 2268 if (actor.Flying)
2269 {
2270 direc *= 4.0f;
2271 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
2272 //bool colliding = (m_physicsActor.IsColliding==true);
2273 //if (controlland)
2274 // m_log.Info("[AGENT]: landCommand");
2275 //if (colliding)
2276 // m_log.Info("[AGENT]: colliding");
2277 //if (m_physicsActor.Flying && colliding && controlland)
2278 //{
2279 // StopFlying();
2280 // m_log.Info("[AGENT]: Stop FLying");
2281 //}
2282 }
2283 else if (!actor.Flying && actor.IsColliding)
2338 { 2284 {
2339 if (direc.Z > 2.0f) 2285 if (direc.Z > 2.0f)
2340 { 2286 {
2341 direc.Z *= 3; 2287 direc.Z *= 3.0f;
2342 2288
2343 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2289 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2344 TrySetMovementAnimation("PREJUMP"); 2290 TrySetMovementAnimation("PREJUMP");
@@ -2347,10 +2293,8 @@ namespace OpenSim.Region.Framework.Scenes
2347 } 2293 }
2348 } 2294 }
2349 2295
2350 newVelocity.X = direc.X; 2296 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2351 newVelocity.Y = direc.Y; 2297 m_forceToApply = direc;
2352 newVelocity.Z = direc.Z;
2353 m_forcesList.Add(newVelocity);
2354 2298
2355 m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); 2299 m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
2356 } 2300 }
@@ -2361,8 +2305,10 @@ namespace OpenSim.Region.Framework.Scenes
2361 2305
2362 public override void Update() 2306 public override void Update()
2363 { 2307 {
2364 const float VELOCITY_TOLERANCE = 0.01f; 2308 const float ROTATION_TOLERANCE = 0.01f;
2365 const float POSITION_TOLERANCE = 10.0f; 2309 const float VELOCITY_TOLERANCE = 0.001f;
2310 const float POSITION_TOLERANCE = 0.05f;
2311 //const int TIME_MS_TOLERANCE = 3000;
2366 2312
2367 SendPrimUpdates(); 2313 SendPrimUpdates();
2368 2314
@@ -2374,17 +2320,25 @@ namespace OpenSim.Region.Framework.Scenes
2374 2320
2375 if (m_isChildAgent == false) 2321 if (m_isChildAgent == false)
2376 { 2322 {
2323 PhysicsActor actor = m_physicsActor;
2324
2325 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to
2326 // grab the latest PhysicsActor velocity, whereas m_velocity is often
2327 // storing a requested force instead of an actual traveling velocity
2328
2377 // Throw away duplicate or insignificant updates 2329 // Throw away duplicate or insignificant updates
2378 if (m_bodyRot != m_lastRotation || 2330 if (!m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
2379 (m_velocity - m_lastVelocity).Length() > VELOCITY_TOLERANCE || 2331 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
2380 (m_pos - m_lastPosition).Length() > POSITION_TOLERANCE) 2332 !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
2333 //Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
2381 { 2334 {
2382 SendTerseUpdateToAllClients(); 2335 SendTerseUpdateToAllClients();
2383 2336
2384 // Update the "last" values 2337 // Update the "last" values
2385 m_lastPosition = m_pos; 2338 m_lastPosition = m_pos;
2386 m_lastRotation = m_bodyRot; 2339 m_lastRotation = m_bodyRot;
2387 m_lastVelocity = m_velocity; 2340 m_lastVelocity = Velocity;
2341 //m_lastTerseSent = Environment.TickCount;
2388 } 2342 }
2389 2343
2390 // followed suggestion from mic bowman. reversed the two lines below. 2344 // followed suggestion from mic bowman. reversed the two lines below.
@@ -2410,11 +2364,16 @@ namespace OpenSim.Region.Framework.Scenes
2410 { 2364 {
2411 m_perfMonMS = Environment.TickCount; 2365 m_perfMonMS = Environment.TickCount;
2412 2366
2367 PhysicsActor actor = m_physicsActor;
2368 Vector3 velocity = (actor != null) ? actor.Velocity : Vector3.Zero;
2369
2413 Vector3 pos = m_pos; 2370 Vector3 pos = m_pos;
2414 pos.Z -= m_appearance.HipOffset; 2371 pos.Z += m_appearance.HipOffset;
2415 2372
2416 remoteClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_regionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId, 2373 //m_log.DebugFormat("[SCENEPRESENCE]: TerseUpdate: Pos={0} Rot={1} Vel={2}", m_pos, m_bodyRot, m_velocity);
2417 pos, m_velocity, Vector3.Zero, m_bodyRot, Vector4.UnitW, m_uuid, null, GetUpdatePriority(remoteClient))); 2374
2375 remoteClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
2376 pos, velocity, Vector3.Zero, m_bodyRot, CollisionPlane, m_uuid, null, GetUpdatePriority(remoteClient)));
2418 2377
2419 m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); 2378 m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
2420 m_scene.StatsReporter.AddAgentUpdates(1); 2379 m_scene.StatsReporter.AddAgentUpdates(1);
@@ -2510,7 +2469,7 @@ namespace OpenSim.Region.Framework.Scenes
2510 return; 2469 return;
2511 2470
2512 Vector3 pos = m_pos; 2471 Vector3 pos = m_pos;
2513 pos.Z -= m_appearance.HipOffset; 2472 pos.Z += m_appearance.HipOffset;
2514 2473
2515 remoteAvatar.m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, 2474 remoteAvatar.m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid,
2516 LocalId, pos, m_appearance.Texture.GetBytes(), 2475 LocalId, pos, m_appearance.Texture.GetBytes(),
@@ -2581,7 +2540,7 @@ namespace OpenSim.Region.Framework.Scenes
2581 // m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); 2540 // m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance);
2582 2541
2583 Vector3 pos = m_pos; 2542 Vector3 pos = m_pos;
2584 pos.Z -= m_appearance.HipOffset; 2543 pos.Z += m_appearance.HipOffset;
2585 2544
2586 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, 2545 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId,
2587 pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot)); 2546 pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot));
@@ -2690,7 +2649,7 @@ namespace OpenSim.Region.Framework.Scenes
2690 } 2649 }
2691 2650
2692 Vector3 pos = m_pos; 2651 Vector3 pos = m_pos;
2693 pos.Z -= m_appearance.HipOffset; 2652 pos.Z += m_appearance.HipOffset;
2694 2653
2695 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, 2654 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId,
2696 pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot)); 2655 pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot));
@@ -2778,7 +2737,8 @@ namespace OpenSim.Region.Framework.Scenes
2778 } 2737 }
2779 2738
2780 // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m 2739 // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m
2781 if (Util.GetDistanceTo(AbsolutePosition, m_LastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance) 2740 if (Util.GetDistanceTo(AbsolutePosition, m_lastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance ||
2741 Util.GetDistanceTo(CameraPosition, m_lastChildAgentUpdateCamPosition) >= Scene.ChildReprioritizationDistance)
2782 { 2742 {
2783 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); 2743 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
2784 cadu.ActiveGroupID = UUID.Zero.Guid; 2744 cadu.ActiveGroupID = UUID.Zero.Guid;
@@ -2792,7 +2752,7 @@ namespace OpenSim.Region.Framework.Scenes
2792 cadu.godlevel = m_godlevel; 2752 cadu.godlevel = m_godlevel;
2793 cadu.GroupAccess = 0; 2753 cadu.GroupAccess = 0;
2794 cadu.Position = new sLLVector3(AbsolutePosition); 2754 cadu.Position = new sLLVector3(AbsolutePosition);
2795 cadu.regionHandle = m_scene.RegionInfo.RegionHandle; 2755 cadu.regionHandle = m_rootRegionHandle;
2796 float multiplier = 1; 2756 float multiplier = 1;
2797 int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); 2757 int innacurateNeighbors = m_scene.GetInaccurateNeighborCount();
2798 if (innacurateNeighbors != 0) 2758 if (innacurateNeighbors != 0)
@@ -2812,11 +2772,9 @@ namespace OpenSim.Region.Framework.Scenes
2812 agentpos.CopyFrom(cadu); 2772 agentpos.CopyFrom(cadu);
2813 2773
2814 m_scene.SendOutChildAgentUpdates(agentpos, this); 2774 m_scene.SendOutChildAgentUpdates(agentpos, this);
2815
2816 m_LastChildAgentUpdatePosition.X = AbsolutePosition.X;
2817 m_LastChildAgentUpdatePosition.Y = AbsolutePosition.Y;
2818 m_LastChildAgentUpdatePosition.Z = AbsolutePosition.Z;
2819 2775
2776 m_lastChildAgentUpdatePosition = AbsolutePosition;
2777 m_lastChildAgentUpdateCamPosition = CameraPosition;
2820 } 2778 }
2821 } 2779 }
2822 2780
@@ -2941,9 +2899,9 @@ namespace OpenSim.Region.Framework.Scenes
2941 m_inTransit = true; 2899 m_inTransit = true;
2942 2900
2943 if ((m_physicsActor != null) && m_physicsActor.Flying) 2901 if ((m_physicsActor != null) && m_physicsActor.Flying)
2944 m_AgentControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY; 2902 m_AgentControlFlags |= AgentManager.ControlFlags.AGENT_CONTROL_FLY;
2945 else if ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0) 2903 else if ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
2946 m_AgentControlFlags &= ~(uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY; 2904 m_AgentControlFlags &= ~AgentManager.ControlFlags.AGENT_CONTROL_FLY;
2947 } 2905 }
2948 2906
2949 public void NotInTransit() 2907 public void NotInTransit()
@@ -2959,7 +2917,7 @@ namespace OpenSim.Region.Framework.Scenes
2959 public void Reset() 2917 public void Reset()
2960 { 2918 {
2961 // Put the child agent back at the center 2919 // Put the child agent back at the center
2962 AbsolutePosition = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 70); 2920 AbsolutePosition = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70);
2963 ResetAnimations(); 2921 ResetAnimations();
2964 } 2922 }
2965 2923
@@ -3069,9 +3027,11 @@ namespace OpenSim.Region.Framework.Scenes
3069 int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize; 3027 int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize;
3070 int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize; 3028 int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize;
3071 3029
3030 Vector3 offset = new Vector3(shiftx, shifty, 0f);
3031
3072 m_DrawDistance = cAgentData.Far; 3032 m_DrawDistance = cAgentData.Far;
3073 if (cAgentData.Position != new Vector3(-1, -1, -1)) // UGH!! 3033 if (cAgentData.Position != new Vector3(-1f, -1f, -1f)) // UGH!!
3074 m_pos = new Vector3(cAgentData.Position.X + shiftx, cAgentData.Position.Y + shifty, cAgentData.Position.Z); 3034 m_pos = cAgentData.Position + offset;
3075 3035
3076 if (Vector3.Distance(AbsolutePosition, posLastSignificantMove) >= Scene.ChildReprioritizationDistance) 3036 if (Vector3.Distance(AbsolutePosition, posLastSignificantMove) >= Scene.ChildReprioritizationDistance)
3077 { 3037 {
@@ -3079,8 +3039,7 @@ namespace OpenSim.Region.Framework.Scenes
3079 ReprioritizeUpdates(); 3039 ReprioritizeUpdates();
3080 } 3040 }
3081 3041
3082 // It's hard to say here.. We can't really tell where the camera position is unless it's in world cordinates from the sending region 3042 m_CameraCenter = cAgentData.Center + offset;
3083 m_CameraCenter = cAgentData.Center;
3084 3043
3085 m_avHeight = cAgentData.Size.Z; 3044 m_avHeight = cAgentData.Size.Z;
3086 //SetHeight(cAgentData.AVHeight); 3045 //SetHeight(cAgentData.AVHeight);
@@ -3093,16 +3052,16 @@ namespace OpenSim.Region.Framework.Scenes
3093 m_sceneViewer.Reset(); 3052 m_sceneViewer.Reset();
3094 3053
3095 //cAgentData.AVHeight; 3054 //cAgentData.AVHeight;
3096 //cAgentData.regionHandle; 3055 m_rootRegionHandle = cAgentData.RegionHandle;
3097 //m_velocity = cAgentData.Velocity; 3056 //m_velocity = cAgentData.Velocity;
3098 } 3057 }
3099 3058
3100 public void CopyTo(AgentData cAgent) 3059 public void CopyTo(AgentData cAgent)
3101 { 3060 {
3102 cAgent.AgentID = UUID; 3061 cAgent.AgentID = UUID;
3103 cAgent.RegionHandle = m_scene.RegionInfo.RegionHandle; 3062 cAgent.RegionHandle = m_rootRegionHandle;
3104 3063
3105 cAgent.Position = m_pos; 3064 cAgent.Position = AbsolutePosition;
3106 cAgent.Velocity = m_velocity; 3065 cAgent.Velocity = m_velocity;
3107 cAgent.Center = m_CameraCenter; 3066 cAgent.Center = m_CameraCenter;
3108 // Don't copy the size; it is inferred from apearance parameters 3067 // Don't copy the size; it is inferred from apearance parameters
@@ -3129,7 +3088,7 @@ namespace OpenSim.Region.Framework.Scenes
3129 3088
3130 cAgent.HeadRotation = m_headrotation; 3089 cAgent.HeadRotation = m_headrotation;
3131 cAgent.BodyRotation = m_bodyRot; 3090 cAgent.BodyRotation = m_bodyRot;
3132 cAgent.ControlFlags = m_AgentControlFlags; 3091 cAgent.ControlFlags = (uint)m_AgentControlFlags;
3133 3092
3134 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) 3093 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID)))
3135 cAgent.GodLevel = (byte)m_godlevel; 3094 cAgent.GodLevel = (byte)m_godlevel;
@@ -3199,7 +3158,8 @@ namespace OpenSim.Region.Framework.Scenes
3199 3158
3200 public void CopyFrom(AgentData cAgent) 3159 public void CopyFrom(AgentData cAgent)
3201 { 3160 {
3202 m_rootRegionHandle= cAgent.RegionHandle; 3161 m_rootRegionHandle = cAgent.RegionHandle;
3162
3203 m_callbackURI = cAgent.CallbackURI; 3163 m_callbackURI = cAgent.CallbackURI;
3204 3164
3205 m_pos = cAgent.Position; 3165 m_pos = cAgent.Position;
@@ -3217,7 +3177,7 @@ namespace OpenSim.Region.Framework.Scenes
3217 3177
3218 m_headrotation = cAgent.HeadRotation; 3178 m_headrotation = cAgent.HeadRotation;
3219 m_bodyRot = cAgent.BodyRotation; 3179 m_bodyRot = cAgent.BodyRotation;
3220 m_AgentControlFlags = cAgent.ControlFlags; 3180 m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags;
3221 3181
3222 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) 3182 if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID)))
3223 m_godlevel = cAgent.GodLevel; 3183 m_godlevel = cAgent.GodLevel;
@@ -3291,47 +3251,18 @@ namespace OpenSim.Region.Framework.Scenes
3291 /// </summary> 3251 /// </summary>
3292 public override void UpdateMovement() 3252 public override void UpdateMovement()
3293 { 3253 {
3294 lock (m_forcesList) 3254 if (m_forceToApply.HasValue)
3295 { 3255 {
3296 if (m_forcesList.Count > 0) 3256 Vector3 force = m_forceToApply.Value;
3297 {
3298 //we are only interested in the last velocity added to the list [Although they are called forces, they are actually velocities]
3299 NewForce force = m_forcesList[m_forcesList.Count - 1];
3300 3257
3301 m_updateflag = true; 3258 m_updateflag = true;
3302 try 3259 movementvector = force;
3303 { 3260 Velocity = force;
3304 movementvector.X = force.X;
3305 movementvector.Y = force.Y;
3306 movementvector.Z = force.Z;
3307 Velocity = movementvector;
3308 }
3309 catch (NullReferenceException)
3310 {
3311 // Under extreme load, this returns a NullReference Exception that we can ignore.
3312 // Ignoring this causes no movement to be sent to the physics engine...
3313 // which when the scene is moving at 1 frame every 10 seconds, it doesn't really matter!
3314 }
3315 3261
3316 m_forcesList.Clear(); 3262 m_forceToApply = null;
3317 }
3318 } 3263 }
3319 } 3264 }
3320 3265
3321 static ScenePresence()
3322 {
3323 Primitive.TextureEntry textu = AvatarAppearance.GetDefaultTexture();
3324 DefaultTexture = textu.GetBytes();
3325
3326 }
3327
3328 public class NewForce
3329 {
3330 public float X;
3331 public float Y;
3332 public float Z;
3333 }
3334
3335 public override void SetText(string text, Vector3 color, double alpha) 3266 public override void SetText(string text, Vector3 color, double alpha)
3336 { 3267 {
3337 throw new Exception("Can't set Text on avatar."); 3268 throw new Exception("Can't set Text on avatar.");
@@ -3342,7 +3273,6 @@ namespace OpenSim.Region.Framework.Scenes
3342 /// </summary> 3273 /// </summary>
3343 public void AddToPhysicalScene(bool isFlying) 3274 public void AddToPhysicalScene(bool isFlying)
3344 { 3275 {
3345
3346 PhysicsScene scene = m_scene.PhysicsScene; 3276 PhysicsScene scene = m_scene.PhysicsScene;
3347 3277
3348 Vector3 pVec = AbsolutePosition; 3278 Vector3 pVec = AbsolutePosition;
@@ -3388,15 +3318,48 @@ namespace OpenSim.Region.Framework.Scenes
3388 // as of this comment the interval is set in AddToPhysicalScene 3318 // as of this comment the interval is set in AddToPhysicalScene
3389 UpdateMovementAnimations(); 3319 UpdateMovementAnimations();
3390 3320
3321 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3322 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3323
3324 CollisionPlane = Vector4.UnitW;
3325
3326 if (coldata.Count != 0)
3327 {
3328 switch (m_movementAnimation)
3329 {
3330 case "STAND":
3331 case "WALK":
3332 case "RUN":
3333 case "CROUCH":
3334 case "CROUCHWALK":
3335 {
3336 ContactPoint lowest;
3337 lowest.SurfaceNormal = Vector3.Zero;
3338 lowest.Position = Vector3.Zero;
3339 lowest.Position.Z = Single.NaN;
3340
3341 foreach (ContactPoint contact in coldata.Values)
3342 {
3343 if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z)
3344 {
3345 lowest = contact;
3346 }
3347 }
3348
3349 CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal));
3350 }
3351 break;
3352 }
3353 }
3354
3391 if (m_invulnerable) 3355 if (m_invulnerable)
3392 return; 3356 return;
3393 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3357
3394 Dictionary<uint, float> coldata = collisionData.m_objCollisionList;
3395 float starthealth = Health; 3358 float starthealth = Health;
3396 uint killerObj = 0; 3359 uint killerObj = 0;
3397 foreach (uint localid in coldata.Keys) 3360 foreach (uint localid in coldata.Keys)
3398 { 3361 {
3399 if (coldata[localid] <= 0.10f || m_invulnerable) 3362 if (coldata[localid].PenetrationDepth <= 0.10f || m_invulnerable)
3400 continue; 3363 continue;
3401 //if (localid == 0) 3364 //if (localid == 0)
3402 //continue; 3365 //continue;
@@ -3406,9 +3369,9 @@ namespace OpenSim.Region.Framework.Scenes
3406 if (part != null && part.ParentGroup.Damage != -1.0f) 3369 if (part != null && part.ParentGroup.Damage != -1.0f)
3407 Health -= part.ParentGroup.Damage; 3370 Health -= part.ParentGroup.Damage;
3408 else 3371 else
3409 Health -= coldata[localid] * 5; 3372 Health -= coldata[localid].PenetrationDepth * 5.0f;
3410 3373
3411 if (Health <= 0) 3374 if (Health <= 0.0f)
3412 { 3375 {
3413 if (localid != 0) 3376 if (localid != 0)
3414 killerObj = localid; 3377 killerObj = localid;
@@ -3471,11 +3434,6 @@ namespace OpenSim.Region.Framework.Scenes
3471 3434
3472 public ScenePresence() 3435 public ScenePresence()
3473 { 3436 {
3474 if (DefaultTexture == null)
3475 {
3476 Primitive.TextureEntry textu = AvatarAppearance.GetDefaultTexture();
3477 DefaultTexture = textu.GetBytes();
3478 }
3479 m_sendCourseLocationsMethod = SendCoarseLocationsDefault; 3437 m_sendCourseLocationsMethod = SendCoarseLocationsDefault;
3480 CreateSceneViewer(); 3438 CreateSceneViewer();
3481 } 3439 }
@@ -3632,19 +3590,10 @@ namespace OpenSim.Region.Framework.Scenes
3632 IgnoredControls &= ~(ScriptControlled)controls; 3590 IgnoredControls &= ~(ScriptControlled)controls;
3633 if (scriptedcontrols.ContainsKey(Script_item_UUID)) 3591 if (scriptedcontrols.ContainsKey(Script_item_UUID))
3634 scriptedcontrols.Remove(Script_item_UUID); 3592 scriptedcontrols.Remove(Script_item_UUID);
3635
3636 } 3593 }
3637 else 3594 else
3638 { 3595 {
3639 3596 scriptedcontrols[Script_item_UUID] = obj;
3640 if (scriptedcontrols.ContainsKey(Script_item_UUID))
3641 {
3642 scriptedcontrols[Script_item_UUID] = obj;
3643 }
3644 else
3645 {
3646 scriptedcontrols.Add(Script_item_UUID, obj);
3647 }
3648 } 3597 }
3649 } 3598 }
3650 ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true); 3599 ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true);
@@ -3662,12 +3611,14 @@ namespace OpenSim.Region.Framework.Scenes
3662 3611
3663 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 3612 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3664 { 3613 {
3614 ScriptControllers takecontrols;
3615
3665 lock (scriptedcontrols) 3616 lock (scriptedcontrols)
3666 { 3617 {
3667 if (scriptedcontrols.ContainsKey(Script_item_UUID)) 3618 if (scriptedcontrols.TryGetValue(Script_item_UUID, out takecontrols))
3668 { 3619 {
3669 ScriptControllers takecontrolls = scriptedcontrols[Script_item_UUID]; 3620 ScriptControlled sctc = takecontrols.eventControls;
3670 ScriptControlled sctc = takecontrolls.eventControls; 3621
3671 ControllingClient.SendTakeControls((int)sctc, false, false); 3622 ControllingClient.SendTakeControls((int)sctc, false, false);
3672 ControllingClient.SendTakeControls((int)sctc, true, false); 3623 ControllingClient.SendTakeControls((int)sctc, true, false);
3673 3624
@@ -3678,7 +3629,6 @@ namespace OpenSim.Region.Framework.Scenes
3678 IgnoredControls |= scData.ignoreControls; 3629 IgnoredControls |= scData.ignoreControls;
3679 } 3630 }
3680 } 3631 }
3681
3682 } 3632 }
3683 } 3633 }
3684 3634
@@ -3745,9 +3695,11 @@ namespace OpenSim.Region.Framework.Scenes
3745 { 3695 {
3746 lock (scriptedcontrols) 3696 lock (scriptedcontrols)
3747 { 3697 {
3748 foreach (UUID scriptUUID in scriptedcontrols.Keys) 3698 foreach (KeyValuePair<UUID, ScriptControllers> kvp in scriptedcontrols)
3749 { 3699 {
3750 ScriptControllers scriptControlData = scriptedcontrols[scriptUUID]; 3700 UUID scriptUUID = kvp.Key;
3701 ScriptControllers scriptControlData = kvp.Value;
3702
3751 ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us 3703 ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us
3752 ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle 3704 ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle
3753 ScriptControlled localChange = localHeld ^ localLast; // the changed bits 3705 ScriptControlled localChange = localHeld ^ localLast; // the changed bits
@@ -3763,37 +3715,40 @@ namespace OpenSim.Region.Framework.Scenes
3763 LastCommands = allflags; 3715 LastCommands = allflags;
3764 } 3716 }
3765 3717
3766 internal static uint RemoveIgnoredControls(uint flags, ScriptControlled Ignored) 3718 internal static AgentManager.ControlFlags RemoveIgnoredControls(AgentManager.ControlFlags flags, ScriptControlled ignored)
3767 { 3719 {
3768 if (Ignored == ScriptControlled.CONTROL_ZERO) 3720 if (ignored == ScriptControlled.CONTROL_ZERO)
3769 return flags; 3721 return flags;
3770 if ((Ignored & ScriptControlled.CONTROL_BACK) != 0) 3722
3771 flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG); 3723 if ((ignored & ScriptControlled.CONTROL_BACK) != 0)
3772 if ((Ignored & ScriptControlled.CONTROL_FWD) != 0) 3724 flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG);
3773 flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS | (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS); 3725 if ((ignored & ScriptControlled.CONTROL_FWD) != 0)
3774 if ((Ignored & ScriptControlled.CONTROL_DOWN) != 0) 3726 flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS | AgentManager.ControlFlags.AGENT_CONTROL_AT_POS);
3775 flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG); 3727 if ((ignored & ScriptControlled.CONTROL_DOWN) != 0)
3776 if ((Ignored & ScriptControlled.CONTROL_UP) != 0) 3728 flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG);
3777 flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS | (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS); 3729 if ((ignored & ScriptControlled.CONTROL_UP) != 0)
3778 if ((Ignored & ScriptControlled.CONTROL_LEFT) != 0) 3730 flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS | AgentManager.ControlFlags.AGENT_CONTROL_UP_POS);
3779 flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS); 3731 if ((ignored & ScriptControlled.CONTROL_LEFT) != 0)
3780 if ((Ignored & ScriptControlled.CONTROL_RIGHT) != 0) 3732 flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS);
3781 flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG | (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG); 3733 if ((ignored & ScriptControlled.CONTROL_RIGHT) != 0)
3782 if ((Ignored & ScriptControlled.CONTROL_ROT_LEFT) != 0) 3734 flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG);
3783 flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG); 3735 if ((ignored & ScriptControlled.CONTROL_ROT_LEFT) != 0)
3784 if ((Ignored & ScriptControlled.CONTROL_ROT_RIGHT) != 0) 3736 flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG);
3785 flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS); 3737 if ((ignored & ScriptControlled.CONTROL_ROT_RIGHT) != 0)
3786 if ((Ignored & ScriptControlled.CONTROL_ML_LBUTTON) != 0) 3738 flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS);
3787 flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN); 3739 if ((ignored & ScriptControlled.CONTROL_ML_LBUTTON) != 0)
3788 if ((Ignored & ScriptControlled.CONTROL_LBUTTON) != 0) 3740 flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN);
3789 flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP | (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN); 3741 if ((ignored & ScriptControlled.CONTROL_LBUTTON) != 0)
3790 //DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, 3742 flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP | AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN);
3791 //DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG, 3743
3792 //DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS, 3744 //DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS,
3793 //DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG, 3745 //DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG,
3794 //DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 3746 //DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS,
3795 //DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 3747 //DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG,
3796 //DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 3748 //DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
3749 //DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
3750 //DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
3751
3797 return flags; 3752 return flags;
3798 } 3753 }
3799 3754