Jo Engine  9
Jo Sega Saturn Engine
sprite_animator.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2017, Johannes Fetz (johannesfetz@gmail.com)
4 ** All rights reserved.
5 **
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions are met:
8 ** * Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** * Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** * Neither the name of the Johannes Fetz nor the
14 ** names of its contributors may be used to endorse or promote products
15 ** derived from this software without specific prior written permission.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 ** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz 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 THIS
26 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
35 #ifndef __JO_SPRITE_ANIMATOR_H__
36 # define __JO_SPRITE_ANIMATOR_H__
37 
39 typedef enum
40 {
46 
48 typedef struct
49 {
50  unsigned short frame0_sprite_id;
51  unsigned short frame_count;
52  unsigned short cur_frame;
53  unsigned char frame_rate;
54  unsigned char frame_skip;
57 
61 extern jo_sprite_anim __jo_sprite_anim_tab[JO_MAX_SPRITE_ANIM];
62 
67 static __jo_force_inline unsigned char jo_get_sprite_anim_frame_rate(const int anim_id)
68 {
69  return __jo_sprite_anim_tab[anim_id].frame_rate;
70 }
71 
76 static __jo_force_inline unsigned short jo_get_sprite_anim_frame_count(const int anim_id)
77 {
78  return __jo_sprite_anim_tab[anim_id].frame_count;
79 }
80 
85 static __jo_force_inline unsigned short jo_get_sprite_anim_frame(const int anim_id)
86 {
87  return __jo_sprite_anim_tab[anim_id].cur_frame;
88 }
89 
94 static __jo_force_inline void jo_set_sprite_anim_frame(const int anim_id, const unsigned char frame)
95 {
96  __jo_sprite_anim_tab[anim_id].cur_frame = frame;
97 }
98 
102 static __jo_force_inline void jo_start_sprite_anim_loop(const int anim_id)
103 {
104  __jo_sprite_anim_tab[anim_id].action = JO_SPRITE_ANIM_START;
105 }
106 
111 static __jo_force_inline bool jo_is_sprite_anim_stopped(const int anim_id)
112 {
113  return __jo_sprite_anim_tab[anim_id].action == JO_SPRITE_ANIM_STOP;
114 }
115 
119 static __jo_force_inline void jo_stop_sprite_anim(const int anim_id)
120 {
121  __jo_sprite_anim_tab[anim_id].action = JO_SPRITE_ANIM_STOP;
122 }
123 
127 static __jo_force_inline void jo_start_sprite_anim(const int anim_id)
128 {
129  __jo_sprite_anim_tab[anim_id].action = JO_SPRITE_ANIM_STOP_AT_LAST_FRAME;
130 }
131 
135 static __jo_force_inline void jo_reset_sprite_anim(const int anim_id)
136 {
137  jo_stop_sprite_anim(anim_id);
138  JO_ZERO(__jo_sprite_anim_tab[anim_id].frame_skip);
139  JO_ZERO(__jo_sprite_anim_tab[anim_id].cur_frame);
140 }
141 
145 static __jo_force_inline void jo_restart_sprite_anim(const int anim_id)
146 {
147  jo_reset_sprite_anim(anim_id);
148  jo_start_sprite_anim(anim_id);
149 }
150 
154 static __jo_force_inline int jo_get_anim_sprite(const int anim_id)
155 {
156  return __jo_sprite_anim_tab[anim_id].frame0_sprite_id + __jo_sprite_anim_tab[anim_id].cur_frame;
157 }
158 
162 static __jo_force_inline int jo_get_anim_sprite_reverse(const int anim_id)
163 {
164  return __jo_sprite_anim_tab[anim_id].frame0_sprite_id + __jo_sprite_anim_tab[anim_id].frame_count - __jo_sprite_anim_tab[anim_id].cur_frame - 1;
165 }
166 
171 static __jo_force_inline int jo_set_sprite_anim_frame_rate(const int anim_id, const unsigned char framerate)
172 {
173  return __jo_sprite_anim_tab[anim_id].frame_rate = framerate;
174 }
175 
183 int jo_replace_sprite_anim(const int at, const unsigned short sprite_id, const unsigned short frame_count, const unsigned char frame_rate);
184 
191 int jo_create_sprite_anim(const unsigned short sprite_id, const unsigned short frame_count, const unsigned char frame_rate);
192 
195 void jo_clear_all_sprite_anim(void);
196 
197 #endif /* !__JO_SPRITE_ANIMATOR_H__ */
198 
199 /*
200 ** END OF FILE
201 */
static __jo_force_inline int jo_get_anim_sprite_reverse(const int anim_id)
Get the sprite to display according to the animation in reverse (current frame)
Definition: sprite_animator.h:162
Definition: sprite_animator.h:43
unsigned short cur_frame
Definition: sprite_animator.h:52
unsigned char frame_skip
Definition: sprite_animator.h:54
int jo_create_sprite_anim(const unsigned short sprite_id, const unsigned short frame_count, const unsigned char frame_rate)
Create an animation.
Internal animation struct.
Definition: sprite_animator.h:48
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: conf.h:154
void jo_clear_all_sprite_anim(void)
Clear all sprite animation.
static __jo_force_inline int jo_set_sprite_anim_frame_rate(const int anim_id, const unsigned char framerate)
Set animation framerate.
Definition: sprite_animator.h:171
jo_sprite_anim __jo_sprite_anim_tab[JO_MAX_SPRITE_ANIM]
Internal animation table.
static __jo_force_inline void jo_set_sprite_anim_frame(const int anim_id, const unsigned char frame)
Set animation frame.
Definition: sprite_animator.h:94
Definition: sprite_animator.h:42
unsigned short frame_count
Definition: sprite_animator.h:51
static __jo_force_inline void jo_reset_sprite_anim(const int anim_id)
Stop animation and reset the animation to the first frame.
Definition: sprite_animator.h:135
Definition: sprite_animator.h:41
static __jo_force_inline bool jo_is_sprite_anim_stopped(const int anim_id)
Determine if the animation is stopped.
Definition: sprite_animator.h:111
unsigned char frame_rate
Definition: sprite_animator.h:53
static __jo_force_inline void jo_restart_sprite_anim(const int anim_id)
Restart animation and stop it at the last frame.
Definition: sprite_animator.h:145
unsigned short frame0_sprite_id
Definition: sprite_animator.h:50
#define JO_ZERO(X)
Set a variable to zero.
Definition: math.h:56
static __jo_force_inline unsigned short jo_get_sprite_anim_frame_count(const int anim_id)
Get animation frame count.
Definition: sprite_animator.h:76
static __jo_force_inline void jo_start_sprite_anim(const int anim_id)
Start animation and stop it at the last frame.
Definition: sprite_animator.h:127
jo_sprite_anim_action action
Definition: sprite_animator.h:55
static __jo_force_inline int jo_get_anim_sprite(const int anim_id)
Get the sprite to display according to the animation (current frame)
Definition: sprite_animator.h:154
jo_sprite_anim_action
Animation action.
Definition: sprite_animator.h:39
static __jo_force_inline unsigned short jo_get_sprite_anim_frame(const int anim_id)
Get current animation frame.
Definition: sprite_animator.h:85
static __jo_force_inline unsigned char jo_get_sprite_anim_frame_rate(const int anim_id)
Get animation frame rate.
Definition: sprite_animator.h:67
static __jo_force_inline void jo_stop_sprite_anim(const int anim_id)
Stop animation.
Definition: sprite_animator.h:119
Definition: sprite_animator.h:44
int jo_replace_sprite_anim(const int at, const unsigned short sprite_id, const unsigned short frame_count, const unsigned char frame_rate)
Replace an existing animation.
static __jo_force_inline void jo_start_sprite_anim_loop(const int anim_id)
Start animation loop.
Definition: sprite_animator.h:102