Jo Engine  2023.08.26
Jo Sega Saturn Engine
sprite_animator.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2020, 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 {
105 }
106 
111 static __jo_force_inline bool jo_is_sprite_anim_stopped(const int anim_id)
112 {
114 }
115 
119 static __jo_force_inline void jo_stop_sprite_anim(const int anim_id)
120 {
122 }
123 
127 static __jo_force_inline void jo_start_sprite_anim(const int anim_id)
128 {
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 {
157 }
158 
162 static __jo_force_inline int jo_get_anim_sprite_reverse(const int anim_id)
163 {
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 
196 
197 #endif /* !__JO_SPRITE_ANIMATOR_H__ */
198 
199 /*
200 ** END OF FILE
201 */
jo_get_sprite_anim_frame_count
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
jo_reset_sprite_anim
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
jo_start_sprite_anim
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::frame0_sprite_id
unsigned short frame0_sprite_id
Definition: sprite_animator.h:50
JO_SPRITE_ANIM_STOP
@ JO_SPRITE_ANIM_STOP
Definition: sprite_animator.h:43
jo_get_anim_sprite_reverse
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
jo_restart_sprite_anim
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
jo_get_sprite_anim_frame
static __jo_force_inline unsigned short jo_get_sprite_anim_frame(const int anim_id)
Get current animation frame.
Definition: sprite_animator.h:85
jo_clear_all_sprite_anim
void jo_clear_all_sprite_anim(void)
Clear all sprite animation.
JO_SPRITE_ANIM_STOP_AT_LAST_FRAME
@ JO_SPRITE_ANIM_STOP_AT_LAST_FRAME
Definition: sprite_animator.h:44
jo_start_sprite_anim_loop
static __jo_force_inline void jo_start_sprite_anim_loop(const int anim_id)
Start animation loop.
Definition: sprite_animator.h:102
jo_sprite_anim::cur_frame
unsigned short cur_frame
Definition: sprite_animator.h:52
jo_set_sprite_anim_frame_rate
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_START
@ JO_SPRITE_ANIM_START
Definition: sprite_animator.h:41
JO_ZERO
#define JO_ZERO(X)
Set a variable to zero.
Definition: math.h:213
jo_sprite_anim::frame_count
unsigned short frame_count
Definition: sprite_animator.h:51
jo_replace_sprite_anim
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.
jo_sprite_anim::frame_rate
unsigned char frame_rate
Definition: sprite_animator.h:53
jo_is_sprite_anim_stopped
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
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: types.h:39
JO_SPRITE_ANIM_START_REVERSE
@ JO_SPRITE_ANIM_START_REVERSE
Definition: sprite_animator.h:42
jo_stop_sprite_anim
static __jo_force_inline void jo_stop_sprite_anim(const int anim_id)
Stop animation.
Definition: sprite_animator.h:119
jo_sprite_anim::action
jo_sprite_anim_action action
Definition: sprite_animator.h:55
__jo_sprite_anim_tab
jo_sprite_anim __jo_sprite_anim_tab[JO_MAX_SPRITE_ANIM]
Internal animation table.
jo_sprite_anim
Internal animation struct.
Definition: sprite_animator.h:49
jo_set_sprite_anim_frame
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
jo_get_anim_sprite
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_get_sprite_anim_frame_rate
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
jo_sprite_anim::frame_skip
unsigned char frame_skip
Definition: sprite_animator.h:54
jo_sprite_anim_action
jo_sprite_anim_action
Animation action.
Definition: sprite_animator.h:40
jo_create_sprite_anim
int jo_create_sprite_anim(const unsigned short sprite_id, const unsigned short frame_count, const unsigned char frame_rate)
Create an animation.