AnimationSet.cs 5.1 KB

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