39 for (; i < tileCount; i++, tile += 32, pos++) {
40 if ((pos - 64) <= 63) {
46 pixel = order[(pos + i * 16) & indexMask];
47 pixelPair = (
u16 *)((
u8 *)tile + (pixel & offsetMask));
51 *pixelPair = *(
u8 *)pixelPair;
53 *pixelPair &= highMask;
74 }
while (step <= 127);
85 u32 secondDissolveStep;
86 u32 thirdDissolveStep;
87 u32 fourthDissolveStep;
89 firstSprite = sprites;
93 secondDissolveStep = step + 1;
94 thirdDissolveStep = step + 2;
95 spriteCursor = firstSprite;
96 fourthDissolveStep = step + 3;
97 spritesRemaining =
count;
102 spritesRemaining -= 1;
104 }
while (spritesRemaining != 0);
108 }
while (step <= 0x7fU);
115 s32 *screenPosition) {
118 s32 *viewCoordinates = &mapWork->
viewX;
129 viewZ = mapWork->
viewY & 0xffff0000;
131 viewX = viewCoordinates[0] & 0xffff0000;
132 viewZ = viewCoordinates[1] & 0xffff0000;
134 x =
object->x -
viewX;
135 y =
object->z - viewZ;
138 if ((x >= -0x1fffff && x <= 0x10fffff) && y > 0 && y < 0xe00000) {
139 *screenPosition++ = x >> 16;
140 *screenPosition = y >> 16;
143 *screenPosition++ = 0;
170 if (controlMode == 4)
174 if (controlMode >= 3 && controlMode <= 4) {
181 objectSystem->
edge = 15;
182 objectSystem->
fill = 0;
193 void *freeObject = 0;
197 if (object->
script == 0) {
213 s32 spritesRemaining;
217 switch (object->
kind & 15) {
222 sprites =
object->target.children;
223 spritesRemaining = 3;
228 }
while (--spritesRemaining >= 0);
252 s32 spriteStorageKind;
257 spriteStorageKind = encodedSprite / 4096;
258 encodedSprite &= 0xfff;
260 if (
object !=
NULL) {
266 if (sprite !=
NULL) {
267 object->animationKind = 1;
268 object->animation = sprite;
271 object->animationKind = 0;
279 object->animation = spriteSlots;
282 if (sprite !=
NULL) {
284 *spriteSlots++ = sprite;
288 *spriteSlots = sprite;
292 if (
object !=
NULL) {
299 object->speedLimit = 0x20000;
303 object->acceleration = 0x10000;
308 object->actionFlags = 1;
310 object->angle = 0x4000;
312 scripted->
homeX =
x / 65536;
313 scripted->
homeZ =
z / 65536;
336#define OBJECT_DISPATCH_DEFINE_APPLY(name, object_type, apply) \
337 void name(object_type rawObject, s32 value) { \
338 struct DispatchObject *object; \
340 s32 spritesRemaining; \
343 object = rawObject; \
345 switch (object->kind & 0xf) { \
347 apply(object->target.child, value); \
350 sprites = object->target.children; \
351 spritesRemaining = 3; \
353 sprite = *sprites++; \
355 apply(sprite, value); \
356 spritesRemaining--; \
357 } while (spritesRemaining >= 0); \
378 s32 spritesRemaining;
381 switch (object->kind & 15) {
387 sprites =
object->target.children;
388 for (spritesRemaining = 3; spritesRemaining >= 0; spritesRemaining--) {
403 if (
object != 0 && (object->
kind & 0xf) == 1)
404 object->target.child->rotation = rotation;
415 if (
object !=
NULL && (object->
kind & 0xf) == 1) {
416 sprite =
object->target.child;
417 if (animationId >= 0) {
428 if (
object != 0 && (object->
kind & 0xf) == 1) {
430 if (animationId >= 0)
439 s32 linkedObjectHandle) {
441 object->argument = linkedObjectHandle;
481 s32 linkedObjectHandle) {
483 if (linkedObjectHandle != 0) {
484 object->value34 = 0x8000;
485 object->value30 = 0x40000;
486 object->argument = linkedObjectHandle;
504 if (waitedFrames > 299)
513 if (
object !=
NULL) {
514 if ((object->
kind & 0xf) == 1)
515 object->target.child->flags = flags;
523 if (
object != 0 && object->
kind == 1) {
533 if (
object != 0 && object->
kind == 1) {
542 if (
object !=
NULL && object->
kind == 1)
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).
s32 ResourceMetadata_Register(struct AnimationObject *sprite, s32 id)
Adds a layer of animation id to a sprite, in its first free layer of four.
void ObjectSystem_Configure(s32 mode)
Allocates and zeroes the 64 sprites and 64 animation layers (from the fixed blocks in mode 3,...
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),...
void ResourceObject_Release(struct AnimationObject *sprite)
Releases a sprite: its VRAM cache entry (unless retainCacheEntry is set), its four animation layers,...
s32 Animation_InitializeObjects(struct AnimationObject *sprite)
Resets each layer of a sprite from its animation's metadata: its facing kind, frames,...
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...
#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...
#define Dma_Fill32(value, destination, size)
Fills size bytes at destination with the word value by DMA3.
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...
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).
void ObjectDispatch_SetChildRotation(struct DispatchObject *object, u32 rotation)
Sets the rotation of an object's sprite, when it has just one.
void ObjectDispatch_StartApproachLink(struct DispatchObject *object, s32 linkedObjectHandle)
Starts an object on the script that approaches its linked object (SC_APPROACH_LINK),...
void Animation_ApplyChildValues(struct DispatchObject *object, u32 param)
Sets the draw parameter of a one-sprite object's layers (see ObjectGroup_SetChildValueUnlessFifteen).
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...
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.
void Animation_SetIndexAndInitObjects(void *rawDispatchObject, s32 animationId)
Gives a one-sprite object's first layer animation id animationId and restarts its layers.
void Map_RenderAnimatedTileFramesForObject(u8 *sprite)
Dissolves a sprite pixel by pixel, four steps a frame, over 32 frames.
void ObjectDispatch_Initialize(struct DispatchObject *object, const s32 *script)
Gives an object a script and starts it from the top.
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...
void ObjectDispatch_RegisterChildMetadata(struct DispatchObject *object, s32 animationId)
Adds a layer of animation id animationId to a one-sprite object's sprite.
void ObjectDispatch_StartPlayerControl(struct DispatchObject *object)
Starts an object on the player control script (SC_PLAYER).
void ObjectDispatch_SetSingleChildFlags(struct DispatchObject *object, u32 flags)
Sets the flags of a one-sprite object's sprite (bit 0: draw its shadow).
UNUSED void ResourceTable_ReservedNoOpC0C4(void)
void ObjectDispatch_StartKeyCheck(struct DispatchObject *object)
Starts an object on the script that runs SC_KEY_COUNT every frame.
void ObjectDispatch_SetChildBlendMode(struct DispatchObject *object, u32 mode)
Sets the OAM blend mode of a one-sprite object's sprite.
void Map_RenderAllAnimatedTileFrames(u8 **sprites, s32 count)
Dissolves count sprites together, pixel by pixel, over 32 frames.
void ObjectDispatch_StartWorldMapControl(struct DispatchObject *object)
Starts an object on the world map control script (SC_WORLD).
UNUSED void ResourceTable_ReservedNoOp2(void)
void ObjectDispatch_Release(struct DispatchObject *object)
Releases an object's sprites and zeroes it, freeing it.
void * ObjectDispatch_FindFreeObject(void)
Returns the first of the 64 objects not in use (with no script), or 0.
UNUSED s32 ObjectDispatch_ReturnTrue(void)
void ObjectSystem_ResumeProjectionAndHideLayers(void)
Resumes the object camera updates and hides BG1-3 and the sprites.
void ObjectDispatch_SelectAnimation(void *rawObject, s32 value)
Switches all of an object's sprites to animation value.
void ObjectDispatch_StartCamera(struct DispatchObject *object, s32 linkedObjectHandle)
Starts an object on the camera script (SC_CAMERA).
void Map_RenderAnimatedTileFrame(u8 *obj, u32 pos)
One step of dissolving a sprite pixel by pixel.
void ObjectDispatch_SetAnimationSpeed(struct DispatchObject *rawObject, s32 value)
Sets the animation speed (timer step) of all of an object's sprites.
#define OBJECT_DISPATCH_DEFINE_APPLY(name, object_type, apply)
Defines name(object, value), which calls apply(sprite, value) on an object's one sprite,...
void ObjectSystem_Initialize(s32 controlMode)
Sets up the object system: allocates and zeroes the 64 objects and registers the per-frame updates.
void ObjectDispatch_StartIdle(struct DispatchObject *object)
Starts an object on the idle script (a lone SC_END).
void ObjectDispatch_WaitForValue16(void *rawObject)
Waits until the object's script reaches SC_END (0x10), at most 300 frames.
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.
void ObjectSystem_SuspendProjectionAndShowSprites(void)
Suspends the object camera updates, starts the palette back to normal and, a frame later,...
What every part of the field object shares: its includes and the few names more than one part uses.
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
#define OBJ_VRAM0
Sprite tile memory, as pret names it: the 32 KB from 0x06010000.
#define SC_END
Return to the main script.
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...
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...
s32 Scheduler_SuspendTasks(SchedulerCallback callback)
Suspends the task running callback, or every task when callback is null, by setting bit 0 of its orde...
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,...
s16 animId
the sprite id whose metadata and frames it uses
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
struct AnimationSpritePart image
u8 width
pixels; zero marks a free sprite
u8 slot
VRAM cache entry holding its tiles.
struct AnimationEntry * entries[4]
its layers; empty ones null
u8 count
layers in use, up to the last one present
u8 useOwnScale
Drawn at its own scale, not scaled by distance (fixed camera).
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,...
u16 radius
Collision radius in pixels: 16, or half the sprite metadata's boxY, when created; the overlap checks ...
u8 spriteStorageKind
Zero hides sprites; one draws a single sprite, two draws a group.
s32 scaleX
16.16 fixed point, 0x10000 full size
s32 scaleY
16.16 fixed point, 0x10000 full size
s32 riseBaseY
Zeroed by FieldObject_Create and not read by the engine; scene code keeps a resting height,...
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...
u8 fill
outline fill colour; 0 when the field sets up
s32 count
sprite group tables taken from unk08
u8 edge
outline edge colour; 15 when the field sets up
The prefix that command handlers read from a field object's 0x70-byte slot.
s16 cursor
the word index of the next command in script
const s32 * script
the running script; SC_END sets gScript_MainScript
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
struct ScriptMotionObject * gObjectSlots
struct VramBlockCacheEntry gVramBlockCache[]