Alchemy
Loading...
Searching...
No Matches

sol_sanctum_elemental_star_ring_setup.h

Go to the documentation of this file.
1#include "battle.h"
2#include "debug.h"
3#include "field.h"
4#include "game.h"
5#include "graphics.h"
6#include "menu.h"
7#include "minigame.h"
8#include "sound.h"
9#include "system.h"
10#include "mem.h"
11#include "dma.h"
12#include "io_reg.h"
13
14// Sol Sanctum's Elemental Star room and its eruption: the lights that float in
15// the room (actors 15 to 24), each pulsing and drifting on its own path from
16// the tables gSolSanctumRing_* and gSolSanctum_Ring*, by its index.
17
19
20/// Legacy actor view used only while setting up the sprite flags.
29 u8 pad20[24];
33 u8 pad44[12];
37};
38
39/// One floating light: its actor, its drift and its pulsing scale, and where it
40/// is while hidden.
42 struct FieldActor *obj;
43 s32 x; ///< 16.16 fixed-point pixels
44 s32 y; ///< 16.16 fixed-point pixels
45 s32 z; ///< 16.16 fixed-point pixels
49 s32 scale; ///< 16.16 fixed point, where 0x10000 is full size
50 s32 scaleStep; ///< 16.16 fixed point
54};
55
56/// The floating lights' work in work slot 33, one entry per light.
60};
61
62/// A scene callback, the lights' work in work slot 33. Every third frame each
63/// light grows to its largest scale and shrinks to a tenth; at the smallest it
64/// vanishes for 24 steps while its drift carries on, and comes back where the
65/// drift has taken it. Its drift is a random speed on each axis, as its tables
66/// allow, turned into a sine swing.
67static void SolSanctum_UpdateRing(void) {
68 struct SolSanctumRingList *list =
69 Runtime_AllocateBlock(33, sizeof(struct SolSanctumRingList));
70 struct SolSanctumRingEntry *entry = list->entries;
71 u32 i;
72
73 i = 0;
74 while (i != list->count) {
75 struct FieldActor *obj;
76 s32 speedX;
77 s32 speedY;
78 s32 speedZ;
79 s32 scale;
80 s32 step;
81 u8 timer;
82 s32 x;
83 s32 y;
84 s32 z;
85 u8 hold;
86
87 obj = entry->obj;
88 speedX = entry->speedX;
89 speedY = entry->speedY;
90 speedZ = entry->speedZ;
91 scale = entry->scale;
92 step = entry->scaleStep;
93 hold = entry->hold;
94 x = entry->x;
95 y = entry->y;
96 z = entry->z;
97 timer = entry->timer;
98 if (--timer == 0) {
99 u32 rx;
100 u32 ry;
101 u32 rz;
102 s32 dx;
103 s32 dy;
104
105 timer = 3;
106 if (hold == 0) {
107 scale += step;
108 if (scale >= gSolSanctumRing_MaxScales[i]) {
110 } else if (scale <= 0x1999) {
112 scale = 0x1999;
113 hold = 24;
114 x = obj->x.fixed;
115 y = obj->y.fixed;
116 z = obj->z.fixed;
117 obj->x.fixed = 0;
118 obj->y.fixed = 0;
119 obj->z.fixed = 0;
120 }
121 obj->scaleX = scale;
122 obj->scaleY = scale;
123 }
124 rx = (gSolSanctum_RingDrift[i][0] * (u32)Engine_RandomNext()) >> 16;
125 ry = (gSolSanctum_RingDrift[i][1] * (u32)Engine_RandomNext()) >> 16;
126 rz = (gSolSanctum_RingDrift[i][2] * (u32)Engine_RandomNext()) >> 16;
127 rx = rx != 0 ? (rx << 16) / 1000 : 0;
128 ry = ry != 0 ? (ry << 16) / 1000 : 0;
129 rz = rz != 0 ? (rz << 16) / 1000 : 0;
130 if (gSolSanctum_RingDirection[i][0] == 1)
131 speedX += rx;
132 else if (gSolSanctum_RingDirection[i][0] == -1)
133 speedX -= rx;
134 else
135 speedX = 0;
136 if (gSolSanctum_RingDirection[i][1] == 1)
137 speedY += ry;
138 else if (gSolSanctum_RingDirection[i][1] == -1)
139 speedY -= ry;
140 else
141 speedY = 0;
142 if (gSolSanctum_RingDirection[i][2] == 1)
143 speedZ += rz;
144 else if (gSolSanctum_RingDirection[i][2] == -1)
145 speedZ -= rz;
146 else
147 speedZ = 0;
148 dx = Engine_MathSin(speedX * gSolSanctum_RingSwing[i][0]) * 2;
149 dy = Engine_MathSin(speedY * gSolSanctum_RingSwing[i][1]) * 2;
150 {
151 s32 dz = Engine_MathCos(speedZ * gSolSanctum_RingSwing[i][2]) * 2;
152
153 if (hold != 0) {
154 x += dx;
155 y += dy;
156 z += dz;
157 if (--hold == 0) {
158 obj->x.fixed = x;
159 obj->targetX = x;
160 if (ry != 0) {
161 obj->y.fixed = y;
162 obj->targetY = y;
163 }
164 obj->z.fixed = z;
165 obj->targetZ = z;
166 }
167 } else {
168 obj->x.fixed += dx;
169 obj->targetX = obj->x.fixed;
170 if (ry != 0) {
171 obj->y.fixed += dy;
172 obj->targetY = obj->y.fixed;
173 }
174 obj->z.fixed += dz;
175 obj->targetZ = obj->z.fixed;
176 }
177 }
178 }
179 entry->speedX = speedX;
180 entry->speedY = speedY;
181 entry->speedZ = speedZ;
182 entry->scale = scale;
183 entry->scaleStep = step;
184 entry->hold = hold;
185 entry->x = x;
186 entry->y = y;
187 entry->z = z;
188 entry->timer = timer;
189 i++;
190 entry++;
191 }
192}
193
194/// Starts the floating lights: count actors (at most 10) from first, each drawn
195/// translucent and starting at its largest scale.
197 // The actors are read through struct SolSanctumRingObject, the plain-C view
198 // this site matches with (scene/README.md): it keeps the sprite-flags address
199 // before the ring-entry store, where FieldActor and AnimationObject swap the
200 // two instructions. The callback reads FieldActor.
201 struct SolSanctumRingList *list;
202 struct SolSanctumRingEntry *entry;
203 struct SolSanctumRingObject *obj;
204 u32 i;
205 s32 none;
206 s32 cleared;
207
208 list = Runtime_AllocateBlock(33, sizeof(struct SolSanctumRingList));
209 entry = list->entries;
210 Dma_Fill32(0, list, sizeof(struct SolSanctumRingList));
211 if (count > SOL_SANCTUM_RING_MAX)
212 count = SOL_SANCTUM_RING_MAX;
213 none = 0;
214 i = none;
215 if (count != 0) {
216 cleared = none;
217 do {
218 obj = (struct SolSanctumRingObject *)Object_GetById(first);
219 {
220 u8 *frame = &obj->anim[38];
221
222 entry->obj = (struct FieldActor *)obj;
223 *frame = cleared;
224 }
225 obj->state = cleared;
230 entry->timer = 3;
231 i++;
232 entry++;
233 first++;
234 } while (i != count);
235 }
236 list->count = count;
238}
struct FieldActor * Object_GetById(s32 actor)
Returns an actor, or NULL if it does not exist.
The engine calls the debug menus import, and their palette swatch tiles.
DMA channel registers, and the DMA and CPU fills.
#define Dma_Fill32(value, destination, size)
Fills size bytes at destination with the word value by DMA3.
Definition dma.h:30
static s32 FieldScheduler_AddCallback(SchedulerCallback callback, s32 priority)
Registers a main-image scheduler callback.
Definition engine_call.h:36
@ OBJECT_BLEND_TRANSLUCENT
s32 Engine_MathSin(s32 angle)
void Engine_ObjectSetBlendMode(struct FieldActor *object, s32 mode)
s32 Engine_RandomNext()
s32 Engine_MathCos(s32 angle)
@ TASK_PRIORITY_SCENE
Definition field_event.h:40
The screen blend's globals and the graphics routines.
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
The hardware's I/O registers and their bits, as pret names them.
The heaps: allocating and freeing blocks.
The reel game's title lettering.
s8 gSolSanctum_RingDirection[][3]
s32 gSolSanctumRing_ScaleSteps[]
s32 gSolSanctumRing_MaxScales[]
u8 gSolSanctum_RingSwing[][3]
u8 gSolSanctum_RingDrift[][3]
static void SolSanctum_UpdateRing(void)
A scene callback, the lights' work in work slot 33.
void SolSanctum_StartFloatingLights(s32 first, u32 count)
Starts the floating lights: count actors (at most 10) from first, each drawn translucent and starting...
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
s16 timer
The parameter its action script reads (a follow distance or an angle to face), the player's frames to...
Definition field_obj.h:109
s32 targetX
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:59
union FieldCoordinate x
16.16 fixed-point pixels
Definition field_obj.h:35
s32 targetZ
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:61
union FieldCoordinate y
16.16 fixed-point pixels
Definition field_obj.h:36
union FieldCoordinate z
16.16 fixed-point pixels
Definition field_obj.h:37
s32 targetY
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:60
s32 scaleX
16.16 fixed point, 0x10000 full size
Definition field_obj.h:39
s32 scaleY
16.16 fixed point, 0x10000 full size
Definition field_obj.h:40
One floating light: its actor, its drift and its pulsing scale, and where it is while hidden.
s32 scale
16.16 fixed point, where 0x10000 is full size
The floating lights' work in work slot 33, one entry per light.
struct SolSanctumRingEntry entries[SOL_SANCTUM_RING_MAX]
Legacy actor view used only while setting up the sprite flags.
The system's routines and globals: interrupts, BIOS sound bias, random numbers and sleep.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
s32 fixed
16.16 fixed-point pixels