AnimationState.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated January 1, 2020. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2020, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #ifndef SPINE_ANIMATIONSTATE_H_
  30. #define SPINE_ANIMATIONSTATE_H_
  31. #include <spine/dll.h>
  32. #include <spine/Animation.h>
  33. #include <spine/AnimationStateData.h>
  34. #include <spine/Event.h>
  35. #include <spine/Array.h>
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. typedef enum {
  40. SP_ANIMATION_START, SP_ANIMATION_INTERRUPT, SP_ANIMATION_END, SP_ANIMATION_COMPLETE, SP_ANIMATION_DISPOSE, SP_ANIMATION_EVENT
  41. } spEventType;
  42. typedef struct spAnimationState spAnimationState;
  43. typedef struct spTrackEntry spTrackEntry;
  44. typedef void (*spAnimationStateListener) (spAnimationState* state, spEventType type, spTrackEntry* entry, spEvent* event);
  45. _SP_ARRAY_DECLARE_TYPE(spTrackEntryArray, spTrackEntry*)
  46. struct spTrackEntry {
  47. spAnimation* animation;
  48. spTrackEntry* next;
  49. spTrackEntry* mixingFrom;
  50. spTrackEntry* mixingTo;
  51. spAnimationStateListener listener;
  52. int trackIndex;
  53. int /*boolean*/ loop;
  54. int /*boolean*/ holdPrevious;
  55. float eventThreshold, attachmentThreshold, drawOrderThreshold;
  56. float animationStart, animationEnd, animationLast, nextAnimationLast;
  57. float delay, trackTime, trackLast, nextTrackLast, trackEnd, timeScale;
  58. float alpha, mixTime, mixDuration, interruptAlpha, totalAlpha;
  59. spMixBlend mixBlend;
  60. spIntArray* timelineMode;
  61. spTrackEntryArray* timelineHoldMix;
  62. float* timelinesRotation;
  63. int timelinesRotationCount;
  64. void* rendererObject;
  65. void* userData;
  66. #ifdef __cplusplus
  67. spTrackEntry() :
  68. animation(0),
  69. next(0), mixingFrom(0), mixingTo(0),
  70. listener(0),
  71. trackIndex(0),
  72. loop(0),
  73. holdPrevious(0),
  74. eventThreshold(0), attachmentThreshold(0), drawOrderThreshold(0),
  75. animationStart(0), animationEnd(0), animationLast(0), nextAnimationLast(0),
  76. delay(0), trackTime(0), trackLast(0), nextTrackLast(0), trackEnd(0), timeScale(0),
  77. alpha(0), mixTime(0), mixDuration(0), interruptAlpha(0), totalAlpha(0),
  78. mixBlend(SP_MIX_BLEND_REPLACE),
  79. timelineMode(0),
  80. timelineHoldMix(0),
  81. timelinesRotation(0),
  82. timelinesRotationCount(0),
  83. rendererObject(0), userData(0) {
  84. }
  85. #endif
  86. };
  87. struct spAnimationState {
  88. spAnimationStateData* const data;
  89. int tracksCount;
  90. spTrackEntry** tracks;
  91. spAnimationStateListener listener;
  92. float timeScale;
  93. void* rendererObject;
  94. void* userData;
  95. int unkeyedState;
  96. #ifdef __cplusplus
  97. spAnimationState() :
  98. data(0),
  99. tracksCount(0),
  100. tracks(0),
  101. listener(0),
  102. timeScale(0),
  103. rendererObject(0),
  104. userData(0),
  105. unkeyedState(0) {
  106. }
  107. #endif
  108. };
  109. /* @param data May be 0 for no mixing. */
  110. SP_API spAnimationState* spAnimationState_create (spAnimationStateData* data);
  111. SP_API void spAnimationState_dispose (spAnimationState* self);
  112. SP_API void spAnimationState_update (spAnimationState* self, float delta);
  113. SP_API int /**bool**/ spAnimationState_apply (spAnimationState* self, struct spSkeleton* skeleton);
  114. SP_API void spAnimationState_clearTracks (spAnimationState* self);
  115. SP_API void spAnimationState_clearTrack (spAnimationState* self, int trackIndex);
  116. /** Set the current animation. Any queued animations are cleared. */
  117. SP_API spTrackEntry* spAnimationState_setAnimationByName (spAnimationState* self, int trackIndex, const char* animationName,
  118. int/*bool*/loop);
  119. SP_API spTrackEntry* spAnimationState_setAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop);
  120. /** Adds an animation to be played delay seconds after the current or last queued animation, taking into account any mix
  121. * duration. */
  122. SP_API spTrackEntry* spAnimationState_addAnimationByName (spAnimationState* self, int trackIndex, const char* animationName,
  123. int/*bool*/loop, float delay);
  124. SP_API spTrackEntry* spAnimationState_addAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop,
  125. float delay);
  126. SP_API spTrackEntry* spAnimationState_setEmptyAnimation(spAnimationState* self, int trackIndex, float mixDuration);
  127. SP_API spTrackEntry* spAnimationState_addEmptyAnimation(spAnimationState* self, int trackIndex, float mixDuration, float delay);
  128. SP_API void spAnimationState_setEmptyAnimations(spAnimationState* self, float mixDuration);
  129. SP_API spTrackEntry* spAnimationState_getCurrent (spAnimationState* self, int trackIndex);
  130. SP_API void spAnimationState_clearListenerNotifications(spAnimationState* self);
  131. SP_API float spTrackEntry_getAnimationTime (spTrackEntry* entry);
  132. /** Use this to dispose static memory before your app exits to appease your memory leak detector*/
  133. SP_API void spAnimationState_disposeStatics ();
  134. #ifdef SPINE_SHORT_NAMES
  135. typedef spEventType EventType;
  136. #define ANIMATION_START SP_ANIMATION_START
  137. #define ANIMATION_INTERRUPT SP_ANIMATION_INTERRUPT
  138. #define ANIMATION_END SP_ANIMATION_END
  139. #define ANIMATION_COMPLETE SP_ANIMATION_COMPLETE
  140. #define ANIMATION_DISPOSE SP_ANIMATION_DISPOSE
  141. #define ANIMATION_EVENT SP_ANIMATION_EVENT
  142. typedef spAnimationStateListener AnimationStateListener;
  143. typedef spTrackEntry TrackEntry;
  144. typedef spAnimationState AnimationState;
  145. #define AnimationState_create(...) spAnimationState_create(__VA_ARGS__)
  146. #define AnimationState_dispose(...) spAnimationState_dispose(__VA_ARGS__)
  147. #define AnimationState_update(...) spAnimationState_update(__VA_ARGS__)
  148. #define AnimationState_apply(...) spAnimationState_apply(__VA_ARGS__)
  149. #define AnimationState_clearTracks(...) spAnimationState_clearTracks(__VA_ARGS__)
  150. #define AnimationState_clearTrack(...) spAnimationState_clearTrack(__VA_ARGS__)
  151. #define AnimationState_setAnimationByName(...) spAnimationState_setAnimationByName(__VA_ARGS__)
  152. #define AnimationState_setAnimation(...) spAnimationState_setAnimation(__VA_ARGS__)
  153. #define AnimationState_addAnimationByName(...) spAnimationState_addAnimationByName(__VA_ARGS__)
  154. #define AnimationState_addAnimation(...) spAnimationState_addAnimation(__VA_ARGS__)
  155. #define AnimationState_setEmptyAnimation(...) spAnimationState_setEmptyAnimation(__VA_ARGS__)
  156. #define AnimationState_addEmptyAnimation(...) spAnimationState_addEmptyAnimation(__VA_ARGS__)
  157. #define AnimationState_setEmptyAnimations(...) spAnimationState_setEmptyAnimations(__VA_ARGS__)
  158. #define AnimationState_getCurrent(...) spAnimationState_getCurrent(__VA_ARGS__)
  159. #define AnimationState_clearListenerNotifications(...) spAnimationState_clearListenerNotifications(__VA_ARGS__)
  160. #endif
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164. #endif /* SPINE_ANIMATIONSTATE_H_ */