![]() |
Super Mario 64 Source
A Super Mario 64 decompilation, brought to you by a bunch of clever folks.
|
#include <ultra64.h>
#include "sm64.h"
#include "moving_texture.h"
#include "area.h"
#include "camera.h"
#include "rendering_graph_node.h"
#include "engine/math_util.h"
#include "memory.h"
#include "save_file.h"
#include "segment2.h"
#include "engine/surface_collision.h"
#include "geo_misc.h"
#include "room.h"
Data Structures | |
struct | MovtexObject |
An object containing all info for a mesh with moving textures. More... | |
struct | MovtexQuad |
Represents a single flat quad with a rotating texture Stores x and z for 4 vertices, though it is often just a rectangle. More... | |
struct | MovtexQuadCollection |
Contains an id and an array of MovtexQuad structs. More... | |
Macros | |
#define | MOVTEX_ATTR_SPEED 0 |
This file contains functions for generating display lists with moving textures (abbreviated movtex). More... | |
#define | MOVTEX_LAYOUT_NOCOLOR 0 |
#define | MOVTEX_LAYOUT_COLORED 1 |
#define | MOVTEX_ATTR_X 1 |
#define | MOVTEX_ATTR_Y 2 |
#define | MOVTEX_ATTR_Z 3 |
#define | MOVTEX_ATTR_NOCOLOR_S 4 |
#define | MOVTEX_ATTR_NOCOLOR_T 5 |
#define | MOVTEX_ATTR_COLORED_R 4 |
#define | MOVTEX_ATTR_COLORED_G 5 |
#define | MOVTEX_ATTR_COLORED_B 6 |
#define | MOVTEX_ATTR_COLORED_S 7 |
#define | MOVTEX_ATTR_COLORED_T 8 |
#define | MOVTEX_VTX_COLOR_DEFAULT 0 |
#define | MOVTEX_VTX_COLOR_YELLOW 1 |
#define | MOVTEX_VTX_COLOR_RED 2 |
Functions | |
Gfx * | geo_wdw_set_initial_water_level (s32 callContext, UNUSED struct GraphNode *node, UNUSED f32 mtx[4][4]) |
Sets the initial water level in Wet-Dry World based on how high Mario jumped into the painting. More... | |
Gfx * | geo_movtex_pause_control (s32 callContext, UNUSED struct GraphNode *node, UNUSED f32 mtx[4][4]) |
Update moving texture counters that determine when to update the coordinates. More... | |
void | movtex_make_quad_vertex (Vtx *verts, s32 index, s16 x, s16 y, s16 z, s16 rot, s16 rotOffset, f32 scale, u8 alpha) |
Make a vertex that's part of a quad with rotating texture. More... | |
Gfx * | movtex_gen_from_quad (s16 y, struct MovtexQuad *quad) |
Generates and returns a display list for a single MovtexQuad at height y. More... | |
Gfx * | movtex_gen_from_quad_array (s16 y, void *quadArrSegmented) |
Generate a display list drawing an array of MoxtexQuad at height 'y'. More... | |
Gfx * | movtex_gen_quads_id (s16 id, s16 y, void *movetexQuadsSegmented) |
Generate the display list for a list of quads by searching through a collection for a given id. More... | |
void * | get_quad_collection_from_id (u32 id) |
Find the quadCollection for a given quad collection id. More... | |
void | movtex_change_texture_format (u32 quadCollectionId, Gfx **gfx) |
Write to 'gfx' a command to set the current texture format for the given quadCollection. More... | |
Gfx * | geo_movtex_draw_water_regions (s32 callContext, struct GraphNode *node, UNUSED f32 mtx[4][4]) |
Geo script responsible for drawing quads with a moving texture at the height of the corresponding water region. More... | |
void | update_moving_texture_offset (s16 *movtexVerts, s32 attr) |
Updates a movtex mesh by adding the movtex's speed to the horizontal or vertical texture coordinates depending on 'attr'. More... | |
void | movtex_write_vertex_first (Vtx *vtx, s16 *movtexVerts, struct MovtexObject *c, s8 attrLayout) |
Make the first vertex of a moving texture with index 0. More... | |
void | movtex_write_vertex_index (Vtx *verts, s32 index, s16 *movtexVerts, struct MovtexObject *d, s8 attrLayout) |
Make a vertex with index > 0. More... | |
Gfx * | movtex_gen_list (s16 *movtexVerts, struct MovtexObject *movtexList, s8 attrLayout) |
Generate a displaylist for a MovtexObject. More... | |
Gfx * | geo_movtex_draw_nocolor (s32 callContext, struct GraphNode *node, UNUSED f32 mtx[4][4]) |
Function for a geo node that draws a MovtexObject in the gMovtexNonColored list. More... | |
Gfx * | geo_movtex_draw_colored (s32 callContext, struct GraphNode *node, UNUSED f32 mtx[4][4]) |
Function for a geo node that draws a MovtexObject in the gMovtexColored list. More... | |
Gfx * | geo_movtex_draw_colored_no_update (s32 callContext, struct GraphNode *node, UNUSED f32 mtx[4][4]) |
Function for a geo node that draws a MovtexObject in the gMovtexColored list, but it doesn't call update_moving_texture_offset since that happens in geo_movtex_update_horizontal. More... | |
Gfx * | geo_movtex_draw_colored_2_no_update (s32 callContext, struct GraphNode *node, UNUSED f32 mtx[4][4]) |
Exact copy of geo_movtex_draw_colored_no_update, but now using the gMovtexColored2 array. More... | |
Gfx * | geo_movtex_update_horizontal (s32 callContext, struct GraphNode *node, UNUSED f32 mtx[4][4]) |
Make textures move horizontally by simply adding a number to the 's' texture coordinate. More... | |
#define MOVTEX_ATTR_COLORED_B 6 |
#define MOVTEX_ATTR_COLORED_G 5 |
#define MOVTEX_ATTR_COLORED_R 4 |
#define MOVTEX_ATTR_COLORED_S 7 |
#define MOVTEX_ATTR_COLORED_T 8 |
#define MOVTEX_ATTR_NOCOLOR_S 4 |
#define MOVTEX_ATTR_NOCOLOR_T 5 |
#define MOVTEX_ATTR_SPEED 0 |
This file contains functions for generating display lists with moving textures (abbreviated movtex).
This is used for water, sand, haze, mist and treadmills. Each mesh using this system has the animated vertices stored as an array of shorts. The first entry is the texture movement speed. After that the vertices are stored in one of two layouts: one without per-vertex color attributes and one with. [speed, v0(x,y,z, s,t) , v1(x,y,z, s,t) , ...] [speed, v0(x,y,z, r,g,b s,t), v1(x,y,z, r,g,b s,t), ...] x, y, z = vertex position as integers s, t = texture coordinatea as 6.10 fixed point number. That means coordinates in range [0, 1024] are a unique part of the image, after that it repeats the image.
The first vertex 'v0' is special because all subsequent vertices inherit its texture offset. So to animate e.g. a treadmill, the speed component arr[0] is simply added to the s component arr[7] every frame and the texture scrolls horizontally over the entire mesh without changing the rest of the array. Note that while the system allows many kinds of vertex animations, in practice the only animation used is horizontally scrolling textures.
After updating the base mesh, the vertices are converted to the format the RSP understands and a display list is generated. The RSP can buffer 16 vertices at a time, and this code assumes everything fits in one buffer, so every moving texture mesh must have at most 16 vertices. As a result some meshes are split up into multiple parts, like the sand pathway inside the pyramid which has 3 parts. The water stream in the Cavern of the Metal Cap fits in one mesh.
Apart from this general system, there is also a simpler system for flat quads with a rotating texture. This is often used for water, but also for mist, toxic haze and lava inside the volcano. One quad is described by the struct MovtexQuad, and multiple MovtexQuads form a MovtexQuadCollection. A geo node has an id that corresponds to the id of a certain MovtexQuadCollection, which will then be matched with the id of entries in gEnvironmentRegions to get the y-position. The x and z coordinates are stored in the MovtexQuads themself, so the water rectangle is separate from the actually drawn rectangle.
#define MOVTEX_ATTR_X 1 |
#define MOVTEX_ATTR_Y 2 |
#define MOVTEX_ATTR_Z 3 |
#define MOVTEX_LAYOUT_COLORED 1 |
#define MOVTEX_LAYOUT_NOCOLOR 0 |
#define MOVTEX_VTX_COLOR_DEFAULT 0 |
#define MOVTEX_VTX_COLOR_RED 2 |
#define MOVTEX_VTX_COLOR_YELLOW 1 |
Function for a geo node that draws a MovtexObject in the gMovtexColored list.
Gfx* geo_movtex_draw_colored_2_no_update | ( | s32 | callContext, |
struct GraphNode * | node, | ||
UNUSED f32 | mtx[4][4] | ||
) |
Exact copy of geo_movtex_draw_colored_no_update, but now using the gMovtexColored2 array.
Used for the sand pits in SSL, both outside and inside the pyramid.
Gfx* geo_movtex_draw_colored_no_update | ( | s32 | callContext, |
struct GraphNode * | node, | ||
UNUSED f32 | mtx[4][4] | ||
) |
Function for a geo node that draws a MovtexObject in the gMovtexColored list, but it doesn't call update_moving_texture_offset since that happens in geo_movtex_update_horizontal.
This is for when a MovtexObject has multiple instances (like TTC treadmills) so you don't want the animation speed to increase the more instances there are.
Function for a geo node that draws a MovtexObject in the gMovtexNonColored list.
Gfx* geo_movtex_draw_water_regions | ( | s32 | callContext, |
struct GraphNode * | node, | ||
UNUSED f32 | mtx[4][4] | ||
) |
Geo script responsible for drawing quads with a moving texture at the height of the corresponding water region.
The node's parameter determines which quad collection is drawn, see moving_texture.h.
Gfx* geo_movtex_pause_control | ( | s32 | callContext, |
UNUSED struct GraphNode * | node, | ||
UNUSED f32 | mtx[4][4] | ||
) |
Update moving texture counters that determine when to update the coordinates.
Textures update when gMovtexCounterPrev != gMovtexCounter. This ensures water / sand flow stops when the game pauses.
Gfx* geo_movtex_update_horizontal | ( | s32 | callContext, |
struct GraphNode * | node, | ||
UNUSED f32 | mtx[4][4] | ||
) |
Make textures move horizontally by simply adding a number to the 's' texture coordinate.
Used for:
Gfx* geo_wdw_set_initial_water_level | ( | s32 | callContext, |
UNUSED struct GraphNode * | node, | ||
UNUSED f32 | mtx[4][4] | ||
) |
Sets the initial water level in Wet-Dry World based on how high Mario jumped into the painting.
Write to 'gfx' a command to set the current texture format for the given quadCollection.
Gfx* movtex_gen_from_quad | ( | s16 | y, |
struct MovtexQuad * | quad | ||
) |
Generates and returns a display list for a single MovtexQuad at height y.
Generate a display list drawing an array of MoxtexQuad at height 'y'.
y: y position of the quads quadArrSegmented: a segmented address to an array of s16. The first number is the number of entries, followed by that number of MovtexQuad structs.
Gfx* movtex_gen_list | ( | s16 * | movtexVerts, |
struct MovtexObject * | movtexList, | ||
s8 | attrLayout | ||
) |
Generate a displaylist for a MovtexObject.
'attrLayout' is one of MOVTEX_LAYOUT_NOCOLOR and MOVTEX_LAYOUT_COLORED.
Generate the display list for a list of quads by searching through a collection for a given id.
id: id of quad array to generate a list for y: height at which the quads are drawn movetexQuadsSegmented: segmented address to the MovtexQuadCollection array that will be searched.
void movtex_make_quad_vertex | ( | Vtx * | verts, |
s32 | index, | ||
s16 | x, | ||
s16 | y, | ||
s16 | z, | ||
s16 | rot, | ||
s16 | rotOffset, | ||
f32 | scale, | ||
u8 | alpha | ||
) |
Make a vertex that's part of a quad with rotating texture.
verts: array of RSP vertices n: index in 'verts' where the vertex is written x, y, z: position rot: base rotation of the texture rotOffset: gets added to base rotation scale: how often the texture repeats, 1 = no repeat
void movtex_write_vertex_first | ( | Vtx * | vtx, |
s16 * | movtexVerts, | ||
struct MovtexObject * | c, | ||
s8 | attrLayout | ||
) |
Make the first vertex of a moving texture with index 0.
This vertex is the base of all vertices with index > 0, which use this vertex's coordinates as base on which to apply offset. The first vertex has offset 0 by definition, simplifying the calculations a bit.
void movtex_write_vertex_index | ( | Vtx * | verts, |
s32 | index, | ||
s16 * | movtexVerts, | ||
struct MovtexObject * | d, | ||
s8 | attrLayout | ||
) |
Make a vertex with index > 0.
The vertex with index 0 is made in movtex_write_vertex_first and subsequent vertices use vertex 0 as a base for their texture coordinates.
Updates a movtex mesh by adding the movtex's speed to the horizontal or vertical texture coordinates depending on 'attr'.
movtexVerts: vertices to update attr: which attribute to change
u8 bbh_movtex_merry_go_round_water_entrance[] |
u8 bbh_movtex_merry_go_round_water_side[] |
Gfx bitfs_dl_lava_floor[] |
Gfx bitfs_dl_lava_sections[] |
s16 bitfs_movtex_tris_lava_first_section[] |
s16 bitfs_movtex_tris_lava_floor[] |
s16 bitfs_movtex_tris_lava_second_section[] |
u8 castle_courtyard_movtex_star_statue_water[] |
Gfx castle_grounds_dl_waterfall[] |
s16 castle_grounds_movtex_tris_waterfall[] |
u8 castle_grounds_movtex_water[] |
u8 ccm_movtex_penguin_puddle_water[] |
Gfx cotmc_dl_water[] |
Gfx cotmc_dl_water_begin[] |
Gfx cotmc_dl_water_end[] |
s16 cotmc_movtex_tris_water[] |
u8 ddd_movtex_area1_water[] |
u8 ddd_movtex_area2_water[] |
s16 gMovetexLastTextureId |
Variable for a little optimization: only set the texture when it differs from the previous texture.
struct MovtexObject gMovtexColored[] |
MovtexObjects that have color attributes per vertex.
struct MovtexObject gMovtexColored2[] |
Treated identically to gMovtexColored.
s16 gMovtexCounter = 1 |
Counters to make textures move iff the game is not paused.
s16 gMovtexCounterPrev = 0 |
u8* gMovtexIdToTexture[] |
An array for converting a movtex texture id to a pointer that can be passed to gDPSetTextureImage.
struct MovtexObject gMovtexNonColored[] |
MovtexObjects that have no color attributes per vertex (though the mesh as a whole can have a blend color).
s8 gMovtexVtxColor = MOVTEX_VTX_COLOR_DEFAULT |
float gPaintingMarioYEntry = 0.0f |
The height at which Mario entered the last painting. Used for Wet-Dry World only.
Variable to ensure the initial Wet-Dry World water level is set only once.
u8 hmc_movtex_dorrie_pool_water[] |
u8 hmc_movtex_toxic_maze_mist[] |
u8 inside_castle_movtex_green_room_water[] |
u8 inside_castle_movtex_moat_water[] |
u8 jrb_movtex_intial_mist[] |
u8 jrb_movtex_sinked_boat_water[] |
u8 jrb_movtex_water[] |
Gfx lll_dl_lava_floor[] |
Gfx lll_dl_lavafall_volcano[] |
s16 lll_movtex_tris_lava_floor[] |
s16 lll_movtex_tris_lavafall_volcano[] |
u8 lll_movtex_volcano_floor_lava[] |
u8 sl_movtex_water[] |
Gfx ssl_dl_pyramid_corners_quicksand[] |
Gfx ssl_dl_pyramid_quicksand[] |
Gfx ssl_dl_pyramid_quicksand_pit_begin[] |
Gfx ssl_dl_pyramid_quicksand_pit_end[] |
Gfx ssl_dl_pyramid_sand_pathway_begin[] |
Gfx ssl_dl_pyramid_sand_pathway_end[] |
Gfx ssl_dl_pyramid_sand_pathway_floor_begin[] |
Gfx ssl_dl_pyramid_sand_pathway_floor_end[] |
Gfx ssl_dl_pyramid_sand_pathway_front_end[] |
Gfx ssl_dl_pyramid_sand_pathway_side_end[] |
Gfx ssl_dl_quicksand_begin[] |
Gfx ssl_dl_quicksand_end[] |
Gfx ssl_dl_quicksand_pit[] |
Gfx ssl_dl_quicksand_pit_begin[] |
Gfx ssl_dl_quicksand_pit_end[] |
Gfx ssl_dl_sides_quicksand[] |
u8 ssl_movtex_puddle_water[] |
u8 ssl_movtex_toxbox_quicksand_mist[] |
s16 ssl_movtex_tris_pyramid_corners_quicksand[] |
s16 ssl_movtex_tris_pyramid_quicksand[] |
s16 ssl_movtex_tris_pyramid_quicksand_pit[] |
s16 ssl_movtex_tris_pyramid_sand_pathway_floor[] |
s16 ssl_movtex_tris_pyramid_sand_pathway_front[] |
s16 ssl_movtex_tris_pyramid_sand_pathway_side[] |
s16 ssl_movtex_tris_quicksand_pit[] |
s16 ssl_movtex_tris_sides_quicksand[] |
u8 ssl_pyramid_sand[] |
u8 ssl_quicksand[] |
u8 thi_movtex_area1_water[] |
u8 thi_movtex_area2_water[] |
Gfx ttc_dl_surface_treadmill[] |
Gfx ttc_dl_surface_treadmill_begin[] |
Gfx ttc_dl_surface_treadmill_end[] |
s16 ttc_movtex_tris_big_surface_treadmill[] |
s16 ttc_movtex_tris_small_surface_treadmill[] |
u8 ttc_yellow_triangle[] |
Gfx ttm_dl_bottom_waterfall[] |
Gfx ttm_dl_puddle_waterfall[] |
Gfx ttm_dl_waterfall[] |
u8 ttm_movtex_puddle[] |
s16 ttm_movtex_tris_begin_puddle_waterfall[] |
s16 ttm_movtex_tris_begin_waterfall[] |
s16 ttm_movtex_tris_end_puddle_waterfall[] |
s16 ttm_movtex_tris_end_waterfall[] |
s16 ttm_movtex_tris_puddle_waterfall[] |
u8 wdw_movtex_area1_water[] |
u8 wdw_movtex_area2_water[] |
u8 wf_movtex_water[] |