1
0

AnimationState.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. #ifndef SPINE_ANIMATIONSTATE_H_
  31. #define SPINE_ANIMATIONSTATE_H_
  32. #include <spine/Animation.h>
  33. #include <spine/AnimationStateData.h>
  34. #include <spine/Event.h>
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. typedef enum {
  39. SP_ANIMATION_START, SP_ANIMATION_INTERRUPT, SP_ANIMATION_END, SP_ANIMATION_COMPLETE, SP_ANIMATION_DISPOSE, SP_ANIMATION_EVENT
  40. } spEventType;
  41. typedef struct spAnimationState spAnimationState;
  42. typedef struct spTrackEntry spTrackEntry;
  43. typedef void (*spAnimationStateListener) (spAnimationState* state, spEventType type, spTrackEntry* entry, spEvent* event);
  44. struct spTrackEntry {
  45. spAnimation* animation;
  46. spTrackEntry* next;
  47. spTrackEntry* mixingFrom;
  48. spAnimationStateListener listener;
  49. int trackIndex;
  50. int /*boolean*/ loop;
  51. float eventThreshold, attachmentThreshold, drawOrderThreshold;
  52. float animationStart, animationEnd, animationLast, nextAnimationLast;
  53. float delay, trackTime, trackLast, nextTrackLast, trackEnd, timeScale;
  54. float alpha, mixTime, mixDuration, mixAlpha;
  55. int* /*boolean*/ timelinesFirst;
  56. int timelinesFirstCount;
  57. float* timelinesRotation;
  58. int timelinesRotationCount;
  59. void* rendererObject;
  60. #ifdef __cplusplus
  61. spTrackEntry() :
  62. animation(0),
  63. next(0), mixingFrom(0),
  64. listener(0),
  65. trackIndex(0),
  66. loop(0),
  67. eventThreshold(0), attachmentThreshold(0), drawOrderThreshold(0),
  68. animationStart(0), animationEnd(0), animationLast(0), nextAnimationLast(0),
  69. delay(0), trackTime(0), trackLast(0), nextTrackLast(0), trackEnd(0), timeScale(0),
  70. alpha(0), mixTime(0), mixDuration(0), mixAlpha(0),
  71. timelinesFirst(0),
  72. timelinesFirstCount(0),
  73. timelinesRotation(0),
  74. timelinesRotationCount(0) {
  75. }
  76. #endif
  77. };
  78. struct spAnimationState {
  79. spAnimationStateData* const data;
  80. int tracksCount;
  81. spTrackEntry** tracks;
  82. spAnimationStateListener listener;
  83. float timeScale;
  84. void* rendererObject;
  85. #ifdef __cplusplus
  86. spAnimationState() :
  87. data(0),
  88. tracksCount(0),
  89. tracks(0),
  90. listener(0),
  91. timeScale(0) {
  92. }
  93. #endif
  94. };
  95. /* @param data May be 0 for no mixing. */
  96. spAnimationState* spAnimationState_create (spAnimationStateData* data);
  97. void spAnimationState_dispose (spAnimationState* self);
  98. void spAnimationState_update (spAnimationState* self, float delta);
  99. void spAnimationState_apply (spAnimationState* self, struct spSkeleton* skeleton);
  100. void spAnimationState_clearTracks (spAnimationState* self);
  101. void spAnimationState_clearTrack (spAnimationState* self, int trackIndex);
  102. /** Set the current animation. Any queued animations are cleared. */
  103. spTrackEntry* spAnimationState_setAnimationByName (spAnimationState* self, int trackIndex, const char* animationName,
  104. int/*bool*/loop);
  105. spTrackEntry* spAnimationState_setAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop);
  106. /** Adds an animation to be played delay seconds after the current or last queued animation, taking into account any mix
  107. * duration. */
  108. spTrackEntry* spAnimationState_addAnimationByName (spAnimationState* self, int trackIndex, const char* animationName,
  109. int/*bool*/loop, float delay);
  110. spTrackEntry* spAnimationState_addAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop,
  111. float delay);
  112. spTrackEntry* spAnimationState_setEmptyAnimation(spAnimationState* self, int trackIndex, float mixDuration);
  113. spTrackEntry* spAnimationState_addEmptyAnimation(spAnimationState* self, int trackIndex, float mixDuration, float delay);
  114. void spAnimationState_setEmptyAnimations(spAnimationState* self, float mixDuration);
  115. spTrackEntry* spAnimationState_getCurrent (spAnimationState* self, int trackIndex);
  116. void spAnimationState_clearListenerNotifications(spAnimationState* self);
  117. float spTrackEntry_getAnimationTime (spTrackEntry* entry);
  118. /** Use this to dispose static memory before your app exits to appease your memory leak detector*/
  119. void spAnimationState_disposeStatics ();
  120. #ifdef SPINE_SHORT_NAMES
  121. typedef spEventType EventType;
  122. #define ANIMATION_START SP_ANIMATION_START
  123. #define ANIMATION_INTERRUPT SP_ANIMATION_INTERRUPT
  124. #define ANIMATION_END SP_ANIMATION_END
  125. #define ANIMATION_COMPLETE SP_ANIMATION_COMPLETE
  126. #define ANIMATION_DISPOSE SP_ANIMATION_DISPOSE
  127. #define ANIMATION_EVENT SP_ANIMATION_EVENT
  128. typedef spAnimationStateListener AnimationStateListener;
  129. typedef spTrackEntry TrackEntry;
  130. typedef spAnimationState AnimationState;
  131. #define AnimationState_create(...) spAnimationState_create(__VA_ARGS__)
  132. #define AnimationState_dispose(...) spAnimationState_dispose(__VA_ARGS__)
  133. #define AnimationState_update(...) spAnimationState_update(__VA_ARGS__)
  134. #define AnimationState_apply(...) spAnimationState_apply(__VA_ARGS__)
  135. #define AnimationState_clearTracks(...) spAnimationState_clearTracks(__VA_ARGS__)
  136. #define AnimationState_clearTrack(...) spAnimationState_clearTrack(__VA_ARGS__)
  137. #define AnimationState_setAnimationByName(...) spAnimationState_setAnimationByName(__VA_ARGS__)
  138. #define AnimationState_setAnimation(...) spAnimationState_setAnimation(__VA_ARGS__)
  139. #define AnimationState_addAnimationByName(...) spAnimationState_addAnimationByName(__VA_ARGS__)
  140. #define AnimationState_addAnimation(...) spAnimationState_addAnimation(__VA_ARGS__)
  141. #define AnimationState_setEmptyAnimation(...) spAnimatinState_setEmptyAnimation(__VA_ARGS__)
  142. #define AnimationState_addEmptyAnimation(...) spAnimatinState_addEmptyAnimation(__VA_ARGS__)
  143. #define AnimationState_setEmptyAnimations(...) spAnimatinState_setEmptyAnimations(__VA_ARGS__)
  144. #define AnimationState_getCurrent(...) spAnimationState_getCurrent(__VA_ARGS__)
  145. #define AnimationState_clearListenerNotifications(...) spAnimatinState_clearListenerNotifications(__VA_ARGS__)
  146. #endif
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150. #endif /* SPINE_ANIMATIONSTATE_H_ */