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