PageRenderTime 38ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcharacter/llmotion.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 264 lines | 110 code | 58 blank | 96 comment | 0 complexity | 012cd139b06a2364ea7e7c77a1e2376b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llmotion.h
  3. * @brief Implementation of LLMotion 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_LLMOTION_H
  27. #define LL_LLMOTION_H
  28. //-----------------------------------------------------------------------------
  29. // Header files
  30. //-----------------------------------------------------------------------------
  31. #include <string>
  32. #include "llerror.h"
  33. #include "llpose.h"
  34. #include "lluuid.h"
  35. class LLCharacter;
  36. //-----------------------------------------------------------------------------
  37. // class LLMotion
  38. //-----------------------------------------------------------------------------
  39. class LLMotion
  40. {
  41. friend class LLMotionController;
  42. public:
  43. enum LLMotionBlendType
  44. {
  45. NORMAL_BLEND,
  46. ADDITIVE_BLEND
  47. };
  48. enum LLMotionInitStatus
  49. {
  50. STATUS_FAILURE,
  51. STATUS_SUCCESS,
  52. STATUS_HOLD
  53. };
  54. // Constructor
  55. LLMotion(const LLUUID &id);
  56. // Destructor
  57. virtual ~LLMotion();
  58. public:
  59. //-------------------------------------------------------------------------
  60. // functions to support MotionController and MotionRegistry
  61. //-------------------------------------------------------------------------
  62. // get the name of this instance
  63. const std::string &getName() const { return mName; }
  64. // set the name of this instance
  65. void setName(const std::string &name) { mName = name; }
  66. const LLUUID& getID() const { return mID; }
  67. // returns the pose associated with the current state of this motion
  68. virtual LLPose* getPose() { return &mPose;}
  69. void fadeOut();
  70. void fadeIn();
  71. F32 getFadeWeight() const { return mFadeWeight; }
  72. F32 getStopTime() const { return mStopTimestamp; }
  73. virtual void setStopTime(F32 time);
  74. BOOL isStopped() const { return mStopped; }
  75. void setStopped(BOOL stopped) { mStopped = stopped; }
  76. BOOL isBlending();
  77. // Activation functions.
  78. // It is OK for other classes to activate a motion,
  79. // but only the controller can deactivate it.
  80. // Thus, if mActive == TRUE, the motion *may* be on the controllers active list,
  81. // but if mActive == FALSE, the motion is gauranteed not to be on the active list.
  82. protected:
  83. // Used by LLMotionController only
  84. void deactivate();
  85. BOOL isActive() { return mActive; }
  86. public:
  87. void activate(F32 time);
  88. public:
  89. //-------------------------------------------------------------------------
  90. // animation callbacks to be implemented by subclasses
  91. //-------------------------------------------------------------------------
  92. // motions must specify whether or not they loop
  93. virtual BOOL getLoop() = 0;
  94. // motions must report their total duration
  95. virtual F32 getDuration() = 0;
  96. // motions must report their "ease in" duration
  97. virtual F32 getEaseInDuration() = 0;
  98. // motions must report their "ease out" duration.
  99. virtual F32 getEaseOutDuration() = 0;
  100. // motions must report their priority level
  101. virtual LLJoint::JointPriority getPriority() = 0;
  102. // motions must report their blend type
  103. virtual LLMotionBlendType getBlendType() = 0;
  104. // called to determine when a motion should be activated/deactivated based on avatar pixel coverage
  105. virtual F32 getMinPixelArea() = 0;
  106. // run-time (post constructor) initialization,
  107. // called after parameters have been set
  108. // must return true to indicate success and be available for activation
  109. virtual LLMotionInitStatus onInitialize(LLCharacter *character) = 0;
  110. // called per time step
  111. // must return TRUE while it is active, and
  112. // must return FALSE when the motion is completed.
  113. virtual BOOL onUpdate(F32 activeTime, U8* joint_mask) = 0;
  114. // called when a motion is deactivated
  115. virtual void onDeactivate() = 0;
  116. // can we crossfade this motion with a new instance when restarted?
  117. // should ultimately always be TRUE, but lack of emote blending, etc
  118. // requires this
  119. virtual BOOL canDeprecate();
  120. // optional callback routine called when animation deactivated.
  121. void setDeactivateCallback( void (*cb)(void *), void* userdata );
  122. protected:
  123. // called when a motion is activated
  124. // must return TRUE to indicate success, or else
  125. // it will be deactivated
  126. virtual BOOL onActivate() = 0;
  127. void addJointState(const LLPointer<LLJointState>& jointState);
  128. protected:
  129. LLPose mPose;
  130. BOOL mStopped; // motion has been stopped;
  131. BOOL mActive; // motion is on active list (can be stopped or not stopped)
  132. //-------------------------------------------------------------------------
  133. // these are set implicitly by the motion controller and
  134. // may be referenced (read only) in the above handlers.
  135. //-------------------------------------------------------------------------
  136. std::string mName; // instance name assigned by motion controller
  137. LLUUID mID;
  138. F32 mActivationTimestamp; // time when motion was activated
  139. F32 mStopTimestamp; // time when motion was told to stop
  140. F32 mSendStopTimestamp; // time when simulator should be told to stop this motion
  141. F32 mResidualWeight; // blend weight at beginning of stop motion phase
  142. F32 mFadeWeight; // for fading in and out based on LOD
  143. U8 mJointSignature[3][LL_CHARACTER_MAX_JOINTS]; // signature of which joints are animated at what priority
  144. void (*mDeactivateCallback)(void* data);
  145. void* mDeactivateCallbackUserData;
  146. };
  147. //-----------------------------------------------------------------------------
  148. // LLTestMotion
  149. //-----------------------------------------------------------------------------
  150. class LLTestMotion : public LLMotion
  151. {
  152. public:
  153. LLTestMotion(const LLUUID &id) : LLMotion(id){}
  154. ~LLTestMotion() {}
  155. static LLMotion *create(const LLUUID& id) { return new LLTestMotion(id); }
  156. BOOL getLoop() { return FALSE; }
  157. F32 getDuration() { return 0.0f; }
  158. F32 getEaseInDuration() { return 0.0f; }
  159. F32 getEaseOutDuration() { return 0.0f; }
  160. LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; }
  161. LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
  162. F32 getMinPixelArea() { return 0.f; }
  163. LLMotionInitStatus onInitialize(LLCharacter*) { llinfos << "LLTestMotion::onInitialize()" << llendl; return STATUS_SUCCESS; }
  164. BOOL onActivate() { llinfos << "LLTestMotion::onActivate()" << llendl; return TRUE; }
  165. BOOL onUpdate(F32 time, U8* joint_mask) { llinfos << "LLTestMotion::onUpdate(" << time << ")" << llendl; return TRUE; }
  166. void onDeactivate() { llinfos << "LLTestMotion::onDeactivate()" << llendl; }
  167. };
  168. //-----------------------------------------------------------------------------
  169. // LLNullMotion
  170. //-----------------------------------------------------------------------------
  171. class LLNullMotion : public LLMotion
  172. {
  173. public:
  174. LLNullMotion(const LLUUID &id) : LLMotion(id) {}
  175. ~LLNullMotion() {}
  176. static LLMotion *create(const LLUUID &id) { return new LLNullMotion(id); }
  177. // motions must specify whether or not they loop
  178. /*virtual*/ BOOL getLoop() { return TRUE; }
  179. // motions must report their total duration
  180. /*virtual*/ F32 getDuration() { return 1.f; }
  181. // motions must report their "ease in" duration
  182. /*virtual*/ F32 getEaseInDuration() { return 0.f; }
  183. // motions must report their "ease out" duration.
  184. /*virtual*/ F32 getEaseOutDuration() { return 0.f; }
  185. // motions must report their priority level
  186. /*virtual*/ LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; }
  187. // motions must report their blend type
  188. /*virtual*/ LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
  189. // called to determine when a motion should be activated/deactivated based on avatar pixel coverage
  190. /*virtual*/ F32 getMinPixelArea() { return 0.f; }
  191. // run-time (post constructor) initialization,
  192. // called after parameters have been set
  193. // must return true to indicate success and be available for activation
  194. /*virtual*/ LLMotionInitStatus onInitialize(LLCharacter *character) { return STATUS_SUCCESS; }
  195. // called when a motion is activated
  196. // must return TRUE to indicate success, or else
  197. // it will be deactivated
  198. /*virtual*/ BOOL onActivate() { return TRUE; }
  199. // called per time step
  200. // must return TRUE while it is active, and
  201. // must return FALSE when the motion is completed.
  202. /*virtual*/ BOOL onUpdate(F32 activeTime, U8* joint_mask) { return TRUE; }
  203. // called when a motion is deactivated
  204. /*virtual*/ void onDeactivate() {}
  205. };
  206. #endif // LL_LLMOTION_H