Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/src/engine/graph_node.h
7857 views
1
#ifndef GRAPH_NODE_H
2
#define GRAPH_NODE_H
3
4
#include <PR/ultratypes.h>
5
#include <PR/gbi.h>
6
7
#include "types.h"
8
#include "game/memory.h"
9
10
#define GRAPH_RENDER_ACTIVE (1 << 0)
11
#define GRAPH_RENDER_CHILDREN_FIRST (1 << 1)
12
#define GRAPH_RENDER_BILLBOARD (1 << 2)
13
#define GRAPH_RENDER_Z_BUFFER (1 << 3)
14
#define GRAPH_RENDER_INVISIBLE (1 << 4)
15
#define GRAPH_RENDER_HAS_ANIMATION (1 << 5)
16
17
// Whether the node type has a function pointer of type GraphNodeFunc
18
#define GRAPH_NODE_TYPE_FUNCTIONAL 0x100
19
20
// Type used for Bowser and an unused geo function in obj_behaviors.c
21
#define GRAPH_NODE_TYPE_400 0x400
22
23
// The discriminant for different types of geo nodes
24
#define GRAPH_NODE_TYPE_ROOT 0x001
25
#define GRAPH_NODE_TYPE_ORTHO_PROJECTION 0x002
26
#define GRAPH_NODE_TYPE_PERSPECTIVE (0x003 | GRAPH_NODE_TYPE_FUNCTIONAL)
27
#define GRAPH_NODE_TYPE_MASTER_LIST 0x004
28
#define GRAPH_NODE_TYPE_START 0x00A
29
#define GRAPH_NODE_TYPE_LEVEL_OF_DETAIL 0x00B
30
#define GRAPH_NODE_TYPE_SWITCH_CASE (0x00C | GRAPH_NODE_TYPE_FUNCTIONAL)
31
#define GRAPH_NODE_TYPE_CAMERA (0x014 | GRAPH_NODE_TYPE_FUNCTIONAL)
32
#define GRAPH_NODE_TYPE_TRANSLATION_ROTATION 0x015
33
#define GRAPH_NODE_TYPE_TRANSLATION 0x016
34
#define GRAPH_NODE_TYPE_ROTATION 0x017
35
#define GRAPH_NODE_TYPE_OBJECT 0x018
36
#define GRAPH_NODE_TYPE_ANIMATED_PART 0x019
37
#define GRAPH_NODE_TYPE_BILLBOARD 0x01A
38
#define GRAPH_NODE_TYPE_DISPLAY_LIST 0x01B
39
#define GRAPH_NODE_TYPE_SCALE 0x01C
40
#define GRAPH_NODE_TYPE_SHADOW 0x028
41
#define GRAPH_NODE_TYPE_OBJECT_PARENT 0x029
42
#define GRAPH_NODE_TYPE_GENERATED_LIST (0x02A | GRAPH_NODE_TYPE_FUNCTIONAL)
43
#define GRAPH_NODE_TYPE_BACKGROUND (0x02C | GRAPH_NODE_TYPE_FUNCTIONAL)
44
#define GRAPH_NODE_TYPE_HELD_OBJ (0x02E | GRAPH_NODE_TYPE_FUNCTIONAL)
45
#define GRAPH_NODE_TYPE_CULLING_RADIUS 0x02F
46
47
// The number of master lists. A master list determines the order and render
48
// mode with which display lists are drawn.
49
#define GFX_NUM_MASTER_LISTS 8
50
51
// Passed as first argument to a GraphNodeFunc to give information about in
52
// which context it was called and what it is expected to do.
53
#define GEO_CONTEXT_CREATE 0 // called when node is created from a geo command
54
#define GEO_CONTEXT_RENDER 1 // called from rendering_graph_node.c
55
#define GEO_CONTEXT_AREA_UNLOAD 2 // called when unloading an area
56
#define GEO_CONTEXT_AREA_LOAD 3 // called when loading an area
57
#define GEO_CONTEXT_AREA_INIT 4 // called when initializing the 8 areas
58
#define GEO_CONTEXT_HELD_OBJ 5 // called when processing a GraphNodeHeldObj
59
60
// The signature for a function stored in a geo node
61
// The context argument depends on the callContext:
62
// - for GEO_CONTEXT_CREATE it is the AllocOnlyPool from which the node was allocated
63
// - for GEO_CONTEXT_RENDER or GEO_CONTEXT_HELD_OBJ it is the top of the float matrix stack with type Mat4
64
// - for GEO_CONTEXT_AREA_* it is the root geo node
65
typedef Gfx *(*GraphNodeFunc)(s32 callContext, struct GraphNode *node, void *context);
66
67
/** An extension of a graph node that includes a function pointer.
68
* Many graph node types have an update function that gets called
69
* when they are processed.
70
*/
71
struct FnGraphNode
72
{
73
/*0x00*/ struct GraphNode node;
74
/*0x14*/ GraphNodeFunc func;
75
};
76
77
/** The very root of the geo tree. Specifies the viewport.
78
*/
79
struct GraphNodeRoot
80
{
81
/*0x00*/ struct GraphNode node;
82
/*0x14*/ u8 areaIndex;
83
/*0x15*/ s8 unk15; // ?
84
/*0x16*/ s16 x;
85
/*0x18*/ s16 y;
86
/*0x1A*/ s16 width; // half width, 160
87
/*0x1C*/ s16 height; // half height
88
/*0x1E*/ s16 numViews; // number of entries in mystery array
89
/*0x20*/ struct GraphNode **views;
90
};
91
92
/** A node that sets up an orthographic projection based on the global
93
* root node. Used to draw the skybox image.
94
*/
95
struct GraphNodeOrthoProjection
96
{
97
/*0x00*/ struct GraphNode node;
98
/*0x14*/ f32 scale;
99
};
100
101
/** A node that sets up a perspective projection. Used for drawing the
102
* game world. It does not set up the camera position, that is done by
103
* the child of this node, which has type GraphNodeCamera.
104
*/
105
struct GraphNodePerspective
106
{
107
/*0x00*/ struct FnGraphNode fnNode;
108
/*0x18*/ s32 unused;
109
/*0x1C*/ f32 fov; // horizontal field of view in degrees
110
/*0x20*/ s16 near; // near clipping plane
111
/*0x22*/ s16 far; // far clipping plane
112
f32 prevFov;
113
f32 prevTimestamp;
114
};
115
116
/** An entry in the master list. It is a linked list of display lists
117
* carrying a transformation matrix.
118
*/
119
struct DisplayListNode
120
{
121
Mtx *transform;
122
void *transformInterpolated;
123
void *displayList;
124
void *displayListInterpolated;
125
struct DisplayListNode *next;
126
};
127
128
/** GraphNode that manages the 8 top-level display lists that will be drawn
129
* Each list has its own render mode, so for example water is drawn in a
130
* different master list than opaque objects.
131
* It also sets the z-buffer on before rendering and off after.
132
*/
133
struct GraphNodeMasterList
134
{
135
/*0x00*/ struct GraphNode node;
136
/*0x14*/ struct DisplayListNode *listHeads[GFX_NUM_MASTER_LISTS];
137
/*0x34*/ struct DisplayListNode *listTails[GFX_NUM_MASTER_LISTS];
138
};
139
140
/** Simply used as a parent to group multiple children.
141
* Does not have any additional functionality.
142
*/
143
struct GraphNodeStart
144
{
145
/*0x00*/ struct GraphNode node;
146
};
147
148
/** GraphNode that only renders its children if the current transformation matrix
149
* has a z-translation (in camera space) greater than minDistance and less than
150
* maxDistance.
151
* Usage examples: Mario has three level's of detail: Normal, low-poly arms only, and fully low-poly
152
* The tower in Whomp's fortress has two levels of detail.
153
*/
154
struct GraphNodeLevelOfDetail
155
{
156
/*0x00*/ struct GraphNode node;
157
/*0x14*/ s16 minDistance;
158
/*0x16*/ s16 maxDistance;
159
};
160
161
/** GraphNode that renders exactly one of its children.
162
* Which one is rendered is determined by the field 'selectedCase'
163
* which is set in the node's function.
164
* Usage examples: room visibility, coin animation, blinking, Mario's power-up / hand pose / cap
165
*/
166
struct GraphNodeSwitchCase
167
{
168
/*0x00*/ struct FnGraphNode fnNode;
169
/*0x18*/ s32 unused;
170
/*0x1C*/ s16 numCases;
171
/*0x1E*/ s16 selectedCase;
172
};
173
174
/**
175
* GraphNode that specifies the location and aim of the camera.
176
* When the roll is 0, the up vector is (0, 1, 0).
177
*/
178
struct GraphNodeCamera
179
{
180
/*0x00*/ struct FnGraphNode fnNode;
181
/*0x18*/ union {
182
// When the node is created, a mode is assigned to the node.
183
// Later in geo_camera_main a Camera is allocated,
184
// the mode is passed to the struct, and the field is overridden
185
// by a pointer to the struct. Gotta save those 4 bytes.
186
s32 mode;
187
struct Camera *camera;
188
} config;
189
/*0x1C*/ Vec3f pos;
190
/*0x28*/ Vec3f focus;
191
Vec3f prevPos;
192
Vec3f prevFocus;
193
u32 prevTimestamp;
194
/*0x34*/ Mat4 *matrixPtr; // pointer to look-at matrix of this camera as a Mat4
195
Mat4 *matrixPtrInterpolated;
196
/*0x38*/ s16 roll; // roll in look at matrix. Doesn't account for light direction unlike rollScreen.
197
/*0x3A*/ s16 rollScreen; // rolls screen while keeping the light direction consistent
198
};
199
200
/** GraphNode that translates and rotates its children.
201
* Usage example: wing cap wings.
202
* There is a dprint function that sets the translation and rotation values
203
* based on the ENEMYINFO array.
204
* The display list can be null, in which case it won't draw anything itself.
205
*/
206
struct GraphNodeTranslationRotation
207
{
208
/*0x00*/ struct GraphNode node;
209
/*0x14*/ void *displayList;
210
/*0x18*/ Vec3s translation;
211
/*0x1E*/ Vec3s rotation;
212
};
213
214
/** GraphNode that translates itself and its children.
215
* Usage example: SUPER MARIO logo letters in debug level select.
216
* The display list can be null, in which case it won't draw anything itself.
217
*/
218
struct GraphNodeTranslation
219
{
220
/*0x00*/ struct GraphNode node;
221
/*0x14*/ void *displayList;
222
/*0x18*/ Vec3s translation;
223
u8 pad1E[2];
224
};
225
226
/** GraphNode that rotates itself and its children.
227
* Usage example: Mario torso / head rotation. Its parameters are dynamically
228
* set by a parent script node in that case.
229
* The display list can be null, in which case it won't draw anything itself.
230
*/
231
struct GraphNodeRotation
232
{
233
/*0x00*/ struct GraphNode node;
234
/*0x14*/ void *displayList;
235
/*0x18*/ Vec3s rotation;
236
Vec3s prevRotation;
237
u32 prevTimestamp;
238
};
239
240
/** GraphNode part that transforms itself and its children based on animation
241
* data. This animation data is not stored in the node itself but in global
242
* variables that are set when object nodes are processed if the object has
243
* animation.
244
* Used for Mario, enemies and anything else with animation data.
245
* The display list can be null, in which case it won't draw anything itself.
246
*/
247
struct GraphNodeAnimatedPart
248
{
249
/*0x00*/ struct GraphNode node;
250
/*0x14*/ void *displayList;
251
/*0x18*/ Vec3s translation;
252
};
253
254
/** A GraphNode that draws a display list rotated in a way to always face the
255
* camera. Note that if the entire object is a billboard (like a coin or 1-up)
256
* then it simply sets the billboard flag for the entire object, this node is
257
* used for billboard parts (like a chuckya or goomba body).
258
*/
259
struct GraphNodeBillboard
260
{
261
/*0x00*/ struct GraphNode node;
262
/*0x14*/ void *displayList;
263
/*0x18*/ Vec3s translation;
264
};
265
266
/** A GraphNode that simply draws a display list without doing any
267
* transformation beforehand. It does inherit the parent's transformation.
268
*/
269
struct GraphNodeDisplayList
270
{
271
/*0x00*/ struct GraphNode node;
272
/*0x14*/ void *displayList;
273
};
274
275
/** GraphNode part that scales itself and its children.
276
* Usage example: Mario's fist or shoe, which grows when attacking. This can't
277
* be done with an animated part sine animation data doesn't support scaling.
278
* Note that many scaling animations (like a goomba getting stomped) happen on
279
* the entire object. This node is only used when a single part needs to be scaled.
280
* There is also a level command that scales the entire level, used for THI.
281
* The display list can be null, in which case it won't draw anything itself.
282
*/
283
struct GraphNodeScale
284
{
285
/*0x00*/ struct GraphNode node;
286
/*0x14*/ void *displayList;
287
/*0x18*/ f32 scale;
288
};
289
290
/** GraphNode that draws a shadow under an object.
291
* Every object starts with a shadow node.
292
* The shadow type determines the shape (round or rectangular), vertices (4 or 9)
293
* and other features.
294
*/
295
struct GraphNodeShadow
296
{
297
/*0x00*/ struct GraphNode node;
298
/*0x14*/ s16 shadowScale; // diameter (when a circle) or side (when a square) of shadow
299
/*0x16*/ u8 shadowSolidity; // opacity of shadow, 255 = opaque
300
/*0x17*/ u8 shadowType; // see ShadowType enum in shadow.h
301
};
302
303
/** GraphNode that contains as its sharedChild a group node containing all
304
* object nodes.
305
*/
306
struct GraphNodeObjectParent
307
{
308
/*0x00*/ struct GraphNode node;
309
/*0x14*/ struct GraphNode *sharedChild;
310
};
311
312
/** GraphNode that draws display lists not directly in memory but generated by
313
* a function.
314
* Used for wobbling paintings, water, environment effects.
315
* It might not draw anything, it could also just update something.
316
* For example: there is a node that stops water flow when the game is paused.
317
* The parameter field gives extra context info. For shifting sand or paintings,
318
* it can determine which texture to use.
319
*/
320
struct GraphNodeGenerated
321
{
322
/*0x00*/ struct FnGraphNode fnNode;
323
/*0x18*/ u32 parameter; // extra context for the function
324
};
325
326
/** GraphNode that draws a background image or a rectangle of a color.
327
* Drawn in an orthographic projection, used for skyboxes.
328
*/
329
struct GraphNodeBackground
330
{
331
/*0x00*/ struct FnGraphNode fnNode;
332
/*0x18*/ s32 unused;
333
/*0x1C*/ s32 background; // background ID, or rgba5551 color if fnNode.func is null
334
Vec3f prevCameraPos;
335
Vec3f prevCameraFocus;
336
u32 prevCameraTimestamp;
337
};
338
339
/** Renders the object that Mario is holding.
340
*/
341
struct GraphNodeHeldObject
342
{
343
/*0x00*/ struct FnGraphNode fnNode;
344
/*0x18*/ s32 playerIndex;
345
/*0x1C*/ struct Object *objNode;
346
/*0x20*/ Vec3s translation;
347
Vec3f prevShadowPos;
348
u32 prevShadowPosTimestamp;
349
};
350
351
/** A node that allows an object to specify a different culling radius than the
352
* default one of 300. For this to work, it needs to be a direct child of the
353
* object node. Used for very large objects, such as shock wave rings that Bowser
354
* creates, tornadoes, the big eel.
355
*/
356
struct GraphNodeCullingRadius
357
{
358
/*0x00*/ struct GraphNode node;
359
/*0x14*/ s16 cullingRadius; // specifies the 'sphere radius' for purposes of frustum culling
360
u8 pad1E[2];
361
};
362
363
extern struct GraphNodeMasterList *gCurGraphNodeMasterList;
364
extern struct GraphNodePerspective *gCurGraphNodeCamFrustum;
365
extern struct GraphNodeCamera *gCurGraphNodeCamera;
366
extern struct GraphNodeHeldObject *gCurGraphNodeHeldObject;
367
extern u16 gAreaUpdateCounter;
368
369
extern struct GraphNode *gCurRootGraphNode;
370
extern struct GraphNode *gCurGraphNodeList[];
371
372
extern s16 gCurGraphNodeIndex;
373
374
extern Vec3f gVec3fZero;
375
extern Vec3s gVec3sZero;
376
extern Vec3f gVec3fOne;
377
extern Vec3s gVec3sOne;
378
379
void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type);
380
381
struct GraphNodeRoot *init_graph_node_root(struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode,
382
s16 areaIndex, s16 x, s16 y, s16 width, s16 height);
383
struct GraphNodeOrthoProjection *init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrthoProjection *graphNode, f32 scale);
384
struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *pool, struct GraphNodePerspective *graphNode,
385
f32 fov, s16 near, s16 far, GraphNodeFunc nodeFunc, s32 unused);
386
struct GraphNodeStart *init_graph_node_start(struct AllocOnlyPool *pool, struct GraphNodeStart *graphNode);
387
struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *pool, struct GraphNodeMasterList *graphNode, s16 on);
388
struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct AllocOnlyPool *pool, struct GraphNodeLevelOfDetail *graphNode,
389
s16 minDistance, s16 maxDistance);
390
struct GraphNodeSwitchCase *init_graph_node_switch_case(struct AllocOnlyPool *pool, struct GraphNodeSwitchCase *graphNode,
391
s16 numCases, s16 selectedCase, GraphNodeFunc nodeFunc, s32 unused);
392
struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool, struct GraphNodeCamera *graphNode,
393
f32 *pos, f32 *focus, GraphNodeFunc func, s32 mode);
394
struct GraphNodeTranslationRotation *init_graph_node_translation_rotation(struct AllocOnlyPool *pool, struct GraphNodeTranslationRotation *graphNode,
395
s32 drawingLayer, void *displayList, Vec3s translation, Vec3s rotation);
396
struct GraphNodeTranslation *init_graph_node_translation(struct AllocOnlyPool *pool, struct GraphNodeTranslation *graphNode,
397
s32 drawingLayer, void *displayList, Vec3s translation);
398
struct GraphNodeRotation *init_graph_node_rotation(struct AllocOnlyPool *pool, struct GraphNodeRotation *graphNode,
399
s32 drawingLayer, void *displayList, Vec3s rotation);
400
struct GraphNodeScale *init_graph_node_scale(struct AllocOnlyPool *pool, struct GraphNodeScale *graphNode,
401
s32 drawingLayer, void *displayList, f32 scale);
402
struct GraphNodeObject *init_graph_node_object(struct AllocOnlyPool *pool, struct GraphNodeObject *graphNode,
403
struct GraphNode *sharedChild, Vec3f pos, Vec3s angle, Vec3f scale);
404
struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct AllocOnlyPool *pool, struct GraphNodeCullingRadius *graphNode, s16 radius);
405
struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct AllocOnlyPool *pool, struct GraphNodeAnimatedPart *graphNode,
406
s32 drawingLayer, void *displayList, Vec3s translation);
407
struct GraphNodeBillboard *init_graph_node_billboard(struct AllocOnlyPool *pool, struct GraphNodeBillboard *graphNode,
408
s32 drawingLayer, void *displayList, Vec3s translation);
409
struct GraphNodeDisplayList *init_graph_node_display_list(struct AllocOnlyPool *pool, struct GraphNodeDisplayList *graphNode,
410
s32 drawingLayer, void *displayList);
411
struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool, struct GraphNodeShadow *graphNode,
412
s16 shadowScale, u8 shadowSolidity, u8 shadowType);
413
struct GraphNodeObjectParent *init_graph_node_object_parent(struct AllocOnlyPool *pool, struct GraphNodeObjectParent *sp1c,
414
struct GraphNode *sharedChild);
415
struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool, struct GraphNodeGenerated *sp1c,
416
GraphNodeFunc gfxFunc, s32 parameter);
417
struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *pool, struct GraphNodeBackground *sp1c,
418
u16 background, GraphNodeFunc backgroundFunc, s32 zero);
419
struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *pool, struct GraphNodeHeldObject *sp1c,
420
struct Object *objNode, Vec3s translation,
421
GraphNodeFunc nodeFunc, s32 playerIndex);
422
struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *childNode);
423
struct GraphNode *geo_remove_child(struct GraphNode *graphNode);
424
struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild);
425
426
void geo_call_global_function_nodes_helper(struct GraphNode *graphNode, s32 callContext);
427
void geo_call_global_function_nodes(struct GraphNode *graphNode, s32 callContext);
428
429
void geo_reset_object_node(struct GraphNodeObject *graphNode);
430
void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f pos, Vec3s angle);
431
void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo *spawn);
432
void geo_obj_init_animation(struct GraphNodeObject *graphNode, struct Animation **animPtrAddr);
433
void geo_obj_init_animation_accel(struct GraphNodeObject *graphNode, struct Animation **animPtrAddr, u32 animAccel);
434
435
s32 retrieve_animation_index(s32 frame, u16 **attributes);
436
437
s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist);
438
void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f position);
439
440
struct GraphNodeRoot *geo_find_root(struct GraphNode *graphNode);
441
442
// graph_node_manager
443
s16 *read_vec3s_to_vec3f(Vec3f, s16 *src);
444
s16 *read_vec3s(Vec3s dst, s16 *src);
445
s16 *read_vec3s_angle(Vec3s dst, s16 *src);
446
void register_scene_graph_node(struct GraphNode *graphNode);
447
448
#endif // GRAPH_NODE_H
449
450