Alchemy
Loading...
Searching...
No Matches

positions.c

Go to the documentation of this file.
1/// @file
2/// Effect positions, projection and id dispatch helpers.
3/// Part of effect.c, the battle effect object, compiled only through it.
4
6
7// Particle motion and projection into the battle view.
8//
9// Effect particles are EffectStep records in 16.16 fixed point. The two
10// integrators move a particle one frame: they add its velocity to its
11// position, add gravity to its vertical speed and then damp every speed by a
12// factor out of 64 (64 keeps the speed, 60 loses about 6% a frame). The 3D one
13// works in field space, before projection; the 2D one works directly on the
14// screen, where a positive gravity pulls down.
15//
16// The EffectPosition_Project* helpers turn a point or a battler into an
17// EffectPosition on the screen. Each returns a point 16 pixels higher than the
18// projection, which is where effects anchor on a battler. They differ only in
19// how the battler is projected: at its sprite's scaled height, scaled for the
20// battle view, or plainly.
21
22/// Moves a particle one frame in three dimensions: adds its velocity, then
23/// gravity to its vertical speed, then damps every speed by damping / 64.
24///
25/// Called each frame for the 3D sparks, motes, shards and shells of 18 parts,
26/// from the casting impacts, the beam sequences and the burst scene to the
27/// lobbed shells and the stat reductions; each then projects the particle
28/// with EffectPosition_ProjectPoint. Changes only the step.
30 s32 gravity) {
31 step->x += step->velocityX;
32 step->y += step->velocityY;
33 step->z += step->velocityZ;
34 step->velocityY += gravity;
35 SET_VELOCITY(step, step->velocityX * damping / 64,
36 step->velocityY * damping / 64, step->velocityZ * damping / 64);
37}
38
39/// Moves a particle one frame on the screen: adds its velocity, then
40/// gravity to its vertical speed, then damps both speeds by damping / 64.
41///
42/// Called each frame for the screen-space sparks, motes, chips and puffs of
43/// 20 parts, among them Thor, Spire, Ramses, Ragnarok, the Titan Blade, the
44/// Helm Splitter, the Djinn attacks and the projectile volleys. Changes only
45/// the step; z and velocityZ are left alone.
47 s32 gravity) {
48 step->x += step->velocityX;
49 step->y += step->velocityY;
50 step->velocityY += gravity;
51 step->velocityX = step->velocityX * damping / 64;
52 step->velocityY = step->velocityY * damping / 64;
53}
54
55/// Projects a point in the current transform onto the screen, 16 pixels
56/// higher, and returns the projection's scale.
57///
58/// The common way an effect places a 3D particle: 35 parts call it each
59/// frame once it has set the view, the casting impacts, beams, Judgment,
60/// Procne and the stat changes most often. Only Astral Blast (stars.c) reads
61/// the scale, to size its stars by depth.
62///
63/// point: three s32s in 16.16, x, y and z (an EffectStep's position).
65 struct EffectPosition *position) {
66 s32 result = Render_ProjectPoint(point, EffectPosition_Coordinates(position));
67 position->y -= 16;
68 return result;
69}
70
71/// The screen position of a battler's sprite, at its scaled height, 16
72/// pixels higher.
73///
74/// Called by BattleFx_RunBeamSequence (beams.c), for the first target, and
75/// BattleFx_RunBurstShower (burst_shower.c), for the user. Leaves the view set
76/// to the battle camera (BattleUnit_ProjectToScreen).
79 position->y -= 16;
80}
81
82/// The screen position of a battler, scaled for the battle view, 16 pixels
83/// higher.
84///
85/// The usual anchor for an effect on its user or first target: called during
86/// the setup of 21 parts, from the casting impacts, beams, the burst
87/// scene and Spire to the healing motes and the stat boosts.
89 struct EffectPosition *position) {
92 position->y -= 16;
93}
94
95/// The screen position of a battler, 16 pixels higher.
96///
97/// Called during the setup of 11 parts, among them the target strikes, Bolt,
98/// the rushing strike, the Titan Blade, the Helm Splitter and the element
99/// pillar.
102 position->y -= 16;
103}
104
105/// Projects a battler onto the screen, raised by half its table height (the
106/// table holds the full height in 16.16) at the sprite's scale. The view is
107/// reset to the battle camera first, so the result does not depend on the
108/// transform an effect has left behind.
109///
110/// Called only by EffectPosition_ProjectSprite. Leaves the render transform
111/// looking from gCameraWork's eye to its position, and always returns 0.
112///
113/// screen: receives x and y.
115 struct BattleCamera *camera;
116 struct MotionObject *object;
117 struct AnimationObject *info;
118 s32 scale;
119 /* FAKEMATCH: the unused 12-byte vector preserves both stack
120 * adjustments and camera-load order. */
121 UNUSED s32 unused[3];
122
123 camera = gCameraWork;
124 object = GetBattleObjectSlotFar(unit)->object;
125 info = GetMotionRecordFar(object, 0);
127 scale = Iwram_MulQ16(Render_ProjectPoint(&object->x, screen), info->scale);
128 // The table height is 16.16: >> 17 takes half of it in whole pixels.
129 screen[1] -= Iwram_MulQ16(scale, BattleUnit_GetEffectHeightFar(unit) >> 17);
130 return 0;
131}
132
133/// Reads the held keys when the first target is an enemy (id 128 or more)
134/// and does nothing with them. Nothing calls it.
135///
136/// XXX: what it was for; a debug build or the Lost Age's twin of this part
137/// would show whether the keys once chose an effect for enemy targets.
140 struct BattleEffectArgument *effect = work->effect;
141
142 if (effect->actors[0] > 0x7f)
143 (void)gKeysHeld;
144}
145
146/// Runs a battle effect from the second range of kinds: 100 to 135 are the
147/// casting impacts (kind - 100), 136 to 199 the beam sequences, 200 and up
148/// the ring and spark scenes.
149///
150/// Reached from the battle's presentation through its far-call stub: from
151/// the attack, item, Psynergy cast and unit transition runners
152/// (battle/staging.c) when the plan has STAGING_BY_ID_RANGE (bit 14 of the
153/// effect word), and always from the plain attack runner and the approach
154/// action (battle/auto_battle.c). Takes heap slots
155/// HEAP_SLOT_BATTLE_SHEET (from EWRAM first), HEAP_SLOT_BATTLE_EFFECT and
156/// HEAP_SLOT_BATTLE_CANVAS for the effect, and releases them in the reverse
157/// order once it returns.
159 s32 kind;
160 s32 value;
161
162 // One local holds the sheet size, then the kind, then the impact.
163 // XXX: why 0x60e bytes, a little over two mote sets (2 * MOTE_SET_BYTES is
164 // 0x604); the largest picture these runners decode into the sheet slot
165 // would settle it.
166 value = 0x60e;
169 sizeof(struct BattleEffectWork));
171 value = effect->kind;
172 kind = value;
173 value = kind - 100;
174 // Unsigned, so kinds below 100 fall through to the beam sequences too.
175 if ((u32)value <= 35) {
176 BattleFx_RunCastingImpact(effect, value);
177 } else if (kind > 199) {
179 } else {
181 }
185}
struct BattleCamera * gCameraWork
void BattleFx_RunRingAndSparkScene(struct BattleEffectArgument *effect)
Plays the selected ring-and-spark strike, restoring the user motion after it.
Definition beams.c:272
void BattleFx_RunBeamSequence(struct BattleEffectArgument *effect)
Draws the selected beam and its projected sparks over the first target: a beam, arc or wave shoots fr...
Definition beams.c:21
void BattleFx_RunCastingImpact(struct BattleEffectArgument *effect, s32 mode)
Gathers sparks around the caster, launches the Djinni and draws the impact on the first target.
What every part of the battle effect object shares: its includes, macros and frame-loop helpers.
#define CANVAS_BYTES
The canvas: 128x128 pixels, one byte each, in its heap slot and in VRAM at BG_CHAR_BLOCK(1).
#define EFFECT_VIEW_FROM_CAMERA(camera)
Starts a frame's 3D projection from the battle camera: resets the transform, then looks from camera->...
static s32 * EffectPosition_Coordinates(struct EffectPosition *position)
Returns the position's three coordinates as an array.
Definition effect_step.h:68
struct BattleObj * GetBattleObjectSlotFar(s32 objectId)
Far call to BattleObjGet.
s32 BattleUnit_GetEffectHeightFar(s32 id)
s32 BattleMotion_ProjectScaledPositionFar(s32 id, s32 *projected)
void * GetMotionRecordFar(struct MotionObject *object, s32 record_index)
s32 BattleMotion_ProjectPositionFar(s32 id, s32 *projected)
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
Definition heap.c:80
void * Runtime_AllocateHeapBlock(s32 kind, s32 size)
Returns heap slot kind's block, first allocating size bytes for it (rounded up to words),...
Definition heap.c:47
@ HEAP_SLOT_BATTLE_EFFECT
Definition heap_state.h:42
@ HEAP_SLOT_BATTLE_SHEET
Definition heap_state.h:44
@ HEAP_SLOT_BATTLE_CANVAS
Definition heap_state.h:43
#define WORK_SLOT(n)
Reads slots through their own addresses; adjacent slots are reached by offsets.
Definition heap_state.h:14
#define Iwram_MulQ16(left, right)
Definition iwram_call.h:127
volatile u32 gKeysHeld
Keys down now.
#define SET_VELOCITY(p, vx, vy, vz)
Definition macros.h:18
void Runtime_ReleaseHeapBlock(s32 slot)
void EffectPosition_ProjectBattler(s32 id, struct EffectPosition *position)
The screen position of a battler, 16 pixels higher.
Definition positions.c:100
void EffectPosition_ProjectScaledBattler(s32 id, struct EffectPosition *position)
The screen position of a battler, scaled for the battle view, 16 pixels higher.
Definition positions.c:88
void BattleFx_DispatchByIdRange(struct BattleEffectArgument *effect)
Runs a battle effect from the second range of kinds: 100 to 135 are the casting impacts (kind - 100),...
Definition positions.c:158
void EffectStep_AdvanceWithGravity2D(struct EffectStep *step, s32 damping, s32 gravity)
Moves a particle one frame on the screen: adds its velocity, then gravity to its vertical speed,...
Definition positions.c:46
void EffectPosition_ProjectSprite(s32 id, struct EffectPosition *position)
The screen position of a battler's sprite, at its scaled height, 16 pixels higher.
Definition positions.c:77
void EffectStep_AdvanceWithGravity3D(struct EffectStep *step, s32 damping, s32 gravity)
Moves a particle one frame in three dimensions: adds its velocity, then gravity to its vertical speed...
Definition positions.c:29
void BattleFx_ProbeKeysForExtendedActor(void)
Reads the held keys when the first target is an enemy (id 128 or more) and does nothing with them.
Definition positions.c:138
s32 BattleUnit_ProjectToScreen(s32 unit, s32 *screen)
Projects a battler onto the screen, raised by half its table height (the table holds the full height ...
Definition positions.c:114
s32 EffectPosition_ProjectPoint(const void *point, struct EffectPosition *position)
Projects a point in the current transform onto the screen, 16 pixels higher, and returns the projecti...
Definition positions.c:64
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
s32 scale
16.16 fixed point, 0x10000 full size
Definition animspr.h:111
The battle camera: its eye, the focus it turns about, and its pitch, yaw and distance.
The command shared by an effect's caller, dispatcher and handlers.
s32 kind
handler table index; 200 more for a critical hit
s16 actors[8]
the targets' unit ids, count of them
The running battle effect's work: its canvas image, 64 particles, the display registers it stages and...
struct BattleEffectArgument * effect
the command being run
struct MotionObject * object
NULL once released.
A point projected onto the screen, with its depth.
Definition effect_step.h:46
s32 y
screen pixels
Definition effect_step.h:59
A moving point of an effect: its position, its velocity and a value each effect uses its own way (a s...
Definition effect_step.h:13
s32 velocityX
16.16 fixed-point pixels per frame
Definition effect_step.h:28
s32 z
16.16 fixed-point pixels
Definition effect_step.h:26
s32 x
16.16 fixed-point pixels
Definition effect_step.h:24
s32 y
16.16 fixed-point pixels
Definition effect_step.h:25
s32 velocityY
16.16 fixed-point pixels per frame
Definition effect_step.h:29
s32 velocityZ
16.16 fixed-point pixels per frame
Definition effect_step.h:30
An effect object that moves and draws one sprite: its position, scale, velocity and target,...
Definition motobj.h:20
s32 x
16.16 fixed-point pixels
Definition motobj.h:23
s32 Render_ProjectPoint(const void *point, s32 *screen)
Reads three word-aligned coordinates from point, transforms them by gTransform and projects them to t...
Definition transform.c:364
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
#define UNUSED
Definition types.h:22