Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
sprite_animator.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, 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*/
34
35#ifndef __JO_SPRITE_ANIMATOR_H__
36# define __JO_SPRITE_ANIMATOR_H__
37
46
48typedef 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
61extern jo_sprite_anim __jo_sprite_anim_tab[JO_MAX_SPRITE_ANIM];
62
63#ifdef JO_DEBUG
64
70# define __JO_SPRITE_ANIM_IS_WRONG(ANIM_ID) \
71 (((unsigned int)(ANIM_ID) >= JO_MAX_SPRITE_ANIM || __jo_sprite_anim_tab[ANIM_ID].frame_count == 0) && \
72 (jo_core_error("Wrong animation id (%d)", (int)(ANIM_ID)), true))
73
74#endif
75
80static __jo_force_inline unsigned char jo_get_sprite_anim_frame_rate(const int anim_id)
81{
82#ifdef JO_DEBUG
83 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
84 return (0);
85#endif
86 return __jo_sprite_anim_tab[anim_id].frame_rate;
87}
88
93static __jo_force_inline unsigned short jo_get_sprite_anim_frame_count(const int anim_id)
94{
95#ifdef JO_DEBUG
96 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
97 return (0);
98#endif
99 return __jo_sprite_anim_tab[anim_id].frame_count;
100}
101
106static __jo_force_inline unsigned short jo_get_sprite_anim_frame(const int anim_id)
107{
108#ifdef JO_DEBUG
109 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
110 return (0);
111#endif
112 return __jo_sprite_anim_tab[anim_id].cur_frame;
113}
114
119static __jo_force_inline void jo_set_sprite_anim_frame(const int anim_id, const unsigned short frame)
120{
121#ifdef JO_DEBUG
122 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
123 return;
124#endif
125 __jo_sprite_anim_tab[anim_id].cur_frame = frame;
126}
127
131static __jo_force_inline void jo_start_sprite_anim_loop(const int anim_id)
132{
133#ifdef JO_DEBUG
134 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
135 return;
136#endif
138}
139
144static __jo_force_inline bool jo_is_sprite_anim_stopped(const int anim_id)
145{
146#ifdef JO_DEBUG
147 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
148 return (true);
149#endif
151}
152
156static __jo_force_inline void jo_stop_sprite_anim(const int anim_id)
157{
158#ifdef JO_DEBUG
159 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
160 return;
161#endif
163}
164
168static __jo_force_inline void jo_start_sprite_anim(const int anim_id)
169{
170#ifdef JO_DEBUG
171 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
172 return;
173#endif
175}
176
180static __jo_force_inline void jo_reset_sprite_anim(const int anim_id)
181{
182#ifdef JO_DEBUG
183 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
184 return;
185#endif
186 jo_stop_sprite_anim(anim_id);
187 JO_ZERO(__jo_sprite_anim_tab[anim_id].frame_skip);
188 JO_ZERO(__jo_sprite_anim_tab[anim_id].cur_frame);
189}
190
194static __jo_force_inline void jo_restart_sprite_anim(const int anim_id)
195{
196#ifdef JO_DEBUG
197 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
198 return;
199#endif
200 jo_reset_sprite_anim(anim_id);
201 jo_start_sprite_anim(anim_id);
202}
203
207static __jo_force_inline int jo_get_anim_sprite(const int anim_id)
208{
209#ifdef JO_DEBUG
210 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
211 return (0);
212#endif
214}
215
220{
221#ifdef JO_DEBUG
222 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
223 return (0);
224#endif
226}
227
232static __jo_force_inline int jo_set_sprite_anim_frame_rate(const int anim_id, const unsigned char framerate)
233{
234#ifdef JO_DEBUG
235 if (__JO_SPRITE_ANIM_IS_WRONG(anim_id))
236 return (0);
237#endif
238 return __jo_sprite_anim_tab[anim_id].frame_rate = framerate;
239}
240
248int jo_replace_sprite_anim(const int at, const unsigned short sprite_id, const unsigned short frame_count, const unsigned char frame_rate);
249
256int jo_create_sprite_anim(const unsigned short sprite_id, const unsigned short frame_count, const unsigned char frame_rate);
257
261void jo_remove_sprite_anim(const int anim_id);
262
266
267#endif /* !__JO_SPRITE_ANIMATOR_H__ */
268
269/*
270** END OF FILE
271*/
#define JO_ZERO(X)
Set a variable to zero.
Definition math.h:240
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:180
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:232
unsigned short frame_count
Definition sprite_animator.h:51
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:168
static __jo_force_inline unsigned short jo_get_sprite_anim_frame(const int anim_id)
Get current animation frame.
Definition sprite_animator.h:106
unsigned char frame_rate
Definition sprite_animator.h:53
unsigned short frame0_sprite_id
Definition sprite_animator.h:50
void jo_remove_sprite_anim(const int anim_id)
Remove a specific animation by ID.
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_action
Animation action.
Definition sprite_animator.h:40
@ JO_SPRITE_ANIM_STOP
Definition sprite_animator.h:43
@ JO_SPRITE_ANIM_STOP_AT_LAST_FRAME
Definition sprite_animator.h:44
@ JO_SPRITE_ANIM_START
Definition sprite_animator.h:41
@ JO_SPRITE_ANIM_START_REVERSE
Definition sprite_animator.h:42
static __jo_force_inline bool jo_is_sprite_anim_stopped(const int anim_id)
Determine if the animation is stopped.
Definition sprite_animator.h:144
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:219
void jo_clear_all_sprite_anim(void)
Clear all sprite animation.
int jo_create_sprite_anim(const unsigned short sprite_id, const unsigned short frame_count, const unsigned char frame_rate)
Create an animation.
#define __JO_SPRITE_ANIM_IS_WRONG(ANIM_ID)
Check the id of an animation given to a function of the engine (Internal usage, JO_DEBUG).
Definition sprite_animator.h:70
jo_sprite_anim __jo_sprite_anim_tab[JO_MAX_SPRITE_ANIM]
Internal animation table.
unsigned short cur_frame
Definition sprite_animator.h:52
static __jo_force_inline unsigned char jo_get_sprite_anim_frame_rate(const int anim_id)
Get animation frame rate.
Definition sprite_animator.h:80
static __jo_force_inline void jo_start_sprite_anim_loop(const int anim_id)
Start animation loop.
Definition sprite_animator.h:131
static __jo_force_inline unsigned short jo_get_sprite_anim_frame_count(const int anim_id)
Get animation frame count.
Definition sprite_animator.h:93
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:207
static __jo_force_inline void jo_set_sprite_anim_frame(const int anim_id, const unsigned short frame)
Set animation frame.
Definition sprite_animator.h:119
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:194
unsigned char frame_skip
Definition sprite_animator.h:54
jo_sprite_anim_action action
Definition sprite_animator.h:55
static __jo_force_inline void jo_stop_sprite_anim(const int anim_id)
Stop animation.
Definition sprite_animator.h:156
Internal animation struct.
Definition sprite_animator.h:49
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39