Alchemy
Loading...
Searching...
No Matches

colosso_marker.h

Go to the documentation of this file.
1#include "unit/field/field.h"
2#include "battle.h"
3#include "debug.h"
4#include "field.h"
5#include "game.h"
6#include "graphics.h"
7#include "menu.h"
8#include "minigame.h"
9#include "sound.h"
10#include "system.h"
11#include "field_event.h"
12#include "field_scene.h"
13#include "io_reg.h"
14#include "io_write_queue.h"
15#include "types.h"
16#include "call.h"
17#include "animspr.h"
18#include "object_runtime.h"
19#include "field_obj.h"
20#include "callback_scheduler.h"
21#include "vram_block.h"
22#include "songs.h"
23
24// The Colosso finals' three courses (Colosso Log, River and Wall): what a
25// stage's guide uses to describe the stage. Isaac appears on the stage to show
26// how it is crossed, a blinking pointer moves over the screen, and Isaac is
27// put back where he stood.
28
29/// The mode and stage bytes of the menu control work, set while Isaac is shown
30/// on the stage and reset when he is put back.
35};
36
37/// Isaac (id) appears at pixel (x, z) on the stage, facing south: he fades in
38/// through the backgrounds while he stretches from thin and tall to his own
39/// shape, settles and nods. His position and facing are kept for
40/// Colosso_RestoreCompetitor.
42 struct CompetitorState *state;
43 struct FieldActor *actor;
44 struct AnimationObject *sprite;
45 s32 i;
46
47 state = (struct CompetitorState *)gMenuCtrlWork;
48 actor = Object_GetById(id);
49 state->mode = 1;
50 state->stage = 4;
53 sprite = (struct AnimationObject *)actor->sprite;
57 actor->facing = FACING_SOUTH;
59 Object_SetMode(actor, 0);
60 Object_SetMode(actor, 1);
61 Engine_ActorSetPosition(id, x << 16, z << 16);
62 Engine_ActorFaceActor(0, 0x4000, 0);
66 0x20000);
67 sprite->image.objectMode = 1;
68 sprite->shadow.objectMode = 1;
70 for (i = 0; i <= 15; i += 2) {
71 actor->scaleX = (i << 12) + 0x1000;
72 actor->scaleY = 0x1f000 - (i << 12);
73 IO_WRITE_QUEUE_PUSH((u32)&REG_BLDALPHA, ((15 - i) << 8) | (i + 1), 0x20000);
75 }
77 actor->scaleX = 0x11000;
78 actor->scaleY = 0xf000;
80 actor->scaleX = 0x10000;
81 actor->scaleY = 0x10000;
83 sprite->image.objectMode = 0;
84 sprite->shadow.objectMode = 0;
87}
88
89/// Puts Isaac (id) back where Colosso_FadeInCompetitor found him: he stands
90/// (or turns south, nods and waits half a second), then returns to his kept
91/// position and facing with his motion stopped.
93 struct CompetitorState *state;
94 struct FieldActor *actor;
95 s32 zero;
96 u8 *control;
97
98 state = (struct CompetitorState *)gMenuCtrlWork;
99 actor = Object_GetById(id);
100 if (gGameState.movementMode == 1) {
103 } else {
107 }
108 zero = 0;
109 // Stored as bytes through a pointer, the plain-C form of state->stage and
110 // state->mode this site matches with (scene/README.md): a struct-field store
111 // at a varying address may pass the load of gColosso_CompetitorStartX
112 // (fixed_scalar_and_varying_struct_p), and a byte store is no struct
113 // reference.
114 control = (u8 *)state;
115 control[offsetof(struct CompetitorState, stage)] = zero;
116 control[offsetof(struct CompetitorState, mode)] = 15;
120 actor->targetX = ACTOR_NO_TARGET;
121 actor->targetZ = ACTOR_NO_TARGET;
122 actor->velocityX = zero;
123 actor->velocityZ = zero;
124 actor->motionFlags = 3;
125 actor->terrainId = 0;
126 actor->y.fixed = zero;
127 ((struct ObjectRuntime *)actor)->terrainHeight = zero;
129 Object_SetMode(actor, 0);
130 Object_SetMode(actor, 1);
132}
133
134/// Stops the actor where it is: no velocity and no destination.
136 struct FieldActor *o = Object_GetById(actor);
137
139 o->velocityX = 0;
140 o->velocityZ = 0;
143}
144
145// The guide's pointer: one 16x16 sprite centred on a point of the screen,
146// shown for 13 frames of every 20, that can glide from point to point.
147
148/// Loads the pointer's picture into a free VRAM block, once.
149static void Colosso_EnsureMarkerSlot(void) {
150
151 if (gColosso_MarkerSlot == -1) {
153 }
154}
155
156/// The pointer's glide start on one axis, read signed or unsigned.
158 s16 signedValue; ///< screen pixels
159 u16 value; ///< screen pixels
160};
161
164extern s16 gColosso_MarkerX;
167extern s16 gColosso_MarkerY;
172
173/// The pointer's scene callback: glide one step, then draw it while it blinks
174/// on (a glide keeps it on).
175static void Colosso_UpdateMarker(void) {
176 s32 tile;
177 s32 total;
178 s32 step;
179 s32 *oam;
180 s16 *steps;
181 s32 *dst;
182 s32 x;
183 s32 y;
184 s32 diff;
185 s32 base;
186 s16 *py;
187 union MarkerCoordinate *sy;
188
189 oam = gColosso_MarkerOam;
191 steps = &gColosso_MarkerSteps;
192 total = *steps;
193 if (total != 0) {
194 step = ++gColosso_MarkerStep;
195 py = &gColosso_MarkerX;
197 diff = gColosso_MarkerEndX - sy->signedValue;
198 base = sy->value;
199 *py = base + diff * (s16)step / total;
203 total;
204 if ((s16)step >= total)
205 *steps = 0;
207 }
208 if (++gColosso_MarkerBlink <= 13) {
209 /* FAKEMATCH(temporary): the size bit (0x40000000) in a local puts the
210 * priority after it; as the literal in the expression, 3 of 124
211 * instructions differ in tbs-en. */
212 s32 size = 0x40000000;
213
216 dst = oam;
217 *dst++ = 0;
218 *dst++ = (y - 8) | ((x - 8) << 16) | size | (gColosso_MarkerPriority << 28);
219 *dst = tile | 0x400;
220 Runtime_PushSlotEntry(oam, 255);
221 } else if (gColosso_MarkerBlink > 19) {
223 }
224}
225
226/// Shows the pointer at screen pixel (x, y), drawn at priority style & 3.
227void Colosso_ShowPointer(u32 x, u32 y, u32 style) {
229
232 gColosso_MarkerPriority = (style & 3);
235
237}
238
239/// Glides the pointer to screen pixel (x, y) over duration frames.
240void Colosso_MovePointer(u32 x, u32 y, u32 duration) {
245 gColosso_MarkerSteps = duration;
247
249}
250
251/// Hides the pointer and frees its VRAM block.
253
257}
258
259/// Walks the actor at 2 pixels a frame towards pixel (x, z) and returns at
260/// once.
261void Colosso_WalkActorTo(s32 actorId, s32 x, s32 z) {
262 struct FieldActor *actor = Engine_ActorLookup(actorId);
263
264 if (actor != 0) {
265 s32 speed = 0x20000;
266 s32 zero = 0;
267
268 actor->speed = speed;
269 actor->acceleration = speed >> 1;
270 actor->paused = zero;
272 Object_SetMode(actor, 5);
273 Engine_ObjectSetPosition(actor, x << 16, actor->y.fixed, z << 16);
274 }
275}
276
277/// Walks the actor at 1.25 pixels a frame to pixel (x, z), waits until it
278/// arrives and stands it there.
280 struct FieldActor *actor = Engine_ActorLookup(actorId);
281
282 if (actor != 0) {
283 s32 speed = 0x14000;
284 s32 zero = 0;
285
286 actor->speed = speed;
287 actor->acceleration = speed >> 1;
288 actor->paused = zero;
290 Object_SetMode(actor, 5);
291 Engine_ObjectSetPosition(actor, x << 16, actor->y.fixed, z << 16);
293 Object_SetMode(actor, 1);
294 }
295}
struct FieldActor * Object_GetById(s32 actor)
Returns an actor, or NULL if it does not exist.
Animated sprites: their layers, frames and colour modes, and the resource slots they draw from.
Calls through a function pointer, by argument count.
The task scheduler: tasks, their order and the scheduler's state.
s16 gColosso_MarkerSlot
void Engine_ActorSetSpriteFlags(struct FieldActor *, s32)
The engine calls the debug menus import, and their palette swatch tiles.
static s32 FieldScheduler_AddCallback(SchedulerCallback callback, s32 priority)
Registers a main-image scheduler callback.
Definition engine_call.h:36
void ObjectDispatch_StartIdle(struct DispatchObject *object)
Starts an object on the idle script (a lone SC_END).
Definition objects.c:471
s32 gColosso_MarkerOam[3]
s32 gColosso_CompetitorStartZ
s32 gColosso_CompetitorStartX
s32 gColosso_CompetitorStartAngle
The scene script layer: the engine services a scene's events call, declared once (Engine_EventBegin,...
void Engine_ObjectSetPosition(struct FieldActor *object, s32 fixed_x, s32 fixed_y, s32 fixed_z)
void Engine_ActorFaceActor(s32 actor, s32 target, s32 frames)
static void Actor_FaceDirection(s32 actor, s32 facing, s32 frames)
void Engine_ActorSetAnimationAndWait(s32 actor, s32 animation)
void Object_SetMode(struct FieldActor *object, s32 animation)
void Engine_ActorSetSpritePriority(s32 actor, s32 priority)
struct FieldActor * Engine_ActorLookup(s32 actor)
s32 Engine_TaskRemoveCallback(void(*callback)(void))
@ TASK_PRIORITY_SCENE
Definition field_event.h:40
void Engine_EventWait(s32 frames)
Field objects and actors, and the scene transition styles.
@ ACTOR_PRIORITY_AUTOMATIC
The sprite takes its priority from the map cell under it.
Definition field_obj.h:153
#define ACTOR_NO_TARGET
A target coordinate that is not set: the object has no target.
Definition field_obj.h:145
The scene table formats: entrances, exits, placements and events, and the macros that write them.
@ FACING_SOUTH
Definition field_scene.h:28
struct GameState gGameState
The screen blend's globals and the graphics routines.
The hardware's I/O registers and their bits, as pret names them.
#define BLDCNT_TGT2_BG2
Definition io_reg.h:136
#define BLDCNT_TGT2_BG0
Definition io_reg.h:134
#define BLDCNT_TGT2_BG1
Definition io_reg.h:135
#define BLDCNT_TGT2_BG3
Definition io_reg.h:137
#define BLEND_ALPHA(top, bottom)
A REG_BLDALPHA value: top and bottom are the two targets' weights, out of 16.
Definition io_reg.h:145
#define REG_BLDALPHA
Definition io_reg.h:142
#define REG_BLDCNT
Definition io_reg.h:119
The register write queue that VBlank carries out after each finished frame.
#define IO_WRITE_QUEUE_PUSH(address, value, control)
Disables interrupts to add one register write or DMA to the queue; a write to a full queue is dropped...
struct ObjectSystemWork * gMenuCtrlWork
The reel game's title lettering.
void FieldObject_WaitForMove(void *fieldObject)
Waits a frame at a time until a field object has arrived at its target, at most 600 frames.
ObjectRuntime, a field object's runtime state, and the object snapshots.
void Runtime_PushSlotEntry(void *slotEntry, s32 slot)
Links a sprite entry into depth slot slot (clamped to 0..255) for this frame.
Definition render.c:79
Song and sound effect ids, indices into gSound_SongTable.
#define SE_252
Definition songs.h:247
void Engine_ActorSetAnimation()
void Engine_ActorSetPosition(u32 actor, s32 x, s32 z)
void Engine_AudioPlayCue()
void Engine_TaskWait()
static void Colosso_EnsureMarkerSlot(void)
Loads the pointer's picture into a free VRAM block, once.
s16 gColosso_MarkerX
void Colosso_ShowPointer(u32 x, u32 y, u32 style)
Shows the pointer at screen pixel (x, y), drawn at priority style & 3.
s16 gColosso_MarkerBlink
union MarkerCoordinate gColosso_MarkerStartX
s16 gColosso_MarkerY
void Colosso_MovePointer(u32 x, u32 y, u32 duration)
Glides the pointer to screen pixel (x, y) over duration frames.
s16 gColosso_MarkerStep
void OverlayObject_ResetMotionFields(s32 actor)
Stops the actor where it is: no velocity and no destination.
void Colosso_WalkActorTo(s32 actorId, s32 x, s32 z)
Walks the actor at 2 pixels a frame towards pixel (x, z) and returns at once.
void Colosso_FadeInCompetitor(s32 id, s32 x, s32 z)
Isaac (id) appears at pixel (x, z) on the stage, facing south: he fades in through the backgrounds wh...
s16 gColosso_MarkerEndY
s16 gColosso_MarkerEndX
static void Colosso_UpdateMarker(void)
The pointer's scene callback: glide one step, then draw it while it blinks on (a glide keeps it on).
s16 gColosso_MarkerPriority
void Colosso_HidePointer(void)
Hides the pointer and frees its VRAM block.
void Colosso_WalkActorToAndStand(s32 actorId, s32 x, s32 z)
Walks the actor at 1.25 pixels a frame to pixel (x, z), waits until it arrives and stands it there.
void Colosso_RestoreCompetitor(s32 id)
Puts Isaac (id) back where Colosso_FadeInCompetitor found him: he stands (or turns south,...
s16 gColosso_MarkerSteps
union MarkerCoordinate gColosso_MarkerStartY
#define offsetof(type, member)
Definition stddef.h:19
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
struct AnimationSpritePart shadow
Definition animspr.h:110
struct AnimationSpritePart image
Definition animspr.h:109
The mode and stage bytes of the menu control work, set while Isaac is shown on the stage and reset wh...
A field object as the object dispatcher's far calls take it.
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
s32 speed
speed limit, 16.16 fixed-point pixels per frame
Definition field_obj.h:55
s32 targetX
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:59
u8 motionFlags
ActorMotionFlag bits; zero is free flight in 3D, and 3 is set on creation.
Definition field_obj.h:83
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
s32 velocityX
16.16 fixed-point pixels per frame
Definition field_obj.h:52
u8 paused
nonzero skips its script and motion, not its update
Definition field_obj.h:93
union FieldCoordinate y
16.16 fixed-point pixels
Definition field_obj.h:36
u8 priorityFlags
ActorPriorityFlag bits, read by the scrolling camera.
Definition field_obj.h:51
union FieldCoordinate z
16.16 fixed-point pixels
Definition field_obj.h:37
u16 facing
1/65536 turns
Definition field_obj.h:34
s32 acceleration
Added toward the target each frame, or taken off the speed when there is none, in 16....
Definition field_obj.h:58
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
s32 velocityZ
16.16 fixed-point pixels per frame
Definition field_obj.h:54
u8 terrainId
The map layer (0 to 3) its ground height is read from, which the scrolling camera updates from the ce...
Definition field_obj.h:47
u8 movementMode
1 while the leader is climbing, 0 otherwise
Definition game_state.h:57
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
s32 terrainHeight
16.16 fixed-point pixels
u16 offset
bytes from the start of OBJ VRAM
Definition vram_tab.h:25
The system's routines and globals: interrupts, BIOS sound bias, random numbers and sleep.
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
s32 fixed
16.16 fixed-point pixels
The pointer's glide start on one axis, read signed or unsigned.
u16 value
screen pixels
s16 signedValue
screen pixels
Declares nothing of its own: it only includes the window, battle command, resource and VRAM table hea...
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
Definition vram_cache.c:106
struct VramBlockCacheEntry gVramBlockCache[]
s32 Resource_LoadFixedBlockBIntoFreeSlot(void)
Loads the pointing hand cursor's tiles (gResource_FixedBlockBTiles, 128 bytes) into a free VRAM slot ...
Definition save.c:1269