AnimationSet.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 OpenSim 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. using System;
  28. using System.Collections.Generic;
  29. using OpenMetaverse;
  30. namespace OpenSim.Region.Environment.Scenes
  31. {
  32. public class AnimationSet
  33. {
  34. public static AvatarAnimations Animations = new AvatarAnimations();
  35. private Animation m_defaultAnimation = new Animation();
  36. private List<Animation> m_animations = new List<Animation>();
  37. public Animation DefaultAnimation
  38. {
  39. get { return m_defaultAnimation; }
  40. }
  41. public AnimationSet()
  42. {
  43. ResetDefaultAnimation();
  44. }
  45. public bool HasAnimation(UUID animID)
  46. {
  47. if (m_defaultAnimation.AnimID == animID)
  48. return true;
  49. for (int i = 0; i < m_animations.Count; ++i)
  50. {
  51. if (m_animations[i].AnimID == animID)
  52. return true;
  53. }
  54. return false;
  55. }
  56. public bool Add(UUID animID, int sequenceNum)
  57. {
  58. lock (m_animations)
  59. {
  60. if (!HasAnimation(animID))
  61. {
  62. m_animations.Add(new Animation(animID, sequenceNum));
  63. return true;
  64. }
  65. }
  66. return false;
  67. }
  68. public bool Remove(UUID animID)
  69. {
  70. lock (m_animations)
  71. {
  72. if (m_defaultAnimation.AnimID == animID)
  73. {
  74. ResetDefaultAnimation();
  75. }
  76. else if (HasAnimation(animID))
  77. {
  78. for (int i = 0; i < m_animations.Count; i++)
  79. {
  80. if (m_animations[i].AnimID == animID)
  81. {
  82. m_animations.RemoveAt(i);
  83. return true;
  84. }
  85. }
  86. }
  87. }
  88. return false;
  89. }
  90. public void Clear()
  91. {
  92. ResetDefaultAnimation();
  93. m_animations.Clear();
  94. }
  95. /// <summary>
  96. /// The default animation is reserved for "main" animations
  97. /// that are mutually exclusive, e.g. flying and sitting.
  98. /// </summary>
  99. public bool SetDefaultAnimation(UUID animID, int sequenceNum)
  100. {
  101. if (m_defaultAnimation.AnimID != animID)
  102. {
  103. m_defaultAnimation = new Animation(animID, sequenceNum);
  104. return true;
  105. }
  106. return false;
  107. }
  108. protected bool ResetDefaultAnimation()
  109. {
  110. return TrySetDefaultAnimation("STAND", 1);
  111. }
  112. /// <summary>
  113. /// Set the animation as the default animation if it's known
  114. /// </summary>
  115. public bool TrySetDefaultAnimation(string anim, int sequenceNum)
  116. {
  117. if (Animations.AnimsUUID.ContainsKey(anim))
  118. {
  119. return SetDefaultAnimation(Animations.AnimsUUID[anim], sequenceNum);
  120. }
  121. return false;
  122. }
  123. public void GetArrays(out UUID[] animIDs, out int[] sequenceNums)
  124. {
  125. lock (m_animations)
  126. {
  127. animIDs = new UUID[m_animations.Count + 1];
  128. sequenceNums = new int[m_animations.Count + 1];
  129. animIDs[0] = m_defaultAnimation.AnimID;
  130. sequenceNums[0] = m_defaultAnimation.SequenceNum;
  131. for (int i = 0; i < m_animations.Count; ++i)
  132. {
  133. animIDs[i + 1] = m_animations[i].AnimID;
  134. sequenceNums[i + 1] = m_animations[i].SequenceNum;
  135. }
  136. }
  137. }
  138. }
  139. }