diff options
author | Jeff Ames | 2008-05-12 17:00:47 +0000 |
---|---|---|
committer | Jeff Ames | 2008-05-12 17:00:47 +0000 |
commit | dce5c470b682fc94a8f2d2fb4c0dc7c6f4d8b2eb (patch) | |
tree | 0ecdabeac816d1ab85d32ddcb62af243c9af7fa4 /OpenSim/Region/Environment/Scenes/ScenePresence.cs | |
parent | * If a region running in grid mode fails to login to the grid service, startu... (diff) | |
download | opensim-SC-dce5c470b682fc94a8f2d2fb4c0dc7c6f4d8b2eb.zip opensim-SC-dce5c470b682fc94a8f2d2fb4c0dc7c6f4d8b2eb.tar.gz opensim-SC-dce5c470b682fc94a8f2d2fb4c0dc7c6f4d8b2eb.tar.bz2 opensim-SC-dce5c470b682fc94a8f2d2fb4c0dc7c6f4d8b2eb.tar.xz |
Move animation handling from ScenePresence into its own class.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/ScenePresence.cs | 201 |
1 files changed, 49 insertions, 152 deletions
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index ef55bd2..5b10bfc 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs | |||
@@ -73,12 +73,10 @@ namespace OpenSim.Region.Environment.Scenes | |||
73 | 73 | ||
74 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 74 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
75 | 75 | ||
76 | public static AvatarAnimations Animations = new AvatarAnimations(); | ||
77 | public static byte[] DefaultTexture; | 76 | public static byte[] DefaultTexture; |
78 | 77 | ||
79 | public LLUUID currentParcelUUID = LLUUID.Zero; | 78 | public LLUUID currentParcelUUID = LLUUID.Zero; |
80 | private List<LLUUID> m_animations = new List<LLUUID>(); | 79 | private AnimationSet m_animations = new AnimationSet(); |
81 | private List<int> m_animationSeqs = new List<int>(); | ||
82 | private Dictionary<LLUUID, ScriptControllers> scriptedcontrols = new Dictionary<LLUUID, ScriptControllers>(); | 80 | private Dictionary<LLUUID, ScriptControllers> scriptedcontrols = new Dictionary<LLUUID, ScriptControllers>(); |
83 | private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO; | 81 | private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO; |
84 | private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO; | 82 | private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO; |
@@ -608,15 +606,8 @@ namespace OpenSim.Region.Environment.Scenes | |||
608 | /// </summary> | 606 | /// </summary> |
609 | public void MakeChildAgent() | 607 | public void MakeChildAgent() |
610 | { | 608 | { |
611 | if (m_animations.Count > 0) | 609 | m_animations.Clear(); |
612 | { | ||
613 | LLUUID movementAnim = m_animations[0]; | ||
614 | |||
615 | m_animations.Clear(); | ||
616 | m_animationSeqs.Clear(); | ||
617 | 610 | ||
618 | SetMovementAnimation(movementAnim); | ||
619 | } | ||
620 | // m_log.DebugFormat( | 611 | // m_log.DebugFormat( |
621 | // "[SCENEPRESENCE]: Downgrading child agent {0}, {1} to a root agent in {2}", | 612 | // "[SCENEPRESENCE]: Downgrading child agent {0}, {1} to a root agent in {2}", |
622 | // Name, UUID, m_scene.RegionInfo.RegionName); | 613 | // Name, UUID, m_scene.RegionInfo.RegionName); |
@@ -1104,66 +1095,31 @@ namespace OpenSim.Region.Environment.Scenes | |||
1104 | if (m_isChildAgent) | 1095 | if (m_isChildAgent) |
1105 | return; | 1096 | return; |
1106 | 1097 | ||
1107 | // Don't let this animation become the movement animation | 1098 | if (m_animations.Add(animID, m_controllingClient.NextAnimationSequenceNumber)) |
1108 | if (m_animations.Count < 1) | ||
1109 | TrySetMovementAnimation("STAND"); | ||
1110 | |||
1111 | if (!m_animations.Contains(animID)) | ||
1112 | { | 1099 | { |
1113 | m_animations.Add(animID); | ||
1114 | m_animationSeqs.Add(m_controllingClient.NextAnimationSequenceNumber); | ||
1115 | SendAnimPack(); | 1100 | SendAnimPack(); |
1116 | } | 1101 | } |
1117 | } | 1102 | } |
1118 | 1103 | ||
1119 | public void RemoveAnimation(LLUUID animID) | 1104 | public void AddAnimation(string name) |
1120 | { | 1105 | { |
1121 | if (m_isChildAgent) | 1106 | if (m_isChildAgent) |
1122 | return; | 1107 | return; |
1123 | 1108 | ||
1124 | if (m_animations.Contains(animID)) | 1109 | LLUUID animID = m_controllingClient.GetDefaultAnimation(name); |
1125 | { | 1110 | if (animID == LLUUID.Zero) |
1126 | if (m_animations[0] == animID) | 1111 | return; |
1127 | { | ||
1128 | TrySetMovementAnimation("STAND"); | ||
1129 | } | ||
1130 | else | ||
1131 | { | ||
1132 | // What a HACK!! Anim list really needs to be an object! | ||
1133 | int idx; | ||
1134 | |||
1135 | for(idx=0;idx < m_animations.Count;idx++) | ||
1136 | { | ||
1137 | if (m_animations[idx] == animID) | ||
1138 | { | ||
1139 | int seq=m_animationSeqs[idx]; | ||
1140 | 1112 | ||
1141 | m_animations.Remove(animID); | 1113 | AddAnimation(animID); |
1142 | m_animationSeqs.Remove(seq); | ||
1143 | SendAnimPack(); | ||
1144 | break; | ||
1145 | } | ||
1146 | } | ||
1147 | } | ||
1148 | } | ||
1149 | } | 1114 | } |
1150 | public void AddAnimation(string name) | 1115 | |
1116 | public void RemoveAnimation(LLUUID animID) | ||
1151 | { | 1117 | { |
1152 | if (m_isChildAgent) | 1118 | if (m_isChildAgent) |
1153 | return; | 1119 | return; |
1154 | 1120 | ||
1155 | // Don't let this animation become the movement animation | 1121 | if (m_animations.Remove(animID)) |
1156 | if (m_animations.Count < 1) | ||
1157 | TrySetMovementAnimation("STAND"); | ||
1158 | |||
1159 | LLUUID animID = m_controllingClient.GetDefaultAnimation(name); | ||
1160 | if (animID == LLUUID.Zero) | ||
1161 | return; | ||
1162 | |||
1163 | if (!m_animations.Contains(animID)) | ||
1164 | { | 1122 | { |
1165 | m_animations.Add(animID); | ||
1166 | m_animationSeqs.Add(m_controllingClient.NextAnimationSequenceNumber); | ||
1167 | SendAnimPack(); | 1123 | SendAnimPack(); |
1168 | } | 1124 | } |
1169 | } | 1125 | } |
@@ -1177,34 +1133,9 @@ namespace OpenSim.Region.Environment.Scenes | |||
1177 | if (animID == LLUUID.Zero) | 1133 | if (animID == LLUUID.Zero) |
1178 | return; | 1134 | return; |
1179 | 1135 | ||
1180 | if (m_animations.Contains(animID)) | 1136 | RemoveAnimation(animID); |
1181 | { | ||
1182 | if (m_animations[0] == animID) | ||
1183 | { | ||
1184 | TrySetMovementAnimation("STAND"); | ||
1185 | } | ||
1186 | else | ||
1187 | { | ||
1188 | // What a HACK!! Anim list really needs to be an object! | ||
1189 | int idx; | ||
1190 | |||
1191 | for(idx = 0; idx < m_animations.Count; idx++) | ||
1192 | { | ||
1193 | if (m_animations[idx] == animID) | ||
1194 | { | ||
1195 | int seq = m_animationSeqs[idx]; | ||
1196 | |||
1197 | m_animations.Remove(animID); | ||
1198 | m_animationSeqs.Remove(seq); | ||
1199 | SendAnimPack(); | ||
1200 | break; | ||
1201 | } | ||
1202 | } | ||
1203 | } | ||
1204 | } | ||
1205 | } | 1137 | } |
1206 | 1138 | ||
1207 | |||
1208 | public void HandleStartAnim(IClientAPI remoteClient, LLUUID animID) | 1139 | public void HandleStartAnim(IClientAPI remoteClient, LLUUID animID) |
1209 | { | 1140 | { |
1210 | AddAnimation(animID); | 1141 | AddAnimation(animID); |
@@ -1216,88 +1147,63 @@ namespace OpenSim.Region.Environment.Scenes | |||
1216 | } | 1147 | } |
1217 | 1148 | ||
1218 | /// <summary> | 1149 | /// <summary> |
1219 | /// The movement animation is the first element of the animation list, | 1150 | /// The movement animation is reserved for "main" animations |
1220 | /// reserved for "main" animations that are mutually exclusive, | 1151 | /// that are mutually exclusive, e.g. flying and sitting. |
1221 | /// like flying and sitting, for example. | ||
1222 | /// </summary> | 1152 | /// </summary> |
1223 | protected void SetMovementAnimation(LLUUID animID) | 1153 | protected void SetMovementAnimation(LLUUID animID) |
1224 | { | 1154 | { |
1225 | if (m_animations.Count < 1) | 1155 | if (m_animations.SetDefaultAnimation(animID, m_controllingClient.NextAnimationSequenceNumber)) |
1226 | { | 1156 | { |
1227 | m_animations.Add(Animations.AnimsLLUUID["STAND"]); | ||
1228 | m_animationSeqs.Add(1); | ||
1229 | SendAnimPack(); | 1157 | SendAnimPack(); |
1230 | } | 1158 | } |
1231 | else | ||
1232 | { | ||
1233 | try | ||
1234 | { | ||
1235 | if (m_animations[0] != animID) | ||
1236 | { | ||
1237 | m_animations[0] = animID; | ||
1238 | m_animationSeqs[0] = m_controllingClient.NextAnimationSequenceNumber; | ||
1239 | SendAnimPack(); | ||
1240 | } | ||
1241 | } | ||
1242 | catch | ||
1243 | { | ||
1244 | m_log.Warn("[AVATAR]: SetMovementAnimation for avatar failed. Attempting recovery..."); | ||
1245 | m_animations[0] = animID; | ||
1246 | m_animationSeqs[0] = m_controllingClient.NextAnimationSequenceNumber; | ||
1247 | SendAnimPack(); | ||
1248 | } | ||
1249 | } | ||
1250 | } | 1159 | } |
1251 | 1160 | ||
1252 | /// <summary> | 1161 | /// <summary> |
1253 | /// Set the first known animation in the given list as the movement animation | 1162 | /// The movement animation is reserved for "main" animations |
1163 | /// that are mutually exclusive, e.g. flying and sitting. | ||
1254 | /// </summary> | 1164 | /// </summary> |
1255 | protected void TrySetMovementAnimation(params string[] anims) | 1165 | protected void TrySetMovementAnimation(string anim) |
1256 | { | 1166 | { |
1257 | foreach (string anim in anims) | 1167 | if (m_animations.TrySetDefaultAnimation(anim, m_controllingClient.NextAnimationSequenceNumber)) |
1258 | { | 1168 | { |
1259 | if (Animations.AnimsLLUUID.ContainsKey(anim)) | 1169 | SendAnimPack(); |
1260 | { | ||
1261 | SetMovementAnimation(Animations.AnimsLLUUID[anim]); | ||
1262 | break; | ||
1263 | } | ||
1264 | } | 1170 | } |
1265 | } | 1171 | } |
1266 | 1172 | ||
1267 | /// <summary> | 1173 | /// <summary> |
1268 | /// This method handles agent movement related animations | 1174 | /// This method determines the proper movement related animation |
1269 | /// </summary> | 1175 | /// </summary> |
1270 | protected void UpdateMovementAnimations() | 1176 | protected string GetMovementAnimation() |
1271 | { | 1177 | { |
1272 | if (m_movementflag != 0) | 1178 | if (m_movementflag != 0) |
1273 | { | 1179 | { |
1274 | // We are moving | 1180 | // We are moving |
1275 | if (m_physicsActor.Flying) | 1181 | if (m_physicsActor.Flying) |
1276 | { | 1182 | { |
1277 | TrySetMovementAnimation("FLY"); | 1183 | return "FLY"; |
1278 | } | 1184 | } |
1279 | else if (((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && | 1185 | else if (((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && |
1280 | PhysicsActor.IsColliding) | 1186 | PhysicsActor.IsColliding) |
1281 | { | 1187 | { |
1282 | TrySetMovementAnimation("CROUCHWALK"); | 1188 | return "CROUCHWALK"; |
1283 | } | 1189 | } |
1284 | else if (!PhysicsActor.IsColliding && m_physicsActor.Velocity.Z < -6) | 1190 | else if (!PhysicsActor.IsColliding && m_physicsActor.Velocity.Z < -6) |
1285 | { | 1191 | { |
1286 | // Client is moving and falling at a velocity greater then 6 meters per unit | 1192 | // Client is moving and falling at a velocity greater then 6 meters per unit |
1287 | TrySetMovementAnimation("FALLDOWN"); | 1193 | return "FALLDOWN"; |
1288 | } | 1194 | } |
1289 | else if (!PhysicsActor.IsColliding && Velocity.Z > 0 && | 1195 | else if (!PhysicsActor.IsColliding && Velocity.Z > 0 && |
1290 | (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0) | 1196 | (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0) |
1291 | { | 1197 | { |
1292 | TrySetMovementAnimation("JUMP"); | 1198 | return "JUMP"; |
1293 | } | 1199 | } |
1294 | else if (m_setAlwaysRun) | 1200 | else if (m_setAlwaysRun) |
1295 | { | 1201 | { |
1296 | TrySetMovementAnimation("RUN"); | 1202 | return "RUN"; |
1297 | } | 1203 | } |
1298 | else | 1204 | else |
1299 | { | 1205 | { |
1300 | TrySetMovementAnimation("WALK"); | 1206 | return "WALK"; |
1301 | } | 1207 | } |
1302 | } | 1208 | } |
1303 | else | 1209 | else |
@@ -1307,29 +1213,34 @@ namespace OpenSim.Region.Environment.Scenes | |||
1307 | if (((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && | 1213 | if (((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && |
1308 | PhysicsActor.IsColliding) | 1214 | PhysicsActor.IsColliding) |
1309 | { | 1215 | { |
1310 | TrySetMovementAnimation("CROUCH"); | 1216 | return "CROUCH"; |
1311 | } | 1217 | } |
1312 | else if (!PhysicsActor.IsColliding && m_physicsActor.Velocity.Z < -6 && !m_physicsActor.Flying) | 1218 | else if (!PhysicsActor.IsColliding && m_physicsActor.Velocity.Z < -6 && !m_physicsActor.Flying) |
1313 | { | 1219 | { |
1314 | TrySetMovementAnimation("FALLDOWN"); | 1220 | return "FALLDOWN"; |
1315 | } | 1221 | } |
1316 | else if (!PhysicsActor.IsColliding && Velocity.Z > 0 && !m_physicsActor.Flying && | 1222 | else if (!PhysicsActor.IsColliding && Velocity.Z > 0 && !m_physicsActor.Flying && |
1317 | (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0) | 1223 | (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0) |
1318 | { | 1224 | { |
1319 | // This is the standing jump | 1225 | // This is the standing jump |
1320 | TrySetMovementAnimation("JUMP"); | 1226 | return "JUMP"; |
1321 | } | 1227 | } |
1322 | else if (m_physicsActor.Flying) | 1228 | else if (m_physicsActor.Flying) |
1323 | { | 1229 | { |
1324 | TrySetMovementAnimation("HOVER"); | 1230 | return "HOVER"; |
1325 | } | 1231 | } |
1326 | else | 1232 | else |
1327 | { | 1233 | { |
1328 | TrySetMovementAnimation("STAND"); | 1234 | return "STAND"; |
1329 | } | 1235 | } |
1330 | } | 1236 | } |
1331 | } | 1237 | } |
1332 | 1238 | ||
1239 | protected void UpdateMovementAnimations() | ||
1240 | { | ||
1241 | TrySetMovementAnimation(GetMovementAnimation()); | ||
1242 | } | ||
1243 | |||
1333 | /// <summary> | 1244 | /// <summary> |
1334 | /// Adds a new movement | 1245 | /// Adds a new movement |
1335 | /// </summary> | 1246 | /// </summary> |
@@ -1422,21 +1333,15 @@ namespace OpenSim.Region.Environment.Scenes | |||
1422 | } | 1333 | } |
1423 | else if ((Util.GetDistanceTo(lastPhysPos, AbsolutePosition) > 0.02) || (Util.GetDistanceTo(m_lastVelocity, m_velocity) > 0.02)) // physics-related movement | 1334 | else if ((Util.GetDistanceTo(lastPhysPos, AbsolutePosition) > 0.02) || (Util.GetDistanceTo(m_lastVelocity, m_velocity) > 0.02)) // physics-related movement |
1424 | { | 1335 | { |
1425 | |||
1426 | |||
1427 | // Send Terse Update to all clients updates lastPhysPos and m_lastVelocity | 1336 | // Send Terse Update to all clients updates lastPhysPos and m_lastVelocity |
1428 | // doing the above assures us that we know what we sent the clients last | 1337 | // doing the above assures us that we know what we sent the clients last |
1429 | SendTerseUpdateToAllClients(); | 1338 | SendTerseUpdateToAllClients(); |
1430 | m_updateCount = 0; | 1339 | m_updateCount = 0; |
1431 | |||
1432 | |||
1433 | |||
1434 | } | 1340 | } |
1435 | 1341 | ||
1436 | // followed suggestion from mic bowman. reversed the two lines below. | 1342 | // followed suggestion from mic bowman. reversed the two lines below. |
1437 | CheckForBorderCrossing(); | 1343 | CheckForBorderCrossing(); |
1438 | CheckForSignificantMovement(); // sends update to the modules. | 1344 | CheckForSignificantMovement(); // sends update to the modules. |
1439 | |||
1440 | } | 1345 | } |
1441 | } | 1346 | } |
1442 | 1347 | ||
@@ -1621,7 +1526,15 @@ namespace OpenSim.Region.Environment.Scenes | |||
1621 | /// </summary> | 1526 | /// </summary> |
1622 | public void SendAnimPack() | 1527 | public void SendAnimPack() |
1623 | { | 1528 | { |
1624 | SendAnimPack(m_animations.ToArray(), m_animationSeqs.ToArray()); | 1529 | if (m_isChildAgent) |
1530 | return; | ||
1531 | |||
1532 | LLUUID[] animIDs; | ||
1533 | int[] sequenceNums; | ||
1534 | |||
1535 | m_animations.GetArrays(out animIDs, out sequenceNums); | ||
1536 | |||
1537 | SendAnimPack(animIDs, sequenceNums); | ||
1625 | } | 1538 | } |
1626 | 1539 | ||
1627 | #endregion | 1540 | #endregion |
@@ -2142,14 +2055,7 @@ namespace OpenSim.Region.Environment.Scenes | |||
2142 | DefaultTexture = textu.ToBytes(); | 2055 | DefaultTexture = textu.ToBytes(); |
2143 | } | 2056 | } |
2144 | 2057 | ||
2145 | List<Guid> animations_work = (List<Guid>)info.GetValue("m_animations", typeof(List<Guid>)); | 2058 | m_animations = (AnimationSet)info.GetValue("m_animations", typeof(AnimationSet)); |
2146 | |||
2147 | foreach (Guid guid in animations_work) | ||
2148 | { | ||
2149 | m_animations.Add(new LLUUID(guid)); | ||
2150 | } | ||
2151 | |||
2152 | m_animationSeqs = (List<int>)info.GetValue("m_animationSeqs", typeof(List<int>)); | ||
2153 | m_updateflag = (bool)info.GetValue("m_updateflag", typeof(bool)); | 2059 | m_updateflag = (bool)info.GetValue("m_updateflag", typeof(bool)); |
2154 | m_movementflag = (byte)info.GetValue("m_movementflag", typeof(byte)); | 2060 | m_movementflag = (byte)info.GetValue("m_movementflag", typeof(byte)); |
2155 | m_forcesList = (List<NewForce>)info.GetValue("m_forcesList", typeof(List<NewForce>)); | 2061 | m_forcesList = (List<NewForce>)info.GetValue("m_forcesList", typeof(List<NewForce>)); |
@@ -2304,16 +2210,7 @@ namespace OpenSim.Region.Environment.Scenes | |||
2304 | 2210 | ||
2305 | base.GetObjectData(info, context); | 2211 | base.GetObjectData(info, context); |
2306 | 2212 | ||
2307 | List<Guid> animations_work = new List<Guid>(); | 2213 | info.AddValue("m_animations", m_animations); |
2308 | |||
2309 | foreach (LLUUID uuid in m_animations) | ||
2310 | { | ||
2311 | animations_work.Add(uuid.UUID); | ||
2312 | } | ||
2313 | |||
2314 | info.AddValue("m_animations", animations_work); | ||
2315 | |||
2316 | info.AddValue("m_animationSeqs", m_animationSeqs); | ||
2317 | info.AddValue("m_updateflag", m_updateflag); | 2214 | info.AddValue("m_updateflag", m_updateflag); |
2318 | info.AddValue("m_movementflag", m_movementflag); | 2215 | info.AddValue("m_movementflag", m_movementflag); |
2319 | info.AddValue("m_forcesList", m_forcesList); | 2216 | info.AddValue("m_forcesList", m_forcesList); |