spritestate.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef spritestate_H_INCLUDED
  2. #define spritestate_H_INCLUDED
  3. #define SPRITESTATE_LAYER_MAX 64
  4. #define SPRITESTATE_ACTION_MAX 32
  5. /* Dynamic information about a sprite layer. */
  6. enum SpriteStateLayerFlags_ {
  7. SPRITESTATE_LAYER_HIDDEN = 1 << 8,
  8. SPRITESTATE_LAYER_TINTED = 1 << 9,
  9. };
  10. enum SpriteStateActionFlags_ {
  11. SPRITESTATE_ACTION_LOOP = 1 << 10,
  12. SPRITESTATE_ACTION_ONESHOT = 1 << 11,
  13. SPRITESTATE_ACTION_STOP = 1 << 12,
  14. SPRITESTATE_ACTION_ONESTOP = SPRITESTATE_ACTION_STOP | SPRITESTATE_ACTION_ONESHOT,
  15. };
  16. typedef struct SpriteStateLayer_ SpriteStateLayer;
  17. /* State for a single sprite layer. */
  18. struct SpriteStateLayer_ {
  19. Color tint;
  20. int flags;
  21. };
  22. typedef struct SpriteStateAction_ SpriteStateAction;
  23. /* State for a single sprite action. */
  24. struct SpriteStateAction_ {
  25. int loop;
  26. int next_action;
  27. int done;
  28. };
  29. /* SpriteState contains dynamic information about a sprite. This was
  30. * separated out of Sprite to allow one sprite to be reused and shown differently
  31. * by several Things.
  32. */
  33. struct SpriteState_ {
  34. Sprite * sprite;
  35. SpriteAction * action_now;
  36. SpriteFrame * frame_now;
  37. int frame_index;
  38. int action_index;
  39. int pose_now;
  40. int direction_now;
  41. double time;
  42. double speedup;
  43. void * data;
  44. /* It's not worth while to use dynamical memory for these, IMO. */
  45. SpriteStateLayer layers[SPRITESTATE_LAYER_MAX];
  46. SpriteStateAction actions[SPRITESTATE_ACTION_MAX];
  47. };
  48. SpriteState * spritestate_alloc();
  49. Sprite * spritestate_sprite_(SpriteState * self, Sprite * sprite);
  50. SpriteState * spritestate_free(SpriteState * self);
  51. Sprite * spritestate_sprite(SpriteState * self);
  52. SpriteState * spritestate_init(SpriteState * self, Sprite * sprite, void * data);
  53. SpriteState * spritestate_done(SpriteState * self);
  54. double spritestate_speedup(SpriteState * self);
  55. double spritestate_speedup_(SpriteState * self, double speedup);
  56. SpriteState * spritestate_new(Sprite * sprite, void * data);
  57. int spritestate_can_draw_p(SpriteState * self);
  58. void spritestate_draw(SpriteState * self, Point * at);
  59. SpriteState * spritestate_now_(SpriteState * self, int actionnow, int framenow);
  60. void spritestate_update(SpriteState * self, double dt);
  61. int spriteaction_ispose(SpriteAction * self, int pose, int direction);
  62. int spritestate_pose_(SpriteState * self, int pose);
  63. int spritestate_pose(SpriteState * self);
  64. int spritestate_direction(SpriteState * self);
  65. int spritestate_direction_(SpriteState * self, int direction);
  66. int spritestate_posedirection_
  67. (SpriteState * self, int pose, int direction);
  68. int spritestate_tint_layer(SpriteState * self, int layer, Color color);
  69. int spritestate_remove_tint_layer(SpriteState * self, int layer);
  70. int spritestate_is_layer_tinted(SpriteState * self, int layer);
  71. Color * spritestate_get_layer_tint(SpriteState * self, int layer);
  72. int spritestate_set_layer_hidden(SpriteState * self, int layer, int hidden);
  73. int spritestate_get_layer_hidden(SpriteState * self, int layer);
  74. int spritestate_remove_tint_layer(SpriteState * self, int layer);
  75. int spritestate_is_layer_tinted(SpriteState * self, int layer);
  76. Color * spritestate_get_layer_tint(SpriteState * self, int layer);
  77. int spritestate_set_action_loop(SpriteState * self, int action, int loopmode);
  78. int spritestate_get_action_loop(SpriteState * self, int action);
  79. int spritestate_is_action_done(SpriteState * self, int action);
  80. int spritestate_set_pose_direction_loop(SpriteState * self, int pose, int direction, int loopmode);
  81. int spritestate_get_pose_direction_loop(SpriteState * self, int pose, int direction);
  82. Sprite * spritestate_sprite_(SpriteState * self, Sprite * sprite);
  83. Sprite * spritestate_sprite(SpriteState * self);
  84. void * spritestate_data(SpriteState * self);
  85. #endif