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 … } | Sizes and limits of the field's sprite pictures. |
Functions
| Name | Description | |
|---|---|---|
Sint32 | fdSpritePictureCacheLoad (Uint32 slot, Uint32 *buf, Sint32 number, Uint32 variant) | Loads the pictures of animation id number into picture cache slot's buffer: the resource listed for it in SpritePictureCacheSources, decoded, its picture offsets turned into pointers, and for variant 1-5 its pixel colours (those up to 223, the basic sprite palettes 0 to 13) remapped through that variant's conversion table; a variant above 5 uses variant 1's. |
Sint32 | fdSpritePictureCacheFindByTag (Sint32 tag) | Returns the pictures 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 *spriteAnimation) | Resets a sprite animation from its metadata: its pictures, scripts, codec and drawing kind, with no script running and no picture shown. |
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 it, 0 when none could be taken, or -1 when all four are in use. |
void | fdSpriteRemoveAnimation (SPR *sprite, Sint32 spriteAnimation) | Removes a sprite animation from its 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 the sprite animation in a sprite's slot index (0 to 3), trimming the sprite's animation count when no later sprite animation remains. |
void | fdSpriteAnimationStart (SPR_ANIMATION *spriteAnimation, Sint32 animation) | Starts the indexed animation on a sprite animation when its metadata contains it. |
Sint32 | fdSpriteStartAnimation (SPR *sprite, Sint32 animation) | Starts an animation on every sprite animation of a sprite (SPRITE_ANIMATION_KEEP_PLACE keeps each one's place and timer), unless the sprite plays it already. |
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) | Takes the sprite and sprite animation pools (from EWRAM first on the World Map, ACTOR_SYSTEM_WORLD_MAP, and IWRAM first otherwise) and clears them, loads the shadow tiles into VRAM cache entry VRAM_CACHE_ENTRY_ACTOR_SHADOW and copies the strided tile copier into RAM. |
void | fdActorShadowFreeTiles (void) | Frees the actors' shadow tiles (VRAM_CACHE_ENTRY_ACTOR_SHADOW). |
void | fdActorShadowLoadTiles (void) | Loads the actors' shadow tiles into VRAM_CACHE_ENTRY_ACTOR_SHADOW. |
SPR_ANIMATION * | fdSpriteAnimationAllocate (Sint32 id) | Takes a free sprite animation and starts it on animation id's first animation. |
void | fdSpriteAnimationClear (void *record) | Zeroes one sprite animation (SPR_ANIMATION); does nothing for NULL. |
struct RESOURCE_OBJECT * | 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: gives back its VRAM cache entry unless it keeps it (retainCacheEntry), clears its four sprite animations and zeroes it. |
Sint32 | fdSpriteAnimationSumCommandLengths (Sint32 id, Uint32 animation, Sint32 timedCount) | Returns how many ticks the first timedCount timed steps of animation number animation of sprite id last. |
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 6 of file field_sprite_animation.c.
Enumerations in detail
anonymous enum
enum { ANIM_SHADOW_TILE_BYTES, ANIM_OAM_FIELD_PRIORITY, PICTURE_CACHE_TAG_SLOT_SHIFT, PICTURE_CACHE_SOURCES_MAX, … }
Sizes and limits of the field's sprite pictures.
| 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_TAG_SLOT_SHIFT | 12 | A picture cache's tag holds its slot above the animation id's bits. |
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 * 16 | The colours of palettes 0 to 13, which syPaletteLoadBasicSpriteColors loads; a variant remaps only these. |
Definition at line 9 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 id number into picture cache slot's buffer:
the resource listed for it in SpritePictureCacheSources, decoded, its picture
offsets turned into pointers, and for variant 1-5 its pixel colours (those up
to 223, the basic sprite palettes 0 to 13) remapped through that variant's
conversion table; a variant above 5 uses variant 1's.
References fdResourceGetMetadataRecordStub(), Sint32, SpriteColorTables, SpritePictureCacheSources, syDecompressTaggedLZ() and syResourceGetTableEntry().
Referenced by fdSpriteViewerRun().
Definition at line 37 of file field_sprite_animation.c.
fdSpritePictureCacheFindByTag
Sint32 fdSpritePictureCacheFindByTag(Sint32 tag)
Returns the pictures loaded into the sprite picture cache with this tag, or 0.
References Sint32.
Referenced by fdSpriteAnimationAllocate(), fdSpriteAnimationReset() and fdSpriteResetAnimations().
Definition at line 111 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 fdResourceGetMetadataRecordStub(), fdSpritePictureCacheFindByTag() and Sint32.
Referenced by fdActorSetFirstSpriteAnimation().
Definition at line 130 of file field_sprite_animation.c.
fdSpriteAnimationReset
void fdSpriteAnimationReset(SPR_ANIMATION *spriteAnimation)
Resets a sprite animation from its metadata: its pictures, scripts, codec and drawing kind, with no script running and no picture shown.
References fdResourceGetMetadataRecordStub() and fdSpritePictureCacheFindByTag().
Referenced by fdSpriteViewerSetLayerSprite().
Definition at line 186 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 it, 0 when none could be taken, or -1 when all four are in use.
References fdResourceGetMetadataRecordStub(), fdSpriteAnimationAllocate() and Sint32.
Referenced by fdActorAddSpriteAnimation(), fdSpriteCreate(), fdSpriteViewerRun(), scAquaRockAddMoaiWater(), scAquaRockInsideAddMoaiWater(), scGaiaRockInsideTurnFaceToAltar() and scMoaiAddWater().
Definition at line 217 of file field_sprite_animation.c.
fdSpriteRemoveAnimation
void fdSpriteRemoveAnimation(SPR *sprite, Sint32 spriteAnimation)
Removes a sprite animation from its sprite and clears it, trimming the sprite's animation count when no later sprite animation remains.
References fdSpriteAnimationClear() and Sint32.
Definition at line 260 of file field_sprite_animation.c.
fdSpriteRemoveAnimationAt
void fdSpriteRemoveAnimationAt(SPR *sprite, Uint32 index)
Removes and clears the sprite animation in a sprite's slot index (0 to 3), trimming the sprite's animation count when no later sprite animation remains.
References fdSpriteAnimationClear() and Sint32.
Definition at line 291 of file field_sprite_animation.c.
fdSpriteAnimationStart
void fdSpriteAnimationStart(SPR_ANIMATION *spriteAnimation, Sint32 animation)
Starts the indexed animation on a sprite animation when its metadata contains
it. Unlike fdSpriteStartAnimation it does not mask
SPRITE_ANIMATION_KEEP_PLACE off, so with it set the index would pass
animationCount only in a set of more than 128 animations.
References fdResourceGetMetadataRecordStub() and Sint32.
Referenced by fdSpriteComposePicture().
Definition at line 322 of file field_sprite_animation.c.
fdSpriteStartAnimation
Sint32 fdSpriteStartAnimation(SPR *sprite, Sint32 animation)
Starts an animation on every sprite animation of a sprite
(SPRITE_ANIMATION_KEEP_PLACE keeps each one's place and timer), unless the
sprite plays it already.
References fdResourceGetMetadataRecordStub() and Sint32.
Referenced by fdActorFlyOnWorldMap(), fdActorMoveAsSand(), fdActorMoveAsSandOnWorldMap(), fdActorMoveOnWorldMap(), fdActorSailOnWorldMap(), fdActorSelectAnimation(), fdActorSetAnimationAndSpeed(), fdActorSpawnWaterSplash(), fdActorUpdatePlayerControl(), scActorEmitRipples(), scActorSpawnWadingSplash(), scAquaRockInsideSplashBeneath(), scKandoreanTempleSpawnSplashRing(), scStaffCreditSpawnGrowingPair(), scTaopoSwampSinkInMud(), scTaopoSwampSinkStump(), scWorldMapSpawnParticle(), scWorldMapSpawnSparkPair() and scWorldMapSpawnTwinSparks().
Definition at line 351 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.
Referenced by scGabombaStatueSetCogTurn().
Definition at line 405 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(), fdActorSetAnimationSpeed(), fdActorSpawnWaterSplash() and scTaopoSwampSinkStump().
Definition at line 424 of file field_sprite_animation.c.
fdActorSystemConfigure
void fdActorSystemConfigure(Sint32 mode)
Takes the sprite and sprite animation pools (from EWRAM first on the World
Map, ACTOR_SYSTEM_WORLD_MAP, and IWRAM first otherwise) and clears them,
loads the shadow tiles into VRAM cache entry VRAM_CACHE_ENTRY_ACTOR_SHADOW
and copies the strided tile copier into RAM.
References ActorShadowTiles, fdRenderCopyStridedCode, fdRenderCopyStridedCodeSize, Sint32, syHeapSlotAllocate(), syHeapSlotAllocateEWRAM(), syPaletteLoadBasicSpriteColors() and syVRAMCacheLoad().
Referenced by fdActorSystemInit().
Definition at line 441 of file field_sprite_animation.c.
fdActorShadowFreeTiles
void fdActorShadowFreeTiles(void)
Frees the actors' shadow tiles (VRAM_CACHE_ENTRY_ACTOR_SHADOW).
References syVRAMCacheFreeEntry().
Definition at line 476 of file field_sprite_animation.c.
fdActorShadowLoadTiles
void fdActorShadowLoadTiles(void)
Loads the actors' shadow tiles into VRAM_CACHE_ENTRY_ACTOR_SHADOW.
References ActorShadowTiles, Sint32 and syVRAMCacheLoad().
Definition at line 482 of file field_sprite_animation.c.
fdSpriteAnimationAllocate
SPR_ANIMATION *fdSpriteAnimationAllocate(Sint32 id)
Takes a free sprite animation and starts it on animation id's first animation.
References fdResourceGetMetadataRecordStub(), fdSpritePictureCacheFindByTag() and Sint32.
Referenced by fdSpriteAddAnimation().
Definition at line 492 of file field_sprite_animation.c.
fdSpriteAnimationClear
void fdSpriteAnimationClear(void *record)
Zeroes one sprite animation (SPR_ANIMATION); does nothing for NULL. Zeroing
kind frees the sprite animation for fdSpriteAnimationAllocate.
Referenced by fdSpriteDestroy(), fdSpriteRemoveAnimation(), fdSpriteRemoveAnimationAt() and scActorScatterCrumbs().
Definition at line 546 of file field_sprite_animation.c.
fdSpriteCreate
struct RESOURCE_OBJECT *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 fdResourceGetMetadataRecordStub(), fdSpriteAddAnimation(), Sint32, syVRAMCacheFindFreeEntry(), syVRAMCacheLoad() and VramCacheEntries.
Referenced by fdActorCreate() and fdSpriteViewerRun().
Definition at line 558 of file field_sprite_animation.c.
fdSpriteDestroy
void fdSpriteDestroy(SPR *sprite)
Releases a sprite: gives back its VRAM cache entry unless it keeps it
(retainCacheEntry), clears its four sprite animations and zeroes it.
References fdSpriteAnimationClear(), Sint32 and syVRAMCacheFreeEntry().
Referenced by fdActorRelease().
Definition at line 637 of file field_sprite_animation.c.
fdSpriteAnimationSumCommandLengths
Sint32 fdSpriteAnimationSumCommandLengths(Sint32 id, Uint32 animation, Sint32 timedCount)
Returns how many ticks the first timedCount timed steps of animation number
animation of sprite id last. Commands are two bytes (command, value);
ANIMCMD_PLAY, ANIMCMD_HOLD, ANIMCMD_JUMP and ANIMCMD_END end the count, and
the values of ANIMCMD_WAIT, ANIMCMD_BLANK and the pictures below ANIMCMD_END
count.
References fdResourceGetMetadataRecordStub() and Sint32.
Definition at line 661 of file field_sprite_animation.c.