Super Mario 64 Source
A Super Mario 64 decompilation, brought to you by a bunch of clever folks.
Functions | Variables
surface_load.c File Reference
#include <ultra64.h>
#include "prevent_bss_reordering.h"
#include "sm64.h"
#include "game/ingame_menu.h"
#include "graph_node.h"
#include "behavior_script.h"
#include "behavior_data.h"
#include "game/memory.h"
#include "game/object_helpers.h"
#include "game/macro_special_objects.h"
#include "surface_collision.h"
#include "game/mario.h"
#include "game/object_list_processor.h"
#include "game/room.h"
#include "surface_load.h"

Functions

static struct SurfaceNodealloc_surface_node (void)
 Allocate the part of the surface node pool to contain a surface node. More...
 
static struct Surfacealloc_surface (void)
 Allocate the part of the surface pool to contain a surface and initialize the surface. More...
 
static void clear_spatial_partition (SpatialPartitionCell *cells)
 Iterates through the entire partition, clearing the surfaces. More...
 
static void clear_static_surfaces (void)
 Clears the static (level) surface partitions for new use. More...
 
static void add_surface_to_cell (s16 dynamic, s16 cellX, s16 cellZ, struct Surface *surface)
 Add a surface to the correct cell list of surfaces. More...
 
static s16 min_3 (s16 a0, s16 a1, s16 a2)
 Returns the lowest of three values. More...
 
static s16 max_3 (s16 a0, s16 a1, s16 a2)
 Returns the highest of three values. More...
 
static s16 lower_cell_index (s16 t)
 Every level is split into 16 * 16 cells of surfaces (to limit computing time). More...
 
static s16 upper_cell_index (s16 t)
 Every level is split into 16 * 16 cells of surfaces (to limit computing time). More...
 
static void add_surface (struct Surface *surface, s32 dynamic)
 Every level is split into 16x16 cells, this takes a surface, finds the appropriate cells (with a buffer), and adds the surface to those cells. More...
 
static void unused_80382B6C (void)
 
static struct Surfaceread_surface_data (s16 *vertexData, s16 **vertexIndices)
 Initialize a surface from reading it's data and putting it into a surface stuct. More...
 
static s32 surface_has_force (s16 surfaceType)
 Returns whether a surface has exertion/moves Mario based on the surface type. More...
 
static s32 surf_has_no_cam_collision (s16 surfaceType)
 Returns whether a surface should have the SURFACE_FLAG_NO_CAM_COLLISION flag. More...
 
static void load_static_surfaces (s16 **data, s16 *vertexData, s16 surfaceType, s8 **surfaceRooms)
 Load in the surfaces for a given surface type. More...
 
static s16read_vertex_data (s16 **data)
 Read the data for vertices for reference by triangles. More...
 
static void load_environmental_regions (s16 **data)
 Loads in special environmental regions, such as water, poison gas, and JRB fog. More...
 
void alloc_surface_pools (void)
 Allocate some of the main pool for surfaces (2300 surf) and for surface nodes (7000 nodes). More...
 
void load_area_terrain (s16 index, s16 *data, s8 *surfaceRooms, s16 *macroObjects)
 Process the level file, loading in vertices, surfaces, some objects, and environmental boxes (water, gas, JRB fog). More...
 
void clear_dynamic_surfaces (void)
 If not in time stop, clear the surface partitions. More...
 
static void unused_80383604 (void)
 
static void transform_object_vertices (s16 **data, s16 *vertexData)
 Applies an object's tranformation to the object's vertices. More...
 
static void load_object_surfaces (s16 **data, s16 *vertexData)
 Load in the surfaces for the gCurrentObject. More...
 
void load_object_collision_model (void)
 Transform an object's vertices, reload them, and render the object. More...
 

Variables

s32 unused8038BE90
 
SpatialPartitionCell gStaticSurfacePartition [16][16]
 Partitions for course and object surfaces. More...
 
SpatialPartitionCell gDynamicSurfacePartition [16][16]
 
struct SurfaceNodesSurfaceNodePool
 Pools of data to contain either surface nodes or surfaces. More...
 
struct SurfacesSurfacePool
 
s16 sSurfacePoolSize
 The size of the surface pool (2300). More...
 
u8 unused8038EEA8 [0x30]
 

Function Documentation

◆ add_surface()

static void add_surface ( struct Surface surface,
s32  dynamic 
)
static

Every level is split into 16x16 cells, this takes a surface, finds the appropriate cells (with a buffer), and adds the surface to those cells.

◆ add_surface_to_cell()

static void add_surface_to_cell ( s16  dynamic,
s16  cellX,
s16  cellZ,
struct Surface surface 
)
static

Add a surface to the correct cell list of surfaces.

(Surface Cucking) Surfaces are sorted by the height of their first

◆ alloc_surface()

static struct Surface* alloc_surface ( void  )
static

Allocate the part of the surface pool to contain a surface and initialize the surface.

A bounds check! If there's more surfaces than the 2300 allowed,

◆ alloc_surface_node()

static struct SurfaceNode* alloc_surface_node ( void  )
static

Allocate the part of the surface node pool to contain a surface node.

A bounds check! If there's more surface nodes than 7000 allowed,

◆ alloc_surface_pools()

void alloc_surface_pools ( void  )

Allocate some of the main pool for surfaces (2300 surf) and for surface nodes (7000 nodes).

◆ clear_dynamic_surfaces()

void clear_dynamic_surfaces ( void  )

If not in time stop, clear the surface partitions.

◆ clear_spatial_partition()

static void clear_spatial_partition ( SpatialPartitionCell cells)
static

Iterates through the entire partition, clearing the surfaces.

◆ clear_static_surfaces()

static void clear_static_surfaces ( void  )
static

Clears the static (level) surface partitions for new use.

◆ load_area_terrain()

void load_area_terrain ( s16  index,
s16 data,
s8 surfaceRooms,
s16 macroObjects 
)

Process the level file, loading in vertices, surfaces, some objects, and environmental boxes (water, gas, JRB fog).

◆ load_environmental_regions()

static void load_environmental_regions ( s16 **  data)
static

Loads in special environmental regions, such as water, poison gas, and JRB fog.

◆ load_object_collision_model()

void load_object_collision_model ( void  )

Transform an object's vertices, reload them, and render the object.

◆ load_object_surfaces()

static void load_object_surfaces ( s16 **  data,
s16 vertexData 
)
static

Load in the surfaces for the gCurrentObject.

This includes setting the flags, exertion, and room.

◆ load_static_surfaces()

static void load_static_surfaces ( s16 **  data,
s16 vertexData,
s16  surfaceType,
s8 **  surfaceRooms 
)
static

Load in the surfaces for a given surface type.

This includes setting the flags, exertion, and room.

◆ lower_cell_index()

static s16 lower_cell_index ( s16  t)
static

Every level is split into 16 * 16 cells of surfaces (to limit computing time).

This function determines the lower cell for a given x/z position.

Some wall checks are larger than the buffer, meaning wall checks can

◆ max_3()

static s16 max_3 ( s16  a0,
s16  a1,
s16  a2 
)
static

Returns the highest of three values.

◆ min_3()

static s16 min_3 ( s16  a0,
s16  a1,
s16  a2 
)
static

Returns the lowest of three values.

◆ read_surface_data()

static struct Surface* read_surface_data ( s16 vertexData,
s16 **  vertexIndices 
)
static

Initialize a surface from reading it's data and putting it into a surface stuct.

◆ read_vertex_data()

static s16* read_vertex_data ( s16 **  data)
static

Read the data for vertices for reference by triangles.

◆ surf_has_no_cam_collision()

static s32 surf_has_no_cam_collision ( s16  surfaceType)
static

Returns whether a surface should have the SURFACE_FLAG_NO_CAM_COLLISION flag.

◆ surface_has_force()

static s32 surface_has_force ( s16  surfaceType)
static

Returns whether a surface has exertion/moves Mario based on the surface type.

◆ transform_object_vertices()

static void transform_object_vertices ( s16 **  data,
s16 vertexData 
)
static

Applies an object's tranformation to the object's vertices.

No bounds check on vertex data

◆ unused_80382B6C()

static void unused_80382B6C ( void  )
static

◆ unused_80383604()

static void unused_80383604 ( void  )
static

◆ upper_cell_index()

static s16 upper_cell_index ( s16  t)
static

Every level is split into 16 * 16 cells of surfaces (to limit computing time).

This function determines the upper cell for a given x/z position.

Some wall checks are larger than the buffer, meaning wall checks can

Variable Documentation

◆ gDynamicSurfacePartition

SpatialPartitionCell gDynamicSurfacePartition[16][16]

◆ gStaticSurfacePartition

SpatialPartitionCell gStaticSurfacePartition[16][16]

Partitions for course and object surfaces.

The arrays represent the 16x16 cells that each level is split into.

◆ sSurfaceNodePool

struct SurfaceNode* sSurfaceNodePool

Pools of data to contain either surface nodes or surfaces.

◆ sSurfacePool

struct Surface* sSurfacePool

◆ sSurfacePoolSize

s16 sSurfacePoolSize

The size of the surface pool (2300).

◆ unused8038BE90

s32 unused8038BE90

◆ unused8038EEA8

u8 unused8038EEA8[0x30]