Jo Engine 2026.11.1
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
67static __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
76static __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
85static __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
94static __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
102static __jo_force_inline void jo_start_sprite_anim_loop(const int anim_id)
103{
105}
106
111static __jo_force_inline bool jo_is_sprite_anim_stopped(const int anim_id)
112{
114}
115
119static __jo_force_inline void jo_stop_sprite_anim(const int anim_id)
120{
122}
123
131
135static __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
145static __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
154static __jo_force_inline int jo_get_anim_sprite(const int anim_id)
155{
157}
158
166
171static __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
183int jo_replace_sprite_anim(const int at, const unsigned short sprite_id, const unsigned short frame_count, const unsigned char frame_rate);
184
191int jo_create_sprite_anim(const unsigned short sprite_id, const unsigned short frame_count, const unsigned char frame_rate);
192
196void jo_remove_sprite_anim(const int anim_id);
197
201
202#endif /* !__JO_SPRITE_ANIMATOR_H__ */
203
204/*
205** END OF FILE
206*/
#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:135
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
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:127
static __jo_force_inline unsigned short jo_get_sprite_anim_frame(const int anim_id)
Get current animation frame.
Definition sprite_animator.h:85
unsigned char frame_rate
Definition sprite_animator.h:53
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
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:111
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
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.
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:67
static __jo_force_inline void jo_start_sprite_anim_loop(const int anim_id)
Start animation loop.
Definition sprite_animator.h:102
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 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
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 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:119
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