diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Animation')
3 files changed, 175 insertions, 9 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs b/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs index 66edfed..b7400ea 100644 --- a/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs +++ b/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs | |||
@@ -28,8 +28,11 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Text; | ||
31 | using log4net; | 32 | using log4net; |
32 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using OpenMetaverse.StructuredData; | ||
35 | |||
33 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
34 | 37 | ||
35 | using Animation = OpenSim.Framework.Animation; | 38 | using Animation = OpenSim.Framework.Animation; |
@@ -60,6 +63,12 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
60 | ResetDefaultAnimation(); | 63 | ResetDefaultAnimation(); |
61 | } | 64 | } |
62 | 65 | ||
66 | public AnimationSet(OSDArray pArray) | ||
67 | { | ||
68 | ResetDefaultAnimation(); | ||
69 | FromOSDArray(pArray); | ||
70 | } | ||
71 | |||
63 | public bool HasAnimation(UUID animID) | 72 | public bool HasAnimation(UUID animID) |
64 | { | 73 | { |
65 | if (m_defaultAnimation.AnimID == animID) | 74 | if (m_defaultAnimation.AnimID == animID) |
@@ -218,5 +227,110 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
218 | foreach (OpenSim.Framework.Animation anim in theArray) | 227 | foreach (OpenSim.Framework.Animation anim in theArray) |
219 | m_animations.Add(anim); | 228 | m_animations.Add(anim); |
220 | } | 229 | } |
230 | |||
231 | // Create representation of this AnimationSet as an OSDArray. | ||
232 | // First two entries in the array are the default and implicitDefault animations | ||
233 | // followed by the other animations. | ||
234 | public OSDArray ToOSDArray() | ||
235 | { | ||
236 | OSDArray ret = new OSDArray(); | ||
237 | ret.Add(DefaultAnimation.PackUpdateMessage()); | ||
238 | ret.Add(ImplicitDefaultAnimation.PackUpdateMessage()); | ||
239 | |||
240 | foreach (OpenSim.Framework.Animation anim in m_animations) | ||
241 | ret.Add(anim.PackUpdateMessage()); | ||
242 | |||
243 | return ret; | ||
244 | } | ||
245 | |||
246 | public void FromOSDArray(OSDArray pArray) | ||
247 | { | ||
248 | this.Clear(); | ||
249 | |||
250 | if (pArray.Count >= 1) | ||
251 | { | ||
252 | m_defaultAnimation = new OpenSim.Framework.Animation((OSDMap)pArray[0]); | ||
253 | } | ||
254 | if (pArray.Count >= 2) | ||
255 | { | ||
256 | m_implicitDefaultAnimation = new OpenSim.Framework.Animation((OSDMap)pArray[1]); | ||
257 | } | ||
258 | for (int ii = 2; ii < pArray.Count; ii++) | ||
259 | { | ||
260 | m_animations.Add(new OpenSim.Framework.Animation((OSDMap)pArray[ii])); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | // Compare two AnimationSets and return 'true' if the default animations are the same | ||
265 | // and all of the animations in the list are equal. | ||
266 | public override bool Equals(object obj) | ||
267 | { | ||
268 | AnimationSet other = obj as AnimationSet; | ||
269 | if (other != null) | ||
270 | { | ||
271 | if (this.DefaultAnimation.Equals(other.DefaultAnimation) | ||
272 | && this.ImplicitDefaultAnimation.Equals(other.ImplicitDefaultAnimation)) | ||
273 | { | ||
274 | // The defaults are the same. Is the list of animations the same? | ||
275 | OpenSim.Framework.Animation[] thisAnims = this.ToArray(); | ||
276 | OpenSim.Framework.Animation[] otherAnims = other.ToArray(); | ||
277 | if (thisAnims.Length == 0 && otherAnims.Length == 0) | ||
278 | return true; // the common case | ||
279 | if (thisAnims.Length == otherAnims.Length) | ||
280 | { | ||
281 | // Do this the hard way but since the list is usually short this won't take long. | ||
282 | foreach (OpenSim.Framework.Animation thisAnim in thisAnims) | ||
283 | { | ||
284 | bool found = false; | ||
285 | foreach (OpenSim.Framework.Animation otherAnim in otherAnims) | ||
286 | { | ||
287 | if (thisAnim.Equals(otherAnim)) | ||
288 | { | ||
289 | found = true; | ||
290 | break; | ||
291 | } | ||
292 | } | ||
293 | if (!found) | ||
294 | { | ||
295 | // If anything is not in the other list, these are not equal | ||
296 | return false; | ||
297 | } | ||
298 | } | ||
299 | // Found everything in the other list. Since lists are equal length, they must be equal. | ||
300 | return true; | ||
301 | } | ||
302 | } | ||
303 | return false; | ||
304 | } | ||
305 | // Don't know what was passed, but the base system will figure it out for me. | ||
306 | return base.Equals(obj); | ||
307 | } | ||
308 | |||
309 | public override string ToString() | ||
310 | { | ||
311 | StringBuilder buff = new StringBuilder(); | ||
312 | buff.Append("dflt="); | ||
313 | buff.Append(DefaultAnimation.ToString()); | ||
314 | buff.Append(",iDflt="); | ||
315 | if (DefaultAnimation.Equals(ImplicitDefaultAnimation)) | ||
316 | buff.Append("same"); | ||
317 | else | ||
318 | buff.Append(ImplicitDefaultAnimation.ToString()); | ||
319 | if (m_animations.Count > 0) | ||
320 | { | ||
321 | buff.Append(",anims="); | ||
322 | bool firstTime = true; | ||
323 | foreach (OpenSim.Framework.Animation anim in m_animations) | ||
324 | { | ||
325 | if (!firstTime) | ||
326 | buff.Append(","); | ||
327 | buff.Append("<"); | ||
328 | buff.Append(anim.ToString()); | ||
329 | buff.Append(">"); | ||
330 | firstTime = false; | ||
331 | } | ||
332 | } | ||
333 | return buff.ToString(); | ||
334 | } | ||
221 | } | 335 | } |
222 | } | 336 | } |
diff --git a/OpenSim/Region/Framework/Scenes/Animation/DefaultAvatarAnimations.cs b/OpenSim/Region/Framework/Scenes/Animation/DefaultAvatarAnimations.cs index c2b0468..b79dd8f 100644 --- a/OpenSim/Region/Framework/Scenes/Animation/DefaultAvatarAnimations.cs +++ b/OpenSim/Region/Framework/Scenes/Animation/DefaultAvatarAnimations.cs | |||
@@ -104,5 +104,31 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
104 | 104 | ||
105 | return UUID.Zero; | 105 | return UUID.Zero; |
106 | } | 106 | } |
107 | |||
108 | /// <summary> | ||
109 | /// Get the name of the animation given a UUID. If there is no matching animation | ||
110 | /// return the UUID as a string. | ||
111 | /// </summary> | ||
112 | public static string GetDefaultAnimationName(UUID uuid) | ||
113 | { | ||
114 | string ret = "unknown"; | ||
115 | if (AnimsUUID.ContainsValue(uuid)) | ||
116 | { | ||
117 | foreach (KeyValuePair<string, UUID> kvp in AnimsUUID) | ||
118 | { | ||
119 | if (kvp.Value == uuid) | ||
120 | { | ||
121 | ret = kvp.Key; | ||
122 | break; | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | else | ||
127 | { | ||
128 | ret = uuid.ToString(); | ||
129 | } | ||
130 | |||
131 | return ret; | ||
132 | } | ||
107 | } | 133 | } |
108 | } \ No newline at end of file | 134 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs index 65c279e..668087f 100644 --- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs +++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs | |||
@@ -93,7 +93,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
93 | GetAnimName(animID), animID, m_scenePresence.Name); | 93 | GetAnimName(animID), animID, m_scenePresence.Name); |
94 | 94 | ||
95 | if (m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, objectID)) | 95 | if (m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, objectID)) |
96 | { | ||
96 | SendAnimPack(); | 97 | SendAnimPack(); |
98 | m_scenePresence.TriggerScenePresenceUpdated(); | ||
99 | } | ||
97 | } | 100 | } |
98 | 101 | ||
99 | // Called from scripts | 102 | // Called from scripts |
@@ -132,7 +135,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
132 | GetAnimName(animID), animID, m_scenePresence.Name); | 135 | GetAnimName(animID), animID, m_scenePresence.Name); |
133 | 136 | ||
134 | if (m_animations.Remove(animID, allowNoDefault)) | 137 | if (m_animations.Remove(animID, allowNoDefault)) |
138 | { | ||
135 | SendAnimPack(); | 139 | SendAnimPack(); |
140 | m_scenePresence.TriggerScenePresenceUpdated(); | ||
141 | } | ||
136 | } | 142 | } |
137 | 143 | ||
138 | public void avnChangeAnim(UUID animID, bool addRemove, bool sendPack) | 144 | public void avnChangeAnim(UUID animID, bool addRemove, bool sendPack) |
@@ -145,7 +151,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
145 | if (addRemove) | 151 | if (addRemove) |
146 | m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, UUID.Zero); | 152 | m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, UUID.Zero); |
147 | else | 153 | else |
148 | m_animations.Remove(animID, true); | 154 | m_animations.Remove(animID, false); |
149 | } | 155 | } |
150 | if(sendPack) | 156 | if(sendPack) |
151 | SendAnimPack(); | 157 | SendAnimPack(); |
@@ -180,8 +186,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
180 | /// The movement animation is reserved for "main" animations | 186 | /// The movement animation is reserved for "main" animations |
181 | /// that are mutually exclusive, e.g. flying and sitting. | 187 | /// that are mutually exclusive, e.g. flying and sitting. |
182 | /// </summary> | 188 | /// </summary> |
183 | public void TrySetMovementAnimation(string anim) | 189 | /// <returns>'true' if the animation was updated</returns> |
190 | public bool TrySetMovementAnimation(string anim) | ||
184 | { | 191 | { |
192 | bool ret = false; | ||
185 | if (!m_scenePresence.IsChildAgent) | 193 | if (!m_scenePresence.IsChildAgent) |
186 | { | 194 | { |
187 | // m_log.DebugFormat( | 195 | // m_log.DebugFormat( |
@@ -198,6 +206,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
198 | // 16384 is CHANGED_ANIMATION | 206 | // 16384 is CHANGED_ANIMATION |
199 | m_scenePresence.SendScriptEventToAttachments("changed", new Object[] { (int)Changed.ANIMATION}); | 207 | m_scenePresence.SendScriptEventToAttachments("changed", new Object[] { (int)Changed.ANIMATION}); |
200 | SendAnimPack(); | 208 | SendAnimPack(); |
209 | ret = true; | ||
201 | } | 210 | } |
202 | } | 211 | } |
203 | else | 212 | else |
@@ -206,6 +215,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
206 | "[SCENE PRESENCE ANIMATOR]: Tried to set movement animation {0} on child presence {1}", | 215 | "[SCENE PRESENCE ANIMATOR]: Tried to set movement animation {0} on child presence {1}", |
207 | anim, m_scenePresence.Name); | 216 | anim, m_scenePresence.Name); |
208 | } | 217 | } |
218 | return ret; | ||
209 | } | 219 | } |
210 | 220 | ||
211 | /// <summary> | 221 | /// <summary> |
@@ -410,11 +420,18 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
410 | Falling = false; | 420 | Falling = false; |
411 | // Walking / crouchwalking / running | 421 | // Walking / crouchwalking / running |
412 | if (move.Z < 0f) | 422 | if (move.Z < 0f) |
423 | { | ||
413 | return "CROUCHWALK"; | 424 | return "CROUCHWALK"; |
414 | else if (m_scenePresence.SetAlwaysRun) | 425 | } |
415 | return "RUN"; | 426 | // We need to prevent these animations if the user tries to make their avatar walk or run whilst |
416 | else | 427 | // specifying AGENT_CONTROL_STOP (pressing down space on viewers). |
417 | return "WALK"; | 428 | else if (!m_scenePresence.AgentControlStopActive) |
429 | { | ||
430 | if (m_scenePresence.SetAlwaysRun) | ||
431 | return "RUN"; | ||
432 | else | ||
433 | return "WALK"; | ||
434 | } | ||
418 | } | 435 | } |
419 | else if (!m_jumping) | 436 | else if (!m_jumping) |
420 | { | 437 | { |
@@ -439,8 +456,12 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
439 | /// <summary> | 456 | /// <summary> |
440 | /// Update the movement animation of this avatar according to its current state | 457 | /// Update the movement animation of this avatar according to its current state |
441 | /// </summary> | 458 | /// </summary> |
442 | public void UpdateMovementAnimations() | 459 | /// <returns>'true' if the animation was changed</returns> |
460 | public bool UpdateMovementAnimations() | ||
443 | { | 461 | { |
462 | // m_log.DebugFormat("[SCENE PRESENCE ANIMATOR]: Updating movement animations for {0}", m_scenePresence.Name); | ||
463 | |||
464 | bool ret = false; | ||
444 | lock (m_animations) | 465 | lock (m_animations) |
445 | { | 466 | { |
446 | string newMovementAnimation = DetermineMovementAnimation(); | 467 | string newMovementAnimation = DetermineMovementAnimation(); |
@@ -454,9 +475,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
454 | 475 | ||
455 | // Only set it if it's actually changed, give a script | 476 | // Only set it if it's actually changed, give a script |
456 | // a chance to stop a default animation | 477 | // a chance to stop a default animation |
457 | TrySetMovementAnimation(CurrentMovementAnimation); | 478 | ret = TrySetMovementAnimation(CurrentMovementAnimation); |
458 | } | 479 | } |
459 | } | 480 | } |
481 | return ret; | ||
460 | } | 482 | } |
461 | 483 | ||
462 | public UUID[] GetAnimationArray() | 484 | public UUID[] GetAnimationArray() |
@@ -535,6 +557,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
535 | /// <param name="objectIDs"></param> | 557 | /// <param name="objectIDs"></param> |
536 | public void SendAnimPack(UUID[] animations, int[] seqs, UUID[] objectIDs) | 558 | public void SendAnimPack(UUID[] animations, int[] seqs, UUID[] objectIDs) |
537 | { | 559 | { |
560 | /* | ||
538 | if (m_scenePresence.IsChildAgent) | 561 | if (m_scenePresence.IsChildAgent) |
539 | return; | 562 | return; |
540 | 563 | ||
@@ -549,6 +572,8 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
549 | { | 572 | { |
550 | client.SendAnimations(animations, seqs, m_scenePresence.ControllingClient.AgentId, objectIDs); | 573 | client.SendAnimations(animations, seqs, m_scenePresence.ControllingClient.AgentId, objectIDs); |
551 | }); | 574 | }); |
575 | */ | ||
576 | m_scenePresence.SendAnimPack(animations, seqs, objectIDs); | ||
552 | } | 577 | } |
553 | 578 | ||
554 | public void SendAnimPackToClient(IClientAPI client) | 579 | public void SendAnimPackToClient(IClientAPI client) |
@@ -580,7 +605,8 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
580 | 605 | ||
581 | m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs); | 606 | m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs); |
582 | 607 | ||
583 | SendAnimPack(animIDs, sequenceNums, objectIDs); | 608 | // SendAnimPack(animIDs, sequenceNums, objectIDs); |
609 | m_scenePresence.SendAnimPack(animIDs, sequenceNums, objectIDs); | ||
584 | } | 610 | } |
585 | 611 | ||
586 | public string GetAnimName(UUID animId) | 612 | public string GetAnimName(UUID animId) |