AnimationState.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /******************************************************************************
  2. * Spine Runtimes Software License
  3. * Version 2
  4. *
  5. * Copyright (c) 2013, Esoteric Software
  6. * All rights reserved.
  7. *
  8. * You are granted a perpetual, non-exclusive, non-sublicensable and
  9. * non-transferable license to install, execute and perform the Spine Runtimes
  10. * Software (the "Software") solely for internal use. Without the written
  11. * permission of Esoteric Software, you may not (a) modify, translate, adapt or
  12. * otherwise create derivative works, improvements of the Software or develop
  13. * new applications using the Software or (b) remove, delete, alter or obscure
  14. * any trademarks or any copyright, trademark, patent or other intellectual
  15. * property or proprietary rights notices on or in the Software, including
  16. * any copy thereof. Redistributions in binary or source form must include
  17. * this license and terms. THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  19. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTARE BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *****************************************************************************/
  28. #ifndef SPINE_ANIMATIONSTATE_H_
  29. #define SPINE_ANIMATIONSTATE_H_
  30. #include <spine/Animation.h>
  31. #include <spine/AnimationStateData.h>
  32. #include <spine/Event.h>
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. typedef enum {
  37. ANIMATION_START, ANIMATION_END, ANIMATION_COMPLETE, ANIMATION_EVENT
  38. } spEventType;
  39. typedef struct spAnimationState spAnimationState;
  40. typedef void (*spAnimationStateListener) (spAnimationState* state, int trackIndex, spEventType type, spEvent* event,
  41. int loopCount);
  42. typedef struct spTrackEntry spTrackEntry;
  43. struct spTrackEntry {
  44. spTrackEntry* next;
  45. spTrackEntry* previous;
  46. spAnimation* animation;
  47. int/*bool*/loop;
  48. float delay, time, lastTime, endTime, timeScale;
  49. spAnimationStateListener listener;
  50. float mixTime, mixDuration;
  51. };
  52. struct spAnimationState {
  53. spAnimationStateData* const data;
  54. float timeScale;
  55. spAnimationStateListener listener;
  56. void* context;
  57. int trackCount;
  58. spTrackEntry** tracks;
  59. };
  60. /* @param data May be 0 for no mixing. */
  61. spAnimationState* spAnimationState_create (spAnimationStateData* data);
  62. void spAnimationState_dispose (spAnimationState* self);
  63. void spAnimationState_update (spAnimationState* self, float delta);
  64. void spAnimationState_apply (spAnimationState* self, struct spSkeleton* skeleton);
  65. void spAnimationState_clearTracks (spAnimationState* self);
  66. void spAnimationState_clearTrack (spAnimationState* self, int trackIndex);
  67. /** Set the current animation. Any queued animations are cleared. */
  68. spTrackEntry* spAnimationState_setAnimationByName (spAnimationState* self, int trackIndex, const char* animationName,
  69. int/*bool*/loop);
  70. spTrackEntry* spAnimationState_setAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop);
  71. /** Adds an animation to be played delay seconds after the current or last queued animation, taking into account any mix
  72. * duration. */
  73. spTrackEntry* spAnimationState_addAnimationByName (spAnimationState* self, int trackIndex, const char* animationName,
  74. int/*bool*/loop, float delay);
  75. spTrackEntry* spAnimationState_addAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop,
  76. float delay);
  77. spTrackEntry* spAnimationState_getCurrent (spAnimationState* self, int trackIndex);
  78. #ifdef SPINE_SHORT_NAMES
  79. typedef spEventType EventType;
  80. typedef spAnimationStateListener AnimationStateListener;
  81. typedef spTrackEntry TrackEntry;
  82. typedef spAnimationState AnimationState;
  83. #define AnimationState_create(...) spAnimationState_create(__VA_ARGS__)
  84. #define AnimationState_dispose(...) spAnimationState_dispose(__VA_ARGS__)
  85. #define AnimationState_update(...) spAnimationState_update(__VA_ARGS__)
  86. #define AnimationState_apply(...) spAnimationState_apply(__VA_ARGS__)
  87. #define AnimationState_clearTracks(...) spAnimationState_clearTracks(__VA_ARGS__)
  88. #define AnimationState_clearTrack(...) spAnimationState_clearTrack(__VA_ARGS__)
  89. #define AnimationState_setAnimationByName(...) spAnimationState_setAnimationByName(__VA_ARGS__)
  90. #define AnimationState_setAnimation(...) spAnimationState_setAnimation(__VA_ARGS__)
  91. #define AnimationState_addAnimationByName(...) spAnimationState_addAnimationByName(__VA_ARGS__)
  92. #define AnimationState_addAnimation(...) spAnimationState_addAnimation(__VA_ARGS__)
  93. #define AnimationState_getCurrent(...) spAnimationState_getCurrent(__VA_ARGS__)
  94. #endif
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif /* SPINE_ANIMATIONSTATE_H_ */