Skip to Content
The Alchemy Project

src/battle/battle_element_glow.c

A unit's element glow: the star field of a cast, the streaks, the pillar and the burst, and restoring the background palette. More…

Included by battle.c.

Structures

NameDescription
structSPARKOne of the star field's sparks, drawn inward to the centre.
structRINGA ring of the star field leaving its centre: its place, its speed and its age.
structSTAR_FIELD_STATEThe star field's state, for the 45 ticks of a cast's glow.

Macros

NameDescription
#defineSTAR_FIELD_SPARKS 16The star field's sparks and rings, and the ticks in which a spent spark starts again.
#defineSTAR_FIELD_RINGS 3
#defineSTAR_FIELD_SPAWN_TICKS 25
#defineSTAR_FIELD_SIZE 128The canvas's width and height in pixels.
#defineSTAR_FIELD_CENTER (STAR_FIELD_SIZE / 2)
#defineSTAR_FIELD_RING_SIZE 32
#defineSTAR_FIELD_TICKS 45The ticks a cast's glow lasts.
#defineSTAR_FIELD_DARKEN_TICKS 25The ticks the background darkens through as the star field gathers, a BACKGROUND_LEVEL_STEP each.
#defineELEMENT_STREAK_TICKS 40The ticks an enemy's cast shows its element's streaks.
#defineSTAR_FIELD_COLORS 64The blue ring sprite sheet's colours, before its pictures; an element's palette replaces them.
#defineSTAR_FIELD_SPARK_PICTURES 7A spark's pictures, by ticks of life left: the rows of ElementGlowSparkSizes.
#defineSTAR_FIELD_PIXEL_SHIFT 10The sparks and rings move in 1/1024 canvas pixels: STAR_FIELD_PIXEL to a pixel.
#defineSTAR_FIELD_PIXEL (1 << STAR_FIELD_PIXEL_SHIFT)

Functions

NameDescription
voidbtElementGlowUpdateStarField (void)Draws the star field's next tick: each spark falls towards the centre and shrinks as its life runs out, a spent one starting again while the field is young, and the three rings move outward.
Sint32btElementGlowUploadStarField (void)Copies the drawn canvas to BG2's tiles, at three quarters of its brightness.
static __inline__ Sint32PolarX (Sint32 angle, Sint32 radius)Returns the x of the point at angle and radius from the origin.
static __inline__ Sint32PolarY (Sint32 angle, Sint32 radius)Returns the y of the point at angle and radius from the origin.
Sint32btElementGlowInitStarField (Sint32 element)Starts a star field of the element: sixteen sparks on random rings and three rings 120 degrees apart, in the element's colours.
Sint32btElementGlowEnd (Sint32 unused)Ends a star field and turns BG2 off.
voidbtElementGlowReservedNoOperation (void)Unused: does nothing.
voidbtElementGlowPlay (Sint32 unitId, Sint32 element, Sint32 mode, Sint32 variant)Plays a glow of the element about a unit, and returns when it is over: the star field, the streaks, the pillar or the burst.
voidbtBackgroundRestorePalette (void)Copies the background's saved palette back undarkened, as the star field of btElementGlowPlay leaves it dark.
voidbtIRQRemoveVCountHandler (void)Unused: removes the VCount interrupt's handler, as btTransitionRun installs one.

Variables

NameDescription
extern const Uint8ElementGlowSparkSizes []The star tables: each picture's size and sprite sheet offset, and the ring's four pictures.
extern const Sint32ElementGlowSparkPictures []Byte offsets into STAR_FIELD_STATE.sheet, a byte a pixel, by ticks of life left.
extern const Sint32ElementGlowRingPictures []The ring's four 32 by 32 ticks, after the sparks' 78 bytes.

Description

A unit's element glow: the star field of a cast, the streaks, the pillar and the burst, and restoring the background palette. Part of battle.c.

Macros in detail

STAR_FIELD_SPARKS

#define STAR_FIELD_SPARKS 16

The star field's sparks and rings, and the ticks in which a spent spark starts again.

Referenced by btElementGlowInitStarField() and btElementGlowUpdateStarField().

Definition at line 26 of file battle_element_glow.c.

STAR_FIELD_RINGS

#define STAR_FIELD_RINGS 3

Referenced by btElementGlowInitStarField() and btElementGlowUpdateStarField().

Definition at line 27 of file battle_element_glow.c.

STAR_FIELD_SPAWN_TICKS

#define STAR_FIELD_SPAWN_TICKS 25

Referenced by btElementGlowUpdateStarField().

Definition at line 28 of file battle_element_glow.c.

STAR_FIELD_SIZE

#define STAR_FIELD_SIZE 128

The canvas's width and height in pixels.

Referenced by btElementGlowInitStarField().

Definition at line 31 of file battle_element_glow.c.

STAR_FIELD_CENTER

#define STAR_FIELD_CENTER (STAR_FIELD_SIZE / 2)

Referenced by btElementGlowPlay() and btElementGlowUpdateStarField().

Definition at line 32 of file battle_element_glow.c.

STAR_FIELD_RING_SIZE

#define STAR_FIELD_RING_SIZE 32

Referenced by btElementGlowUpdateStarField().

Definition at line 33 of file battle_element_glow.c.

STAR_FIELD_TICKS

#define STAR_FIELD_TICKS 45

The ticks a cast's glow lasts.

Referenced by btElementGlowPlay().

Definition at line 36 of file battle_element_glow.c.

STAR_FIELD_DARKEN_TICKS

#define STAR_FIELD_DARKEN_TICKS 25

The ticks the background darkens through as the star field gathers, a BACKGROUND_LEVEL_STEP each.

Referenced by btElementGlowPlay().

Definition at line 40 of file battle_element_glow.c.

ELEMENT_STREAK_TICKS

#define ELEMENT_STREAK_TICKS 40

The ticks an enemy's cast shows its element's streaks.

Referenced by btElementGlowPlay().

Definition at line 43 of file battle_element_glow.c.

STAR_FIELD_COLORS

#define STAR_FIELD_COLORS 64

The blue ring sprite sheet's colours, before its pictures; an element's palette replaces them.

Referenced by btElementGlowInitStarField().

Definition at line 47 of file battle_element_glow.c.

STAR_FIELD_SPARK_PICTURES

#define STAR_FIELD_SPARK_PICTURES 7

A spark's pictures, by ticks of life left: the rows of ElementGlowSparkSizes.

Referenced by btElementGlowUpdateStarField().

Definition at line 50 of file battle_element_glow.c.

STAR_FIELD_PIXEL_SHIFT

#define STAR_FIELD_PIXEL_SHIFT 10

The sparks and rings move in 1/1024 canvas pixels: STAR_FIELD_PIXEL to a pixel.

Referenced by btElementGlowUpdateStarField().

Definition at line 54 of file battle_element_glow.c.

STAR_FIELD_PIXEL

#define STAR_FIELD_PIXEL (1 << STAR_FIELD_PIXEL_SHIFT)

Referenced by btElementGlowInitStarField() and btElementGlowUpdateStarField().

Definition at line 55 of file battle_element_glow.c.

Functions in detail

btElementGlowUpdateStarField

void btElementGlowUpdateStarField(void)

Draws the star field's next tick: each spark falls towards the centre and shrinks as its life runs out, a spent one starting again while the field is young, and the three rings move outward.

References ElementGlowRingPictures, ElementGlowSparkPictures, ElementGlowSparkSizes, Sint32, syCos(), syDivFX(), syRandom(), sySin() and sySquartFX().

Referenced by btElementGlowEnd() and btElementGlowInitStarField().

Definition at line 84 of file battle_element_glow.c.

btElementGlowUploadStarField

Sint32 btElementGlowUploadStarField(void)

Copies the drawn canvas to BG2's tiles, at three quarters of its brightness.

References Sint32 and syColorBufferScaleThreeQuarters().

Referenced by btElementGlowEnd() and btElementGlowInitStarField().

Definition at line 218 of file battle_element_glow.c.

PolarX

static __inline__ Sint32 PolarX(Sint32 angle, Sint32 radius)

Returns the x of the point at angle and radius from the origin.

References Sint32 and syCos().

Referenced by btElementGlowInitStarField().

Definition at line 236 of file battle_element_glow.c.

PolarY

static __inline__ Sint32 PolarY(Sint32 angle, Sint32 radius)

Returns the y of the point at angle and radius from the origin.

References Sint32 and sySin().

Referenced by btElementGlowInitStarField().

Definition at line 242 of file battle_element_glow.c.

btElementGlowInitStarField

Sint32 btElementGlowInitStarField(Sint32 element)

Starts a star field of the element: sixteen sparks on random rings and three rings 120 degrees apart, in the element's colours. Returns the upload event's index.

References btEffectBuildBlitterStub(), btEffectLoadBlitterStub(), btElementGlowUpdateStarField(), btElementGlowUploadStarField(), PolarX(), PolarY(), Sint32, syCos(), syDecompressTaggedLZ(), syDMAXCopy(), syHeapSlotAllocate(), syHeapSlotAllocateEWRAM(), syRandom(), syResourceGetTableEntry(), sySetEvent() and sySin().

Referenced by btElementGlowPlay().

Definition at line 250 of file battle_element_glow.c.

btElementGlowEnd

Sint32 btElementGlowEnd(Sint32 unused)

Ends a star field and turns BG2 off.

References btElementGlowUpdateStarField(), btElementGlowUploadStarField(), Sint32, syCloseEvent() and syHeapSlotRelease().

Referenced by btElementGlowPlay().

Definition at line 343 of file battle_element_glow.c.

btElementGlowReservedNoOperation

void btElementGlowReservedNoOperation(void)

Unused: does nothing.

Definition at line 357 of file battle_element_glow.c.

btElementGlowPlay

void btElementGlowPlay(Sint32 unitId, Sint32 element, Sint32 mode, Sint32 variant)

Plays a glow of the element about a unit, and returns when it is over: the star field, the streaks, the pillar or the burst.

References btBackgroundSetMode(), btColorBufferScale(), btEffectEndElementStreaksStub(), btEffectRunElementBurstStub(), btEffectRunElementPillarStub(), btEffectStartElementStreaksStub(), btElementGlowEnd(), btElementGlowInitStarField(), btMotionProjectScaledPos(), Sint32, syIOWriteQueueStore16() and sySynch().

Referenced by btActionRunBuild(), btDjinnRecoveryCountDownSide(), btProcessTurnEnd(), btStagingRunFullScreen(), btStagingRunPsynergyCast() and btUnitProcessActionEnd().

Definition at line 363 of file battle_element_glow.c.

btBackgroundRestorePalette

void btBackgroundRestorePalette(void)

Copies the background's saved palette back undarkened, as the star field of btElementGlowPlay leaves it dark.

References btBackgroundSetPaletteLevel().

Referenced by btStagingRunFullScreen() and btStagingRunPsynergyCast().

Definition at line 474 of file battle_element_glow.c.

btIRQRemoveVCountHandler

void btIRQRemoveVCountHandler(void)

Unused: removes the VCount interrupt's handler, as btTransitionRun installs one.

References syIntFunction().

Definition at line 481 of file battle_element_glow.c.