src/field/field_sprite_animation.c
Sprites, their animations and the picture caches they draw from. More…
Included by field.c.
Macros
| Name | Description | |
|---|---|---|
#define | SPRITE_SIZE_KEY (width, height) (((width) << 8) + (height)) | A sprite size as one number, width in the high byte and height in the low, to pick its OAM shape and size with one switch. |
Enumerations
| Name | Description | |
|---|---|---|
enum | anonymous enum { ANIM_SHADOW_TILE_BYTES, ANIM_OAM_FIELD_PRIORITY, PICTURE_CAC … } | The field sprites' shadow size, OAM priority, picture cache limits and basic colours. |
Functions
| Name | Description | |
|---|---|---|
Sint32 | fdSpritePictureCacheLoad (Uint32 slot, Uint32 *buf, Sint32 number, Uint32 variant) | Loads the pictures of animation number into picture cache slot, at buf: the resource SpritePictureCacheSources lists for it, decoded, its picture offsets turned into pointers, and for variant 1 to 5 its colours of the basic sprite palettes recoloured through that variant's table (a variant above 5 takes variant 1's). |
Sint32 | fdSpritePictureCacheFindByTag (Sint32 tag) | Returns the buffer loaded into the sprite picture cache with this tag, or 0. |
Sint32 | fdSpriteResetAnimations (SPR *sprite) | Resets each sprite animation of a sprite from its animation's metadata: its facing kind, pictures, scripts and codec, with no picture shown and no script running. |
void | fdSpriteAnimationReset (SPR_ANIMATION *layer) | Resets one sprite animation from its animation's metadata, as fdSpriteResetAnimations does for each sprite animation. |
Sint32 | fdSpriteAddAnimation (SPR *sprite, Sint32 id) | Adds a sprite animation of animation id to a sprite, in the first of its four slots that is free. |
void | fdSpriteRemoveAnimation (SPR *sprite, Sint32 layer) | Removes the sprite animation handle from a sprite and clears it, trimming the sprite's animation count when no later sprite animation remains. |
void | fdSpriteRemoveAnimationAt (SPR *sprite, Uint32 index) | Removes and clears a sprite's sprite animation index (0 to 3), trimming the sprite's animation count when no later sprite animation remains. |
void | fdSpriteAnimationStart (SPR_ANIMATION *layer, Sint32 animation) | Starts animation animation on one sprite animation, when its set has that many; SPRITE_ANIMATION_KEEP_PLACE keeps its place and timer. |
Sint32 | fdSpriteStartAnimation (SPR *sprite, Sint32 animation) | Starts animation (its SPRITE_ANIMATION_INDEX_MASK bits) on every sprite animation of a sprite, unless the sprite plays it already; SPRITE_ANIMATION_KEEP_PLACE keeps each one's place and timer. |
Sint32 | fdSpriteSetAnimationTimers (SPR *sprite, Sint32 ticks) | Sets each playing sprite animation's timer to the given duration in ticks. |
void | fdSpriteSetAnimationSpeed (SPR *sprite, Sint32 step) | Sets the timer step, the animation speed, of each playing sprite animation of a sprite (16 is normal speed). |
void | fdActorSystemConfigure (Sint32 mode) | Allocates and zeroes the 64 sprites and 64 sprite animations (HEAP_SLOT_SPRITES and HEAP_SLOT_SPRITE_ANIMATIONS, from EWRAM first in ACTOR_SYSTEM_WORLD_MAP and IWRAM first otherwise), loads the basic sprite palettes, loads the shadow tiles into VRAM_CACHE_ENTRY_ACTOR_SHADOW and puts the sprite tile uploader in RAM. |
SPR_ANIMATION * | fdSpriteAnimationAllocate (Sint32 id) | Takes a free sprite animation and starts it on the first animation of animation id; NULL when none is free. |
void | fdSpriteAnimationClear (SPR_ANIMATION *record) | Zeroes one sprite animation (SPR_ANIMATION); does nothing for NULL. |
SPR * | fdSpriteCreate (Sint32 id) | Creates a sprite for animation id, taking one of the 64 free sprites and a VRAM cache entry for its tiles. |
void | fdSpriteDestroy (SPR *sprite) | Releases a sprite: its VRAM cache entry (unless retainCacheEntry is set), its four sprite animations, and then zeroes its 56 bytes. |
Sint32 | fdSpriteAnimationSumCommandLengths (Sint32 id, Uint32 animation, Sint32 timedCount) | Returns how long, in ticks, the first timedCount timed commands of animation animation of animation id last: the sum of the arguments of its picture, wait and blank commands, up to timedCount of them or the first play, hold, jump or end command. |
Description
Sprites, their animations and the picture caches they draw from. Part of
field.c.
Macros in detail
SPRITE_SIZE_KEY
#define SPRITE_SIZE_KEY(width, height) (((width) << 8) + (height))
A sprite size as one number, width in the high byte and height in the low, to pick its OAM shape and size with one switch.
Referenced by fdSpriteCreate().
Definition at line 8 of file field_sprite_animation.c.
Enumerations in detail
anonymous enum
enum { ANIM_SHADOW_TILE_BYTES, ANIM_OAM_FIELD_PRIORITY, PICTURE_CACHE_SOURCES_MAX, PICTURE_CACHE_PICTURES_MAX, … }
The field sprites' shadow size, OAM priority, picture cache limits and basic colours.
| Enumerator | Value | Description |
|---|---|---|
ANIM_SHADOW_TILE_BYTES | 16 * 8 | 16x8 pixels, 256 colours |
ANIM_OAM_FIELD_PRIORITY | OBJ_PRIORITY(2) | Priority 2, the field's for its sprites: in front of a map layer at 3, or at 2 since a sprite wins a tie, and behind one at 1. |
PICTURE_CACHE_SOURCES_MAX | 256 | Rows of SpritePictureCacheSources searched, at most. |
PICTURE_CACHE_PICTURES_MAX | 256 | Picture offsets at the head of a decoded set, at most. |
BASIC_SPRITE_COLORS | 14 * PALETTE_COLORS | The colours of palettes 0 to 13, which syPaletteLoadBasicSpriteColors loads; a variant remaps only these. |
Definition at line 12 of file field_sprite_animation.c.
Functions in detail
fdSpritePictureCacheLoad
Sint32 fdSpritePictureCacheLoad(Uint32 slot, Uint32 *buf, Sint32 number, Uint32 variant)
Loads the pictures of animation number into picture cache slot, at buf:
the resource SpritePictureCacheSources lists for it, decoded, its picture
offsets turned into pointers, and for variant 1 to 5 its colours of the basic
sprite palettes recoloured through that variant's table (a variant above 5
takes variant 1's). Returns the size of one picture in pixels, or 0 when
nothing was loaded.
References pixels, Sint32, SpriteColorTables, SpritePictureCacheSources, syDecompressTaggedLZ(), syResourceGetMetadataRecordStub() and syResourceGetTableEntry().
Referenced by fdSpriteViewerRun().
Definition at line 36 of file field_sprite_animation.c.
fdSpritePictureCacheFindByTag
Sint32 fdSpritePictureCacheFindByTag(Sint32 tag)
Returns the buffer loaded into the sprite picture cache with this tag, or 0.
References Sint32.
Referenced by fdSpriteAnimationAllocate(), fdSpriteAnimationReset() and fdSpriteResetAnimations().
Definition at line 113 of file field_sprite_animation.c.
fdSpriteResetAnimations
Sint32 fdSpriteResetAnimations(SPR *sprite)
Resets each sprite animation of a sprite from its animation's metadata: its facing kind, pictures, scripts and codec, with no picture shown and no script running.
References fdSpritePictureCacheFindByTag(), Sint32 and syResourceGetMetadataRecordStub().
Referenced by fdActorSetFirstSpriteAnimation().
Definition at line 129 of file field_sprite_animation.c.
fdSpriteAnimationReset
void fdSpriteAnimationReset(SPR_ANIMATION *layer)
Resets one sprite animation from its animation's metadata, as
fdSpriteResetAnimations does for each sprite animation.
References fdSpritePictureCacheFindByTag() and syResourceGetMetadataRecordStub().
Referenced by fdSpriteViewerSetLayerSprite().
Definition at line 177 of file field_sprite_animation.c.
fdSpriteAddAnimation
Sint32 fdSpriteAddAnimation(SPR *sprite, Sint32 id)
Adds a sprite animation of animation id to a sprite, in the first of its
four slots that is free. Returns the new sprite animation, 0 when none is
free, or -1 when the sprite's four slots are taken.
References fdSpriteAnimationAllocate(), Sint32 and syResourceGetMetadataRecordStub().
Referenced by fdActorAddSpriteAnimation(), fdSpriteCreate(), fdSpriteViewerRun() and scAltinPeakRollCart().
Definition at line 207 of file field_sprite_animation.c.
fdSpriteRemoveAnimation
void fdSpriteRemoveAnimation(SPR *sprite, Sint32 layer)
Removes the sprite animation handle from a sprite and clears it, trimming the sprite's animation count when no later sprite animation remains.
References fdSpriteAnimationClear() and Sint32.
Definition at line 251 of file field_sprite_animation.c.
fdSpriteRemoveAnimationAt
void fdSpriteRemoveAnimationAt(SPR *sprite, Uint32 index)
Removes and clears a sprite's sprite animation index (0 to 3), trimming the
sprite's animation count when no later sprite animation remains.
References fdSpriteAnimationClear() and Sint32.
Definition at line 283 of file field_sprite_animation.c.
fdSpriteAnimationStart
void fdSpriteAnimationStart(SPR_ANIMATION *layer, Sint32 animation)
Starts animation animation on one sprite animation, when its set has that
many; SPRITE_ANIMATION_KEEP_PLACE keeps its place and timer.
References Sint32 and syResourceGetMetadataRecordStub().
Referenced by fdSpriteComposePicture().
Definition at line 312 of file field_sprite_animation.c.
fdSpriteStartAnimation
Sint32 fdSpriteStartAnimation(SPR *sprite, Sint32 animation)
Starts animation (its SPRITE_ANIMATION_INDEX_MASK bits) on every sprite
animation of a sprite, unless the sprite plays it already;
SPRITE_ANIMATION_KEEP_PLACE keeps each one's place and timer.
References Sint32 and syResourceGetMetadataRecordStub().
Referenced by fdActorMoveOnWorldMap(), fdActorSetAnimationAndSpeed(), fdActorUpdatePlayerControl(), scBilibinSpawnRipple(), scCottageRoomsBSpawnRingPair(), scMercuryLighthouseHopAcrossPool(), scMercuryLighthouseRestoreLights(), scMercuryLighthouseSpawnRipple(), scMercuryLighthouseSpawnSparkPair(), scSolSanctumEruptionRaiseGoldenRings(), scSpawnGoldenRing(), scSpawnPsynergyRings() and scValePlazaSpawnEffectPair().
Definition at line 343 of file field_sprite_animation.c.
fdSpriteSetAnimationTimers
Sint32 fdSpriteSetAnimationTimers(SPR *sprite, Sint32 ticks)
Sets each playing sprite animation's timer to the given duration in ticks. Returns 0.
References Sint32.
Definition at line 395 of file field_sprite_animation.c.
fdSpriteSetAnimationSpeed
void fdSpriteSetAnimationSpeed(SPR *sprite, Sint32 step)
Sets the timer step, the animation speed, of each playing sprite animation of a sprite (16 is normal speed).
References Sint32.
Referenced by fdActorSetAnimationAndSpeed().
Definition at line 420 of file field_sprite_animation.c.
fdActorSystemConfigure
void fdActorSystemConfigure(Sint32 mode)
Allocates and zeroes the 64 sprites and 64 sprite animations
(HEAP_SLOT_SPRITES and HEAP_SLOT_SPRITE_ANIMATIONS, from EWRAM first in
ACTOR_SYSTEM_WORLD_MAP and IWRAM first otherwise), loads the basic sprite
palettes, loads the shadow tiles into VRAM_CACHE_ENTRY_ACTOR_SHADOW and puts
the sprite tile uploader in RAM.
References ActorShadowTiles, fdTileCopyStrided, fdTileCopyStridedCodeSize, Sint32, syHeapSlotAllocate(), syHeapSlotAllocateEWRAM(), syPaletteLoadBasicSpriteColors() and syVRAMCacheLoad().
Referenced by fdActorSystemInit().
Definition at line 442 of file field_sprite_animation.c.
fdSpriteAnimationAllocate
SPR_ANIMATION *fdSpriteAnimationAllocate(Sint32 id)
Takes a free sprite animation and starts it on the first animation of
animation id; NULL when none is free.
References fdSpritePictureCacheFindByTag(), Sint32 and syResourceGetMetadataRecordStub().
Referenced by fdSpriteAddAnimation().
Definition at line 482 of file field_sprite_animation.c.
fdSpriteAnimationClear
void fdSpriteAnimationClear(SPR_ANIMATION *record)
Zeroes one sprite animation (SPR_ANIMATION); does nothing for NULL. Zeroing
kind frees the sprite animation for fdSpriteAnimationAllocate.
Referenced by fdSpriteDestroy(), fdSpriteRemoveAnimation(), fdSpriteRemoveAnimationAt(), scAltinPeakStopCartAndJumpOff() and scColossoShowItemIcon().
Definition at line 538 of file field_sprite_animation.c.
fdSpriteCreate
SPR *fdSpriteCreate(Sint32 id)
Creates a sprite for animation id, taking one of the 64 free sprites and a
VRAM cache entry for its tiles.
References fdSpriteAddAnimation(), memcpy(), Sint32, syResourceGetMetadataRecordStub(), syVRAMCacheFindFreeEntry(), syVRAMCacheLoad() and VramCacheEntries.
Referenced by fdActorCreate() and fdSpriteViewerRun().
Definition at line 550 of file field_sprite_animation.c.
fdSpriteDestroy
void fdSpriteDestroy(SPR *sprite)
Releases a sprite: its VRAM cache entry (unless retainCacheEntry is set), its
four sprite animations, and then zeroes its 56 bytes.
References fdSpriteAnimationClear(), Sint32 and syVRAMCacheFreeEntry().
Referenced by fdActorRelease().
Definition at line 647 of file field_sprite_animation.c.
fdSpriteAnimationSumCommandLengths
Sint32 fdSpriteAnimationSumCommandLengths(Sint32 id, Uint32 animation, Sint32 timedCount)
Returns how long, in ticks, the first timedCount timed commands of
animation animation of animation id last: the sum of the arguments of its
picture, wait and blank commands, up to timedCount of them or the first play,
hold, jump or end command.
References Sint32 and syResourceGetMetadataRecordStub().
Definition at line 667 of file field_sprite_animation.c.