OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
anim.h
Go to the documentation of this file.
1
51
52#ifndef OPENSNES_ANIM_H
53#define OPENSNES_ANIM_H
54
55#include <snes/types.h>
56
58#define ANIM_LOOP 0
60#define ANIM_ONCE 1
61
63#define ANIM_F_FINISHED 0x01
64
66#define ANIM_NONE 0xFFFF
67
80typedef struct {
81 const u16 *frames;
82 const u8 *durations;
87} AnimClip;
88
103
105#define ANIM_PLAYER_INIT {0, 0, 0, 0, 0}
106
124void animPlay(AnimPlayer *p, const AnimClip *clip);
125
130
142
144#define animFrame(_p) ((_p)->clip ? (_p)->clip->frames[(_p)->frame] : ANIM_NONE)
145
147#define animDone(_p) ((_p)->flags & ANIM_F_FINISHED)
148
150#define animStop(_p) do { (_p)->clip = 0; (_p)->flags = 0; } while (0)
151
163#define animTickOam(_p, _id) do { \
164 u16 _af = animTick(_p); \
165 if (_af != ANIM_NONE && oambuffer[_id].oamframeid != _af) { \
166 oambuffer[_id].oamframeid = _af; \
167 oambuffer[_id].oamrefresh = 1; \
168 } \
169} while (0)
170
184#define animTickMeta(_p, _tbl) ((_tbl)[animTick(_p)])
185
200#define DECLARE_ANIM_CLIP(name, mode_, speed_, ...) \
201 static const u16 name##_frames[] = { __VA_ARGS__ }; \
202 _Static_assert(sizeof(name##_frames) / sizeof(u16) <= 255, \
203 "DECLARE_ANIM_CLIP: a clip holds at most 255 frames"); \
204 static const AnimClip name = { \
205 name##_frames, \
206 0, \
207 (u8)(sizeof(name##_frames) / sizeof(u16)), \
208 (speed_), \
209 (mode_), \
210 0, \
211 }
212
213#endif /* OPENSNES_ANIM_H */
u16 animTick(AnimPlayer *p)
Advance one tick; return the current frame value.
void animPlay(AnimPlayer *p, const AnimClip *clip)
Start (or keep) a clip — continue-if-same semantics.
void animRestart(AnimPlayer *p)
Force-restart the current clip from frame 0, even mid-flight.
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:53
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:47
An animation clip — ROM-resident, 12 bytes.
Definition anim.h:80
u8 mode
Definition anim.h:85
const u8 * durations
Definition anim.h:82
u8 len
Definition anim.h:83
u8 reserved
Definition anim.h:86
u8 speed
Definition anim.h:84
const u16 * frames
Definition anim.h:81
A playback head — RAM, 8 bytes, array-friendly.
Definition anim.h:96
u8 flags
Definition anim.h:100
u8 ticks
Definition anim.h:99
u8 frame
Definition anim.h:98
u8 reserved
Definition anim.h:101
const AnimClip * clip
Definition anim.h:97
OpenSNES Standard Types.