TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Project516/sm64dx/llms.txt
Use this file to discover all available pages before exploring further.
src/engine/ directory is the heart of sm64dx’s runtime: it contains the four interpreter-style engines that drive everything from loading a level to moving a Goomba. Surface collision queries triangles stored in a spatial grid, the geometry layout engine builds the scene-graph tree used by the renderer, the level script engine interprets a byte-code stream that wires up areas and objects, and the behavior script engine steps each active object through its per-frame logic. All four systems share the types defined in include/types.h.
Surface collision system
Every walkable floor, ceiling, and wall in the game is represented as aSurface triangle. The collision system loads these triangles into a cell-based spatial hash at level load time (surface_load.c) and then answers point queries—find floor, find ceiling, find walls—each frame.
The Surface struct
TerrainData is a typedef for s16, and Vec3Terrain is TerrainData[3]. Vertex coordinates are stored as signed 16-bit integers, which constrains the level boundary to ±32 768 units; the actual enforced playfield limit is ±8 192 (LEVEL_BOUNDARY_MAX).
Wall collision data
Collision query API
find_floor and find_ceil return the Y position of the nearest surface and write a pointer to the Surface struct through their output parameter. Callers typically use the returned Y value for physics and the Surface pointer to read terrain type or the owning object.
The spatial grid uses
CELL_SIZE = 0x400 (1024 units) and spans ±8192 in X and Z. Dynamic surfaces—those attached to moving objects—are rebuilt from object->collisionData each frame before queries run.Geometry layout system
The geo layout engine reads a stream ofGeoLayout (uintptr_t) words and constructs a tree of GraphNode structs that the renderer traverses to emit display-list commands. Each node type represents a different rendering operation.
Base GraphNode
struct GraphNode node as its first member, making all node types safely castable from GraphNode *.
Graph node types
The geo layout interpreter creates one of the following node types depending on the command byte it reads. Each command function ingeo_layout.h maps to one node type:
| Command function | Node role |
|---|---|
geo_layout_cmd_node_root | Root of the scene graph |
geo_layout_cmd_node_ortho_projection | Orthographic projection (HUD, menus) |
geo_layout_cmd_node_perspective | Perspective camera frustum |
geo_layout_cmd_node_master_list | Groups draw calls by rendering layer |
geo_layout_cmd_node_level_of_detail | Switches child based on camera distance |
geo_layout_cmd_node_switch_case | Switches child based on a game variable |
geo_layout_cmd_node_camera | Camera transform node |
geo_layout_cmd_node_translation_rotation | Local TRS transform |
geo_layout_cmd_node_animated_part | Per-joint transform driven by animation data |
geo_layout_cmd_node_billboard | Always faces the camera |
geo_layout_cmd_node_display_list | Emits a static display list |
geo_layout_cmd_node_shadow | Draws Mario’s circular shadow |
geo_layout_cmd_node_object_parent | Attachment point for held objects |
geo_layout_cmd_node_generated | Calls a C function to emit a display list |
geo_layout_cmd_node_background | Skybox / background render |
geo_layout_cmd_node_held_obj | Renders the object Mario is holding |
geo_layout_cmd_node_culling_radius | Sphere-based frustum culling |
Object graph node
When an object is active, itsObjectNode.gfx field is a GraphNodeObject—a specialized graph node with position, rotation, scale, and animation state:
Level script system
Level scripts are arrays ofLevelScript (uintptr_t) words interpreted by level_script_execute(). They orchestrate area loading, segment DMA, object spawning, and transition sequencing.
sStack[32]) and a ScriptStatus enum (SCRIPT_RUNNING, SCRIPT_PAUSED, SCRIPT_PAUSED2) so it can yield across frames while waiting for DMA transfers to complete. The macro vocabulary—LOAD_RAW, JUMP, CALL, RETURN, SLEEP, SPAWN_OBJ, SET_REG, etc.—is defined in include/level_commands.h.
Behavior script system
Every object’s per-frame logic is driven by aBehaviorScript array interpreted by cur_obj_update() in behavior_script.c. The type alias is simple:
gCurBhvCommand and dispatches to one of ~50 command handlers. Two result codes control flow:
Object behavior fields
TheObject struct stores the interpreter’s runtime state alongside the behavior pointer:
behavior_script.h: