PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcharacter/llmotioncontroller.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 232 lines | 99 code | 46 blank | 87 comment | 0 complexity | c129b7568c875cbf8531e190ed7c1b16 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llmotioncontroller.h
  3. * @brief Implementation of LLMotionController class.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLMOTIONCONTROLLER_H
  27. #define LL_LLMOTIONCONTROLLER_H
  28. //-----------------------------------------------------------------------------
  29. // Header files
  30. //-----------------------------------------------------------------------------
  31. #include <string>
  32. #include <map>
  33. #include <deque>
  34. #include "lluuidhashmap.h"
  35. #include "llmotion.h"
  36. #include "llpose.h"
  37. #include "llframetimer.h"
  38. #include "llstatemachine.h"
  39. #include "llstring.h"
  40. //-----------------------------------------------------------------------------
  41. // Class predeclaration
  42. // This is necessary because llcharacter.h includes this file.
  43. //-----------------------------------------------------------------------------
  44. class LLCharacter;
  45. //-----------------------------------------------------------------------------
  46. // LLMotionRegistry
  47. //-----------------------------------------------------------------------------
  48. typedef LLMotion*(*LLMotionConstructor)(const LLUUID &id);
  49. class LLMotionRegistry
  50. {
  51. public:
  52. // Constructor
  53. LLMotionRegistry();
  54. // Destructor
  55. ~LLMotionRegistry();
  56. // adds motion classes to the registry
  57. // returns true if successfull
  58. BOOL registerMotion( const LLUUID& id, LLMotionConstructor create);
  59. // creates a new instance of a named motion
  60. // returns NULL motion is not registered
  61. LLMotion *createMotion( const LLUUID &id );
  62. // initialization of motion failed, don't try to create this motion again
  63. void markBad( const LLUUID& id );
  64. protected:
  65. typedef std::map<LLUUID, LLMotionConstructor> motion_map_t;
  66. motion_map_t mMotionTable;
  67. };
  68. //-----------------------------------------------------------------------------
  69. // class LLMotionController
  70. //-----------------------------------------------------------------------------
  71. class LLMotionController
  72. {
  73. public:
  74. typedef std::list<LLMotion*> motion_list_t;
  75. typedef std::set<LLMotion*> motion_set_t;
  76. BOOL mIsSelf;
  77. public:
  78. // Constructor
  79. LLMotionController();
  80. // Destructor
  81. virtual ~LLMotionController();
  82. // set associated character
  83. // this must be called exactly once by the containing character class.
  84. // this is generally done in the Character constructor
  85. void setCharacter( LLCharacter *character );
  86. // registers a motion with the controller
  87. // (actually just forwards call to motion registry)
  88. // returns true if successfull
  89. BOOL registerMotion( const LLUUID& id, LLMotionConstructor create );
  90. // creates a motion from the registry
  91. LLMotion *createMotion( const LLUUID &id );
  92. // unregisters a motion with the controller
  93. // (actually just forwards call to motion registry)
  94. // returns true if successfull
  95. void removeMotion( const LLUUID& id );
  96. // start motion
  97. // begins playing the specified motion
  98. // returns true if successful
  99. BOOL startMotion( const LLUUID &id, F32 start_offset );
  100. // stop motion
  101. // stops a playing motion
  102. // in reality, it begins the ease out transition phase
  103. // returns true if successful
  104. BOOL stopMotionLocally( const LLUUID &id, BOOL stop_immediate );
  105. // Move motions from loading to loaded
  106. void updateLoadingMotions();
  107. // update motions
  108. // invokes the update handlers for each active motion
  109. // activates sequenced motions
  110. // deactivates terminated motions`
  111. void updateMotions(bool force_update = false);
  112. // minimal update (e.g. while hidden)
  113. void updateMotionsMinimal();
  114. void clearBlenders() { mPoseBlender.clearBlenders(); }
  115. // flush motions
  116. // releases all motion instances
  117. void flushAllMotions();
  118. //Flush is a liar.
  119. void deactivateAllMotions();
  120. // pause and continue all motions
  121. void pauseAllMotions();
  122. void unpauseAllMotions();
  123. BOOL isPaused() const { return mPaused; }
  124. void setTimeStep(F32 step);
  125. void setTimeFactor(F32 time_factor);
  126. F32 getTimeFactor() const { return mTimeFactor; }
  127. motion_list_t& getActiveMotions() { return mActiveMotions; }
  128. void incMotionCounts(S32& num_motions, S32& num_loading_motions, S32& num_loaded_motions, S32& num_active_motions, S32& num_deprecated_motions);
  129. //protected:
  130. bool isMotionActive( LLMotion *motion );
  131. bool isMotionLoading( LLMotion *motion );
  132. LLMotion *findMotion( const LLUUID& id ) const;
  133. void dumpMotions();
  134. const LLFrameTimer& getFrameTimer() { return mTimer; }
  135. protected:
  136. // internal operations act on motion instances directly
  137. // as there can be duplicate motions per id during blending overlap
  138. void deleteAllMotions();
  139. BOOL activateMotionInstance(LLMotion *motion, F32 time);
  140. BOOL deactivateMotionInstance(LLMotion *motion);
  141. void deprecateMotionInstance(LLMotion* motion);
  142. BOOL stopMotionInstance(LLMotion *motion, BOOL stop_imemdiate);
  143. void removeMotionInstance(LLMotion* motion);
  144. void updateRegularMotions();
  145. void updateAdditiveMotions();
  146. void resetJointSignatures();
  147. void updateMotionsByType(LLMotion::LLMotionBlendType motion_type);
  148. void updateIdleMotion(LLMotion* motionp);
  149. void updateIdleActiveMotions();
  150. void purgeExcessMotions();
  151. void deactivateStoppedMotions();
  152. protected:
  153. F32 mTimeFactor;
  154. static LLMotionRegistry sRegistry;
  155. LLPoseBlender mPoseBlender;
  156. LLCharacter *mCharacter;
  157. // Life cycle of an animation:
  158. //
  159. // Animations are instantiated and immediately put in the mAllMotions map for their entire lifetime.
  160. // If the animations depend on any asset data, the appropriate data is fetched from the data server,
  161. // and the animation is put on the mLoadingMotions list.
  162. // Once an animations is loaded, it will be initialized and put on the mLoadedMotions list.
  163. // Any animation that is currently playing also sits in the mActiveMotions list.
  164. typedef std::map<LLUUID, LLMotion*> motion_map_t;
  165. motion_map_t mAllMotions;
  166. motion_set_t mLoadingMotions;
  167. motion_set_t mLoadedMotions;
  168. motion_list_t mActiveMotions;
  169. motion_set_t mDeprecatedMotions;
  170. LLFrameTimer mTimer;
  171. F32 mPrevTimerElapsed;
  172. F32 mAnimTime;
  173. F32 mLastTime;
  174. BOOL mHasRunOnce;
  175. BOOL mPaused;
  176. F32 mPauseTime;
  177. F32 mTimeStep;
  178. S32 mTimeStepCount;
  179. F32 mLastInterp;
  180. U8 mJointSignature[2][LL_CHARACTER_MAX_JOINTS];
  181. };
  182. //-----------------------------------------------------------------------------
  183. // Class declaractions
  184. //-----------------------------------------------------------------------------
  185. #include "llcharacter.h"
  186. #endif // LL_LLMOTIONCONTROLLER_H