52 record = &work->
slots[slot];
59 for (count = 0; count < 256; count++) {
63 entryNumber = *numbers;
74 for (count = 0; count < 256; count++) {
77 *offset += (
u32)buffer;
82 pixels = (
u8 *)(offset + 1);
83 end = (
u8 *)buffer + size;
88 for (; pixels < end; pixels++) {
89 u32 colorIndex = *pixels;
91 if (colorIndex <= 0xdf) {
92 colorIndex = colorMap[colorIndex];
121 for (i = 0; i < sprite->
count; i++) {
127 if (metadata->
width == 0)
167 if (metadata->
width != 0) {
198 if (layerHandle != 0) {
205 layerHandle = (
s32)*entry;
206 }
while (layerHandle != 0);
211 if (layerHandle == 0)
216 if (sprite->
count == 0) {
223 if (freeIndex == sprite->
count)
224 sprite->
count = freeIndex + 1;
236 if (sprite !=
NULL && layer != 0) {
250 if (laterLayers == 0)
251 sprite->
count = index;
264 layer = sprite->
entries[index];
274 if (laterLayers == 0)
275 sprite->
count = index;
300 layer->
script = (
u8 *)scriptAddress;
302 if (keepPlace == 0) {
303 layer->
pos = keepPlace;
304 layer->
timer = keepPlace;
336 s32 selectedAnimation;
338 if (layer != 0 && layer->
scripts != 0) {
343 layer->
script = (
u8 *)selectedAnimation;
345 if (keepPlace == 0) {
358 if (i < sprite->count)
380 if (layer != 0 && layer->
scripts != 0)
383 }
while (remaining != 0);
397 s32 remaining = count;
400 if (layer != 0 && layer->
scripts != 0)
403 }
while (remaining != 0);
459 if (metadata->
width != 0) {
462 if (candidate->
kind == 0) {
530 if (metadata->
width == 0)
534 if (sprite->
width == 0) {
539 if (freeSprite ==
NULL)
546 freeSprite->
slot = slot;
548 freeSprite->
flags = 1;
600 memcpy(freeSprite, attributes,
sizeof(attributes));
602 attribute = (
u32 *)freeSprite;
636 }
while (--remaining >= 0);
661 duration = script[1];
669 durationSum += duration;
671 if (frameCount == 0) {
void AnimationObjects_SetActiveTimerSteps(struct AnimationObject *sprite, s32 step)
Sets the timer step, the animation speed, of each animated layer of a sprite (16 is normal speed).
s32 ResourceSlot_Load(u32 slot, u32 *buffer, s32 number, u32 variant)
Loads the frames of animation id number into resource slot slot's buffer: the resource listed for it ...
s32 ResourceMetadata_Register(struct AnimationObject *sprite, s32 id)
Adds a layer of animation id to a sprite, in its first free layer of four.
struct AnimationEntry * AnimationObject_Allocate(s32 id)
Takes a free animation layer record and starts it on animation id's first animation.
void ResourceMetadata_ClearRecord(struct AnimationEntry *record)
Zeroes one animation layer (struct AnimationEntry); does nothing for NULL.
void ResourceMetadata_ReleaseSlot(struct AnimationObject *sprite, u32 index)
Removes and clears a sprite's layer number no (0-3), trimming the sprite's layer count when no later ...
void ObjectSystem_Configure(s32 mode)
Allocates and zeroes the 64 sprites and 64 animation layers (from the fixed blocks in mode 3,...
s32 AnimationObjects_SelectAnimation(struct AnimationObject *sprite, s32 animation)
Starts animation flags & 0x7f on every layer of a sprite (bit 7 keeps each layer's place and timer),...
s32 AnimationObjects_SetActiveFrameTimers(struct AnimationObject *sprite, s32 frames)
Sets each animated layer's timer to the given duration in frames.
void ResourceMetadata_Unregister(struct AnimationObject *sprite, s32 layer)
Removes the layer handle from a sprite and clears it, trimming the sprite's layer count when no later...
s32 Animation_LookupValueByKey(s32 tag)
Returns the buffer loaded into the resource slot with this tag, or 0.
void ResourceObject_Release(struct AnimationObject *sprite)
Releases a sprite: its VRAM cache entry (unless retainCacheEntry is set), its four animation layers,...
@ ANIMATION_OAM_FULL_COLOR
@ ANIMATION_OAM_PRIORITY_2
@ ANIMATION_SHADOW_CACHE_ENTRY
@ ANIMATION_SHADOW_TILE_BYTES
16x8 pixels, 256 colours
struct ResourceSlotNumber gResourceSlot_NumberTable[]
s32 Animation_InitializeObjects(struct AnimationObject *sprite)
Resets each layer of a sprite from its animation's metadata: its facing kind, frames,...
s32 ResourceMetadata_SumCommandLengths(s32 id, u32 animation, s32 frameCount)
Returns how long the first frameCount frames of animation number animation of id last: the sum of the...
void Animation_SetWorkEntry(struct AnimationEntry *layer, s32 animation)
Starts the indexed animation on a layer when its metadata contains it.
void Animation_InitWorkFromMetadata(struct AnimationEntry *layer)
Resets one animation layer from its animation's metadata, as Animation_InitializeObjects does for eac...
struct AnimationObject * ResourceObject_Create(s32 id)
Creates a sprite for animation id, taking one of the 64 free sprites and a VRAM cache entry for its t...
#define Dma_Fill32Cell(cell, value, destination, size)
Dma_Fill32 through the caller's own volatile word cell, so a function that fills several blocks keeps...
#define Dma_Fill32(value, destination, size)
Fills size bytes at destination with the word value by DMA3.
struct AnimationMetadata * Resource_GetMetadataRecordFar(u32 number)
What every part of the field object shares: its includes and the few names more than one part uses.
@ ANIM_CMD_JUMP
continue at script position arg
@ ANIM_CMD_WAIT
keep the current frame arg frames longer
@ ANIM_CMD_BLANK
show nothing for arg
@ ANIM_CMD_END
blank the layer and stop its script
@ ANIM_CMD_PLAY
switch to animation arg
@ ANIM_CMD_HOLD
stay on this command and frame for good
struct AnimationObject * gSpriteObjects
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
void * Runtime_AllocateHeapBlock(s32 kind, s32 size)
Returns heap slot kind's block, first allocating size bytes for it (rounded up to words),...
@ HEAP_SLOT_FRAME_UPLOADER
#define RamCode_LoadSlot(slot, code, bytes)
Allocates a work-slot copy; release it with Runtime_ReleaseHeapBlock.
s32 Resource_DecodeType01(const void *source, void *destination)
Decodes a type-01 resource and returns its unpacked byte count.
One animation layer of a sprite: its animation id, frames, running script and timer.
u8 param
SpriteColorMode its pixels are drawn with; 0 when taken.
u8 pos
byte offset of the next command in script
u8 ** scripts
the metadata's command scripts, one per animation number
u8 step
taken off timer each frame; 16 is normal speed
u8 * script
the running script; null when stopped (ANIM_CMD_END)
u8 kind
The facing table its frames follow (from the metadata, or ANIM_CMD_SET_KIND); zero marks a free layer...
s16 animId
the sprite id whose metadata and frames it uses
u8 mode
frame codec: 1 type-01, 3 LZ, anything else raw
void ** frames
frame pointers, from the metadata or a resource slot
u16 timer
Time left on the current frame in sixteenths of a frame, read signed: each timed command adds its arg...
u8 frame
frame shown, frameBase plus the facing offset; 255 none
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
u16 rotation
1/65536 turns
u8 flags
bits: 1 outlined in ObjectSystemWork's edge and fill colours | 0 shadow drawn (set when created)
u8 width
pixels; zero marks a free sprite
u8 lastNo
The animation number last selected, which selecting again skips.
u8 slot
VRAM cache entry holding its tiles.
struct AnimationEntry * entries[4]
its layers; empty ones null
u8 count
layers in use, up to the last one present
s32 scale
16.16 fixed point, 0x10000 full size
u8 retainCacheEntry
Keeps the VRAM cache entry when it is released or off screen.
u8 dirty
nonzero redraws its pixels into VRAM when next drawn
The hardware sprite attributes one part of an animated sprite (its image or its shadow) is drawn with...
u16 tile
first sprite tile in VRAM
The object system's work: the flag that suspends sprite projection, the outline's edge and fill colou...
struct ResourceSlot slots[8]
A row of gResourceSlot_NumberTable: the packed resource that holds an animation number's frames,...
A resource slot: the tag of the animation loaded into it (slot number and animation id) and the buffe...
s32 tag
(slot << 12) | animation id
void * buffer
the decoded frames, their offsets made pointers
u16 offset
bytes from the start of OBJ VRAM
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.
u8 gResourceSlot_ConversionTables[][256]
const u8 gObject_ShadowTiles[]
struct AnimationEntry * gAnimationObjects[]
u8 Tile_CopyStridedCodeSize[]
void Palette_LoadBasicObjColors(void)
Loads the basic sprite palettes (palettes 0 to 13).
void * memcpy(void *destination, const void *source, unsigned long size)
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
s32 Resource_FindFreeEntry(void)
Returns the number of the first free cache entry, or VRAM_CACHE_ENTRY_COUNT when all are taken.
s32 VramCache_Load(u32 no, u32 size, const void *src)
Gives cache entry no size bytes of sprite VRAM and copies src there.
struct VramBlockCacheEntry gVramBlockCache[]