aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Animation
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2009-11-17 15:20:02 +0000
committerJustin Clark-Casey (justincc)2009-11-17 15:20:02 +0000
commit61c76d1810fcb430cf9c7441044c70486efd9bc5 (patch)
tree3876b67af2cc5a60269d4b39c0062afc55c88165 /OpenSim/Region/Framework/Scenes/Animation
parentrefactor: move most animation methods from ScenePresence into a new ScenePres... (diff)
downloadopensim-SC-61c76d1810fcb430cf9c7441044c70486efd9bc5.zip
opensim-SC-61c76d1810fcb430cf9c7441044c70486efd9bc5.tar.gz
opensim-SC-61c76d1810fcb430cf9c7441044c70486efd9bc5.tar.bz2
opensim-SC-61c76d1810fcb430cf9c7441044c70486efd9bc5.tar.xz
refactor: move AnimationSet
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Animation')
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs185
1 files changed, 185 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs b/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs
new file mode 100644
index 0000000..9176d3d
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Animation/AnimationSet.cs
@@ -0,0 +1,185 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using OpenSim.Framework;
31using OpenMetaverse;
32
33using Animation = OpenSim.Framework.Animation;
34
35namespace OpenSim.Region.Framework.Scenes.Animation
36{
37 [Serializable]
38 public class AnimationSet
39 {
40 public static AvatarAnimations Animations = new AvatarAnimations();
41
42 private OpenSim.Framework.Animation m_defaultAnimation = new OpenSim.Framework.Animation();
43 private List<OpenSim.Framework.Animation> m_animations = new List<OpenSim.Framework.Animation>();
44
45 public OpenSim.Framework.Animation DefaultAnimation
46 {
47 get { return m_defaultAnimation; }
48 }
49
50 public AnimationSet()
51 {
52 ResetDefaultAnimation();
53 }
54
55 public bool HasAnimation(UUID animID)
56 {
57 if (m_defaultAnimation.AnimID == animID)
58 return true;
59
60 for (int i = 0; i < m_animations.Count; ++i)
61 {
62 if (m_animations[i].AnimID == animID)
63 return true;
64 }
65
66 return false;
67 }
68
69 public bool Add(UUID animID, int sequenceNum, UUID objectID)
70 {
71 lock (m_animations)
72 {
73 if (!HasAnimation(animID))
74 {
75 m_animations.Add(new OpenSim.Framework.Animation(animID, sequenceNum, objectID));
76 return true;
77 }
78 }
79 return false;
80 }
81
82 public bool Remove(UUID animID)
83 {
84 lock (m_animations)
85 {
86 if (m_defaultAnimation.AnimID == animID)
87 {
88 ResetDefaultAnimation();
89 }
90 else if (HasAnimation(animID))
91 {
92 for (int i = 0; i < m_animations.Count; i++)
93 {
94 if (m_animations[i].AnimID == animID)
95 {
96 m_animations.RemoveAt(i);
97 return true;
98 }
99 }
100 }
101 }
102 return false;
103 }
104
105 public void Clear()
106 {
107 ResetDefaultAnimation();
108 m_animations.Clear();
109 }
110
111 /// <summary>
112 /// The default animation is reserved for "main" animations
113 /// that are mutually exclusive, e.g. flying and sitting.
114 /// </summary>
115 public bool SetDefaultAnimation(UUID animID, int sequenceNum, UUID objectID)
116 {
117 if (m_defaultAnimation.AnimID != animID)
118 {
119 m_defaultAnimation = new OpenSim.Framework.Animation(animID, sequenceNum, objectID);
120 return true;
121 }
122 return false;
123 }
124
125 protected bool ResetDefaultAnimation()
126 {
127 return TrySetDefaultAnimation("STAND", 1, UUID.Zero);
128 }
129
130 /// <summary>
131 /// Set the animation as the default animation if it's known
132 /// </summary>
133 public bool TrySetDefaultAnimation(string anim, int sequenceNum, UUID objectID)
134 {
135 if (Animations.AnimsUUID.ContainsKey(anim))
136 {
137 return SetDefaultAnimation(Animations.AnimsUUID[anim], sequenceNum, objectID);
138 }
139 return false;
140 }
141
142 public void GetArrays(out UUID[] animIDs, out int[] sequenceNums, out UUID[] objectIDs)
143 {
144 lock (m_animations)
145 {
146 animIDs = new UUID[m_animations.Count + 1];
147 sequenceNums = new int[m_animations.Count + 1];
148 objectIDs = new UUID[m_animations.Count + 1];
149
150 animIDs[0] = m_defaultAnimation.AnimID;
151 sequenceNums[0] = m_defaultAnimation.SequenceNum;
152 objectIDs[0] = m_defaultAnimation.ObjectID;
153
154 for (int i = 0; i < m_animations.Count; ++i)
155 {
156 animIDs[i + 1] = m_animations[i].AnimID;
157 sequenceNums[i + 1] = m_animations[i].SequenceNum;
158 objectIDs[i + 1] = m_animations[i].ObjectID;
159 }
160 }
161 }
162
163 public OpenSim.Framework.Animation[] ToArray()
164 {
165 OpenSim.Framework.Animation[] theArray = new OpenSim.Framework.Animation[m_animations.Count];
166 uint i = 0;
167 try
168 {
169 foreach (OpenSim.Framework.Animation anim in m_animations)
170 theArray[i++] = anim;
171 }
172 catch
173 {
174 /* S%^t happens. Ignore. */
175 }
176 return theArray;
177 }
178
179 public void FromArray(OpenSim.Framework.Animation[] theArray)
180 {
181 foreach (OpenSim.Framework.Animation anim in theArray)
182 m_animations.Add(anim);
183 }
184 }
185}