llmotion.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /**
  2. * @file llmotion.h
  3. * @brief Implementation of LLMotion class.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLMOTION_H
  33. #define LL_LLMOTION_H
  34. #include <string>
  35. #include "llerror.h"
  36. #include "llpose.h"
  37. #include "lluuid.h"
  38. class LLCharacter;
  39. class LLKeyframeMotion;
  40. class LLMotion
  41. {
  42. friend class LLMotionController;
  43. protected:
  44. LOG_CLASS(LLMotion);
  45. public:
  46. enum LLMotionBlendType
  47. {
  48. NORMAL_BLEND,
  49. ADDITIVE_BLEND
  50. };
  51. enum LLMotionInitStatus
  52. {
  53. STATUS_FAILURE,
  54. STATUS_SUCCESS,
  55. STATUS_HOLD
  56. };
  57. LLMotion(const LLUUID& id);
  58. virtual ~LLMotion() = default;
  59. LL_INLINE virtual LLKeyframeMotion* asKeyframeMotion()
  60. {
  61. return NULL;
  62. }
  63. // Gets the name of this instance
  64. LL_INLINE const std::string& getName() const { return mName; }
  65. // Sets the name of this instance
  66. LL_INLINE void setName(const std::string& name) { mName = name; }
  67. LL_INLINE const LLUUID& getID() const { return mID; }
  68. // Returns the pose associated with the current state of this motion
  69. LL_INLINE virtual LLPose* getPose() { return &mPose;}
  70. void fadeOut();
  71. void fadeIn();
  72. LL_INLINE F32 getFadeWeight() const { return mFadeWeight; }
  73. LL_INLINE F32 getStopTime() const { return mStopTimestamp; }
  74. virtual void setStopTime(F32 time);
  75. LL_INLINE bool isStopped() const { return mStopped; }
  76. LL_INLINE void setStopped(bool stopped) { mStopped = stopped; }
  77. bool isBlending() const;
  78. LL_INLINE virtual bool needsUpdate() const { return isBlending(); }
  79. // Activation methods.
  80. // It is OK for other classes to activate a motion, but only the controller
  81. // can deactivate it. Thus, if mActive == true, the motion *may* be on the
  82. // controllers active list, but if mActive == false, the motion is
  83. // guaranteed not to be on the active list.
  84. void activate(F32 time);
  85. LL_INLINE bool isActive() const { return mActive; }
  86. // Motions must specify whether or not they loop
  87. virtual bool getLoop() = 0;
  88. // Motions must report their total duration
  89. virtual F32 getDuration() = 0;
  90. // Motions must report their "ease in" duration
  91. virtual F32 getEaseInDuration() = 0;
  92. // Motions must report their "ease out" duration.
  93. virtual F32 getEaseOutDuration() = 0;
  94. // Motions must report their priority level
  95. virtual LLJoint::JointPriority getPriority() = 0;
  96. // Motions must report their blend type
  97. virtual LLMotionBlendType getBlendType() = 0;
  98. // Called to determine when a motion should be activated/deactivated based
  99. // on avatar pixel coverage.
  100. virtual F32 getMinPixelArea() = 0;
  101. // Run-time (post constructor) initialization, called after parameters have
  102. // been set. Must return true to indicate success and be available for
  103. // activation.
  104. virtual LLMotionInitStatus onInitialize(LLCharacter* character) = 0;
  105. // Called per time step. Must return true while it is active, and must
  106. // return false when the motion is completed.
  107. virtual bool onUpdate(F32 active_time, U8* joint_mask) = 0;
  108. // Called when a motion is deactivated.
  109. virtual void onDeactivate() = 0;
  110. // Can we crossfade this motion with a new instance when restarted ?
  111. // Should ultimately always be true, but lack of emote blending etc
  112. // requires this
  113. LL_INLINE virtual bool canDeprecate() { return true; }
  114. // Optional callback routine called when animation deactivated.
  115. void setDeactivateCallback(void (*cb)(void*), void* userdata);
  116. // Expose enabled status so the effects of given motion can be turned on
  117. // or off independently of their active state (only used and overridden so
  118. // far by LLHeadRotMotion).
  119. LL_INLINE virtual void enable() {}
  120. LL_INLINE virtual void disable() {}
  121. LL_INLINE virtual bool isEnabled() const { return true; }
  122. protected:
  123. // Used by LLMotionController only
  124. void deactivate();
  125. // Called when a motion is activated. Must return true to indicate success,
  126. // or else it will be deactivated.
  127. virtual bool onActivate() = 0;
  128. void addJointState(const LLPointer<LLJointState>& jointState);
  129. protected:
  130. LLPose mPose;
  131. // These are set implicitly by the motion controller and may be referenced
  132. // (read only) in the above handlers.
  133. std::string mName;
  134. LLUUID mID;
  135. F32 mActivationTimestamp; // Time when motion was activated
  136. F32 mStopTimestamp; // Time when motion was told to stop
  137. // Time when sim should be told to stop this motion
  138. F32 mSendStopTimestamp;
  139. // Blend weight at beginning of stop motion phase
  140. F32 mResidualWeight;
  141. F32 mFadeWeight; // For fading in and out based on LOD
  142. void (*mDeactivateCallback)(void*);
  143. void* mDeactivateCallbackUserData;
  144. // Signature of which joints are animated at what priority
  145. U8 mJointSignature[3][LL_CHARACTER_MAX_ANIMATED_JOINTS];
  146. bool mStopped; // Motion has been stopped;
  147. // Motion is on active list (can be stopped or not stopped)
  148. bool mActive;
  149. };
  150. class LLNullMotion final : public LLMotion
  151. {
  152. public:
  153. LLNullMotion(const LLUUID& id)
  154. : LLMotion(id)
  155. {
  156. }
  157. LL_INLINE static LLMotion* create(const LLUUID& id)
  158. {
  159. return new LLNullMotion(id);
  160. }
  161. // Motions must specify whether or not they loop
  162. LL_INLINE bool getLoop() override { return true; }
  163. // Motions must report their total duration
  164. LL_INLINE F32 getDuration() override { return 1.f; }
  165. // Motions must report their "ease in" duration
  166. LL_INLINE F32 getEaseInDuration() override { return 0.f; }
  167. // Motions must report their "ease out" duration.
  168. LL_INLINE F32 getEaseOutDuration() override { return 0.f; }
  169. // Motions must report their priority level
  170. LL_INLINE LLJoint::JointPriority getPriority() override { return LLJoint::HIGH_PRIORITY; }
  171. // Motions must report their blend type
  172. LL_INLINE LLMotionBlendType getBlendType() override { return NORMAL_BLEND; }
  173. // Called to determine when a motion should be activated/deactivated based
  174. // on avatar pixel coverage.
  175. LL_INLINE F32 getMinPixelArea() override { return 0.f; }
  176. // Run-time (post constructor) initialization, called after parameters have
  177. // been set. Must return true to indicate success and be available for
  178. // activation.
  179. LL_INLINE LLMotionInitStatus onInitialize(LLCharacter*) override
  180. {
  181. return STATUS_SUCCESS;
  182. }
  183. // Called when a motion is activated. Must return true to indicate success,
  184. // or else it will be deactivated.
  185. LL_INLINE bool onActivate() override { return true; }
  186. // Called per time step. Must return true while it is active, and must
  187. // return false when the motion is completed.
  188. LL_INLINE bool onUpdate(F32, U8*) override { return true; }
  189. // Called when a motion is deactivated
  190. LL_INLINE void onDeactivate() override {}
  191. };
  192. #endif // LL_LLMOTION_H