Merge pull request #438 from s4Ys369/revert-434-patch-1
[sm64pc.git] / include / types.h
blob48b4fcd0a9bc934d452d9f52ed9cb1fbccaf37d6
1 #ifndef _SM64_TYPES_H_
2 #define _SM64_TYPES_H_
4 // This file contains various data types used in Super Mario 64 that don't yet
5 // have an appropriate header.
7 #include <ultra64.h>
8 #include "macros.h"
11 // Certain functions are marked as having return values, but do not
12 // actually return a value. This causes undefined behavior, which we'd rather
13 // avoid on modern GCC. This only impacts -O2 and can matter for both the function
14 // itself and functions that call it.
15 #ifdef AVOID_UB
16 #define BAD_RETURN(cmd) void
17 #else
18 #define BAD_RETURN(cmd) cmd
19 #endif
22 struct Controller
24 /*0x00*/ s16 rawStickX; //
25 /*0x02*/ s16 rawStickY; //
26 /*0x04*/ float stickX; // [-64, 64] positive is right
27 /*0x08*/ float stickY; // [-64, 64] positive is up
28 /*0x0C*/ float stickMag; // distance from center [0, 64]
29 /*0x10*/ u16 buttonDown;
30 /*0x12*/ u16 buttonPressed;
31 /*0x14*/ OSContStatus *statusData;
32 /*0x18*/ OSContPad *controllerData;
33 /*0x1C*/ int port;
36 typedef f32 Vec2f[2];
37 typedef f32 Vec3f[3]; // X, Y, Z, where Y is up
38 typedef s16 Vec3s[3];
39 typedef s32 Vec3i[3];
40 typedef f32 Vec4f[4];
41 typedef s16 Vec4s[4];
43 typedef f32 Mat4[4][4];
45 typedef uintptr_t GeoLayout;
46 typedef uintptr_t LevelScript;
47 typedef s16 Movtex;
48 typedef s16 MacroObject;
49 typedef s16 Collision;
50 typedef s16 Trajectory;
51 typedef s16 PaintingData;
52 typedef uintptr_t BehaviorScript;
54 enum SpTaskState {
55 SPTASK_STATE_NOT_STARTED,
56 SPTASK_STATE_RUNNING,
57 SPTASK_STATE_INTERRUPTED,
58 SPTASK_STATE_FINISHED,
59 SPTASK_STATE_FINISHED_DP
62 struct SPTask
64 /*0x00*/ OSTask task;
65 /*0x40*/ OSMesgQueue *msgqueue;
66 /*0x44*/ OSMesg msg;
67 /*0x48*/ enum SpTaskState state;
68 }; // size = 0x4C, align = 0x8
70 struct VblankHandler
72 OSMesgQueue *queue;
73 OSMesg msg;
76 #define ANIM_FLAG_NOLOOP (1 << 0) // 0x01
77 #define ANIM_FLAG_FORWARD (1 << 1) // 0x02
78 #define ANIM_FLAG_2 (1 << 2) // 0x04
79 #define ANIM_FLAG_HOR_TRANS (1 << 3) // 0x08
80 #define ANIM_FLAG_VERT_TRANS (1 << 4) // 0x10
81 #define ANIM_FLAG_5 (1 << 5) // 0x20
82 #define ANIM_FLAG_6 (1 << 6) // 0x40
83 #define ANIM_FLAG_7 (1 << 7) // 0x80
85 struct Animation {
86 /*0x00*/ s16 flags;
87 /*0x02*/ s16 unk02;
88 /*0x04*/ s16 unk04;
89 /*0x06*/ s16 unk06;
90 /*0x08*/ s16 unk08;
91 /*0x0A*/ s16 unk0A;
92 /*0x0C*/ const s16 *values;
93 /*0x10*/ const u16 *index;
94 /*0x14*/ u32 length; // only used with Mario animations to determine how much to load. 0 otherwise.
97 #define ANIMINDEX_NUMPARTS(animindex) (sizeof(animindex) / sizeof(u16) / 6 - 1)
99 struct GraphNode
101 /*0x00*/ s16 type; // structure type
102 /*0x02*/ s16 flags; // hi = drawing layer, lo = rendering modes
103 /*0x04*/ struct GraphNode *prev;
104 /*0x08*/ struct GraphNode *next;
105 /*0x0C*/ struct GraphNode *parent;
106 /*0x10*/ struct GraphNode *children;
109 // struct AnimInfo?
110 struct GraphNodeObject_sub
112 /*0x00 0x38*/ s16 animID;
113 /*0x02 0x3A*/ s16 animYTrans;
114 /*0x04 0x3C*/ struct Animation *curAnim;
115 /*0x08 0x40*/ s16 animFrame;
116 /*0x0A 0x42*/ u16 animTimer;
117 /*0x0C 0x44*/ s32 animFrameAccelAssist;
118 /*0x10 0x48*/ s32 animAccel;
121 struct GraphNodeObject
123 /*0x00*/ struct GraphNode node;
124 /*0x14*/ struct GraphNode *sharedChild;
125 /*0x18*/ s8 unk18;
126 /*0x19*/ s8 unk19;
127 /*0x1A*/ Vec3s angle;
128 /*0x20*/ Vec3f pos;
129 /*0x2C*/ Vec3f scale;
130 /*0x38*/ struct GraphNodeObject_sub unk38;
131 /*0x4C*/ struct SpawnInfo *unk4C;
132 /*0x50*/ void *throwMatrix; // matrix ptr
133 /*0x54*/ Vec3f cameraToObject;
136 struct ObjectNode
138 struct GraphNodeObject gfx;
139 struct ObjectNode *next;
140 struct ObjectNode *prev;
143 // NOTE: Since ObjectNode is the first member of Object, it is difficult to determine
144 // whether some of these pointers point to ObjectNode or Object.
146 struct Object
148 /*0x000*/ struct ObjectNode header;
149 /*0x068*/ struct Object *parentObj;
150 /*0x06C*/ struct Object *prevObj;
151 /*0x070*/ u32 collidedObjInteractTypes;
152 /*0x074*/ s16 activeFlags;
153 /*0x076*/ s16 numCollidedObjs;
154 /*0x078*/ struct Object *collidedObjs[4];
155 /*0x088*/
156 union
158 // Object fields. See object_fields.h.
159 u32 asU32[0x50];
160 s32 asS32[0x50];
161 s16 asS16[0x50][2];
162 f32 asF32[0x50];
163 #if !IS_64_BIT
164 s16 *asS16P[0x50];
165 s32 *asS32P[0x50];
166 struct Animation **asAnims[0x50];
167 struct Waypoint *asWaypoint[0x50];
168 struct ChainSegment *asChainSegment[0x50];
169 struct Object *asObject[0x50];
170 struct Surface *asSurface[0x50];
171 void *asVoidPtr[0x50];
172 const void *asConstVoidPtr[0x50];
173 #endif
174 } rawData;
175 #if IS_64_BIT
176 union {
177 s16 *asS16P[0x50];
178 s32 *asS32P[0x50];
179 struct Animation **asAnims[0x50];
180 struct Waypoint *asWaypoint[0x50];
181 struct ChainSegment *asChainSegment[0x50];
182 struct Object *asObject[0x50];
183 struct Surface *asSurface[0x50];
184 void *asVoidPtr[0x50];
185 const void *asConstVoidPtr[0x50];
186 } ptrData;
187 #endif
188 /*0x1C8*/ u32 unused1;
189 /*0x1CC*/ const BehaviorScript *curBhvCommand;
190 /*0x1D0*/ u32 bhvStackIndex;
191 /*0x1D4*/ uintptr_t bhvStack[8];
192 /*0x1F4*/ s16 bhvDelayTimer;
193 /*0x1F6*/ s16 respawnInfoType;
194 /*0x1F8*/ f32 hitboxRadius;
195 /*0x1FC*/ f32 hitboxHeight;
196 /*0x200*/ f32 hurtboxRadius;
197 /*0x204*/ f32 hurtboxHeight;
198 /*0x208*/ f32 hitboxDownOffset;
199 /*0x20C*/ const BehaviorScript *behavior;
200 /*0x210*/ u32 unused2;
201 /*0x214*/ struct Object *platform;
202 /*0x218*/ void *collisionData;
203 /*0x21C*/ Mat4 transform;
204 /*0x25C*/ void *respawnInfo;
207 struct ObjectHitbox
209 /*0x00*/ u32 interactType;
210 /*0x04*/ u8 downOffset;
211 /*0x05*/ s8 damageOrCoinValue;
212 /*0x06*/ s8 health;
213 /*0x07*/ s8 numLootCoins;
214 /*0x08*/ s16 radius;
215 /*0x0A*/ s16 height;
216 /*0x0C*/ s16 hurtboxRadius;
217 /*0x0E*/ s16 hurtboxHeight;
220 struct Waypoint
222 s16 flags;
223 Vec3s pos;
226 struct Surface
228 /*0x00*/ s16 type;
229 /*0x02*/ s16 force;
230 /*0x04*/ s8 flags;
231 /*0x05*/ s8 room;
232 /*0x06*/ s16 lowerY;
233 /*0x08*/ s16 upperY;
234 /*0x0A*/ Vec3s vertex1;
235 /*0x10*/ Vec3s vertex2;
236 /*0x16*/ Vec3s vertex3;
237 /*0x1C*/ struct {
238 f32 x;
239 f32 y;
240 f32 z;
241 } normal;
242 /*0x28*/ f32 originOffset;
243 /*0x2C*/ struct Object *object;
246 struct MarioBodyState
248 /*0x00*/ u32 action;
249 /*0x04*/ s8 capState; /// see MarioCapGSCId
250 /*0x05*/ s8 eyeState;
251 /*0x06*/ s8 handState;
252 /*0x07*/ s8 wingFlutter; /// whether Mario's wing cap wings are fluttering
253 /*0x08*/ s16 modelState;
254 /*0x0A*/ s8 grabPos;
255 /*0x0B*/ u8 punchState; /// 2 bits for type of punch, 6 bits for punch animation timer
256 /*0x0C*/ Vec3s torsoAngle;
257 /*0x12*/ Vec3s headAngle;
258 /*0x18*/ Vec3f heldObjLastPosition; /// also known as HOLP
259 u8 padding[4];
262 struct OffsetSizePair
264 u32 offset;
265 u32 size;
268 struct MarioAnimDmaRelatedThing
270 u32 count;
271 u8 *srcAddr;
272 struct OffsetSizePair anim[1]; // dynamic size
275 struct MarioAnimation
277 struct MarioAnimDmaRelatedThing *animDmaTable;
278 u8 *currentAnimAddr;
279 struct Animation *targetAnim;
280 u8 padding[4];
283 struct MarioState
285 /*0x00*/ u16 unk00;
286 /*0x02*/ u16 input;
287 /*0x04*/ u32 flags;
288 /*0x08*/ u32 particleFlags;
289 /*0x0C*/ u32 action;
290 /*0x10*/ u32 prevAction;
291 /*0x14*/ u32 terrainSoundAddend;
292 /*0x18*/ u16 actionState;
293 /*0x1A*/ u16 actionTimer;
294 /*0x1C*/ u32 actionArg;
295 /*0x20*/ f32 intendedMag;
296 /*0x24*/ s16 intendedYaw;
297 /*0x26*/ s16 invincTimer;
298 /*0x28*/ u8 framesSinceA;
299 /*0x29*/ u8 framesSinceB;
300 /*0x2A*/ u8 wallKickTimer;
301 /*0x2B*/ u8 doubleJumpTimer;
302 /*0x2C*/ Vec3s faceAngle;
303 /*0x32*/ Vec3s angleVel;
304 /*0x38*/ s16 slideYaw;
305 /*0x3A*/ s16 twirlYaw;
306 /*0x3C*/ Vec3f pos;
307 /*0x48*/ Vec3f vel;
308 /*0x54*/ f32 forwardVel;
309 /*0x58*/ f32 slideVelX;
310 /*0x5C*/ f32 slideVelZ;
311 /*0x60*/ struct Surface *wall;
312 /*0x64*/ struct Surface *ceil;
313 /*0x68*/ struct Surface *floor;
314 /*0x6C*/ f32 ceilHeight;
315 /*0x70*/ f32 floorHeight;
316 /*0x74*/ s16 floorAngle;
317 /*0x76*/ s16 waterLevel;
318 /*0x78*/ struct Object *interactObj;
319 /*0x7C*/ struct Object *heldObj;
320 /*0x80*/ struct Object *usedObj;
321 /*0x84*/ struct Object *riddenObj;
322 /*0x88*/ struct Object *marioObj;
323 /*0x8C*/ struct SpawnInfo *spawnInfo;
324 /*0x90*/ struct Area *area;
325 /*0x94*/ struct PlayerCameraState *statusForCamera;
326 /*0x98*/ struct MarioBodyState *marioBodyState;
327 /*0x9C*/ struct Controller *controller;
328 /*0xA0*/ struct MarioAnimation *animation;
329 /*0xA4*/ u32 collidedObjInteractTypes;
330 /*0xA8*/ s16 numCoins;
331 /*0xAA*/ s16 numStars;
332 /*0xAC*/ s8 numKeys; // Unused key mechanic
333 /*0xAD*/ s8 numLives;
334 /*0xAE*/ s16 health;
335 /*0xB0*/ s16 unkB0;
336 /*0xB2*/ u8 hurtCounter;
337 /*0xB3*/ u8 healCounter;
338 /*0xB4*/ u8 squishTimer;
339 /*0xB5*/ u8 fadeWarpOpacity;
340 /*0xB6*/ u16 capTimer;
341 /*0xB8*/ s16 unkB8;
342 /*0xBC*/ f32 peakHeight;
343 /*0xC0*/ f32 quicksandDepth;
344 /*0xC4*/ f32 unkC4;
347 #endif