From 4cc6722aa9053d6fbeed0353e32c215f22c2c2ac Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 22 Aug 2008 19:17:51 +0000 Subject: [PATCH] Simian: Added Animation struct and AnimationSet class (adapted from OpenSim) to track avatar animations git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@2157 52acb1d6-8a22-11de-b505-999d5b087335 --- Programs/Simian/AnimationSet.cs | 157 ++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 Programs/Simian/AnimationSet.cs diff --git a/Programs/Simian/AnimationSet.cs b/Programs/Simian/AnimationSet.cs new file mode 100644 index 00000000..3528c538 --- /dev/null +++ b/Programs/Simian/AnimationSet.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using OpenMetaverse; + +namespace Simian +{ + public struct Animation + { + public UUID ID; + public int SequenceNum; + + public Animation(UUID id, int sequenceNum) + { + ID = id; + SequenceNum = sequenceNum; + } + } + + public class AnimationSet + { + private Animation defaultAnimation; + private List animations = new List(); + + public AnimationSet() + { + ResetDefaultAnimation(); + } + + public bool HasAnimation(UUID animID) + { + if (defaultAnimation.ID == animID) + return true; + + lock (animations) + { + for (int i = 0; i < animations.Count; ++i) + { + if (animations[i].ID == animID) + return true; + } + } + + return false; + } + + public bool Add(UUID animID, ref int sequenceCounter) + { + lock (animations) + { + if (!HasAnimation(animID)) + { + int sequenceNum = Interlocked.Increment(ref sequenceCounter); + animations.Add(new Animation(animID, sequenceNum)); + return true; + } + } + + return false; + } + + public bool Add(UUID animID, int sequenceNum) + { + lock (animations) + { + if (!HasAnimation(animID)) + { + animations.Add(new Animation(animID, sequenceNum)); + return true; + } + } + + return false; + } + + public bool Remove(UUID animID) + { + if (defaultAnimation.ID == animID) + { + ResetDefaultAnimation(); + return true; + } + else if (HasAnimation(animID)) + { + lock (animations) + { + for (int i = 0; i < animations.Count; i++) + { + if (animations[i].ID == animID) + { + animations.RemoveAt(i); + return true; + } + } + } + } + + return false; + } + + public void Clear() + { + ResetDefaultAnimation(); + lock (animations) animations.Clear(); + } + + public bool SetDefaultAnimation(UUID animID, ref int sequenceCounter) + { + if (defaultAnimation.ID != animID) + { + int sequenceNum = Interlocked.Increment(ref sequenceCounter); + defaultAnimation = new Animation(animID, sequenceNum); + return true; + } + else + { + return false; + } + } + + public bool SetDefaultAnimation(UUID animID, int sequenceNum) + { + if (defaultAnimation.ID != animID) + { + defaultAnimation = new Animation(animID, sequenceNum); + return true; + } + else + { + return false; + } + } + + public void GetArrays(out UUID[] animIDs, out int[] sequenceNums) + { + lock (animations) + { + animIDs = new UUID[animations.Count + 1]; + sequenceNums = new int[animations.Count + 1]; + + animIDs[0] = defaultAnimation.ID; + sequenceNums[0] = defaultAnimation.SequenceNum; + + for (int i = 0; i < animations.Count; ++i) + { + animIDs[i + 1] = animations[i].ID; + sequenceNums[i + 1] = animations[i].SequenceNum; + } + } + } + + protected bool ResetDefaultAnimation() + { + return SetDefaultAnimation(Animations.STAND, 1); + } + } +}