Alchemy
Loading...
Searching...
No Matches

animspr.h

Go to the documentation of this file.
1#ifndef ALCHEMY_ANIMSPR_H
2#define ALCHEMY_ANIMSPR_H
3
4/// @file
5/// Animated sprites: their layers, frames and colour modes, and the resource
6/// slots they draw from.
7
8#include "edition.h"
9#include "types.h"
10#include "static_assert.h"
11#include "render_placement.h"
12
13/// AnimationEntry.param: how Render_DecodeFrame colours a layer's pixels.
14/// Modes 1 to 6 and 9 to 11 run them through a 256-byte table (the five
15/// gResourceSlot_ConversionTables, then the four gRuntime_ByteRemapTable
16/// ones); the solid modes paint every drawn pixel one colour of the basic
17/// sprite palette. Mode 8 is a second white and mode 12 reads past the tables.
20 SPRITE_COLOR_GRB = 1, ///< red and green swapped
21 SPRITE_COLOR_RBG = 2, ///< green and blue swapped
22 SPRITE_COLOR_BGR = 3, ///< red and blue swapped
23 SPRITE_COLOR_GBR = 4, ///< red to blue, green to red, blue to green
24 SPRITE_COLOR_BRG = 5, ///< red to green, green to blue, blue to red
25 SPRITE_COLOR_GREY = 6, ///< greyscale
26 SPRITE_COLOR_WHITE = 7, ///< solid colour 15, white
27 SPRITE_COLOR_BLUE_TINT = 9, ///< blue raised to full
28 SPRITE_COLOR_RED_TINT = 10, ///< red raised to full
29 SPRITE_COLOR_GREEN_TINT = 11, ///< green raised to full
30 SPRITE_COLOR_FILL = 13, ///< solid gDecodeFillByte
31 SPRITE_COLOR_BLACK = 14, ///< solid colour 1, black
32 SPRITE_COLOR_HIDDEN = 15 ///< solid colour 0, transparent
33};
34
35/// One animation layer of a sprite: its animation id, frames, running script
36/// and timer.
38 s16 animId; ///< the sprite id whose metadata and frames it uses
39 /// Time left on the current frame in sixteenths of a frame, read signed:
40 /// each timed command adds its argument times 16, each frame takes off step.
42 /// The facing table its frames follow (from the metadata, or
43 /// ANIM_CMD_SET_KIND); zero marks a free layer record.
45 u8 param; ///< SpriteColorMode its pixels are drawn with; 0 when taken
46 u8 priority; ///< drawing order 0 to 3 among the layers; above 3 not drawn
47 u8 mode; ///< frame codec: 1 type-01, 3 LZ, anything else raw
48 void **frames; ///< frame pointers, from the metadata or a resource slot
49 u8 **scripts; ///< the metadata's command scripts, one per animation number
50 u8 *script; ///< the running script; null when stopped (ANIM_CMD_END)
51 u8 pos; ///< byte offset of the next command in script
52 u8 step; ///< taken off timer each frame; 16 is normal speed
53 u8 frame; ///< frame shown, frameBase plus the facing offset; 255 none
54 u8 frameBase; ///< frame the script chose, before facing; 255 blank
55};
56
57/// A resource slot: the tag of the animation loaded into it (slot number and
58/// animation id) and the buffer holding its frames.
60 s32 tag; ///< (slot << 12) | animation id
61 void *buffer; ///< the decoded frames, their offsets made pointers
62};
63
64/// The object system's work: the flag that suspends sprite projection, the
65/// outline's edge and fill colours, and the resource slots. Heap slot 6.
67 u16 used; ///< sprite pixel bytes composed since the camera reset it
68 u8 unk02[2]; ///< not named by TBS code
69 s16 suspended; ///< nonzero while a menu has suspended sprite projection
70 u8 edge; ///< outline edge colour; 15 when the field sets up
71 u8 fill; ///< outline fill colour; 0 when the field sets up
72 u8 unk08[0x10]; ///< the sprite group tables, taken in turn by count
73 s32 count; ///< sprite group tables taken from unk08
75};
76
77STATIC_ASSERT(offsetof(struct ObjectSystemWork, suspended) == 4);
78STATIC_ASSERT(offsetof(struct ObjectSystemWork, count) == 0x18);
79STATIC_ASSERT(offsetof(struct ObjectSystemWork, slots) == 0x1c);
80STATIC_ASSERT(sizeof(struct ObjectSystemWork) == 0x5c);
81
82/// The hardware sprite attributes one part of an animated sprite (its image or
83/// its shadow) is drawn with.
85 /// The link to the next part queued in the same depth slot this frame
86 /// (Runtime_PushSlotEntry).
88 /// The OAM entry's attributes 0 to 2.
89 ///@{
90 u16 y : 8; ///< screen pixels
91 u16 affine : 2; ///< 0 plain, 1 affine, 3 affine at double size
94 u16 fullColor : 1; ///< 256 colours; set for both parts when created
96 u16 x : 9; ///< screen pixels
97 u16 affineIndex : 5; ///< affine matrix, or 8 for a mirrored plain sprite
98 u16 size : 2;
99 u16 tile : 10; ///< first sprite tile in VRAM
100 u16 priority : 2; ///< 2 when created
102 ///@}
103 u8 unk0a[2]; ///< zero when created; not named by TBS code
104};
105
106/// An animated sprite: its image and shadow, scale, rotation, size and up to
107/// four animation layers.
111 s32 scale; ///< 16.16 fixed point, 0x10000 full size
112 u8 slot; ///< VRAM cache entry holding its tiles
113 /// Keeps the VRAM cache entry when it is released or off screen.
115 /// Drawn at its own scale, not scaled by distance (fixed camera).
117 u8 unk1d2 : 6; ///< not named by TBS code
118 u16 rotation; ///< 1/65536 turns
119 u8 width; ///< pixels; zero marks a free sprite
120 u8 height; ///< pixels
121 s8 offsetX; ///< pixels
122 s8 offsetY; ///< pixels
123 /// The animation number last selected, which selecting again skips.
125 u8 dirty; ///< nonzero redraws its pixels into VRAM when next drawn
126 /// bits: 1 outlined in ObjectSystemWork's edge and fill colours |
127 /// 0 shadow drawn (set when created)
129 u8 count; ///< layers in use, up to the last one present
130 struct AnimationEntry *entries[4]; ///< its layers; empty ones null
131};
132
133STATIC_ASSERT(sizeof(struct AnimationEntry) == 0x18);
134STATIC_ASSERT(sizeof(struct AnimationSpritePart) == 0x0c);
135STATIC_ASSERT(offsetof(struct AnimationObject, scale) == 0x18);
136STATIC_ASSERT(offsetof(struct AnimationObject, rotation) == 0x1e);
137STATIC_ASSERT(offsetof(struct AnimationObject, width) == 0x20);
138STATIC_ASSERT(sizeof(struct AnimationObject) == 0x38);
139STATIC_ASSERT(offsetof(struct AnimationObject, entries) == 0x28);
140
141#endif
SpriteColorMode
AnimationEntry.param: how Render_DecodeFrame colours a layer's pixels.
Definition animspr.h:18
@ SPRITE_COLOR_NORMAL
Definition animspr.h:19
@ SPRITE_COLOR_BGR
red and blue swapped
Definition animspr.h:22
@ SPRITE_COLOR_BLACK
solid colour 1, black
Definition animspr.h:31
@ SPRITE_COLOR_WHITE
solid colour 15, white
Definition animspr.h:26
@ SPRITE_COLOR_RED_TINT
red raised to full
Definition animspr.h:28
@ SPRITE_COLOR_GRB
red and green swapped
Definition animspr.h:20
@ SPRITE_COLOR_GREEN_TINT
green raised to full
Definition animspr.h:29
@ SPRITE_COLOR_HIDDEN
solid colour 0, transparent
Definition animspr.h:32
@ SPRITE_COLOR_GBR
red to blue, green to red, blue to green
Definition animspr.h:23
@ SPRITE_COLOR_FILL
solid gDecodeFillByte
Definition animspr.h:30
@ SPRITE_COLOR_BRG
red to green, green to blue, blue to red
Definition animspr.h:24
@ SPRITE_COLOR_BLUE_TINT
blue raised to full
Definition animspr.h:27
@ SPRITE_COLOR_RBG
green and blue swapped
Definition animspr.h:21
@ SPRITE_COLOR_GREY
greyscale
Definition animspr.h:25
The edition's language, for C to compare (LANGUAGE == LANGUAGE_GERMAN).
A sprite's screen position and scale.
STATIC_ASSERT, a compile-time check that emits nothing.
#define STATIC_ASSERT(condition)
C89 permits repeated extern declarations of the same array.
#define offsetof(type, member)
Definition stddef.h:19
One animation layer of a sprite: its animation id, frames, running script and timer.
Definition animspr.h:37
u8 frameBase
frame the script chose, before facing; 255 blank
Definition animspr.h:54
u8 param
SpriteColorMode its pixels are drawn with; 0 when taken.
Definition animspr.h:45
u8 pos
byte offset of the next command in script
Definition animspr.h:51
u8 ** scripts
the metadata's command scripts, one per animation number
Definition animspr.h:49
u8 step
taken off timer each frame; 16 is normal speed
Definition animspr.h:52
u8 * script
the running script; null when stopped (ANIM_CMD_END)
Definition animspr.h:50
u8 kind
The facing table its frames follow (from the metadata, or ANIM_CMD_SET_KIND); zero marks a free layer...
Definition animspr.h:44
s16 animId
the sprite id whose metadata and frames it uses
Definition animspr.h:38
u8 mode
frame codec: 1 type-01, 3 LZ, anything else raw
Definition animspr.h:47
void ** frames
frame pointers, from the metadata or a resource slot
Definition animspr.h:48
u16 timer
Time left on the current frame in sixteenths of a frame, read signed: each timed command adds its arg...
Definition animspr.h:41
u8 frame
frame shown, frameBase plus the facing offset; 255 none
Definition animspr.h:53
u8 priority
drawing order 0 to 3 among the layers; above 3 not drawn
Definition animspr.h:46
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
struct AnimationSpritePart shadow
Definition animspr.h:110
s8 offsetX
pixels
Definition animspr.h:121
s8 offsetY
pixels
Definition animspr.h:122
struct AnimationSpritePart image
Definition animspr.h:109
u16 rotation
1/65536 turns
Definition animspr.h:118
u8 flags
bits: 1 outlined in ObjectSystemWork's edge and fill colours | 0 shadow drawn (set when created)
Definition animspr.h:128
u8 width
pixels; zero marks a free sprite
Definition animspr.h:119
u8 height
pixels
Definition animspr.h:120
u8 lastNo
The animation number last selected, which selecting again skips.
Definition animspr.h:124
u8 slot
VRAM cache entry holding its tiles.
Definition animspr.h:112
struct AnimationEntry * entries[4]
its layers; empty ones null
Definition animspr.h:130
u8 count
layers in use, up to the last one present
Definition animspr.h:129
u8 useOwnScale
Drawn at its own scale, not scaled by distance (fixed camera).
Definition animspr.h:116
u8 unk1d2
not named by TBS code
Definition animspr.h:117
s32 scale
16.16 fixed point, 0x10000 full size
Definition animspr.h:111
u8 retainCacheEntry
Keeps the VRAM cache entry when it is released or off screen.
Definition animspr.h:114
u8 dirty
nonzero redraws its pixels into VRAM when next drawn
Definition animspr.h:125
The hardware sprite attributes one part of an animated sprite (its image or its shadow) is drawn with...
Definition animspr.h:84
u16 fullColor
256 colours; set for both parts when created
Definition animspr.h:94
u8 unk0a[2]
zero when created; not named by TBS code
Definition animspr.h:103
u16 y
The OAM entry's attributes 0 to 2.
Definition animspr.h:90
u16 x
screen pixels
Definition animspr.h:96
u8 unk00[4]
The link to the next part queued in the same depth slot this frame (Runtime_PushSlotEntry).
Definition animspr.h:87
u16 tile
first sprite tile in VRAM
Definition animspr.h:99
u16 affine
0 plain, 1 affine, 3 affine at double size
Definition animspr.h:91
u16 affineIndex
affine matrix, or 8 for a mirrored plain sprite
Definition animspr.h:97
u16 priority
2 when created
Definition animspr.h:100
The object system's work: the flag that suspends sprite projection, the outline's edge and fill colou...
Definition animspr.h:66
u16 used
sprite pixel bytes composed since the camera reset it
Definition animspr.h:67
struct ResourceSlot slots[8]
Definition animspr.h:74
u8 unk02[2]
not named by TBS code
Definition animspr.h:68
u8 fill
outline fill colour; 0 when the field sets up
Definition animspr.h:71
s16 suspended
nonzero while a menu has suspended sprite projection
Definition animspr.h:69
s32 count
sprite group tables taken from unk08
Definition animspr.h:73
u8 edge
outline edge colour; 15 when the field sets up
Definition animspr.h:70
u8 unk08[0x10]
the sprite group tables, taken in turn by count
Definition animspr.h:72
A resource slot: the tag of the animation loaded into it (slot number and animation id) and the buffe...
Definition animspr.h:59
s32 tag
(slot << 12) | animation id
Definition animspr.h:60
void * buffer
the decoded frames, their offsets made pointers
Definition animspr.h:61
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
signed char s8
Definition types.h:10
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11