Super Mario 64 Source
A Super Mario 64 decompilation, brought to you by a bunch of clever folks.
Functions | Variables
graph_node.c File Reference
#include <ultra64.h>
#include "sm64.h"
#include "game/level_update.h"
#include "math_util.h"
#include "game/memory.h"
#include "graph_node.h"
#include "game/rendering_graph_node.h"
#include "game/area.h"
#include "geo_layout.h"

Functions

void init_scene_graph_node_links (struct GraphNode *graphNode, s32 type)
 Initialize a geo node with a given type. More...
 
struct GraphNodeRootinit_graph_node_root (struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode, s16 areaIndex, s16 x, s16 y, s16 width, s16 height)
 Allocated and returns a newly created root node. More...
 
struct GraphNodeOrthoProjectioninit_graph_node_ortho_projection (struct AllocOnlyPool *pool, struct GraphNodeOrthoProjection *graphNode, f32 scale)
 Allocates and returns a newly created otrhographic projection node. More...
 
struct GraphNodePerspectiveinit_graph_node_perspective (struct AllocOnlyPool *pool, struct GraphNodePerspective *graphNode, f32 fov, s16 near, s16 far, GraphNodeFunc nodeFunc, s32 unused)
 Allocates and returns a newly created perspective node. More...
 
struct GraphNodeStartinit_graph_node_start (struct AllocOnlyPool *pool, struct GraphNodeStart *graphNode)
 Allocates and returns a newly created start node. More...
 
struct GraphNodeMasterListinit_graph_node_master_list (struct AllocOnlyPool *pool, struct GraphNodeMasterList *graphNode, s16 on)
 Allocates and returns a newly created master list node. More...
 
struct GraphNodeLevelOfDetailinit_graph_node_render_range (struct AllocOnlyPool *pool, struct GraphNodeLevelOfDetail *graphNode, s16 minDistance, s16 maxDistance)
 Allocates and returns a newly created render range node. More...
 
struct GraphNodeSwitchCaseinit_graph_node_switch_case (struct AllocOnlyPool *pool, struct GraphNodeSwitchCase *graphNode, s16 numCases, s16 selectedCase, GraphNodeFunc nodeFunc, s32 unused)
 Allocates and returns a newly created switch case node. More...
 
struct GraphNodeCamerainit_graph_node_camera (struct AllocOnlyPool *pool, struct GraphNodeCamera *graphNode, f32 *fromPos, f32 *toPos, GraphNodeFunc func, s32 preset)
 Allocates and returns a newly created camera node. More...
 
struct GraphNodeTranslationRotationinit_graph_node_translation_rotation (struct AllocOnlyPool *pool, struct GraphNodeTranslationRotation *graphNode, s32 drawingLayer, void *displayList, Vec3s translation, Vec3s rotation)
 Allocates and returns a newly created translation rotation node. More...
 
struct GraphNodeTranslationinit_graph_node_translation (struct AllocOnlyPool *pool, struct GraphNodeTranslation *graphNode, s32 drawingLayer, void *displayList, Vec3s translation)
 Allocates and returns a newly created translation node. More...
 
struct GraphNodeRotationinit_graph_node_rotation (struct AllocOnlyPool *pool, struct GraphNodeRotation *graphNode, s32 drawingLayer, void *displayList, Vec3s rotation)
 Allocates and returns a newly created rotation node. More...
 
struct GraphNodeScaleinit_graph_node_scale (struct AllocOnlyPool *pool, struct GraphNodeScale *graphNode, s32 drawingLayer, void *displayList, f32 scale)
 Allocates and returns a newly created scaling node. More...
 
struct GraphNodeObjectinit_graph_node_object (struct AllocOnlyPool *pool, struct GraphNodeObject *graphNode, struct GraphNode *sharedChild, Vec3f pos, Vec3s angle, Vec3f scale)
 Allocates and returns a newly created object node. More...
 
struct GraphNodeCullingRadiusinit_graph_node_culling_radius (struct AllocOnlyPool *pool, struct GraphNodeCullingRadius *graphNode, s16 radius)
 Allocates and returns a newly created frustum culling radius node. More...
 
struct GraphNodeAnimatedPartinit_graph_node_animated_part (struct AllocOnlyPool *pool, struct GraphNodeAnimatedPart *graphNode, s32 drawingLayer, void *displayList, Vec3s translation)
 Allocates and returns a newly created animated part node. More...
 
struct GraphNodeBillboardinit_graph_node_billboard (struct AllocOnlyPool *pool, struct GraphNodeBillboard *graphNode, s32 drawingLayer, void *displayList, Vec3s translation)
 Allocates and returns a newly created billboard node. More...
 
struct GraphNodeDisplayListinit_graph_node_display_list (struct AllocOnlyPool *pool, struct GraphNodeDisplayList *graphNode, s32 drawingLayer, void *displayList)
 Allocates and returns a newly created displaylist node. More...
 
struct GraphNodeShadowinit_graph_node_shadow (struct AllocOnlyPool *pool, struct GraphNodeShadow *graphNode, s16 shadowScale, u8 shadowSolidity, u8 shadowType)
 Allocates and returns a newly created shadow node. More...
 
struct GraphNodeObjectParentinit_graph_node_object_parent (struct AllocOnlyPool *pool, struct GraphNodeObjectParent *graphNode, struct GraphNode *sharedChild)
 Allocates and returns a newly created object parent node. More...
 
struct GraphNodeGeneratedinit_graph_node_generated (struct AllocOnlyPool *pool, struct GraphNodeGenerated *graphNode, GraphNodeFunc gfxFunc, s32 parameter)
 Allocates and returns a newly created generated node. More...
 
struct GraphNodeBackgroundinit_graph_node_background (struct AllocOnlyPool *pool, struct GraphNodeBackground *graphNode, u16 background, GraphNodeFunc backgroundFunc, s32 zero)
 Allocates and returns a newly created background node. More...
 
struct GraphNodeHeldObjectinit_graph_node_held_object (struct AllocOnlyPool *pool, struct GraphNodeHeldObject *graphNode, s32 objNode, Vec3s translation, GraphNodeFunc nodeFunc, s32 unused)
 Allocates and returns a newly created held object node. More...
 
struct GraphNodegeo_add_child (struct GraphNode *parent, struct GraphNode *childNode)
 Adds 'childNode' to the end of the list children from 'parent'. More...
 
struct GraphNodegeo_remove_child (struct GraphNode *graphNode)
 Remove a node from the scene graph. More...
 
struct GraphNodegeo_make_first_child (struct GraphNode *newFirstChild)
 Reorders the given node so it's the first child of its parent. More...
 
void geo_call_global_function_nodes_helper (struct GraphNode *graphNode, s32 callContext)
 Helper function for geo_call_global_function_nodes that recursively traverses the scene graph and calls the functions of global nodes. More...
 
void geo_call_global_function_nodes (struct GraphNode *graphNode, s32 callContext)
 Call the update functions of geo nodes that are stored in global variables. More...
 
void geo_reset_object_node (struct GraphNodeObject *graphNode)
 When objects are cleared, this is called on all object nodes (loaded or unloaded). More...
 
void geo_obj_init (struct GraphNodeObject *graphNode, void *sharedChild, Vec3f pos, Vec3s angle)
 Initialize an object node using the given parameters. More...
 
void geo_obj_init_spawninfo (struct GraphNodeObject *graphNode, struct SpawnInfo *spawn)
 Initialize and object node using the given SpawnInfo struct. More...
 
void geo_obj_init_animation (struct GraphNodeObject *graphNode, void *sp34)
 Initialize the animation of an object node. More...
 
void geo_obj_init_animation_accel (struct GraphNodeObject *graphNode, void *sp34, u32 animAccel)
 Initialize the animation of an object node. More...
 
s32 retrieve_animation_index (s32 frame, u16 **attributes)
 Retrieves an index into animation data based on the attribute pointer An attribute is an x-, y- or z-component of the translation / rotation for a part Each attribute is a pair of s16's, where the first s16 represents the maximum frame and the second s16 the actual index. More...
 
s16 geo_update_animation_frame (struct GraphNodeObject_sub *obj, s32 *accelAssist)
 Update the animation frame of an object. More...
 
void geo_retreive_animation_translation (struct GraphNodeObject *obj, Vec3f position)
 Unused function to retrieve an object's current animation translation Assumes that it has x, y and z data in animations, which isn't always the case since some animation types only have vertical or lateral translation. More...
 
struct GraphNodeRootgeo_find_root (struct GraphNode *graphNode)
 Unused function to find the root of the geo node tree, which should be a GraphNodeRoot. More...
 

Variables

s16 identityMtx [4][4] = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }
 
s16 zeroMtx [4][4] = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }
 
Vec3f gVec3fZero = { 0.0f, 0.0f, 0.0f }
 
Vec3s gVec3sZero = { 0, 0, 0 }
 
Vec3f gVec3fOne = { 1.0f, 1.0f, 1.0f }
 
UNUSED Vec3s gVec3sOne = { 1, 1, 1 }
 

Function Documentation

◆ geo_add_child()

struct GraphNode* geo_add_child ( struct GraphNode parent,
struct GraphNode childNode 
)

Adds 'childNode' to the end of the list children from 'parent'.

◆ geo_call_global_function_nodes()

void geo_call_global_function_nodes ( struct GraphNode graphNode,
s32  callContext 
)

Call the update functions of geo nodes that are stored in global variables.

These variables include gCurGraphNodeMasterList, gCurGraphNodeCamFrustum, gCurGraphNodeCamera and gCurGraphNodeObject. callContext is one of the GEO_CONTEXT_ defines. The graphNode argument should be of type GraphNodeRoot.

◆ geo_call_global_function_nodes_helper()

void geo_call_global_function_nodes_helper ( struct GraphNode graphNode,
s32  callContext 
)

Helper function for geo_call_global_function_nodes that recursively traverses the scene graph and calls the functions of global nodes.

◆ geo_find_root()

struct GraphNodeRoot* geo_find_root ( struct GraphNode graphNode)

Unused function to find the root of the geo node tree, which should be a GraphNodeRoot.

If it is not for some reason, null is returned.

◆ geo_make_first_child()

struct GraphNode* geo_make_first_child ( struct GraphNode newFirstChild)

Reorders the given node so it's the first child of its parent.

This is called on the Mario object when he is spawned. That's why Mario's object is always drawn before any other objects. (Note that the geo order is independent from processing group order, where Mario is not first.)

◆ geo_obj_init()

void geo_obj_init ( struct GraphNodeObject graphNode,
void sharedChild,
Vec3f  pos,
Vec3s  angle 
)

Initialize an object node using the given parameters.

◆ geo_obj_init_animation()

void geo_obj_init_animation ( struct GraphNodeObject graphNode,
void sp34 
)

Initialize the animation of an object node.

◆ geo_obj_init_animation_accel()

void geo_obj_init_animation_accel ( struct GraphNodeObject graphNode,
void sp34,
u32  animAccel 
)

Initialize the animation of an object node.

◆ geo_obj_init_spawninfo()

void geo_obj_init_spawninfo ( struct GraphNodeObject graphNode,
struct SpawnInfo spawn 
)

Initialize and object node using the given SpawnInfo struct.

◆ geo_remove_child()

struct GraphNode* geo_remove_child ( struct GraphNode graphNode)

Remove a node from the scene graph.

It changes the links with its siblings and with its parent, it doesn't deallocate the memory since geo nodes are allocated in a pointer-bumping pool that gets thrown out when changing areas.

◆ geo_reset_object_node()

void geo_reset_object_node ( struct GraphNodeObject graphNode)

When objects are cleared, this is called on all object nodes (loaded or unloaded).

◆ geo_retreive_animation_translation()

void geo_retreive_animation_translation ( struct GraphNodeObject obj,
Vec3f  position 
)

Unused function to retrieve an object's current animation translation Assumes that it has x, y and z data in animations, which isn't always the case since some animation types only have vertical or lateral translation.

This might have been used for positioning the shadow under an object, which currently happens in-line in geo_process_shadow where it also accounts for animations without lateral translation.

◆ geo_update_animation_frame()

s16 geo_update_animation_frame ( struct GraphNodeObject_sub obj,
s32 accelAssist 
)

Update the animation frame of an object.

The animation flags determine whether it plays forwards or backwards, and whether it stops or loops at the end etc.

◆ init_graph_node_animated_part()

struct GraphNodeAnimatedPart* init_graph_node_animated_part ( struct AllocOnlyPool pool,
struct GraphNodeAnimatedPart graphNode,
s32  drawingLayer,
void displayList,
Vec3s  translation 
)

Allocates and returns a newly created animated part node.

◆ init_graph_node_background()

struct GraphNodeBackground* init_graph_node_background ( struct AllocOnlyPool pool,
struct GraphNodeBackground graphNode,
u16  background,
GraphNodeFunc  backgroundFunc,
s32  zero 
)

Allocates and returns a newly created background node.

◆ init_graph_node_billboard()

struct GraphNodeBillboard* init_graph_node_billboard ( struct AllocOnlyPool pool,
struct GraphNodeBillboard graphNode,
s32  drawingLayer,
void displayList,
Vec3s  translation 
)

Allocates and returns a newly created billboard node.

◆ init_graph_node_camera()

struct GraphNodeCamera* init_graph_node_camera ( struct AllocOnlyPool pool,
struct GraphNodeCamera graphNode,
f32 fromPos,
f32 toPos,
GraphNodeFunc  func,
s32  preset 
)

Allocates and returns a newly created camera node.

◆ init_graph_node_culling_radius()

struct GraphNodeCullingRadius* init_graph_node_culling_radius ( struct AllocOnlyPool pool,
struct GraphNodeCullingRadius graphNode,
s16  radius 
)

Allocates and returns a newly created frustum culling radius node.

◆ init_graph_node_display_list()

struct GraphNodeDisplayList* init_graph_node_display_list ( struct AllocOnlyPool pool,
struct GraphNodeDisplayList graphNode,
s32  drawingLayer,
void displayList 
)

Allocates and returns a newly created displaylist node.

◆ init_graph_node_generated()

struct GraphNodeGenerated* init_graph_node_generated ( struct AllocOnlyPool pool,
struct GraphNodeGenerated graphNode,
GraphNodeFunc  gfxFunc,
s32  parameter 
)

Allocates and returns a newly created generated node.

◆ init_graph_node_held_object()

struct GraphNodeHeldObject* init_graph_node_held_object ( struct AllocOnlyPool pool,
struct GraphNodeHeldObject graphNode,
s32  objNode,
Vec3s  translation,
GraphNodeFunc  nodeFunc,
s32  unused 
)

Allocates and returns a newly created held object node.

◆ init_graph_node_master_list()

struct GraphNodeMasterList* init_graph_node_master_list ( struct AllocOnlyPool pool,
struct GraphNodeMasterList graphNode,
s16  on 
)

Allocates and returns a newly created master list node.

◆ init_graph_node_object()

struct GraphNodeObject* init_graph_node_object ( struct AllocOnlyPool pool,
struct GraphNodeObject graphNode,
struct GraphNode sharedChild,
Vec3f  pos,
Vec3s  angle,
Vec3f  scale 
)

Allocates and returns a newly created object node.

◆ init_graph_node_object_parent()

struct GraphNodeObjectParent* init_graph_node_object_parent ( struct AllocOnlyPool pool,
struct GraphNodeObjectParent graphNode,
struct GraphNode sharedChild 
)

Allocates and returns a newly created object parent node.

◆ init_graph_node_ortho_projection()

struct GraphNodeOrthoProjection* init_graph_node_ortho_projection ( struct AllocOnlyPool pool,
struct GraphNodeOrthoProjection graphNode,
f32  scale 
)

Allocates and returns a newly created otrhographic projection node.

◆ init_graph_node_perspective()

struct GraphNodePerspective* init_graph_node_perspective ( struct AllocOnlyPool pool,
struct GraphNodePerspective graphNode,
f32  fov,
s16  near,
s16  far,
GraphNodeFunc  nodeFunc,
s32  unused 
)

Allocates and returns a newly created perspective node.

◆ init_graph_node_render_range()

struct GraphNodeLevelOfDetail* init_graph_node_render_range ( struct AllocOnlyPool pool,
struct GraphNodeLevelOfDetail graphNode,
s16  minDistance,
s16  maxDistance 
)

Allocates and returns a newly created render range node.

◆ init_graph_node_root()

struct GraphNodeRoot* init_graph_node_root ( struct AllocOnlyPool pool,
struct GraphNodeRoot graphNode,
s16  areaIndex,
s16  x,
s16  y,
s16  width,
s16  height 
)

Allocated and returns a newly created root node.

◆ init_graph_node_rotation()

struct GraphNodeRotation* init_graph_node_rotation ( struct AllocOnlyPool pool,
struct GraphNodeRotation graphNode,
s32  drawingLayer,
void displayList,
Vec3s  rotation 
)

Allocates and returns a newly created rotation node.

◆ init_graph_node_scale()

struct GraphNodeScale* init_graph_node_scale ( struct AllocOnlyPool pool,
struct GraphNodeScale graphNode,
s32  drawingLayer,
void displayList,
f32  scale 
)

Allocates and returns a newly created scaling node.

◆ init_graph_node_shadow()

struct GraphNodeShadow* init_graph_node_shadow ( struct AllocOnlyPool pool,
struct GraphNodeShadow graphNode,
s16  shadowScale,
u8  shadowSolidity,
u8  shadowType 
)

Allocates and returns a newly created shadow node.

◆ init_graph_node_start()

struct GraphNodeStart* init_graph_node_start ( struct AllocOnlyPool pool,
struct GraphNodeStart graphNode 
)

Allocates and returns a newly created start node.

◆ init_graph_node_switch_case()

struct GraphNodeSwitchCase* init_graph_node_switch_case ( struct AllocOnlyPool pool,
struct GraphNodeSwitchCase graphNode,
s16  numCases,
s16  selectedCase,
GraphNodeFunc  nodeFunc,
s32  unused 
)

Allocates and returns a newly created switch case node.

◆ init_graph_node_translation()

struct GraphNodeTranslation* init_graph_node_translation ( struct AllocOnlyPool pool,
struct GraphNodeTranslation graphNode,
s32  drawingLayer,
void displayList,
Vec3s  translation 
)

Allocates and returns a newly created translation node.

◆ init_graph_node_translation_rotation()

struct GraphNodeTranslationRotation* init_graph_node_translation_rotation ( struct AllocOnlyPool pool,
struct GraphNodeTranslationRotation graphNode,
s32  drawingLayer,
void displayList,
Vec3s  translation,
Vec3s  rotation 
)

Allocates and returns a newly created translation rotation node.

◆ init_scene_graph_node_links()

void init_scene_graph_node_links ( struct GraphNode graphNode,
s32  type 
)

Initialize a geo node with a given type.

Sets all links such that there are no siblings, parent or children for this node.

◆ retrieve_animation_index()

s32 retrieve_animation_index ( s32  frame,
u16 **  attributes 
)

Retrieves an index into animation data based on the attribute pointer An attribute is an x-, y- or z-component of the translation / rotation for a part Each attribute is a pair of s16's, where the first s16 represents the maximum frame and the second s16 the actual index.

This index can be used to index in the array with actual animation values.

Variable Documentation

◆ gVec3fOne

Vec3f gVec3fOne = { 1.0f, 1.0f, 1.0f }

◆ gVec3fZero

Vec3f gVec3fZero = { 0.0f, 0.0f, 0.0f }

◆ gVec3sOne

UNUSED Vec3s gVec3sOne = { 1, 1, 1 }

◆ gVec3sZero

Vec3s gVec3sZero = { 0, 0, 0 }

◆ identityMtx

s16 identityMtx[4][4] = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }

◆ zeroMtx

s16 zeroMtx[4][4] = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }