aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJeff Ames2008-05-12 04:31:28 +0000
committerJeff Ames2008-05-12 04:31:28 +0000
commitdc67264f6d45a725a8dda7db4556affd54acf6d3 (patch)
tree39417466e27e2b7d922735697f98ed1090bbc0a4
parentFormatting cleanup. (diff)
downloadopensim-SC-dc67264f6d45a725a8dda7db4556affd54acf6d3.zip
opensim-SC-dc67264f6d45a725a8dda7db4556affd54acf6d3.tar.gz
opensim-SC-dc67264f6d45a725a8dda7db4556affd54acf6d3.tar.bz2
opensim-SC-dc67264f6d45a725a8dda7db4556affd54acf6d3.tar.xz
Refactoring animation handling in ScenePresence.
-rw-r--r--OpenSim/Region/Environment/Scenes/ScenePresence.cs244
1 files changed, 101 insertions, 143 deletions
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
index f391cb5..063e2c8 100644
--- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
@@ -397,15 +397,7 @@ namespace OpenSim.Region.Environment.Scenes
397 397
398 AbsolutePosition = m_controllingClient.StartPos; 398 AbsolutePosition = m_controllingClient.StartPos;
399 399
400 // Move them into an object to (hopefully) avoid threading issues. 400 TrySetMovementAnimation("STAND");
401 try
402 {
403 SetMovementAnimation(Animations.AnimsLLUUID["STAND"]);
404 }
405 catch (KeyNotFoundException)
406 {
407 m_log.Warn("[AVATAR]: KeyNotFound Exception playing avatar stand animation");
408 }
409 401
410 RegisterToEvents(); 402 RegisterToEvents();
411 SetDirectionVectors(); 403 SetDirectionVectors();
@@ -618,12 +610,12 @@ namespace OpenSim.Region.Environment.Scenes
618 { 610 {
619 if (m_animations.Count > 0) 611 if (m_animations.Count > 0)
620 { 612 {
621 LLUUID movement=m_animations[0]; 613 LLUUID movementAnim = m_animations[0];
622 614
623 m_animations.Clear(); 615 m_animations.Clear();
624 m_animationSeqs.Clear(); 616 m_animationSeqs.Clear();
625 617
626 SetMovementAnimation(movement); 618 SetMovementAnimation(movementAnim);
627 } 619 }
628// m_log.DebugFormat( 620// m_log.DebugFormat(
629// "[SCENEPRESENCE]: Downgrading child agent {0}, {1} to a root agent in {2}", 621// "[SCENEPRESENCE]: Downgrading child agent {0}, {1} to a root agent in {2}",
@@ -689,7 +681,7 @@ namespace OpenSim.Region.Environment.Scenes
689 { 681 {
690 AbsolutePosition = AbsolutePosition + new LLVector3(0, 0, (1.56f / 6)); 682 AbsolutePosition = AbsolutePosition + new LLVector3(0, 0, (1.56f / 6));
691 } 683 }
692 SetMovementAnimation(Animations.AnimsLLUUID["LAND"]); 684 TrySetMovementAnimation("LAND");
693 SendFullUpdateToAllClients(); 685 SendFullUpdateToAllClients();
694 } 686 }
695 687
@@ -815,9 +807,9 @@ namespace OpenSim.Region.Environment.Scenes
815 807
816 if ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 808 if ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
817 { 809 {
818 // TODO: This doesn't quite work yet -- probably a parent ID problem 810 // TODO: This doesn't enable the "stand up" button on the viewer yet (probably a parent ID problem)
819 // m_parentID = (what should this be?) 811 // m_parentID = ???
820 SetMovementAnimation(Animations.AnimsLLUUID["SIT_GROUND"]); 812 TrySetMovementAnimation("SIT_GROUND");
821 } 813 }
822 // In the future, these values might need to go global. 814 // In the future, these values might need to go global.
823 // Here's where you get them. 815 // Here's where you get them.
@@ -826,10 +818,6 @@ namespace OpenSim.Region.Environment.Scenes
826 // m_headrotation = agentData.AgentData.HeadRotation; 818 // m_headrotation = agentData.AgentData.HeadRotation;
827 // m_state = agentData.AgentData.State; 819 // m_state = agentData.AgentData.State;
828 820
829
830
831
832
833 if (m_allowMovement) 821 if (m_allowMovement)
834 { 822 {
835 int i = 0; 823 int i = 0;
@@ -908,10 +896,13 @@ namespace OpenSim.Region.Environment.Scenes
908 } 896 }
909 } 897 }
910 } 898 }
911 if ((update_movementflag) || (update_rotation && DCFlagKeyPressed)) 899
900 if (update_movementflag || (update_rotation && DCFlagKeyPressed))
912 { 901 {
913 AddNewMovement(agent_control_v3, q); 902 AddNewMovement(agent_control_v3, q);
914 UpdateMovementAnimations(update_movementflag); 903
904 if (update_movementflag)
905 UpdateMovementAnimations();
915 } 906 }
916 } 907 }
917 908
@@ -955,7 +946,7 @@ namespace OpenSim.Region.Environment.Scenes
955 } 946 }
956 } 947 }
957 948
958 SetMovementAnimation(Animations.AnimsLLUUID["STAND"]); 949 TrySetMovementAnimation("STAND");
959 } 950 }
960 951
961 private void SendSitResponse(IClientAPI remoteClient, LLUUID targetID, LLVector3 offset) 952 private void SendSitResponse(IClientAPI remoteClient, LLUUID targetID, LLVector3 offset)
@@ -1088,7 +1079,7 @@ namespace OpenSim.Region.Environment.Scenes
1088 Velocity = new LLVector3(0, 0, 0); 1079 Velocity = new LLVector3(0, 0, 0);
1089 RemoveFromPhysicalScene(); 1080 RemoveFromPhysicalScene();
1090 1081
1091 SetMovementAnimation(Animations.AnimsLLUUID["SIT"]); 1082 TrySetMovementAnimation("SIT");
1092 SendFullUpdateToAllClients(); 1083 SendFullUpdateToAllClients();
1093 // This may seem stupid, but Our Full updates don't send avatar rotation :P 1084 // This may seem stupid, but Our Full updates don't send avatar rotation :P
1094 // So we're also sending a terse update (which has avatar rotation) 1085 // So we're also sending a terse update (which has avatar rotation)
@@ -1115,7 +1106,7 @@ namespace OpenSim.Region.Environment.Scenes
1115 1106
1116 // Don't let this animation become the movement animation 1107 // Don't let this animation become the movement animation
1117 if (m_animations.Count < 1) 1108 if (m_animations.Count < 1)
1118 SetMovementAnimation(Animations.AnimsLLUUID["STAND"]); 1109 TrySetMovementAnimation("STAND");
1119 1110
1120 if (!m_animations.Contains(animID)) 1111 if (!m_animations.Contains(animID))
1121 { 1112 {
@@ -1134,7 +1125,7 @@ namespace OpenSim.Region.Environment.Scenes
1134 { 1125 {
1135 if (m_animations[0] == animID) 1126 if (m_animations[0] == animID)
1136 { 1127 {
1137 SetMovementAnimation(Animations.AnimsLLUUID["STAND"]); 1128 TrySetMovementAnimation("STAND");
1138 } 1129 }
1139 else 1130 else
1140 { 1131 {
@@ -1163,9 +1154,9 @@ namespace OpenSim.Region.Environment.Scenes
1163 1154
1164 // Don't let this animation become the movement animation 1155 // Don't let this animation become the movement animation
1165 if (m_animations.Count < 1) 1156 if (m_animations.Count < 1)
1166 SetMovementAnimation(Animations.AnimsLLUUID["STAND"]); 1157 TrySetMovementAnimation("STAND");
1167 1158
1168 LLUUID animID=m_controllingClient.GetDefaultAnimation(name); 1159 LLUUID animID = m_controllingClient.GetDefaultAnimation(name);
1169 if (animID == LLUUID.Zero) 1160 if (animID == LLUUID.Zero)
1170 return; 1161 return;
1171 1162
@@ -1182,7 +1173,7 @@ namespace OpenSim.Region.Environment.Scenes
1182 if (m_isChildAgent) 1173 if (m_isChildAgent)
1183 return; 1174 return;
1184 1175
1185 LLUUID animID=m_controllingClient.GetDefaultAnimation(name); 1176 LLUUID animID = m_controllingClient.GetDefaultAnimation(name);
1186 if (animID == LLUUID.Zero) 1177 if (animID == LLUUID.Zero)
1187 return; 1178 return;
1188 1179
@@ -1190,18 +1181,18 @@ namespace OpenSim.Region.Environment.Scenes
1190 { 1181 {
1191 if (m_animations[0] == animID) 1182 if (m_animations[0] == animID)
1192 { 1183 {
1193 SetMovementAnimation(Animations.AnimsLLUUID["STAND"]); 1184 TrySetMovementAnimation("STAND");
1194 } 1185 }
1195 else 1186 else
1196 { 1187 {
1197 // What a HACK!! Anim list really needs to be an object! 1188 // What a HACK!! Anim list really needs to be an object!
1198 int idx; 1189 int idx;
1199 1190
1200 for(idx=0;idx < m_animations.Count;idx++) 1191 for(idx = 0; idx < m_animations.Count; idx++)
1201 { 1192 {
1202 if (m_animations[idx] == animID) 1193 if (m_animations[idx] == animID)
1203 { 1194 {
1204 int seq=m_animationSeqs[idx]; 1195 int seq = m_animationSeqs[idx];
1205 1196
1206 m_animations.Remove(animID); 1197 m_animations.Remove(animID);
1207 m_animationSeqs.Remove(seq); 1198 m_animationSeqs.Remove(seq);
@@ -1229,139 +1220,112 @@ namespace OpenSim.Region.Environment.Scenes
1229 /// reserved for "main" animations that are mutually exclusive, 1220 /// reserved for "main" animations that are mutually exclusive,
1230 /// like flying and sitting, for example. 1221 /// like flying and sitting, for example.
1231 /// </summary> 1222 /// </summary>
1232 protected void SetMovementAnimation(LLUUID anim) 1223 protected void SetMovementAnimation(LLUUID animID)
1233 { 1224 {
1234 if (m_animations.Count < 1) 1225 if (m_animations.Count < 1)
1235 { 1226 {
1236 m_animations.Add(Animations.AnimsLLUUID["STAND"]); 1227 m_animations.Add(Animations.AnimsLLUUID["STAND"]);
1237 m_animationSeqs.Add(1); 1228 m_animationSeqs.Add(1);
1238
1239 SendAnimPack();
1240 } 1229 }
1241 else 1230 else
1242 { 1231 {
1243 try 1232 try
1244 { 1233 {
1245 if (m_animations[0] != anim) 1234 if (m_animations[0] != animID)
1246 { 1235 {
1247 m_animations[0] = anim; 1236 m_animations[0] = animID;
1248 m_animationSeqs[0] = m_controllingClient.NextAnimationSequenceNumber; 1237 m_animationSeqs[0] = m_controllingClient.NextAnimationSequenceNumber;
1249 } 1238 }
1250 SendAnimPack();
1251 } 1239 }
1252 catch 1240 catch
1253 { 1241 {
1254 m_log.Warn("[AVATAR]: SetMovementAnimation for avatar failed. Attempting recovery..."); 1242 m_log.Warn("[AVATAR]: SetMovementAnimation for avatar failed. Attempting recovery...");
1255 m_animations[0] = anim; 1243 m_animations[0] = animID;
1256 m_animationSeqs[0] = m_controllingClient.NextAnimationSequenceNumber; 1244 m_animationSeqs[0] = m_controllingClient.NextAnimationSequenceNumber;
1257 SendAnimPack();
1258 } 1245 }
1259 } 1246 }
1247 SendAnimPack();
1260 } 1248 }
1261 1249
1262 /// <summary> 1250 /// <summary>
1263 /// This method handles agent movement related animations 1251 /// Set the first known animation in the given list as the movement animation
1264 /// </summary> 1252 /// </summary>
1265 protected void UpdateMovementAnimations(bool update_movementflag) 1253 protected void TrySetMovementAnimation(params string[] anims)
1266 { 1254 {
1267 1255 foreach (string anim in anims)
1268
1269 if (update_movementflag)
1270 { 1256 {
1271 // Are we moving? 1257 if (Animations.AnimsLLUUID.ContainsKey(anim))
1272 if (m_movementflag != 0)
1273 { 1258 {
1274 // We are moving 1259 SetMovementAnimation(Animations.AnimsLLUUID[anim]);
1275 1260 break;
1276 if (m_physicsActor.Flying) 1261 }
1277 { 1262 }
1278 // We are flying 1263 }
1279 SetMovementAnimation(Animations.AnimsLLUUID["FLY"]);
1280 }
1281 else if (((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) &&
1282 PhysicsActor.IsColliding)
1283 {
1284 // Client is pressing the page down button and moving and is colliding with something
1285 SetMovementAnimation(Animations.AnimsLLUUID["CROUCHWALK"]);
1286 }
1287 else if (!PhysicsActor.IsColliding && m_physicsActor.Velocity.Z < -6)
1288 {
1289 // Client is moving and falling at a velocity greater then 6 meters per unit
1290 SetMovementAnimation(Animations.AnimsLLUUID["FALLDOWN"]);
1291 }
1292 else if (!PhysicsActor.IsColliding && Velocity.Z > 0 &&
1293 (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0)
1294 {
1295 // Client is moving, and colliding and pressing the page up button but isn't flying
1296 try
1297 {
1298 SetMovementAnimation(Animations.AnimsLLUUID["JUMP"]);
1299 }
1300 catch (KeyNotFoundException)
1301 { }
1302 }
1303 else if (m_setAlwaysRun)
1304 {
1305 // We are running
1306 try
1307 {
1308 SetMovementAnimation(Animations.AnimsLLUUID["RUN"]);
1309 }
1310 catch (KeyNotFoundException)
1311 { }
1312 }
1313 else
1314 {
1315 // We're moving, but we're not doing anything else.. so play the stand animation
1316 try
1317 {
1318 SetMovementAnimation(Animations.AnimsLLUUID["WALK"]);
1319 }
1320 catch (KeyNotFoundException)
1321 { }
1322 1264
1323 } 1265 /// <summary>
1266 /// This method handles agent movement related animations
1267 /// </summary>
1268 protected void UpdateMovementAnimations()
1269 {
1270 if (m_movementflag != 0)
1271 {
1272 // We are moving
1273 if (m_physicsActor.Flying)
1274 {
1275 TrySetMovementAnimation("FLY");
1276 }
1277 else if (((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) &&
1278 PhysicsActor.IsColliding)
1279 {
1280 TrySetMovementAnimation("CROUCHWALK");
1281 }
1282 else if (!PhysicsActor.IsColliding && m_physicsActor.Velocity.Z < -6)
1283 {
1284 // Client is moving and falling at a velocity greater then 6 meters per unit
1285 TrySetMovementAnimation("FALLDOWN");
1286 }
1287 else if (!PhysicsActor.IsColliding && Velocity.Z > 0 &&
1288 (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0)
1289 {
1290 TrySetMovementAnimation("JUMP");
1291 }
1292 else if (m_setAlwaysRun)
1293 {
1294 TrySetMovementAnimation("RUN");
1324 } 1295 }
1325 else 1296 else
1326 { 1297 {
1327 // Not moving 1298 TrySetMovementAnimation("WALK");
1328 1299 }
1329 if (((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && 1300 }
1330 PhysicsActor.IsColliding) 1301 else
1331 { 1302 {
1332 // Client pressing the page down button 1303 // Not moving
1333 SetMovementAnimation(Animations.AnimsLLUUID["CROUCH"]);
1334 }
1335 else if (!PhysicsActor.IsColliding && m_physicsActor.Velocity.Z < -6 && !m_physicsActor.Flying)
1336 {
1337 // Not colliding and not flying, and we're falling at high speed
1338 SetMovementAnimation(Animations.AnimsLLUUID["FALLDOWN"]);
1339 }
1340 else if (!PhysicsActor.IsColliding && Velocity.Z > 0 && !m_physicsActor.Flying &&
1341 (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0)
1342 {
1343 // This is the standing jump
1344 SetMovementAnimation(Animations.AnimsLLUUID["JUMP"]);
1345 }
1346 else if (m_physicsActor.Flying)
1347 {
1348 // We're flying but not moving
1349 SetMovementAnimation(Animations.AnimsLLUUID["HOVER"]);
1350 }
1351 else
1352 {
1353 // We're not moving.. and we're not doing anything.. so play the stand animation
1354 try
1355 {
1356 1304
1357 SetMovementAnimation(Animations.AnimsLLUUID["STAND"]); 1305 if (((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) &&
1358 } 1306 PhysicsActor.IsColliding)
1359 catch (KeyNotFoundException) 1307 {
1360 { } 1308 TrySetMovementAnimation("CROUCH");
1361 } 1309 }
1310 else if (!PhysicsActor.IsColliding && m_physicsActor.Velocity.Z < -6 && !m_physicsActor.Flying)
1311 {
1312 TrySetMovementAnimation("FALLDOWN");
1313 }
1314 else if (!PhysicsActor.IsColliding && Velocity.Z > 0 && !m_physicsActor.Flying &&
1315 (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0)
1316 {
1317 // This is the standing jump
1318 TrySetMovementAnimation("JUMP");
1319 }
1320 else if (m_physicsActor.Flying)
1321 {
1322 TrySetMovementAnimation("HOVER");
1323 }
1324 else
1325 {
1326 TrySetMovementAnimation("STAND");
1362 } 1327 }
1363 } 1328 }
1364
1365 } 1329 }
1366 1330
1367 /// <summary> 1331 /// <summary>
@@ -1402,19 +1366,13 @@ namespace OpenSim.Region.Environment.Scenes
1402 { 1366 {
1403 if (!m_physicsActor.Flying && m_physicsActor.IsColliding) 1367 if (!m_physicsActor.Flying && m_physicsActor.IsColliding)
1404 { 1368 {
1405 //direc.z *= 40;
1406 if (direc.z > 2.0f) 1369 if (direc.z > 2.0f)
1407 { 1370 {
1408 direc.z *= 3; 1371 direc.z *= 3;
1409 //System.Console.WriteLine("Jump"); 1372
1410 // PreJump and jump happen too quickly. Many times prejump gets ignored. 1373 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
1411 try 1374 TrySetMovementAnimation("PREJUMP");
1412 { 1375 TrySetMovementAnimation("JUMP");
1413 SetMovementAnimation(Animations.AnimsLLUUID["PREJUMP"]);
1414 SetMovementAnimation(Animations.AnimsLLUUID["JUMP"]);
1415 }
1416 catch (KeyNotFoundException)
1417 { }
1418 } 1376 }
1419 } 1377 }
1420 } 1378 }
@@ -2045,10 +2003,10 @@ namespace OpenSim.Region.Environment.Scenes
2045 m_scene.EventManager.TriggerAvatarKill(killerObj, this); 2003 m_scene.EventManager.TriggerAvatarKill(killerObj, this);
2046 } 2004 }
2047 2005
2048 2006 if (Velocity.X > 0 || Velocity.Y > 0)
2049 bool isUserMoving = Velocity.X > 0 || Velocity.Y > 0; 2007 UpdateMovementAnimations();
2050 UpdateMovementAnimations(isUserMoving);
2051 } 2008 }
2009
2052 public void setHealthWithUpdate(float health) 2010 public void setHealthWithUpdate(float health)
2053 { 2011 {
2054 Health = health; 2012 Health = health;