Skip to Content
The Alchemy Project

src/field/field_psynergy_canvas.c

The canvas a field effect draws into and its darkening, an actor appearing in a whirl of sparks, and the field particles that fly to their targets. More…

Included by field_psynergy.c.

Structures

NameDescription
structAPPEAR_SPARKS_STATEfdActorAppearInSparks's state (heap slot HEAP_SLOT_BATTLE_EFFECT): the spark picture, and the sparks that circle the actor and their sprites.

Macros

NameDescription
#defineCANVAS_RAMP_COLORS 32The canvas's ramp of colours, from colour 224 (palette 14 of the 256-colour canvas), which the darkening maps index by a colour's place in it.
#defineCANVAS_SPRITE_DEPTH 250The depth the canvas sprite is drawn at, between OAM_DEPTH_WINDOW and OAM_DEPTH_FRONT.
#defineBG_VRAM ((void *)BG_CHAR_BLOCK(0))
#defineTILE_SIZE 32
#defineCANVAS_DMA DMA_COPY_WORDS(CANVAS_SPRITE_BYTES / 4)The canvas in words, as one 32-bit DMA.
#defineAPPEAR_SPARK_COUNT 64The sparks that circle an actor as it appears.
#defineSPARK_LIFE 50The ticks one spark lives.
#definePHASE_SPARKS_GATHER 0The appearance's phases: sparks gather alone at first, then the actor spins and widens among them.
#definePHASE_ACTOR_WIDENS 1
#definePHASE_DONE 999
#defineSPARKLE_PICTURES 4RESOURCE_SPARKLE_FADE's sparkles, each smaller and fainter than the last.
#defineAPPEAR_SPAWN_TICKS 10The ticks the sparks keep coming, and the ticks the actor then takes to widen from nothing to full width.
#defineAPPEAR_WIDEN_TICKS 64
#definePARTICLE_FRONT_LIFT 508A particle marked FIELD_PARTICLE_LIFTED_BY_Z is raised to this height less its row, in pixels, and pushed as far down the field.

Functions

NameDescription
voidfdBattleEffectStepVector2 (Sint32 *vector, Sint32 damping, Sint32 gravity)Moves a 2D point by its velocity, damped and pulled by gravity (fdAdvanceWithGravity2D).
voidfdBattleEffectStepVector3 (Sint32 *vector, Sint32 damping, Sint32 gravity)Moves a 3D point by its velocity, damped and pulled by gravity (fdAdvanceWithGravity3D).
voidfdBattleEffectPlotHalfCanvasPixel (Sint32 x, Sint32 y, Sint32 color)Plots a pixel of colour color at (x, y) on the half canvas, the first 64-pixel square of the pair.
voidfdBattleEffectPlotCanvasPixel (Sint32 x, Sint32 y, Sint32 color)Plots a pixel of colour color at (x, y) on the 128-pixel-wide canvas pair: x from 64 lands on the second canvas.
voidfdBattleEffectDrawHalfCanvasLine ( Sint32 x0, Sint32 y0, Sint32 x1, Sint32 y1, Sint32 color)Draws a line of half canvas pixels from x0, y0 to x1, y1, Bresenham's way: one pixel per step along the longer axis.
voidfdBattleEffectDrawHalfCanvasCircle (Sint32 cx, Sint32 cy, Sint32 radius, Sint32 color)Draws a circle of the given radius round (cx, cy) on the half canvas, by the midpoint method: each step plots the eight symmetric points.
voidfdBattleEffectDrawCanvasBlock ( const Uint8 *src, Sint32 x, Sint32 y, Sint32 width, Sint32 height)Copies a width by height block of colour indices onto the half canvas at x, y, skipping zeros (clear pixels).
voidfdColorBufferDarkenOneLevel (Uint8 *buf, Sint32 count)Maps each drawn (nonzero) canvas pixel of buffer, count of them, through ColorBufferDarkenOneLevelMap, one level darker down the ramp of colours 224 to 254.
voidfdColorBufferDarkenTwoLevels (Uint8 *buf, Sint32 count)Maps each drawn (nonzero) canvas pixel of buffer, count of them, through ColorBufferDarkenTwoLevelsMap, two levels darker.
voidfdColorBufferDarkenFourLevels (Uint8 *buf, Sint32 count)Maps each drawn (nonzero) canvas pixel of buffer, count of them, through ColorBufferDarkenFourLevelsMap, four levels darker.
voidfdBattleEffectUploadCanvas (void)The canvas's tick callback: counts the tick and carries out the command the effect left for it, copying the canvas into the sprite's tiles (or to the start of BG VRAM), and clearing or fading it after the copy.
voidfdBattleEffectDrawCanvasSprite (void)The canvas sprite's tick callback: places the sprite at the state's position (whole pixels), scale and angle, and draws it.
voidfdBattleEffectStartCanvasSprite (void)Starts the canvas sprite of the field Psynergy scenes: its state, a cleared 64x64 canvas copied into the sprite's tiles, and a map from each canvas pixel (row by row) to its place in the tiles.
voidfdBattleEffectEndCanvasSprite (void)Ends the canvas sprite: stops its draw and upload callbacks, waits a tick and frees its sprite state, canvas and pixel map.
voidfdActorAppearInSparks (Sint32 actorId)An actor appears in a whirl of sparks, as Alex does on Venus Lighthouse: APPEAR_SPARK_COUNT sparkles (RESOURCE_SPARKLE_FADE) circle round where it stands, each rising and closing in for SPARK_LIFE ticks.
voidfdParticleUpdate (FIELD_PARTICLE *effect)Updates one field particle: counts its age, runs its callback (after any delay), moves it and draws it.
voidfdParticleDraw (FIELD_PARTICLE *object)Draws a field particle at its screen position and scale, when it is near the screen: x from -32 to 272 pixels and z from -32 to 224, both exclusive.
voidfdParticleUpdateMotion (FIELD_PARTICLE *effect)Moves a field particle toward its target, turning at most turnStepMax a tick when turnStepLimited is set and speeding up by acceleration to speedMax.
Uint32fdParticleHasPendingTarget (FIELD_PARTICLE *effect)Whether a particle that stops at its target is still on its way there.
voidfdParticleSetPos (FIELD_PARTICLE *effect, Sint32 x, Sint32 z)Places a field particle at (x, z), at rest with no target.
voidfdParticleSetAnimation (FIELD_PARTICLE *effect, Sint32 mode)Sets the animation of a field effect sprite.
voidfdParticleSetCallback (FIELD_PARTICLE *effect, EFFECT_CALLBACK callback)Gives a field particle its per-tick callback, starting at state 0.
voidfdParticleInit (FIELD_PARTICLE *effect, Sint32 kind, Sint32 x, Sint32 z)Starts a field particle with a sprite of the given kind at (x, z), at full size and in front of everything: it will fly to its target at up to 2 pixels a tick, turning a limited step at a time, and stop there.
voidfdParticleFree (FIELD_PARTICLE *effect)Frees a field particle's sprite and clears the particle, leaving it inactive.

Description

The canvas a field effect draws into and its darkening, an actor appearing in a whirl of sparks, and the field particles that fly to their targets. Part of field_psynergy.c.

Macros in detail

CANVAS_RAMP_COLORS

#define CANVAS_RAMP_COLORS 32

The canvas's ramp of colours, from colour 224 (palette 14 of the 256-colour canvas), which the darkening maps index by a colour's place in it.

Referenced by fdColorBufferDarkenFourLevels(), fdColorBufferDarkenOneLevel() and fdColorBufferDarkenTwoLevels().

Definition at line 167 of file field_psynergy_canvas.c.

CANVAS_SPRITE_DEPTH

#define CANVAS_SPRITE_DEPTH 250

The depth the canvas sprite is drawn at, between OAM_DEPTH_WINDOW and OAM_DEPTH_FRONT.

Referenced by fdBattleEffectStartCanvasSprite().

Definition at line 226 of file field_psynergy_canvas.c.

BG_VRAM

#define BG_VRAM ((void *)BG_CHAR_BLOCK(0))

Referenced by fdBattleEffectUploadCanvas().

Definition at line 227 of file field_psynergy_canvas.c.

TILE_SIZE

#define TILE_SIZE 32

Referenced by fdBattleEffectStartCanvasSprite() and fdBattleEffectUploadCanvas().

Definition at line 228 of file field_psynergy_canvas.c.

CANVAS_DMA

#define CANVAS_DMA DMA_COPY_WORDS(CANVAS_SPRITE_BYTES / 4)

The canvas in words, as one 32-bit DMA.

Referenced by fdBattleEffectUploadCanvas().

Definition at line 231 of file field_psynergy_canvas.c.

APPEAR_SPARK_COUNT

#define APPEAR_SPARK_COUNT 64

The sparks that circle an actor as it appears.

Referenced by fdActorAppearInSparks().

Definition at line 394 of file field_psynergy_canvas.c.

SPARK_LIFE

#define SPARK_LIFE 50

The ticks one spark lives.

Referenced by fdActorAppearInSparks().

Definition at line 406 of file field_psynergy_canvas.c.

PHASE_SPARKS_GATHER

#define PHASE_SPARKS_GATHER 0

The appearance's phases: sparks gather alone at first, then the actor spins and widens among them.

Referenced by fdActorAppearInSparks().

Definition at line 409 of file field_psynergy_canvas.c.

PHASE_ACTOR_WIDENS

#define PHASE_ACTOR_WIDENS 1

Referenced by fdActorAppearInSparks().

Definition at line 410 of file field_psynergy_canvas.c.

PHASE_DONE

#define PHASE_DONE 999

Referenced by fdActorAppearInSparks().

Definition at line 411 of file field_psynergy_canvas.c.

SPARKLE_PICTURES

#define SPARKLE_PICTURES 4

RESOURCE_SPARKLE_FADE's sparkles, each smaller and fainter than the last.

Referenced by fdActorAppearInSparks().

Definition at line 413 of file field_psynergy_canvas.c.

APPEAR_SPAWN_TICKS

#define APPEAR_SPAWN_TICKS 10

The ticks the sparks keep coming, and the ticks the actor then takes to widen from nothing to full width.

Referenced by fdActorAppearInSparks().

Definition at line 416 of file field_psynergy_canvas.c.

APPEAR_WIDEN_TICKS

#define APPEAR_WIDEN_TICKS 64

Referenced by fdActorAppearInSparks().

Definition at line 417 of file field_psynergy_canvas.c.

PARTICLE_FRONT_LIFT

#define PARTICLE_FRONT_LIFT 508

A particle marked FIELD_PARTICLE_LIFTED_BY_Z is raised to this height less its row, in pixels, and pushed as far down the field. The two cancel on screen, but its depth (height plus row, in fdRenderApplyProjectedPlacement) becomes twice this less its row, far past the depth list's end, so it is drawn in the last slot an actor can take (OAM_DEPTH_WINDOW - 1), in front of everything that stands on the field.

Referenced by fdParticleDraw().

Definition at line 589 of file field_psynergy_canvas.c.

Functions in detail

fdBattleEffectStepVector2

void fdBattleEffectStepVector2(Sint32 *vector, Sint32 damping, Sint32 gravity)

Moves a 2D point by its velocity, damped and pulled by gravity (fdAdvanceWithGravity2D).

References fdAdvanceWithGravity2D() and Sint32.

Definition at line 7 of file field_psynergy_canvas.c.

fdBattleEffectStepVector3

void fdBattleEffectStepVector3(Sint32 *vector, Sint32 damping, Sint32 gravity)

Moves a 3D point by its velocity, damped and pulled by gravity (fdAdvanceWithGravity3D).

References fdAdvanceWithGravity3D() and Sint32.

Referenced by dbPsynergyTest2UpdateRocks(), scNorthernReachesShatterIceWall(), scParticleUpdateFalling() and scVenusLighthouseEntranceUpdateDust().

Definition at line 14 of file field_psynergy_canvas.c.

fdBattleEffectPlotHalfCanvasPixel

void fdBattleEffectPlotHalfCanvasPixel(Sint32 x, Sint32 y, Sint32 color)

Plots a pixel of colour color at (x, y) on the half canvas, the first 64-pixel square of the pair.

References Sint32.

Referenced by fdBattleEffectDrawHalfCanvasCircle() and fdBattleEffectDrawHalfCanvasLine().

Definition at line 21 of file field_psynergy_canvas.c.

fdBattleEffectPlotCanvasPixel

void fdBattleEffectPlotCanvasPixel(Sint32 x, Sint32 y, Sint32 color)

Plots a pixel of colour color at (x, y) on the 128-pixel-wide canvas pair: x from 64 lands on the second canvas.

References Sint32.

Referenced by fdCanvasPlotPolarPixel().

Definition at line 32 of file field_psynergy_canvas.c.

fdBattleEffectDrawHalfCanvasLine

void fdBattleEffectDrawHalfCanvasLine( Sint32 x0, Sint32 y0, Sint32 x1, Sint32 y1, Sint32 color)

Draws a line of half canvas pixels from x0, y0 to x1, y1, Bresenham's way: one pixel per step along the longer axis.

References fdBattleEffectPlotHalfCanvasPixel() and Sint32.

Definition at line 47 of file field_psynergy_canvas.c.

fdBattleEffectDrawHalfCanvasCircle

void fdBattleEffectDrawHalfCanvasCircle(Sint32 cx, Sint32 cy, Sint32 radius, Sint32 color)

Draws a circle of the given radius round (cx, cy) on the half canvas, by the midpoint method: each step plots the eight symmetric points.

References fdBattleEffectPlotHalfCanvasPixel() and Sint32.

Definition at line 112 of file field_psynergy_canvas.c.

fdBattleEffectDrawCanvasBlock

void fdBattleEffectDrawCanvasBlock( const Uint8 *src, Sint32 x, Sint32 y, Sint32 width, Sint32 height)

Copies a width by height block of colour indices onto the half canvas at x, y, skipping zeros (clear pixels). Nothing is drawn of a block that would not fit inside the canvas's first 63 pixels each way.

References Sint32.

Referenced by fdPsynergyUpdateArrow().

Definition at line 144 of file field_psynergy_canvas.c.

fdColorBufferDarkenOneLevel

void fdColorBufferDarkenOneLevel(Uint8 *buf, Sint32 count)

Maps each drawn (nonzero) canvas pixel of buffer, count of them, through ColorBufferDarkenOneLevelMap, one level darker down the ramp of colours 224 to 254.

References ColorBufferDarkenOneLevelMap and Sint32.

Referenced by fdBattleEffectUploadCanvas().

Definition at line 172 of file field_psynergy_canvas.c.

fdColorBufferDarkenTwoLevels

void fdColorBufferDarkenTwoLevels(Uint8 *buf, Sint32 count)

Maps each drawn (nonzero) canvas pixel of buffer, count of them, through ColorBufferDarkenTwoLevelsMap, two levels darker.

References ColorBufferDarkenTwoLevelsMap and Sint32.

Referenced by fdBattleEffectUploadCanvas().

Definition at line 190 of file field_psynergy_canvas.c.

fdColorBufferDarkenFourLevels

void fdColorBufferDarkenFourLevels(Uint8 *buf, Sint32 count)

Maps each drawn (nonzero) canvas pixel of buffer, count of them, through ColorBufferDarkenFourLevelsMap, four levels darker.

References ColorBufferDarkenFourLevelsMap and Sint32.

Referenced by fdBattleEffectUploadCanvas().

Definition at line 208 of file field_psynergy_canvas.c.

fdBattleEffectUploadCanvas

void fdBattleEffectUploadCanvas(void)

The canvas's tick callback: counts the tick and carries out the command the effect left for it, copying the canvas into the sprite's tiles (or to the start of BG VRAM), and clearing or fading it after the copy.

References fdColorBufferDarkenFourLevels(), fdColorBufferDarkenOneLevel(), fdColorBufferDarkenTwoLevels(), syDMAXCopy() and syWordsFill().

Referenced by fdBattleEffectEndCanvasSprite() and fdBattleEffectStartCanvasSprite().

Definition at line 236 of file field_psynergy_canvas.c.

fdBattleEffectDrawCanvasSprite

void fdBattleEffectDrawCanvasSprite(void)

The canvas sprite's tick callback: places the sprite at the state's position (whole pixels), scale and angle, and draws it. A sprite scaled to nothing is not drawn.

References fdEffectSpriteDraw(), fdEffectSpriteInit() and Sint32.

Referenced by fdBattleEffectEndCanvasSprite() and fdBattleEffectStartCanvasSprite().

Definition at line 277 of file field_psynergy_canvas.c.

fdBattleEffectStartCanvasSprite

void fdBattleEffectStartCanvasSprite(void)

Starts the canvas sprite of the field Psynergy scenes: its state, a cleared 64x64 canvas copied into the sprite's tiles, and a map from each canvas pixel (row by row) to its place in the tiles. fdBattleEffectDrawCanvasSprite draws the sprite and fdBattleEffectUploadCanvas uploads the canvas each tick; fdBattleEffectEndCanvasSprite ends it.

References fdBattleEffectDrawCanvasSprite(), fdBattleEffectUploadCanvas(), Sint32, syDMAXCopy(), syHeapSlotAllocate(), syHeapSlotAllocateEWRAM() and sySetEvent().

Referenced by fdPsynergyArrow(), fdPsynergyBurst(), fdPsynergyCyclone(), fdPsynergyPound() and fdPsynergyRing().

Definition at line 337 of file field_psynergy_canvas.c.

fdBattleEffectEndCanvasSprite

void fdBattleEffectEndCanvasSprite(void)

Ends the canvas sprite: stops its draw and upload callbacks, waits a tick and frees its sprite state, canvas and pixel map.

References fdBattleEffectDrawCanvasSprite(), fdBattleEffectUploadCanvas(), syCloseEvent(), syHeapSlotRelease() and sySynch().

Referenced by fdPsynergyArrow(), fdPsynergyBurst(), fdPsynergyCyclone(), fdPsynergyEndRing() and fdPsynergyPound().

Definition at line 383 of file field_psynergy_canvas.c.

fdActorAppearInSparks

void fdActorAppearInSparks(Sint32 actorId)

An actor appears in a whirl of sparks, as Alex does on Venus Lighthouse: APPEAR_SPARK_COUNT sparkles (RESOURCE_SPARKLE_FADE) circle round where it stands, each rising and closing in for SPARK_LIFE ticks. The actor spins and widens from nothing to full width over APPEAR_WIDEN_TICKS, when its shadow shows again, and the sparks stop coming APPEAR_SPAWN_TICKS later.

References fdActorGetSpriteDepth(), fdActorGetSpritePriority(), fdActorLookup(), fdActorSetSpriteFlagsStub(), fdCameraWorldToScreen(), fdEffectSpriteDraw(), fdEffectSpriteInit(), Sint32, syDecompressTaggedLZ(), syHeapSlotAllocate(), syHeapSlotRelease(), syRandom(), syResourceGetTableEntry(), sySynch(), syVectorAddPolarOffset(), syVRAMCacheFindFreeEntry(), syVRAMCacheFreeEntry() and syVRAMCacheLoad().

Referenced by scVenusLighthouseDoubtLeaving().

Definition at line 424 of file field_psynergy_canvas.c.

fdParticleUpdate

void fdParticleUpdate(FIELD_PARTICLE *effect)

Updates one field particle: counts its age, runs its callback (after any delay), moves it and draws it.

References fdParticleDraw() and fdParticleUpdateMotion().

Referenced by fdBattleEffectUpdateAllEffectSlots() and fdEffectUpdateAllSlots().

Definition at line 564 of file field_psynergy_canvas.c.

fdParticleDraw

void fdParticleDraw(FIELD_PARTICLE *object)

Draws a field particle at its screen position and scale, when it is near the screen: x from -32 to 272 pixels and z from -32 to 224, both exclusive.

References fdRenderApplyProjectedPlacementStub() and Sint32.

Referenced by fdParticleUpdate().

Definition at line 593 of file field_psynergy_canvas.c.

fdParticleUpdateMotion

void fdParticleUpdateMotion(FIELD_PARTICLE *effect)

Moves a field particle toward its target, turning at most turnStepMax a tick when turnStepLimited is set and speeding up by acceleration to speedMax. One that stops at its target lands on it once within 8 pixels.

References fdParticleSetPos(), Sint32, syAtan(), syCos(), sySin(), sySquartFX() and sySquartIWRAM().

Referenced by fdParticleUpdate().

Definition at line 616 of file field_psynergy_canvas.c.

fdParticleHasPendingTarget

Uint32 fdParticleHasPendingTarget(FIELD_PARTICLE *effect)

Whether a particle that stops at its target is still on its way there.

Referenced by fdEffectUpdateHaltParticle(), fdEffectUpdateMarsSpark(), fdEffectUpdateOutAndBack(), fdEffectUpdateRadialBurst(), fdEffectUpdateRadialSpread(), fdEffectUpdateRandomTargetParticle() and fdRetreatUpdateSpark().

Definition at line 677 of file field_psynergy_canvas.c.

fdParticleSetPos

void fdParticleSetPos(FIELD_PARTICLE *effect, Sint32 x, Sint32 z)

Places a field particle at (x, z), at rest with no target.

References Sint32.

Referenced by fdParticleInit() and fdParticleUpdateMotion().

Definition at line 687 of file field_psynergy_canvas.c.

fdParticleSetAnimation

void fdParticleSetAnimation(FIELD_PARTICLE *effect, Sint32 mode)

Sets the animation of a field effect sprite.

References fdSpriteStartAnimationStub() and Sint32.

Referenced by fdDjinnRunJupiterJoinEffect(), fdDjinnRunMarsJoinEffect(), fdDjinnRunMercuryJoinEffect(), fdDjinnRunVenusJoinEffect(), fdParticleInit(), fdPsynergyForce() and fdPsynergyRetreat().

Definition at line 696 of file field_psynergy_canvas.c.

fdParticleSetCallback

void fdParticleSetCallback(FIELD_PARTICLE *effect, EFFECT_CALLBACK callback)

Gives a field particle its per-tick callback, starting at state 0.

Referenced by fdDjinnRunJupiterJoinEffect(), fdDjinnRunMarsJoinEffect(), fdDjinnRunMercuryJoinEffect(), fdDjinnRunVenusJoinEffect(), fdPsynergyForce(), fdPsynergyHalt() and fdPsynergyRetreat().

Definition at line 702 of file field_psynergy_canvas.c.

fdParticleInit

void fdParticleInit(FIELD_PARTICLE *effect, Sint32 kind, Sint32 x, Sint32 z)

Starts a field particle with a sprite of the given kind at (x, z), at full size and in front of everything: it will fly to its target at up to 2 pixels a tick, turning a limited step at a time, and stop there.

References fdParticleSetAnimation(), fdParticleSetPos(), fdSpriteCreateStub(), Sint32 and syRandom().

Referenced by fdDjinnRunJupiterJoinEffect(), fdDjinnRunMarsJoinEffect(), fdDjinnRunMercuryJoinEffect(), fdDjinnRunVenusJoinEffect(), fdPsynergyForce(), fdPsynergyHalt() and fdPsynergyRetreat().

Definition at line 713 of file field_psynergy_canvas.c.

fdParticleFree

void fdParticleFree(FIELD_PARTICLE *effect)

Frees a field particle's sprite and clears the particle, leaving it inactive.

References fdSpriteDestroyStub().

Referenced by fdEffectReleaseSlots(), fdEffectRunAngledApproachPhases(), fdEffectUpdateHaltParticle(), fdEffectUpdateMarsSpark(), fdEffectUpdateOutAndBack(), fdEffectUpdateRadialBurst(), fdEffectUpdateRadialSpread(), fdEffectUpdateRandomTargetParticle(), fdPsynergyEnd() and fdRetreatUpdateSpark().

Definition at line 748 of file field_psynergy_canvas.c.