Alchemy
Loading...
Searching...
No Matches

object_runtime.h

Go to the documentation of this file.
1#ifndef ALCHEMY_OBJECT_RUNTIME_H
2#define ALCHEMY_OBJECT_RUNTIME_H
3
4/// @file
5/// ObjectRuntime, a field object's runtime state, and the object snapshots.
6
7#include "unit/field/field.h"
8#include "object_lookup.h"
9#include "types.h"
10#include "static_assert.h"
11
12/// One of the 64 field objects in the object pool (heap slot 5): its script,
13/// position, motion toward a target, animation and update callback.
15 s32 *script; ///< the object script it runs; null when the object is free
16 s16 step; ///< the script cursor, in words
17 u16 angle; ///< 1/65536 turns
18 s32 x; ///< 16.16 fixed-point pixels
19 s32 y; ///< 16.16 fixed-point pixels
20 s32 z; ///< 16.16 fixed-point pixels
21 s32 terrainHeight; ///< 16.16 fixed-point pixels
22 u8 unk18[0x08]; ///< the x and y scales, FieldActor.scaleX and scaleY
23 u16 radius; ///< collision radius in pixels
24 u8 terrainId; ///< the map layer its ground height is read from
25 /// FieldActor.priorityFlags: 1 for placed actors, 2 for footprints.
27 s32 velocityX; ///< 16.16 fixed-point pixels per frame
28 s32 velocityY; ///< 16.16 fixed-point pixels per frame
29 s32 velocityZ; ///< 16.16 fixed-point pixels per frame
30 s32 speedLimit; ///< 16.16 fixed-point pixels per frame
31 /// Added toward the target each frame, or taken off the speed when there is
32 /// none, in 16.16 fixed-point pixels per frame; 0x10000 when created.
34 s32 targetX; ///< 16.16 fixed-point pixels; 0x80000000 when unset
35 s32 targetY; ///< 16.16 fixed-point pixels; 0x80000000 when unset
36 s32 targetZ; ///< 16.16 fixed-point pixels; 0x80000000 when unset
37 /// FieldActor's bounce and gravity, and a word FieldObject_Create zeroes.
38 u8 unk44[0x0c];
39 void *animation; ///< its sprite, or its list of four, by animationKind
40 /// Low four bits: 0 no sprite, 1 one sprite, 2 a group of up to four.
42 /// FieldActor.motionFlags: 3 when created, 4 for a placed actor above the
43 /// ground; zero is free flight in 3D.
45 u8 arrivalAxis; ///< the ARRIVAL_AXIS_* that decides arrival
46 u8 conditionResult; ///< the object script's last flag test
47 u8 snapToTarget; ///< nonzero lands it exactly on its target
48 /// FieldActor.collisionFlags: bit 0 solid, bit 1 the player pushes it,
49 /// bits 2 to 4 for talk and Psynergy targets; placed actors take 1.
51 u8 actionFlags; ///< FieldActor.steeringFlags: bit 0 faces its motion
52 u8 movementState; ///< nonzero skips its script and motion (paused)
53 /// Byte 0, when nonzero, keeps its sprite's VRAM cache entry while sprites
54 /// are suspended or it is off screen; byte 1 is the object script's
55 /// SC_LOOP count.
56 u8 unk5c[0x02];
57 u16 wait; ///< the object script's wait, in frames
58 /// Not named by TBS code through this struct. Its bytes are the frames a
59 /// solid object has refused the object's move and the frozen flag
60 /// (ScriptMotionObject's refused and frozen), then two bytes scene code
61 /// uses.
62 void *callback;
63 /// The parameter its action script reads (a follow distance or an angle),
64 /// or the player's frames to its next footprint.
66 s16 footprintSide; ///< the side of the player's next footprint (2 after a
67 ///< stop)
68 /// The object its action script follows or faces.
70 /// The update hook (FieldActor.update), which the unused
71 /// ObjectDispatch_SetUpdateValue sets as a word.
72 u8 unk6c[0x04];
73};
74
75STATIC_ASSERT(sizeof(struct ObjectRuntime) == 0x70);
83
85
86/// Actors kept across a battle or a saved scene, with parallel sprite state.
87/// The slot list ends in OBJECT_SNAPSHOT_EMPTY unless every entry is filled.
89 u8 slots[OBJECT_SNAPSHOT_CAPACITY]; ///< actor numbers, or
90 ///< OBJECT_SNAPSHOT_EMPTY
91 struct ObjectRuntime actors[OBJECT_SNAPSHOT_CAPACITY]; ///< copied by DMA
92 u8 animations[OBJECT_SNAPSHOT_CAPACITY]; ///< each sprite's lastNo
93 u8 spriteFlags[OBJECT_SNAPSHOT_CAPACITY]; ///< restored through the dispatcher
94 u8 priorities[OBJECT_SNAPSHOT_CAPACITY]; ///< both image and shadow priority
95};
96
98STATIC_ASSERT(offsetof(struct ObjectTableSnapshot, animations) == 0xe20);
99STATIC_ASSERT(offsetof(struct ObjectTableSnapshot, spriteFlags) == 0xe40);
100STATIC_ASSERT(offsetof(struct ObjectTableSnapshot, priorities) == 0xe60);
101STATIC_ASSERT(sizeof(struct ObjectTableSnapshot) == 0xe80);
102
104
105#endif
Declares nothing: an empty header kept for the files that include it.
struct ObjectTableSnapshot gObjectSnapshots
@ OBJECT_SNAPSHOT_EMPTY
@ OBJECT_SNAPSHOT_CAPACITY
STATIC_ASSERT, a compile-time check that emits nothing.
#define STATIC_ASSERT(condition)
C89 permits repeated extern declarations of the same array.
#define offsetof(type, member)
Definition stddef.h:19
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
void * callback
Not named by TBS code through this struct.
s32 targetZ
16.16 fixed-point pixels; 0x80000000 when unset
u16 angle
1/65536 turns
u8 unk5c[0x02]
Byte 0, when nonzero, keeps its sprite's VRAM cache entry while sprites are suspended or it is off sc...
s32 velocityZ
16.16 fixed-point pixels per frame
s32 terrainHeight
16.16 fixed-point pixels
u8 snapToTarget
nonzero lands it exactly on its target
s32 velocityX
16.16 fixed-point pixels per frame
u8 actionFlags
FieldActor.steeringFlags: bit 0 faces its motion.
u8 unk44[0x0c]
FieldActor's bounce and gravity, and a word FieldObject_Create zeroes.
u8 priorityFlags
FieldActor.priorityFlags: 1 for placed actors, 2 for footprints.
u8 arrivalAxis
the ARRIVAL_AXIS_* that decides arrival
u8 conditionResult
the object script's last flag test
u16 radius
collision radius in pixels
s32 targetY
16.16 fixed-point pixels; 0x80000000 when unset
s32 velocityY
16.16 fixed-point pixels per frame
u8 movementState
nonzero skips its script and motion (paused)
s16 footprintSide
the side of the player's next footprint (2 after a stop)
s32 z
16.16 fixed-point pixels
s32 acceleration
Added toward the target each frame, or taken off the speed when there is none, in 16....
s32 targetX
16.16 fixed-point pixels; 0x80000000 when unset
u8 collisionFlags
FieldActor.collisionFlags: bit 0 solid, bit 1 the player pushes it, bits 2 to 4 for talk and Psynergy...
s32 * script
the object script it runs; null when the object is free
u8 unk18[0x08]
the x and y scales, FieldActor.scaleX and scaleY
u8 flags
FieldActor.motionFlags: 3 when created, 4 for a placed actor above the ground; zero is free flight in...
void * animation
its sprite, or its list of four, by animationKind
u16 wait
the object script's wait, in frames
s32 x
16.16 fixed-point pixels
s16 step
the script cursor, in words
s32 speedLimit
16.16 fixed-point pixels per frame
s32 y
16.16 fixed-point pixels
u8 animationKind
Low four bits: 0 no sprite, 1 one sprite, 2 a group of up to four.
struct ObjectRuntime * linkedObject
The object its action script follows or faces.
s16 action
The parameter its action script reads (a follow distance or an angle), or the player's frames to its ...
u8 terrainId
the map layer its ground height is read from
u8 unk6c[0x04]
The update hook (FieldActor.update), which the unused ObjectDispatch_SetUpdateValue sets as a word.
Actors kept across a battle or a saved scene, with parallel sprite state.
u8 animations[OBJECT_SNAPSHOT_CAPACITY]
each sprite's lastNo
struct ObjectRuntime actors[OBJECT_SNAPSHOT_CAPACITY]
copied by DMA
u8 slots[OBJECT_SNAPSHOT_CAPACITY]
actor numbers, or OBJECT_SNAPSHOT_EMPTY
u8 priorities[OBJECT_SNAPSHOT_CAPACITY]
both image and shadow priority
u8 spriteFlags[OBJECT_SNAPSHOT_CAPACITY]
restored through the dispatcher
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11