Alchemy
Loading...
Searching...
No Matches

objects.c

Go to the documentation of this file.
1/// @file
2/// Field objects: the object pool, dissolving sprites, starting scripts.
3/// Part of field.c, the field object, compiled only through it.
4
5#include "../field_internal.h"
6
7/// One step of dissolving a sprite pixel by pixel. In each 8x8 tile (256
8/// colours) one pixel is cleared, in gMap_TileDissolveOrder's order; each
9/// tile runs one step ahead of the last, and only tiles whose step is 64-127
10/// clear a pixel. obj is the sprite (struct AnimationObject), pos the step
11/// (0-127). Writes the sprite's tiles in OBJ VRAM. Called by the two
12/// functions below and, as render_animated_tile_frameFar, by the battle's
13/// playback (battle/battle/playback.c).
15 u16 *tile;
16 s32 tileCount;
17 u32 i;
18 const u8 *order;
19 u32 highMask;
20 u32 indexMask;
21 u8 offsetMask;
22
23 struct AnimationObject *sprite = (struct AnimationObject *)obj;
24
25 // The sprite's tiles in OBJ VRAM.
26 tile = (u16 *)(OBJ_VRAM0 + gVramBlockCache[sprite->slot].offset);
27 tileCount = (sprite->width * sprite->height) / 64;
28 i = 0;
29
30 if (i < tileCount) {
32 highMask = 0xff00;
33 indexMask = 0x3f;
34 offsetMask = 0x3e;
35
36 // A tile is 64 bytes (32 halfwords) at 8 bits a pixel. The unsigned
37 // test passes only steps 64 to 127, so later tiles start clearing
38 // first and the dissolve sweeps across the sprite.
39 for (; i < tileCount; i++, tile += 32, pos++) {
40 if ((pos - 64) <= 63) {
41 u8 pixel;
42 u16 *pixelPair;
43 u32 isOdd;
44
45 // VRAM takes no byte writes: rewrite the pixel pair, clearing one.
46 pixel = order[(pos + i * 16) & indexMask];
47 pixelPair = (u16 *)((u8 *)tile + (pixel & offsetMask));
48 isOdd = 1;
49 isOdd &= pixel;
50 if (isOdd != 0)
51 *pixelPair = *(u8 *)pixelPair;
52 else
53 *pixelPair &= highMask;
54 }
55 }
56 }
57}
58
59/// Dissolves a sprite pixel by pixel, four steps a frame, over 32 frames.
60/// Called through Map_RenderAnimatedTileFramesForObjectFar by the auto
61/// battle (battle/battle/auto_battle.c).
63 u32 step;
64
65 step = 0;
66 // Finish all four dissolve steps before waiting for the next video frame.
67 do {
68 Map_RenderAnimatedTileFrame(sprite, step);
69 Map_RenderAnimatedTileFrame(sprite, step + 1);
70 Map_RenderAnimatedTileFrame(sprite, step + 2);
71 Map_RenderAnimatedTileFrame(sprite, step + 3);
72 step += 4;
73 WaitFrames(1);
74 } while (step <= 127);
75}
76
77/// Dissolves count sprites together, pixel by pixel, over 32 frames.
78/// Called through Map_RenderAllAnimatedTileFramesFar by the battle's staging
79/// (battle/battle/staging.c), after the unit is taken off its lists.
81 u8 **firstSprite;
82 u8 **spriteCursor;
83 s32 spritesRemaining;
84 u32 step;
85 u32 secondDissolveStep;
86 u32 thirdDissolveStep;
87 u32 fourthDissolveStep;
88
89 firstSprite = sprites;
90 step = 0;
91 do {
92 if (count > 0) {
93 secondDissolveStep = step + 1;
94 thirdDissolveStep = step + 2;
95 spriteCursor = firstSprite;
96 fourthDissolveStep = step + 3;
97 spritesRemaining = count;
98 do {
99 Map_RenderAnimatedTileFrame(*spriteCursor, step);
100 Map_RenderAnimatedTileFrame(*spriteCursor, secondDissolveStep);
101 Map_RenderAnimatedTileFrame(*spriteCursor, thirdDissolveStep);
102 spritesRemaining -= 1;
103 Map_RenderAnimatedTileFrame(*spriteCursor++, fourthDissolveStep);
104 } while (spritesRemaining != 0);
105 }
106 WaitFrames(1U);
107 step += 4;
108 } while (step <= 0x7fU);
109}
110
111/// Writes the object's screen position, in pixels, to screenPosition[0..1] and
112/// returns 0 when it is on or near the screen; otherwise writes 0, 0 and
113/// returns -1.
115 s32 *screenPosition) {
116 struct MapScrollWork *mapWork = gMapWork[0];
117#ifndef UBFIX
118 s32 *viewCoordinates = &mapWork->viewX;
119#endif
120 s32 viewX;
121 s32 viewZ;
122 s32 x;
123 s32 y;
124
125 // UB: viewY is a separate member, not a second element of viewX.
126 // Direct member loads change the EN save set and load order (96 bytes each).
127#ifdef UBFIX
128 viewX = mapWork->viewX & 0xffff0000;
129 viewZ = mapWork->viewY & 0xffff0000;
130#else
131 viewX = viewCoordinates[0] & 0xffff0000;
132 viewZ = viewCoordinates[1] & 0xffff0000;
133#endif
134 x = object->x - viewX;
135 y = object->z - viewZ;
136 // Across, from 32 pixels left of the screen to 32 past its 240; down,
137 // below the view's top and above 224.
138 if ((x >= -0x1fffff && x <= 0x10fffff) && y > 0 && y < 0xe00000) {
139 *screenPosition++ = x >> 16;
140 *screenPosition = y >> 16;
141 return 0;
142 }
143 *screenPosition++ = 0;
144 *screenPosition = 0;
145 return -1;
146}
147
148/// Sets up the object system: allocates and zeroes the 64 objects and
149/// registers the per-frame updates. Mode 4 moves objects with
150/// Object_UpdateAllMotion; modes 3 and 4 use the fixed camera.
151///
152/// Called through ObjectSystem_InitializeFar by the field scene runner
153/// (object/object/run_scene.c: 2 for a layered map, MODE_WORLD_MAP for the
154/// world map) and the battle's encounter (4), and directly by the sprite
155/// viewer (2). Allocates heap slot 6 for the ObjectSystemWork and slot 5 for
156/// the objects, and sets the sprite outline colours.
157void ObjectSystem_Initialize(s32 controlMode) {
158 struct ObjectSystemWork *objectSystem;
159 struct ObjectRuntime *objectPool;
160 volatile u32 fill;
161
162 objectSystem = Runtime_AllocateBlock(6, sizeof(*objectSystem));
163 objectPool =
164 Runtime_AllocateBlock(5, FIELD_OBJECT_COUNT * sizeof(*objectPool));
165 ObjectSystem_Configure(controlMode);
166 Dma_Fill32Cell(fill, 0, objectPool, FIELD_OBJECT_COUNT * sizeof(*objectPool));
167 Dma_Fill32Cell(fill, 0, objectSystem, sizeof(*objectSystem));
168 // The scheduler runs higher orders first: the objects move (0xc8a) before
169 // the camera follows them (0xc80).
170 if (controlMode == 4)
172 else
174 if (controlMode >= 3 && controlMode <= 4) {
176 } else {
178 gIwram_Data2 = 0;
179 gIwram_Data1 = 0;
180 }
181 objectSystem->edge = 15;
182 objectSystem->fill = 0;
183}
184
186
188
189/// Returns the first of the 64 objects not in use (with no script), or 0.
190/// Called by FieldObject_Create.
192 struct ObjectRuntime *object = gObjectSlots;
193 void *freeObject = 0;
194 s32 objectIndex = 0;
195
196 while (objectIndex <= FIELD_OBJECT_COUNT - 1) {
197 if (object->script == 0) {
198 freeObject = object;
199 break;
200 }
201 objectIndex++;
202 object++;
203 }
204 return freeObject;
205}
206
207/// Releases an object's sprites and zeroes it, freeing it.
208/// Clearing the script lets ObjectDispatch_FindFreeObject hand the object out
209/// again. Reached through SC_FREE (Script_FreeObject) and, as
210/// ObjectDispatch_ReleaseFar, from the battle, the Psynergy effects and the
211/// field scene's objects.
213 s32 spritesRemaining;
214 void **sprites;
215
216 if (object) {
217 switch (object->kind & 15) {
218 case 1: // one sprite
219 ResourceObject_Release(object->target.child);
220 break;
221 case 2: // up to four sprites
222 sprites = object->target.children;
223 spritesRemaining = 3;
224 do {
225 struct AnimationObject *sprite = *sprites++;
226 if (sprite)
228 } while (--spritesRemaining >= 0);
229 break;
230 }
231 Dma_Fill32(0, object, sizeof(struct ObjectRuntime));
232 }
233}
234
235/// Creates a field object at (x, y, z), in 16.16 pixels, or returns 0 when
236/// none is free. id / 4096 is the kind (0: one sprite, 2: two sprites, id
237/// and id + 1) and the low 12 bits the sprite's animation id.
238///
239/// Called as Object_CreateFar by the battle's placement, the Psynergy
240/// effects, the field scene's actors and markers and the scene scripts, and
241/// directly by the player control for footprints (25) and ripples (24).
242/// Gives the object gObjectDispatch_DefaultScript (a lone SC_END), its home
243/// position and the default motion values; a group's sprite list is taken from
244/// the ObjectSystemWork's group tables.
245struct ObjectRuntime *FieldObject_Create(s32 encodedSprite, s32 x, s32 y,
246 s32 z) {
247 struct ObjectRuntime *object;
248 struct FieldActor *actor;
249 struct ScriptMotionObject *motion;
250 struct ScriptObjectRuntime *scripted;
251 struct AnimationObject *sprite;
252 s32 spriteStorageKind;
253 void **spriteSlots;
254
255 // The ROM searches twice and drops the first result.
257 spriteStorageKind = encodedSprite / 4096;
258 encodedSprite &= 0xfff;
260 if (object != NULL) {
261 actor = (struct FieldActor *)object;
262 actor->radius = 16;
263 switch (spriteStorageKind) {
264 case 0:
265 sprite = ResourceObject_Create(encodedSprite);
266 if (sprite != NULL) {
267 object->animationKind = 1;
268 object->animation = sprite;
269 actor->radius = Resource_GetMetadataRecordFar(encodedSprite)->boxY >> 1;
270 } else {
271 object->animationKind = 0;
272 }
273 break;
274 case 2:
275 // Take a zeroed list of four sprites, and fill it with id and id + 1.
276 spriteSlots =
277 (void **)((u32 *)gMenuCtrlWork + gMenuCtrlWork->count++ + 2);
278 object->animationKind = spriteStorageKind;
279 object->animation = spriteSlots;
280 Dma_Fill32(0, spriteSlots, 0x10);
281 sprite = ResourceObject_Create(encodedSprite);
282 if (sprite != NULL) {
283 actor->radius = Resource_GetMetadataRecordFar(encodedSprite)->boxY >> 1;
284 *spriteSlots++ = sprite;
285 }
286 sprite = ResourceObject_Create(encodedSprite + 1);
287 if (sprite != NULL)
288 *spriteSlots = sprite;
289 break;
290 }
291 }
292 if (object != NULL) {
293 motion = (struct ScriptMotionObject *)object;
294 scripted = (struct ScriptObjectRuntime *)object;
296 // Up to 2 pixels a frame, gaining 1 a frame; unit scale; facing a
297 // quarter turn.
298 object->script = (s32 *)gObjectDispatch_DefaultScript;
299 object->speedLimit = 0x20000;
300 object->step = 0;
301 actor->scaleX = 0x10000;
302 actor->scaleY = 0x10000;
303 object->acceleration = 0x10000;
304 object->flags = 3;
305 motion->gravity = 0x10000;
306 motion->vertical.bounce = 0x4000;
307 object->collisionFlags = 0;
308 object->actionFlags = 1;
309 actor->riseBaseY = 0;
310 object->angle = 0x4000;
311 // Its home position, in pixels.
312 scripted->homeX = x / 65536;
313 scripted->homeZ = z / 65536;
314 }
315 return object;
316}
317
318/// Gives an object a script and starts it from the top.
319/// Sets the script and clears the cursor, the pause, the loop count and the
320/// last flag test. Called by the Start functions below and the player
321/// control, and as ObjectDispatch_InitializeFar by the battle's placement,
322/// the Psynergy effects and the field scene's events.
324 const s32 *script) {
325 if (object != 0) {
326 object->value04 = 0;
327 object->value00 = (u32)script;
328 object->value5b = 0;
329 object->value5d = 0;
330 object->value57 = 0;
331 }
332}
333
334/// Defines name(object, value), which calls apply(sprite, value) on an
335/// object's one sprite, or on each sprite of its group.
336#define OBJECT_DISPATCH_DEFINE_APPLY(name, object_type, apply) \
337 void name(object_type rawObject, s32 value) { \
338 struct DispatchObject *object; \
339 void **sprites; \
340 s32 spritesRemaining; \
341 void *sprite; \
342 \
343 object = rawObject; \
344 if (object != 0) { \
345 switch (object->kind & 0xf) { \
346 case 1: \
347 apply(object->target.child, value); \
348 break; \
349 case 2: \
350 sprites = object->target.children; \
351 spritesRemaining = 3; \
352 do { \
353 sprite = *sprites++; \
354 if (sprite != 0) \
355 apply(sprite, value); \
356 spritesRemaining--; \
357 } while (spritesRemaining >= 0); \
358 break; \
359 } \
360 } \
361 }
362
363/// Switches all of an object's sprites to animation value.
366
367/// Sets the animation speed (timer step) of all of an object's sprites.
369 struct DispatchObject *,
371
372/// Both of the above: switches all of an object's sprites to animation and
373/// sets their timer step to step.
375 s32 animation, s32 step) {
376 void **sprites;
377 void *sprite;
378 s32 spritesRemaining;
379
380 if (object != 0) {
381 switch (object->kind & 15) {
382 case 1:
383 AnimationObjects_SelectAnimation(object->target.child, animation);
384 AnimationObjects_SetActiveTimerSteps(object->target.child, step);
385 break;
386 case 2:
387 sprites = object->target.children;
388 for (spritesRemaining = 3; spritesRemaining >= 0; spritesRemaining--) {
389 sprite = *sprites++;
390 if (sprite != 0) {
393 }
394 }
395 break;
396 }
397 }
398}
399
400/// Sets the rotation of an object's sprite, when it has just one.
402 u32 rotation) {
403 if (object != 0 && (object->kind & 0xf) == 1)
404 object->target.child->rotation = rotation;
405}
406
407/// Gives a one-sprite object's first layer animation id animationId and
408/// restarts its layers.
409/// A negative animationId does nothing.
410void Animation_SetIndexAndInitObjects(void *rawDispatchObject,
411 s32 animationId) {
412 struct DispatchObject *object = rawDispatchObject;
413 struct AnimationObject *sprite;
414
415 if (object != NULL && (object->kind & 0xf) == 1) {
416 sprite = object->target.child;
417 if (animationId >= 0) {
418 sprite->entries[0]->animId = animationId;
420 }
421 }
422}
423
424/// Adds a layer of animation id animationId to a one-sprite object's sprite.
425/// A negative animationId does nothing.
427 s32 animationId) {
428 if (object != 0 && (object->kind & 0xf) == 1) {
429 struct AnimationObject *sprite = object->target.child;
430 if (animationId >= 0)
431 ResourceMetadata_Register(sprite, animationId);
432 }
433}
434
435/// Starts an object on the script that approaches its linked object
436/// (SC_APPROACH_LINK), linked to linkedObjectHandle. The functions below start
437/// the engine's other scripts (object_script.c).
439 s32 linkedObjectHandle) {
441 object->argument = linkedObjectHandle;
442}
443
444/// Starts an object on the script that runs SC_KEY_COUNT every frame.
445/// The field scene runner (object/object/run_scene.c) gives it to the leader
446/// when gGameState.movementMode is 2.
449}
450
451/// Starts an object on the script that moves it by the keys (SC_KEYS).
452/// The field scene runner gives it to the leader when gGameState.movementMode
453/// is 1.
456}
457
458/// Starts an object on the player control script (SC_PLAYER).
459/// The field scene runner's usual choice for the leader on a layered map.
462}
463
464/// Starts an object on the world map control script (SC_WORLD).
465/// The field scene runner gives it to the leader on the world map.
468}
469
470/// Starts an object on the idle script (a lone SC_END).
473}
474
475/// Starts an object on the camera script (SC_CAMERA). With a leader to
476/// follow, it also gets a speed limit of 4 pixels a frame and an
477/// acceleration of 0.5 (value30 and value34 are those fields). Called through
478/// ObjectDispatch_StartCameraFar by the field scene's actors, the Psynergy
479/// camera and the Colosso and Kolima Forest scenes.
481 s32 linkedObjectHandle) {
483 if (linkedObjectHandle != 0) {
484 object->value34 = 0x8000;
485 object->value30 = 0x40000;
486 object->argument = linkedObjectHandle;
487 object->value64 = 0;
488 }
489}
490
491/// Waits until the object's script reaches SC_END (0x10), at most 300 frames.
492/// Called through ObjectDispatch_WaitForValue16Far by the Psynergy actor
493/// commands and by scenes that wait for a scripted move (Colosso, Venus
494/// Lighthouse, Vale).
495void ObjectDispatch_WaitForValue16(void *rawObject) {
496 struct ScriptInterpreter *interpreter = rawObject;
497 s32 waitedFrames;
498
499 waitedFrames = 0;
500 if (interpreter->script[interpreter->cursor] != SC_END) {
501 do {
502 WaitFrames(1);
503 waitedFrames++;
504 if (waitedFrames > 299)
505 break;
506 } while (interpreter->script[interpreter->cursor] != SC_END);
507 }
508}
509
510/// Sets the flags of a one-sprite object's sprite (bit 0: draw its shadow).
512 u32 flags) {
513 if (object != NULL) {
514 if ((object->kind & 0xf) == 1)
515 object->target.child->flags = flags;
516 }
517}
518
519/// Sets the OAM blend mode of a one-sprite object's sprite.
520/// This one and the next two test the whole kind byte, not its low four
521/// bits, so an object with high kind bits set is left alone.
523 if (object != 0 && object->kind == 1) {
524 struct AnimationObject *sprite = object->target.child;
525 sprite->image.objectMode = mode;
526 }
527}
528
529/// Makes the fixed camera draw a one-sprite object at its own scale instead of
530/// scaling it by distance.
532 u32 fixedScale) {
533 if (object != 0 && object->kind == 1) {
534 struct AnimationObject *sprite = object->target.child;
535 sprite->useOwnScale = fixedScale;
536 }
537}
538
539/// Sets the draw parameter of a one-sprite object's layers (see
540/// ObjectGroup_SetChildValueUnlessFifteen).
541void Animation_ApplyChildValues(struct DispatchObject *object, u32 param) {
542 if (object != NULL && object->kind == 1)
544}
545
546/// Suspends the object camera updates, starts the palette back to normal and,
547/// a frame later, shows the sprites with BG1-3 hidden, leaving BG0 unchanged.
548/// Called through
549/// ObjectSystem_SuspendProjectionAndShowSpritesFar by scenes (Colosso, the
550/// Tolbi ship, Vale, Venus Lighthouse). The scenes except Colosso pair it
551/// with ObjectSystem_ResumeProjectionAndHideLayers.
557 WaitFrames(1);
561}
562
563/// Resumes the object camera updates and hides BG1-3 and the sprites.
564/// Called through ObjectSystem_ResumeProjectionAndHideLayersFar by the same
565/// scenes except Colosso.
569 REG_DISPCNT &=
571}
572
574
575#undef OBJECT_DISPATCH_DEFINE_APPLY
void AnimationObjects_SetActiveTimerSteps(struct AnimationObject *sprite, s32 step)
Sets the timer step, the animation speed, of each animated layer of a sprite (16 is normal speed).
Definition animation.c:392
s32 ResourceMetadata_Register(struct AnimationObject *sprite, s32 id)
Adds a layer of animation id to a sprite, in its first free layer of four.
Definition animation.c:191
void ObjectSystem_Configure(s32 mode)
Allocates and zeroes the 64 sprites and 64 animation layers (from the fixed blocks in mode 3,...
Definition animation.c:411
s32 AnimationObjects_SelectAnimation(struct AnimationObject *sprite, s32 animation)
Starts animation flags & 0x7f on every layer of a sprite (bit 7 keeps each layer's place and timer),...
Definition animation.c:317
void ResourceObject_Release(struct AnimationObject *sprite)
Releases a sprite: its VRAM cache entry (unless retainCacheEntry is set), its four animation layers,...
Definition animation.c:624
s32 Animation_InitializeObjects(struct AnimationObject *sprite)
Resets each layer of a sprite from its animation's metadata: its facing kind, frames,...
Definition animation.c:118
struct AnimationObject * ResourceObject_Create(s32 id)
Creates a sprite for animation id, taking one of the 64 free sprites and a VRAM cache entry for its t...
Definition animation.c:512
#define Dma_Fill32Cell(cell, value, destination, size)
Dma_Fill32 through the caller's own volatile word cell, so a function that fills several blocks keeps...
Definition dma.h:42
#define Dma_Fill32(value, destination, size)
Fills size bytes at destination with the word value by DMA3.
Definition dma.h:30
const u8 gMap_TileDissolveOrder[64]
The order in which the 64 pixels of a sprite's tile in OBJ VRAM dissolve; read by Map_RenderAnimatedT...
Definition facing.c:68
void BattleFx_ApplyColorToTargetBufferFar(s32 mode, s32 half)
void BattleFx_StartBufferInterpolationFar(s32 frames)
struct AnimationMetadata * Resource_GetMetadataRecordFar(u32 number)
void ObjectDispatch_StartMoveByKeys(struct DispatchObject *object)
Starts an object on the script that moves it by the keys (SC_KEYS).
Definition objects.c:454
void ObjectDispatch_SetChildRotation(struct DispatchObject *object, u32 rotation)
Sets the rotation of an object's sprite, when it has just one.
Definition objects.c:401
void ObjectDispatch_StartApproachLink(struct DispatchObject *object, s32 linkedObjectHandle)
Starts an object on the script that approaches its linked object (SC_APPROACH_LINK),...
Definition objects.c:438
void Animation_ApplyChildValues(struct DispatchObject *object, u32 param)
Sets the draw parameter of a one-sprite object's layers (see ObjectGroup_SetChildValueUnlessFifteen).
Definition objects.c:541
void ObjectDispatch_SetAnimationAndSpeed(struct DispatchObject *object, s32 animation, s32 step)
Both of the above: switches all of an object's sprites to animation and sets their timer step to step...
Definition objects.c:374
struct ObjectRuntime * FieldObject_Create(s32 encodedSprite, s32 x, s32 y, s32 z)
Creates a field object at (x, y, z), in 16.16 pixels, or returns 0 when none is free.
Definition objects.c:245
void Animation_SetIndexAndInitObjects(void *rawDispatchObject, s32 animationId)
Gives a one-sprite object's first layer animation id animationId and restarts its layers.
Definition objects.c:410
void Map_RenderAnimatedTileFramesForObject(u8 *sprite)
Dissolves a sprite pixel by pixel, four steps a frame, over 32 frames.
Definition objects.c:62
void ObjectDispatch_Initialize(struct DispatchObject *object, const s32 *script)
Gives an object a script and starts it from the top.
Definition objects.c:323
s32 Map_GetScreenRelativePosition(struct ObjectRuntime *object, s32 *screenPosition)
Writes the object's screen position, in pixels, to screenPosition[0..1] and returns 0 when it is on o...
Definition objects.c:114
void ObjectDispatch_RegisterChildMetadata(struct DispatchObject *object, s32 animationId)
Adds a layer of animation id animationId to a one-sprite object's sprite.
Definition objects.c:426
void ObjectDispatch_StartPlayerControl(struct DispatchObject *object)
Starts an object on the player control script (SC_PLAYER).
Definition objects.c:460
void ObjectDispatch_SetSingleChildFlags(struct DispatchObject *object, u32 flags)
Sets the flags of a one-sprite object's sprite (bit 0: draw its shadow).
Definition objects.c:511
UNUSED void ResourceTable_ReservedNoOpC0C4(void)
Definition objects.c:185
void ObjectDispatch_StartKeyCheck(struct DispatchObject *object)
Starts an object on the script that runs SC_KEY_COUNT every frame.
Definition objects.c:447
void ObjectDispatch_SetChildBlendMode(struct DispatchObject *object, u32 mode)
Sets the OAM blend mode of a one-sprite object's sprite.
Definition objects.c:522
void Map_RenderAllAnimatedTileFrames(u8 **sprites, s32 count)
Dissolves count sprites together, pixel by pixel, over 32 frames.
Definition objects.c:80
void ObjectDispatch_StartWorldMapControl(struct DispatchObject *object)
Starts an object on the world map control script (SC_WORLD).
Definition objects.c:466
UNUSED void ResourceTable_ReservedNoOp2(void)
Definition objects.c:187
void ObjectDispatch_Release(struct DispatchObject *object)
Releases an object's sprites and zeroes it, freeing it.
Definition objects.c:212
void * ObjectDispatch_FindFreeObject(void)
Returns the first of the 64 objects not in use (with no script), or 0.
Definition objects.c:191
UNUSED s32 ObjectDispatch_ReturnTrue(void)
Definition objects.c:573
void ObjectSystem_ResumeProjectionAndHideLayers(void)
Resumes the object camera updates and hides BG1-3 and the sprites.
Definition objects.c:566
void ObjectDispatch_SelectAnimation(void *rawObject, s32 value)
Switches all of an object's sprites to animation value.
Definition objects.c:365
void ObjectDispatch_StartCamera(struct DispatchObject *object, s32 linkedObjectHandle)
Starts an object on the camera script (SC_CAMERA).
Definition objects.c:480
void Map_RenderAnimatedTileFrame(u8 *obj, u32 pos)
One step of dissolving a sprite pixel by pixel.
Definition objects.c:14
void ObjectDispatch_SetAnimationSpeed(struct DispatchObject *rawObject, s32 value)
Sets the animation speed (timer step) of all of an object's sprites.
Definition objects.c:370
#define OBJECT_DISPATCH_DEFINE_APPLY(name, object_type, apply)
Defines name(object, value), which calls apply(sprite, value) on an object's one sprite,...
Definition objects.c:336
void ObjectSystem_Initialize(s32 controlMode)
Sets up the object system: allocates and zeroes the 64 objects and registers the per-frame updates.
Definition objects.c:157
void ObjectDispatch_StartIdle(struct DispatchObject *object)
Starts an object on the idle script (a lone SC_END).
Definition objects.c:471
void ObjectDispatch_WaitForValue16(void *rawObject)
Waits until the object's script reaches SC_END (0x10), at most 300 frames.
Definition objects.c:495
void ObjectDispatch_SetChildFixedScale(struct DispatchObject *object, u32 fixedScale)
Makes the fixed camera draw a one-sprite object at its own scale instead of scaling it by distance.
Definition objects.c:531
void ObjectSystem_SuspendProjectionAndShowSprites(void)
Suspends the object camera updates, starts the palette back to normal and, a frame later,...
Definition objects.c:552
s32 gIwram_Data2
s32 gIwram_Data1
What every part of the field object shares: its includes and the few names more than one part uses.
@ FIELD_OBJECT_COUNT
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
void * gMapWork[]
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
#define OBJ_VRAM0
Sprite tile memory, as pret names it: the 32 KB from 0x06010000.
Definition io_reg.h:170
@ DISPCNT_OBJ_ON
Definition io_reg.h:44
@ DISPCNT_BG3_ON
Definition io_reg.h:43
@ DISPCNT_BG2_ON
Definition io_reg.h:42
@ DISPCNT_BG1_ON
Definition io_reg.h:41
#define REG_DISPCNT
Definition io_reg.h:9
struct ObjectSystemWork * gMenuCtrlWork
#define SC_END
Return to the main script.
Definition objcmd.h:32
void ObjectSystem_UpdateCamera(void)
Each frame, with the scrolling camera: places every object's sprite on the screen.
void ObjectSystem_UpdateCameraFixed(void)
Each frame, with the fixed camera: places every object's sprite, from the 64th object down,...
void Object_UpdateAllThumb(void)
Advances all 64 field objects by one frame, as Object_UpdateAll does for the eight script objects,...
void Object_UpdateAllMotion(void)
Advances the first 14 objects' motion by one frame, without running their scripts: steering towards a...
void Object_SetPositionAndResetMotion(struct ObjectRuntime *object, s32 x, s32 y, s32 z)
Places the object at (x, y, z), in 16.16 pixels, clears its movement target and stops it.
const s32 gObjectDispatch_EndScript[]
The idle script ObjectDispatch_StartIdle gives an object.
const s32 gObjectDispatch_KeysScript[]
Started by ObjectDispatch_StartMoveByKeys.
const s32 gObjectDispatch_ApproachLinkScript[]
Started by ObjectDispatch_StartApproachLink.
const s32 gObjectDispatch_CameraScript[]
Started by ObjectDispatch_StartCamera.
const s32 gObjectDispatch_PlayerScript[]
Started by ObjectDispatch_StartPlayerControl.
const s32 gObjectDispatch_KeyCheckScript[]
Runs SC_KEY_COUNT every frame; started by ObjectDispatch_StartKeyCheck.
const s32 gObjectDispatch_DefaultScript[]
The script FieldObject_Create gives every new object: it does nothing and returns to the idle script.
const s32 gObjectDispatch_WorldMapScript[]
Started by ObjectDispatch_StartWorldMapControl.
s32 Scheduler_ResumeTasks(SchedulerCallback callback)
Resumes the task running callback, or every task when callback is null, by clearing bit 0 of its orde...
Definition scheduler.c:243
s32 Scheduler_AddOrUpdateCallback(SchedulerCallback callback, s32 order)
Schedules callback with order, or gives a task already running it the new order, and re-sorts the tab...
Definition scheduler.c:102
s32 Scheduler_SuspendTasks(SchedulerCallback callback)
Suspends the task running callback, or every task when callback is null, by setting bit 0 of its orde...
Definition scheduler.c:172
void ObjectGroup_SetChildValueUnlessFifteen(void *rawSprite, u32 value)
Sets the draw parameter of each of a sprite's layers to value, except layers whose parameter is 15,...
#define NULL
Definition bilibin.h:6
s16 animId
the sprite id whose metadata and frames it uses
Definition animspr.h:38
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
struct AnimationSpritePart image
Definition animspr.h:109
u8 width
pixels; zero marks a free sprite
Definition animspr.h:119
u8 height
pixels
Definition animspr.h:120
u8 slot
VRAM cache entry holding its tiles.
Definition animspr.h:112
struct AnimationEntry * entries[4]
its layers; empty ones null
Definition animspr.h:130
u8 count
layers in use, up to the last one present
Definition animspr.h:129
u8 useOwnScale
Drawn at its own scale, not scaled by distance (fixed camera).
Definition animspr.h:116
A field object as the object dispatcher's far calls take it.
u8 kind
low four bits: 0 no sprite, 1 one, 2 up to four
union DispatchObject::@360171073024331352270206224065071342064266305270 target
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
u16 radius
Collision radius in pixels: 16, or half the sprite metadata's boxY, when created; the overlap checks ...
Definition field_obj.h:43
u8 spriteStorageKind
Zero hides sprites; one draws a single sprite, two draws a group.
Definition field_obj.h:78
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 riseBaseY
Zeroed by FieldObject_Create and not read by the engine; scene code keeps a resting height,...
Definition field_obj.h:71
The field map's work: the followed position, screen shake, tile animations, blend script,...
Definition map_scroll.h:27
s32 viewY
the view's top left, 16.16 fixed-point pixels
Definition map_scroll.h:40
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
s32 z
16.16 fixed-point pixels
s32 * script
the object script it runs; null when the object is free
s32 x
16.16 fixed-point pixels
s32 y
16.16 fixed-point pixels
The object system's work: the flag that suspends sprite projection, the outline's edge and fill colou...
Definition animspr.h:66
u8 fill
outline fill colour; 0 when the field sets up
Definition animspr.h:71
s32 count
sprite group tables taken from unk08
Definition animspr.h:73
u8 edge
outline edge colour; 15 when the field sets up
Definition animspr.h:70
The prefix that command handlers read from a field object's 0x70-byte slot.
Definition script.h:16
s16 cursor
the word index of the next command in script
Definition script.h:18
const s32 * script
the running script; SC_END sets gScript_MainScript
Definition script.h:17
A field object as the motion code sees it: its script, position, motion toward a target,...
u8 collisionFlags
bit 7: a solid object refuses its move
s32 gravity
Taken off velocityY each frame above the ground, 16.16 fixed-point pixels per frame; also scales a fl...
union ScriptMotionObject::@251026000204114031114155171320036163006104311101 vertical
A field object as its object script commands see it: the script and its place, position,...
s16 homeX
Its home, in pixels: where it was created or placed.
s32 x
16.16 fixed-point pixels
s32 y
16.16 fixed-point pixels
const s32 * script
null when the object is free
s32 z
16.16 fixed-point pixels
void * animation
its sprite, or its list of four, by animationKind
u16 offset
bytes from the start of OBJ VRAM
Definition vram_tab.h:25
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13
#define UNUSED
Definition types.h:22
unsigned char u8
Definition types.h:11
struct ScriptMotionObject * gObjectSlots
struct VramBlockCacheEntry gVramBlockCache[]