Skip to Content
The Alchemy Project

src/field/field_sprite_draw.c

Drawing sprites: composing their animations' pictures and placing projected sprites on screen. More…

Included by field.c.

Macros

NameDescription
#defineFACING_TABLE_ENTRY (table, direction)Facing table table's entry for facing angle direction, the turn cut into as many sectors as the table has entries.
#definePLACEMENT_SHADOW_DEPTH (PLACEMENT_IMAGE_DEPTH - 2)The depth slot fdRenderApplyProjectedPlacement gives a sprite's shadow: two behind the sprite's own, PLACEMENT_IMAGE_DEPTH (field/field.h).
#definePROJECTED_MARGIN 32How far past the screen's left, right and top edges a projected sprite's point may lie and still be drawn, and past its bottom edge.
#definePROJECTED_MARGIN_BELOW 48
#definePROJECTED_NEAREST_DEPTH 384The depth slot of a projected sprite at depth 0; the slot falls by one for each two units of depth.
#defineOAM_ATTR01_KEPT_BITS 0xc000fc00The size, shape, colours, mosaic and mode of a sprite's OAM attributes 0 and 1, which placing it keeps.

Enumerations

NameDescription
enumSPR_PICTURE_CODEC { SPRITE_PICTURE_RAW, SPRITE_PICTURE_TAGGED_LZ, SPRITE_PICTURE … }SPR_ANIMATION.mode: how a layer's pictures are packed, each with its decoder.

Functions

NameDescription
voidfdSpriteSkipToStop (SPR *sprite)Runs each of the sprite's sprite animations on to its next stop (an end, hold, jump or play command), taking the pictures and settings on the way, and leaves the stop to run next; marks the sprite and each sprite animation changed.
Sint32fdSpriteComposePicture (SPR *sprite, Uint32 direction)Advances a sprite's animations by one tick, picks each sprite animation's picture for the facing direction, and when any picture changed redraws the sprite: the sprite animations composed by priority into one pixel buffer, an optional outline, and the result uploaded to the sprite's VRAM tiles.
voidfdRenderPlaceSpritePartPair (SPR *sprite, FIXED screenX, Sint32 height, Sint32 screenY, Sint32 groundHeight, FIXED *scale)Positions a sprite's image (part 0) and shadow (part 1) on the screen: the image centred on screenX and raised height above screenY, the shadow at groundHeight. scale is the sprite's (x, y) scale (16.16); above 1.0 both parts use the double-size affine mode.
voidfdRenderApplyProjectedPlacement (SPR *sprite, Sint32 *pos, Sint32 *scale, Sint32 mode)Places a sprite for the scrolling camera and queues it for drawing: the sprite at the screen point of a projected position (x, height, y, ground), scaled by scale[0] and scale[1] and turned by its rotation, and its shadow on the ground below; both go into the depth list by their screen row.
voidfdRenderApplyProjectedPlacementAtDepth ( SPR *sprite, Sint32 *pos, Sint32 *scale, Sint32 mode, Sint32 depth)fdRenderApplyProjectedPlacement into the given draw slot: the sprite and its shadow both go to depth, and mode chooses the picture as facing does there.
voidfdRenderPlaceProjectedSprite ( SPR *sprite, Sint32 *point, Sint32 *scale, Sint32 facing, Sint32 depth)Places a sprite at a 3D point for the fixed camera and queues it for drawing: projected to the screen and scaled by its distance (unless useOwnScale keeps its own scale), with an affine matrix as needed and its shadow on the ground below. depth 0 sorts it by distance; any other value is its draw slot.
voidfdSpriteSetFirstAnimationColorMode (SPR *sprite, Uint32 colorMode)Sets the colour mode (SPR_COL_MODE) of the sprite's first sprite animation and has it drawn again.
voidfdSpriteSetAnimationColorModes (SPR *sprite, Uint32 colorMode)Sets the colour mode of every sprite animation of the sprite that is not hidden (SPRITE_COLOR_HIDDEN) and has it drawn again.

Description

Drawing sprites: composing their animations' pictures and placing projected sprites on screen. Part of field.c.

Macros in detail

FACING_TABLE_ENTRY

#define FACING_TABLE_ENTRY(table, direction)

Facing table table's entry for facing angle direction, the turn cut into as many sectors as the table has entries.

Referenced by fdSpriteComposePicture().

Definition at line 17 of file field_sprite_draw.c.

PLACEMENT_SHADOW_DEPTH

#define PLACEMENT_SHADOW_DEPTH (PLACEMENT_IMAGE_DEPTH - 2)

The depth slot fdRenderApplyProjectedPlacement gives a sprite's shadow: two behind the sprite's own, PLACEMENT_IMAGE_DEPTH (field/field.h).

Referenced by fdRenderApplyProjectedPlacement().

Definition at line 405 of file field_sprite_draw.c.

PROJECTED_MARGIN

#define PROJECTED_MARGIN 32

How far past the screen's left, right and top edges a projected sprite's point may lie and still be drawn, and past its bottom edge.

Referenced by fdRenderPlaceProjectedSprite().

Definition at line 639 of file field_sprite_draw.c.

PROJECTED_MARGIN_BELOW

#define PROJECTED_MARGIN_BELOW 48

Referenced by fdRenderPlaceProjectedSprite().

Definition at line 640 of file field_sprite_draw.c.

PROJECTED_NEAREST_DEPTH

#define PROJECTED_NEAREST_DEPTH 384

The depth slot of a projected sprite at depth 0; the slot falls by one for each two units of depth.

Referenced by fdRenderPlaceProjectedSprite().

Definition at line 643 of file field_sprite_draw.c.

OAM_ATTR01_KEPT_BITS

#define OAM_ATTR01_KEPT_BITS 0xc000fc00

The size, shape, colours, mosaic and mode of a sprite's OAM attributes 0 and 1, which placing it keeps.

Referenced by fdRenderPlaceProjectedSprite().

Definition at line 646 of file field_sprite_draw.c.

Enumerations in detail

SPR_PICTURE_CODEC

enum SPR_PICTURE_CODEC

SPR_ANIMATION.mode: how a layer's pictures are packed, each with its decoder.

EnumeratorValueDescription
SPRITE_PICTURE_RAW0
SPRITE_PICTURE_TAGGED_LZ1syDecompressTaggedLZ's format
SPRITE_PICTURE_LZ3LZ-compressed

Definition at line 8 of file field_sprite_draw.c.

Functions in detail

fdSpriteSkipToStop

void fdSpriteSkipToStop(SPR *sprite)

Runs each of the sprite's sprite animations on to its next stop (an end, hold, jump or play command), taking the pictures and settings on the way, and leaves the stop to run next; marks the sprite and each sprite animation changed. The battle's motion calls it before it releases a borrowed sprite buffer.

References Sint32.

Definition at line 25 of file field_sprite_draw.c.

fdSpriteComposePicture

Sint32 fdSpriteComposePicture(SPR *sprite, Uint32 direction)

Advances a sprite's animations by one tick, picks each sprite animation's picture for the facing direction, and when any picture changed redraws the sprite: the sprite animations composed by priority into one pixel buffer, an optional outline, and the result uploaded to the sprite's VRAM tiles.

References AnimationFacingEightPictures, AnimationFacingFivePictures, AnimationFacingFrontBack, AnimationFacingFrontBackSwapped, AnimationFacingOnePicture, AnimationFacingThreePictures, fdDecompressLZ(), fdGridDrawOutlineCode, fdSpriteAnimationStart(), GridDrawOutlineCodeSize, Sint32, SpriteColorTintTables, syDecompressSpritePicture(), syDecompressTaggedLZ(), syHeapAllocate(), syHeapRelease(), syHeapSlotRelease(), sySoundPlayStub(), syVRAMCacheLoad() and syWordsClear().

Referenced by fdActorSystemPlaceSprites(), fdRenderApplyProjectedPlacement(), fdRenderApplyProjectedPlacementAtDepth() and fdRenderPlaceProjectedSprite().

Definition at line 71 of file field_sprite_draw.c.

fdRenderPlaceSpritePartPair

void fdRenderPlaceSpritePartPair(SPR *sprite, FIXED screenX, Sint32 height, Sint32 screenY, Sint32 groundHeight, FIXED *scale)

Positions a sprite's image (part 0) and shadow (part 1) on the screen: the image centred on screenX and raised height above screenY, the shadow at groundHeight. scale is the sprite's (x, y) scale (16.16); above 1.0 both parts use the double-size affine mode.

References Sint32.

Definition at line 362 of file field_sprite_draw.c.

fdRenderApplyProjectedPlacement

void fdRenderApplyProjectedPlacement(SPR *sprite, Sint32 *pos, Sint32 *scale, Sint32 mode)

Places a sprite for the scrolling camera and queues it for drawing: the sprite at the screen point of a projected position (x, height, y, ground), scaled by scale[0] and scale[1] and turned by its rotation, and its shadow on the ground below; both go into the depth list by their screen row.

References fdSpriteComposePicture(), Sint32, syCos(), syOAMAddSpriteAtDepthClamped(), syOAMMatrixAllocateFromTransform() and sySin().

Referenced by fdActorSystemPlaceSprites() and fdSpriteViewerPlaceRing().

Definition at line 411 of file field_sprite_draw.c.

fdRenderApplyProjectedPlacementAtDepth

void fdRenderApplyProjectedPlacementAtDepth( SPR *sprite, Sint32 *pos, Sint32 *scale, Sint32 mode, Sint32 depth)

fdRenderApplyProjectedPlacement into the given draw slot: the sprite and its shadow both go to depth, and mode chooses the picture as facing does there. Unlike it, it also moves a double-size sprite's shadow out by twice its half size.

References fdSpriteComposePicture(), Sint32, syCos(), syOAMAddSpriteAtDepth(), syOAMMatrixAllocateFromTransform() and sySin().

Referenced by fdActorSystemPlaceSprites().

Definition at line 522 of file field_sprite_draw.c.

fdRenderPlaceProjectedSprite

void fdRenderPlaceProjectedSprite( SPR *sprite, Sint32 *point, Sint32 *scale, Sint32 facing, Sint32 depth)

Places a sprite at a 3D point for the fixed camera and queues it for drawing: projected to the screen and scaled by its distance (unless useOwnScale keeps its own scale), with an affine matrix as needed and its shadow on the ground below. depth 0 sorts it by distance; any other value is its draw slot.

References fdSpriteComposePicture(), Sint32, syAffineMatrixBuild(), syConvert3Dto2D(), syOAMAddSpriteAtDepthClamped() and syVRAMCacheReleaseVRAM().

Referenced by fdActorPlaceSprites().

Definition at line 652 of file field_sprite_draw.c.

fdSpriteSetFirstAnimationColorMode

void fdSpriteSetFirstAnimationColorMode(SPR *sprite, Uint32 colorMode)

Sets the colour mode (SPR_COL_MODE) of the sprite's first sprite animation and has it drawn again.

Definition at line 781 of file field_sprite_draw.c.

fdSpriteSetAnimationColorModes

void fdSpriteSetAnimationColorModes(SPR *sprite, Uint32 colorMode)

Sets the colour mode of every sprite animation of the sprite that is not hidden (SPRITE_COLOR_HIDDEN) and has it drawn again.

References Sint32.

Referenced by fdActorSetSpriteColorMode(), fdActorSpawnWaterSplash() and scTaopoSwampSinkStump().

Definition at line 792 of file field_sprite_draw.c.