HackerSM64 v2.0.0
* buffers: refresh 15 and revert to base decomp * behavior script * color helper functions * extended bounds * egeo_layout * fixed model ids * camera conf improved * message panel ucode small * graph node * level script * mathutil updates * mathutil updates (allow unused funcs) * behaviors a - beta_fish * Add librtc and fix some data declarations * Move GRUCODE define to proper location in makefile * Refresh 15 * extra * Make ROM name smaller and change messages printed on build a bit * Fix console (lol) * Update UNF to latest master * Make ucode load from .o's (and also fix Super3D) * Fix crash with rumble + custom mario model * graph node and mathutil * removed behaviors * Ldtob documentation * _Putfld labeling * area * behavior actions * camera * debug updates * bubbles * envfx snow * farcall helpers * game init * geo misc * hud * only check if VC on render init * ingame menu * revert goddard to base decomp * insn disasm * interaction documentation * level geo * level update defines * macro special objects formatting changes * main.h documentation * map parser documentation & formatting * airborne documentation * mario actions automatic documentation * mario actions cutscene documentation * mario actions moving documentation and options * mario actions object documentation and options * mario stationary documentation * mario submerged documentation * mario misc documentation * mario step: ledge grab fixes and documentation * mario documentation * memory.h documentation * moving textures * object behaviors * object collision * fix flamethrower bug * object helpers * object list processor documentation * paintings * platform displacement * print / printf * puppycam absf * puppyprint updates and formatting changes * rendering graph node performance optimizations * rumble opt and doc * hqvm back to ultrasm64 * save file documentation and unlock defines * s2d engine * reset various files to ultrasm64 * file select * intro geo documentation * screen transition documentation * segment2.h * shadow overhaul * skybox refactor * sound init: clean up define usage + documentation * spawn object optimizations and documentation * spawn sound cleanup * sram to ultrasm64 * star select cleanup * title screen cleanup * dialogs / text * rename stomp smoke * stomp smoke -> small water splash * updated README * compilation flags * optimized file positions + support function/data sections * surface collision performance improvements * surface load optimizations * camera conf documentation * Allow easier command for opening puppyprint debug * Rearranged framebuffers & fixed puppyprint console printing * Fix shadow scaling and shifting * Fix SILHOUETTE, OBJECTS_REJ, and ucode loading, also clean up render phase system a bit. * Fixed build with BETTER_HANGING off * Clean up OBJECTS_REJ ifdefs * Fix duplicate comment & graph render layers/flags bitmask * Fixed build with BETTER_HANGING off * Fix Fast64 importing by reverting sSegmentTable change * Readded missing functions that caused build errors with Mario head enabled * Fixed clang compilation issues * Add INTER mode for geo_update_layer_transparency * Fix build warnings * bugfix: miscalculation in obj_turn_toward_object * Some puppytech fixes * Further Puppycamera fixes * Fix BUGFIX_DIALOG_TIME_STOP Fixes #136 * Fix sliding platform bparams * Add LEGACY_SHADOW_IDS define for Fast64 compatibility * Apply suggested changes * Better find_in_bounds_yaw_wdw_bob_thi ifdef * Fix build warnings for unused functions * Fixed stale reference bug from obj_mark_for_deletion change * Fixed incorrect digit for 100s #145 * Change groundpound-fix define and functionality to just disable bonking * Fixed puppyroll #134 * Adjust height value for terrain angle to kick in * fixed hi score flashing * Remove menudata backup (#131) Not considered important enough to keep * Fix fread() build warning * Add COURSE_NUM_TO_INDEX to save_file_get_star_flags check in bhv_unagi_init * Fix approach_s16 return value * Use boolean defines for oCapDoScaleVertically * Make the door lock a part of the key door model to eliminate z-fighting, also reduce z fighting on numbered doors with AUTO_LOD enabled. * Move flames to LAYER_TRANSPARENT_INTER * Resolved some compiler warnings and added FALL_THROUGH define (#168) * Address some more compiler warnings with different define toggles * Remove unnecessary fallthrough attribute * fixed geo_process_billboard floating point exception * Allow water to face any direction * Initialize focOffset so that BBH doesn't crash * Removed superfluous RDP commands when switching microcodes which would override scissor * Set OBJ_FLAG_DONT_CALC_COLL_DIST on bhvUkikiCage * Fix rumble build * Fixed UNLOCK_FPS strobing * Update src/game/object_helpers.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update src/game/object_helpers.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Fix LEGACY_SHADOW_IDS id conflict * Use the vanilla default value for rotating fire bars if bparam2 is 0 * START_LEVEL safeguard * Fix some drawing distance issues caused by AUTO_COLLISION_DISTANCE * Fix rumble build * Fixed spline poll code using the wrong values for keyframes * Update readme with better credits Better credits for individual contributors * add arthur * added falco and moose * add fazana * le funny typo * added S2DEX engine to credits * silhouette + axo + ratio * remove specific callouts + add auto col distance * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Revert formatting changes to match vanilla decomp * Re-implement Y buffer for find_ceil * Re-implement POWER_STARS_HEAL for normal Power Stars * Start level comment & exit course comment/collapse * utilize reonucam technique for FAST_VERTICAL_CAMERA_MOVEMENT * Fix "MAX_REFERENCED_WALLS" typo * Allow stop_and_set_height_to_floor to work at any height if Mario is teleporting (#213) * Revert stop_and_set_height_to_floor to vanilla Fixes #208 * Fixed sAudioEnabled so that it disables audio CPU processing as well * Fixed puppyprint debug RDP us calculations * Renamed sAudioEnabled to gAudioEnabled * Replaced mtxf_to_mtx_asm with an equivalent implementation that supports WORLD_SCALE * Moved extended bounds and world scale configuration to a new config_world.h file * Default all objects to non-rej (#227) Fixes #221 (Default all objects to non-rej) * Fix #221 * Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled (#211) * Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled * Change vtl decrement in visual_surface_display from 6 to 3 Fixes #207 * Make area in SL igloo wider to prevent a softlock (#233) Fixes #210 * Fix coin formation coins being deleted if they spawn in the middle of a floor, also fix TTM slide coin position (#232) Fixes #201 * Make UNLOCK_ALL apply to more things * Fix wrong ifdef/ifndef in bhv_invisible_objects_under_bridge_init * Change chain chomp load/unload distances depending on number of segments (#237) Fixes #192 * added WATER_PLUNGE_UPWARP define * Add reonucam patch (#239) * added reonucam patch Fixes #218 * Fix how shadows handle water/transparency/height (#228) * Fix how shadows handle water/transparency/height * Change shadow check for flying carpets from a level specific check to a oPlatformOnTrackType check Fixes #179 * added reonucam credit * delete unnecesary patches * Apply suggested changes * murdered more patches * UNLOCK_ALL unlocks the cap boxes * UNLOCK_ALL unlocks cap boxes (slightly more epic edition) * revert ceil buffer * Renamed HD_INTRO_TEXTURES define, separated intro floombas * prevent double definition of floombas * actually prevent floomba redefinition * Develop/refactor default defines (#242) * Changed default config options * Added build dir to includePaths for pngs * disable NO_SLEEP by default * Disable puppyprint by default Sorry fazana 😔 * fix typos * add comment about BETTER_REVERB console perf * disable blue coin switch retry by default * Update config_audio.h Co-authored-by: Reonu <danileon95@gmail.com> Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com> * revert air step line to vanilla to fix bitfs scaling platform issue (#247) Fixes #200 * Fix stuttering on thin slopes (#248) * Fix stuttering on thin slopes * Revert vec3f_find_ceil calls to vanilla * Rename vec3f_find_ceil to find_mario_ceil * Update src/engine/surface_collision.h Fixes #249 * Swap static and dynamic surface checks back to vanilla order (#253) * Swap static and dynamic surface checks back to vanilla order * re-enable DISABLE_ALL config Fixes #251 #252 * Fixed save and quitting while in widescreen (#257) * Fixed save and quitting while in widescreen * use define for the level * all my homies hate ifdefs * skip wall offsets < 0 (#255) Fixes #255 * #264: Document non-stop stars' issues (#267) * #264: Document non-stop stars' issues * Update include/config/config_game.h * nonstop vanilla comment * derive margin_radius from radius after capping at 200 (#266) Fixes #259 * Config cleanup/refactor (#269) * Moved puppyprint define to graphics / rearranged some debug defines for ease of access * Moved compatibility safeguards to config_safeguards.h * spacing and comment formatting * #272 Move GFX_POOL_SIZE to config_graphics.h * disable EASIER_DIALOG_TRIGGER by default * prevent redefining warnings * small ifdef typo * changed ifndef to undefs Fixes #262 Fixes #272 * Improved movement config documentation related to turning around (#271) Fixes #270 * rename CUSTOM_DEBUG, add comments (#275) * Update README.md (#277) * v2.0.0 Co-authored-by: CrashOveride95 <crashoveride953@gmail.com> Co-authored-by: Arceveti <73617174+Arceveti@users.noreply.github.com> Co-authored-by: n64 <n64> Co-authored-by: Fazana <52551480+FazanaJ@users.noreply.github.com> Co-authored-by: Mr-Wiseguy <mrwiseguyromhacking@gmail.com> Co-authored-by: aglab2 <aglab3@gmail.com> Co-authored-by: gheskett <gheskett@gmail.com> Co-authored-by: Reonu <danileon95@gmail.com> Co-authored-by: Axollyon <20480418+Axollyon@users.noreply.github.com> Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com>
This commit is contained in:
924 files changed
+44258
-30676
No files matched your search
+106
-173
@@ -1,7 +1,5 @@
|
||||
#include <PR/ultratypes.h>
|
||||
|
||||
#include "prevent_bss_reordering.h"
|
||||
|
||||
#include "sm64.h"
|
||||
#include "game/ingame_menu.h"
|
||||
#include "graph_node.h"
|
||||
@@ -33,22 +31,26 @@ struct SurfaceNode *sSurfaceNodePool;
|
||||
struct Surface *sSurfacePool;
|
||||
|
||||
/**
|
||||
* The size of the surface pool (2300).
|
||||
* The size of the surface node pool (SURFACE_NODE_POOL_SIZE).
|
||||
*/
|
||||
s16 sSurfacePoolSize;
|
||||
s32 sSurfaceNodePoolSize = SURFACE_NODE_POOL_SIZE;
|
||||
|
||||
u8 gSurfacePoolError = 0;
|
||||
/**
|
||||
* The size of the surface pool (SURFACE_POOL_SIZE).
|
||||
*/
|
||||
s32 sSurfacePoolSize = SURFACE_POOL_SIZE;
|
||||
|
||||
u8 gSurfacePoolError = 0x0;
|
||||
|
||||
/**
|
||||
* Allocate the part of the surface node pool to contain a surface node.
|
||||
*/
|
||||
static struct SurfaceNode *alloc_surface_node(void) {
|
||||
struct SurfaceNode *node = &sSurfaceNodePool[gSurfaceNodesAllocated];
|
||||
gSurfaceNodesAllocated++;
|
||||
struct SurfaceNode *node = &sSurfaceNodePool[gSurfaceNodesAllocated++];
|
||||
|
||||
node->next = NULL;
|
||||
|
||||
if (gSurfaceNodesAllocated >= SURFACE_NODE_POOL_SIZE) {
|
||||
if (gSurfaceNodesAllocated >= sSurfaceNodePoolSize) {
|
||||
gSurfacePoolError |= NOT_ENOUGH_ROOM_FOR_NODES;
|
||||
}
|
||||
|
||||
@@ -61,16 +63,15 @@ static struct SurfaceNode *alloc_surface_node(void) {
|
||||
*/
|
||||
static struct Surface *alloc_surface(void) {
|
||||
|
||||
struct Surface *surface = &sSurfacePool[gSurfacesAllocated];
|
||||
gSurfacesAllocated++;
|
||||
struct Surface *surface = &sSurfacePool[gSurfacesAllocated++];
|
||||
|
||||
if (gSurfacesAllocated >= sSurfacePoolSize) {
|
||||
gSurfacePoolError |= NOT_ENOUGH_ROOM_FOR_SURFACES;
|
||||
}
|
||||
|
||||
surface->type = 0;
|
||||
surface->type = SURFACE_DEFAULT;
|
||||
surface->force = 0;
|
||||
surface->flags = 0;
|
||||
surface->flags = SURFACE_FLAGS_NONE;
|
||||
surface->room = 0;
|
||||
surface->object = NULL;
|
||||
|
||||
@@ -81,7 +82,7 @@ static struct Surface *alloc_surface(void) {
|
||||
* Iterates through the entire partition, clearing the surfaces.
|
||||
*/
|
||||
static void clear_spatial_partition(SpatialPartitionCell *cells) {
|
||||
register s32 i = NUM_CELLS * NUM_CELLS;
|
||||
register s32 i = sqr(NUM_CELLS);
|
||||
|
||||
while (i--) {
|
||||
(*cells)[SPATIAL_PARTITION_FLOORS].next = NULL;
|
||||
@@ -108,18 +109,16 @@ static void clear_static_surfaces(void) {
|
||||
* @param surface The surface to add
|
||||
*/
|
||||
static void add_surface_to_cell(s32 dynamic, s32 cellX, s32 cellZ, struct Surface *surface) {
|
||||
struct SurfaceNode *newNode = alloc_surface_node();
|
||||
struct SurfaceNode *list;
|
||||
s32 surfacePriority;
|
||||
s32 priority;
|
||||
s32 sortDir;
|
||||
s32 sortDir = 1; // highest to lowest, then insertion order (water and floors)
|
||||
s32 listIndex;
|
||||
s32 isWater = SURFACE_IS_NEW_WATER(surface->type);
|
||||
|
||||
if (surface->normal.y > 0.01) {
|
||||
listIndex = isWater ? SPATIAL_PARTITION_WATER : SPATIAL_PARTITION_FLOORS;
|
||||
sortDir = 1; // highest to lowest, then insertion order
|
||||
} else if (surface->normal.y < -0.01) {
|
||||
if (SURFACE_IS_NEW_WATER(surface->type)) {
|
||||
listIndex = SPATIAL_PARTITION_WATER;
|
||||
} else if (surface->normal.y > NORMAL_FLOOR_THRESHOLD) {
|
||||
listIndex = SPATIAL_PARTITION_FLOORS;
|
||||
} else if (surface->normal.y < NORMAL_CEIL_THRESHOLD) {
|
||||
listIndex = SPATIAL_PARTITION_CEILS;
|
||||
sortDir = -1; // lowest to highest, then insertion order
|
||||
} else {
|
||||
@@ -127,8 +126,9 @@ static void add_surface_to_cell(s32 dynamic, s32 cellX, s32 cellZ, struct Surfac
|
||||
sortDir = 0; // insertion order
|
||||
}
|
||||
|
||||
surfacePriority = surface->upperY * sortDir;
|
||||
s32 surfacePriority = surface->upperY * sortDir;
|
||||
|
||||
struct SurfaceNode *newNode = alloc_surface_node();
|
||||
newNode->surface = surface;
|
||||
|
||||
if (dynamic) {
|
||||
@@ -158,30 +158,24 @@ static void add_surface_to_cell(s32 dynamic, s32 cellX, s32 cellZ, struct Surfac
|
||||
* @param coord The coordinate to test
|
||||
*/
|
||||
static s32 lower_cell_index(s32 coord) {
|
||||
s32 index;
|
||||
|
||||
// Move from range [-0x2000, 0x2000) to [0, 0x4000)
|
||||
// Move from range [-LEVEL_BOUNDARY_MAX, LEVEL_BOUNDARY_MAX) to [0, 2 * LEVEL_BOUNDARY_MAX)
|
||||
coord += LEVEL_BOUNDARY_MAX;
|
||||
if (coord < 0) {
|
||||
coord = 0;
|
||||
}
|
||||
|
||||
// [0, 16)
|
||||
index = coord / CELL_SIZE;
|
||||
// [0, NUM_CELLS)
|
||||
s32 index = coord / CELL_SIZE;
|
||||
|
||||
// Include extra cell if close to boundary
|
||||
//! Some wall checks are larger than the buffer, meaning wall checks can
|
||||
// miss walls that are near a cell border.
|
||||
if (coord % CELL_SIZE < 50) {
|
||||
index -= 1;
|
||||
index--;
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
// Potentially > 15, but since the upper index is <= 15, not exploitable
|
||||
return index;
|
||||
// Potentially > NUM_CELLS - 1, but since the upper index is <= NUM_CELLS - 1, not exploitable
|
||||
return MAX(0, index);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,30 +184,24 @@ static s32 lower_cell_index(s32 coord) {
|
||||
* @param coord The coordinate to test
|
||||
*/
|
||||
static s32 upper_cell_index(s32 coord) {
|
||||
s32 index;
|
||||
|
||||
// Move from range [-0x2000, 0x2000) to [0, 0x4000)
|
||||
// Move from range [-LEVEL_BOUNDARY_MAX, LEVEL_BOUNDARY_MAX) to [0, 2 * LEVEL_BOUNDARY_MAX)
|
||||
coord += LEVEL_BOUNDARY_MAX;
|
||||
if (coord < 0) {
|
||||
coord = 0;
|
||||
}
|
||||
|
||||
// [0, 16)
|
||||
index = coord / CELL_SIZE;
|
||||
// [0, NUM_CELLS)
|
||||
s32 index = coord / CELL_SIZE;
|
||||
|
||||
// Include extra cell if close to boundary
|
||||
//! Some wall checks are larger than the buffer, meaning wall checks can
|
||||
// miss walls that are near a cell border.
|
||||
if (coord % CELL_SIZE > CELL_SIZE - 50) {
|
||||
index += 1;
|
||||
}
|
||||
|
||||
if (index > (NUM_CELLS - 1)) {
|
||||
index = (NUM_CELLS - 1);
|
||||
index++;
|
||||
}
|
||||
|
||||
// Potentially < 0, but since lower index is >= 0, not exploitable
|
||||
return index;
|
||||
return MIN((NUM_CELLS - 1), index);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,21 +212,16 @@ static s32 upper_cell_index(s32 coord) {
|
||||
* @param dynamic Boolean determining whether the surface is static or dynamic
|
||||
*/
|
||||
static void add_surface(struct Surface *surface, s32 dynamic) {
|
||||
s32 minX, minZ, maxX, maxZ;
|
||||
|
||||
s32 minCellX, minCellZ, maxCellX, maxCellZ;
|
||||
|
||||
s32 cellZ, cellX;
|
||||
s32 minX, maxX, minZ, maxZ;
|
||||
|
||||
minX = min_3i(surface->vertex1[0], surface->vertex2[0], surface->vertex3[0]);
|
||||
minZ = min_3i(surface->vertex1[2], surface->vertex2[2], surface->vertex3[2]);
|
||||
maxX = max_3i(surface->vertex1[0], surface->vertex2[0], surface->vertex3[0]);
|
||||
maxZ = max_3i(surface->vertex1[2], surface->vertex2[2], surface->vertex3[2]);
|
||||
min_max_3i(surface->vertex1[0], surface->vertex2[0], surface->vertex3[0], &minX, &maxX);
|
||||
min_max_3i(surface->vertex1[2], surface->vertex2[2], surface->vertex3[2], &minZ, &maxZ);
|
||||
|
||||
minCellX = lower_cell_index(minX);
|
||||
maxCellX = upper_cell_index(maxX);
|
||||
minCellZ = lower_cell_index(minZ);
|
||||
maxCellZ = upper_cell_index(maxZ);
|
||||
s32 minCellX = lower_cell_index(minX);
|
||||
s32 maxCellX = upper_cell_index(maxX);
|
||||
s32 minCellZ = lower_cell_index(minZ);
|
||||
s32 maxCellZ = upper_cell_index(maxZ);
|
||||
|
||||
for (cellZ = minCellZ; cellZ <= maxCellZ; cellZ++) {
|
||||
for (cellX = minCellX; cellX <= maxCellX; cellX++) {
|
||||
@@ -253,58 +236,36 @@ static void add_surface(struct Surface *surface, s32 dynamic) {
|
||||
* @param vertexIndices Helper which tells positions in vertexData to start reading vertices
|
||||
*/
|
||||
static struct Surface *read_surface_data(TerrainData *vertexData, TerrainData **vertexIndices) {
|
||||
struct Surface *surface;
|
||||
register s32 x1, y1, z1;
|
||||
register s32 x2, y2, z2;
|
||||
register s32 x3, y3, z3;
|
||||
Vec3t v[3];
|
||||
Vec3f n;
|
||||
s32 offset1, offset2, offset3;
|
||||
Vec3t offset;
|
||||
s16 min, max;
|
||||
|
||||
offset1 = (3 * (*vertexIndices)[0]);
|
||||
offset2 = (3 * (*vertexIndices)[1]);
|
||||
offset3 = (3 * (*vertexIndices)[2]);
|
||||
vec3_prod_val(offset, (*vertexIndices), 3);
|
||||
|
||||
x1 = *(vertexData + offset1 + 0);
|
||||
y1 = *(vertexData + offset1 + 1);
|
||||
z1 = *(vertexData + offset1 + 2);
|
||||
vec3s_copy(v[0], (vertexData + offset[0]));
|
||||
vec3s_copy(v[1], (vertexData + offset[1]));
|
||||
vec3s_copy(v[2], (vertexData + offset[2]));
|
||||
|
||||
x2 = *(vertexData + offset2 + 0);
|
||||
y2 = *(vertexData + offset2 + 1);
|
||||
z2 = *(vertexData + offset2 + 2);
|
||||
|
||||
x3 = *(vertexData + offset3 + 0);
|
||||
y3 = *(vertexData + offset3 + 1);
|
||||
z3 = *(vertexData + offset3 + 2);
|
||||
|
||||
// (v2 - v1) x (v3 - v2)
|
||||
n[0] = ((y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2));
|
||||
n[1] = ((z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2));
|
||||
n[2] = ((x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2));
|
||||
find_vector_perpendicular_to_plane(n, v[0], v[1], v[2]);
|
||||
|
||||
vec3f_normalize(n);
|
||||
|
||||
surface = alloc_surface();
|
||||
struct Surface *surface = alloc_surface();
|
||||
|
||||
surface->vertex1[0] = x1;
|
||||
surface->vertex2[0] = x2;
|
||||
surface->vertex3[0] = x3;
|
||||
|
||||
surface->vertex1[1] = y1;
|
||||
surface->vertex2[1] = y2;
|
||||
surface->vertex3[1] = y3;
|
||||
|
||||
surface->vertex1[2] = z1;
|
||||
surface->vertex2[2] = z2;
|
||||
surface->vertex3[2] = z3;
|
||||
vec3s_copy(surface->vertex1, v[0]);
|
||||
vec3s_copy(surface->vertex2, v[1]);
|
||||
vec3s_copy(surface->vertex3, v[2]);
|
||||
|
||||
surface->normal.x = n[0];
|
||||
surface->normal.y = n[1];
|
||||
surface->normal.z = n[2];
|
||||
|
||||
surface->originOffset = -(n[0] * x1 + n[1] * y1 + n[2] * z1);
|
||||
surface->originOffset = -vec3_dot(n, v[0]);
|
||||
|
||||
surface->lowerY = (min_3i(y1, y2, y3) - 5);
|
||||
surface->upperY = (max_3i(y1, y2, y3) + 5);
|
||||
min_max_3s(v[0][1], v[1][1], v[2][1], &min, &max);
|
||||
surface->lowerY = (min - SURFACE_VERTICAL_BUFFER);
|
||||
surface->upperY = (max + SURFACE_VERTICAL_BUFFER);
|
||||
|
||||
return surface;
|
||||
}
|
||||
@@ -340,7 +301,7 @@ static s32 surface_has_force(s32 surfaceType) {
|
||||
* SURFACE_FLAG_NO_CAM_COLLISION flag.
|
||||
*/
|
||||
static s32 surf_has_no_cam_collision(s32 surfaceType) {
|
||||
s32 flags = 0;
|
||||
s32 flags = SURFACE_FLAGS_NONE;
|
||||
|
||||
switch (surfaceType) {
|
||||
case SURFACE_NO_CAM_COLLISION:
|
||||
@@ -363,28 +324,25 @@ static s32 surf_has_no_cam_collision(s32 surfaceType) {
|
||||
*/
|
||||
static void load_static_surfaces(TerrainData **data, TerrainData *vertexData, s32 surfaceType, RoomData **surfaceRooms) {
|
||||
s32 i;
|
||||
s32 numSurfaces;
|
||||
struct Surface *surface;
|
||||
s32 room = 0;
|
||||
RoomData room = 0;
|
||||
#ifndef ALL_SURFACES_HAVE_FORCE
|
||||
s16 hasForce = surface_has_force(surfaceType);
|
||||
#endif
|
||||
s32 flags = surf_has_no_cam_collision(surfaceType);
|
||||
|
||||
numSurfaces = *(*data);
|
||||
*data += 1;
|
||||
s32 numSurfaces = *(*data)++;
|
||||
|
||||
for (i = 0; i < numSurfaces; i++) {
|
||||
if (*surfaceRooms != NULL) {
|
||||
room = *(*surfaceRooms);
|
||||
*surfaceRooms += 1;
|
||||
room = *(*surfaceRooms)++;
|
||||
}
|
||||
|
||||
surface = read_surface_data(vertexData, data);
|
||||
if (surface != NULL) {
|
||||
surface->room = room;
|
||||
surface->type = surfaceType;
|
||||
surface->flags = (s8) flags;
|
||||
surface->flags = flags;
|
||||
|
||||
#ifdef ALL_SURFACES_HAVE_FORCE
|
||||
surface->force = *(*data + 3);
|
||||
@@ -404,7 +362,7 @@ static void load_static_surfaces(TerrainData **data, TerrainData *vertexData, s3
|
||||
#else
|
||||
*data += 3;
|
||||
if (hasForce) {
|
||||
*data += 1;
|
||||
(*data)++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -414,13 +372,9 @@ static void load_static_surfaces(TerrainData **data, TerrainData *vertexData, s3
|
||||
* Read the data for vertices for reference by triangles.
|
||||
*/
|
||||
static TerrainData *read_vertex_data(TerrainData **data) {
|
||||
s32 numVertices;
|
||||
TerrainData *vertexData;
|
||||
s32 numVertices = *(*data)++;
|
||||
|
||||
numVertices = *(*data);
|
||||
(*data)++;
|
||||
|
||||
vertexData = *data;
|
||||
TerrainData *vertexData = *data;
|
||||
*data += 3 * numVertices;
|
||||
|
||||
return vertexData;
|
||||
@@ -445,11 +399,10 @@ static void load_environmental_regions(TerrainData **data) {
|
||||
* Allocate some of the main pool for surfaces (2300 surf) and for surface nodes (7000 nodes).
|
||||
*/
|
||||
void alloc_surface_pools(void) {
|
||||
sSurfacePoolSize = SURFACE_POOL_SIZE;
|
||||
sSurfaceNodePool = main_pool_alloc(SURFACE_NODE_POOL_SIZE * sizeof(struct SurfaceNode), MEMORY_POOL_LEFT);
|
||||
sSurfaceNodePool = main_pool_alloc(sSurfaceNodePoolSize * sizeof(struct SurfaceNode), MEMORY_POOL_LEFT);
|
||||
sSurfacePool = main_pool_alloc(sSurfacePoolSize * sizeof(struct Surface), MEMORY_POOL_LEFT);
|
||||
|
||||
gCCMEnteredSlide = 0;
|
||||
gCCMEnteredSlide = FALSE;
|
||||
reset_red_coins_collected();
|
||||
}
|
||||
|
||||
@@ -532,8 +485,7 @@ void load_area_terrain(s32 index, TerrainData *data, RoomData *surfaceRooms, s16
|
||||
// are prefixed by a terrain "type." This type is reused for surfaces as the surface
|
||||
// type.
|
||||
while (TRUE) {
|
||||
terrainLoadType = *data;
|
||||
data++;
|
||||
terrainLoadType = *data++;
|
||||
|
||||
if (TERRAIN_LOAD_IS_SURFACE_TYPE_LOW(terrainLoadType)) {
|
||||
load_static_surfaces(&data, vertexData, terrainLoadType, &surfaceRooms);
|
||||
@@ -588,56 +540,43 @@ void clear_dynamic_surfaces(void) {
|
||||
* Applies an object's transformation to the object's vertices.
|
||||
*/
|
||||
void transform_object_vertices(TerrainData **data, TerrainData *vertexData) {
|
||||
register TerrainData *vertices;
|
||||
register f32 vx, vy, vz;
|
||||
register s32 numVertices;
|
||||
Mat4 *objectTransform = &o->transform;
|
||||
|
||||
Mat4 *objectTransform;
|
||||
Mat4 m;
|
||||
register s32 numVertices = *(*data)++;
|
||||
|
||||
objectTransform = &gCurrentObject->transform;
|
||||
register TerrainData *vertices = *data;
|
||||
|
||||
numVertices = *(*data);
|
||||
(*data)++;
|
||||
|
||||
vertices = *data;
|
||||
|
||||
if (gCurrentObject->header.gfx.throwMatrix == NULL) {
|
||||
gCurrentObject->header.gfx.throwMatrix = objectTransform;
|
||||
obj_build_transform_from_pos_and_angle(gCurrentObject, O_POS_INDEX, O_FACE_ANGLE_INDEX);
|
||||
if (o->header.gfx.throwMatrix == NULL) {
|
||||
o->header.gfx.throwMatrix = objectTransform;
|
||||
obj_build_transform_from_pos_and_angle(o, O_POS_INDEX, O_FACE_ANGLE_INDEX);
|
||||
}
|
||||
|
||||
obj_apply_scale_to_matrix(gCurrentObject, m, *objectTransform);
|
||||
Mat4 transform;
|
||||
mtxf_scale_vec3f(transform, *objectTransform, o->header.gfx.scale);
|
||||
|
||||
// Go through all vertices, rotating and translating them to transform the object.
|
||||
Vec3f pos;
|
||||
while (numVertices--) {
|
||||
vx = *(vertices++);
|
||||
vy = *(vertices++);
|
||||
vz = *(vertices++);
|
||||
vec3s_to_vec3f(pos, vertices);
|
||||
vertices += 3;
|
||||
|
||||
//! No bounds check on vertex data
|
||||
*vertexData++ = (TerrainData)(vx * m[0][0] + vy * m[1][0] + vz * m[2][0] + m[3][0]);
|
||||
*vertexData++ = (TerrainData)(vx * m[0][1] + vy * m[1][1] + vz * m[2][1] + m[3][1]);
|
||||
*vertexData++ = (TerrainData)(vx * m[0][2] + vy * m[1][2] + vz * m[2][2] + m[3][2]);
|
||||
linear_mtxf_mul_vec3_and_translate(transform, vertexData, pos);
|
||||
|
||||
vertexData += 3;
|
||||
}
|
||||
|
||||
*data = vertices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load in the surfaces for the gCurrentObject. This includes setting the flags, exertion, and room.
|
||||
* Load in the surfaces for the o. This includes setting the flags, exertion, and room.
|
||||
*/
|
||||
void load_object_surfaces(TerrainData **data, TerrainData *vertexData) {
|
||||
s32 surfaceType;
|
||||
s32 i;
|
||||
s32 numSurfaces;
|
||||
s32 room;
|
||||
|
||||
surfaceType = *(*data);
|
||||
(*data)++;
|
||||
|
||||
numSurfaces = *(*data);
|
||||
(*data)++;
|
||||
s32 surfaceType = *(*data)++;
|
||||
s32 numSurfaces = *(*data)++;
|
||||
|
||||
#ifndef ALL_SURFACES_HAVE_FORCE
|
||||
TerrainData hasForce = surface_has_force(surfaceType);
|
||||
@@ -647,17 +586,13 @@ void load_object_surfaces(TerrainData **data, TerrainData *vertexData) {
|
||||
|
||||
// The DDD warp is initially loaded at the origin and moved to the proper
|
||||
// position in paintings.c and doesn't update its room, so set it here.
|
||||
if (gCurrentObject->behavior == segmented_to_virtual(bhvDddWarp)) {
|
||||
room = 5;
|
||||
} else {
|
||||
room = 0;
|
||||
}
|
||||
RoomData room = (o->behavior == segmented_to_virtual(bhvDddWarp)) ? 5 : 0;
|
||||
|
||||
for (i = 0; i < numSurfaces; i++) {
|
||||
struct Surface *surface = read_surface_data(vertexData, data);
|
||||
|
||||
if (surface != NULL) {
|
||||
surface->object = gCurrentObject;
|
||||
surface->object = o;
|
||||
surface->type = surfaceType;
|
||||
|
||||
#ifdef ALL_SURFACES_HAVE_FORCE
|
||||
@@ -671,7 +606,7 @@ void load_object_surfaces(TerrainData **data, TerrainData *vertexData) {
|
||||
#endif
|
||||
|
||||
surface->flags |= flags;
|
||||
surface->room = (s8) room;
|
||||
surface->room = room;
|
||||
add_surface(surface, TRUE);
|
||||
}
|
||||
|
||||
@@ -688,21 +623,16 @@ void load_object_surfaces(TerrainData **data, TerrainData *vertexData) {
|
||||
}
|
||||
|
||||
#ifdef AUTO_COLLISION_DISTANCE
|
||||
// From Kaze
|
||||
static void get_optimal_coll_dist(struct Object *obj) {
|
||||
register f32 thisVertDist, maxDist = 0.0f;
|
||||
Vec3f v;
|
||||
TerrainData *collisionData = gCurrentObject->collisionData;
|
||||
TerrainData *collisionData = o->collisionData;
|
||||
obj->oFlags |= OBJ_FLAG_DONT_CALC_COLL_DIST;
|
||||
collisionData++;
|
||||
register u32 vertsLeft = *(collisionData);
|
||||
collisionData++;
|
||||
// vertices = *data;
|
||||
register u32 vertsLeft = *(collisionData)++;
|
||||
while (vertsLeft) {
|
||||
v[0] = *(collisionData + 0) * obj->header.gfx.scale[0];
|
||||
v[1] = *(collisionData + 1) * obj->header.gfx.scale[1];
|
||||
v[2] = *(collisionData + 2) * obj->header.gfx.scale[2];
|
||||
thisVertDist = (sqr(v[0]) + sqr(v[1]) + sqr(v[2]));
|
||||
vec3_prod(v, collisionData, obj->header.gfx.scale);
|
||||
thisVertDist = vec3_sumsq(v);
|
||||
if (thisVertDist > maxDist) maxDist = thisVertDist;
|
||||
collisionData += 3;
|
||||
vertsLeft--;
|
||||
@@ -720,30 +650,33 @@ void load_object_collision_model(void) {
|
||||
OSTime first = osGetTime();
|
||||
#endif
|
||||
|
||||
TerrainData *collisionData = gCurrentObject->collisionData;
|
||||
f32 marioDist = gCurrentObject->oDistanceToMario;
|
||||
TerrainData *collisionData = o->collisionData;
|
||||
f32 marioDist = o->oDistanceToMario;
|
||||
|
||||
// On an object's first frame, the distance is set to 19000.0f.
|
||||
// If the distance hasn't been updated, update it now.
|
||||
if (gCurrentObject->oDistanceToMario == 19000.0f) {
|
||||
marioDist = dist_between_objects(gCurrentObject, gMarioObject);
|
||||
if (o->oDistanceToMario == 19000.0f) {
|
||||
marioDist = dist_between_objects(o, gMarioObject);
|
||||
}
|
||||
|
||||
#ifdef AUTO_COLLISION_DISTANCE
|
||||
if (!(gCurrentObject->oFlags & OBJ_FLAG_DONT_CALC_COLL_DIST)) {
|
||||
get_optimal_coll_dist(gCurrentObject);
|
||||
if (!(o->oFlags & OBJ_FLAG_DONT_CALC_COLL_DIST)) {
|
||||
get_optimal_coll_dist(o);
|
||||
}
|
||||
#endif
|
||||
|
||||
// If the object collision is supposed to be loaded more than the
|
||||
// drawing distance, extend the drawing range.
|
||||
if (gCurrentObject->oCollisionDistance > gCurrentObject->oDrawingDistance) {
|
||||
gCurrentObject->oDrawingDistance = gCurrentObject->oCollisionDistance;
|
||||
if (o->oCollisionDistance > o->oDrawingDistance) {
|
||||
o->oDrawingDistance = o->oCollisionDistance;
|
||||
}
|
||||
|
||||
// Update if no Time Stop, in range, and in the current room.
|
||||
if (!(gTimeStopState & TIME_STOP_ACTIVE) && (marioDist < gCurrentObject->oCollisionDistance)
|
||||
&& !(gCurrentObject->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) {
|
||||
if (
|
||||
!(gTimeStopState & TIME_STOP_ACTIVE)
|
||||
&& (marioDist < o->oCollisionDistance)
|
||||
&& !(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)
|
||||
) {
|
||||
collisionData++;
|
||||
transform_object_vertices(&collisionData, vertexData);
|
||||
|
||||
@@ -752,8 +685,8 @@ void load_object_collision_model(void) {
|
||||
load_object_surfaces(&collisionData, vertexData);
|
||||
}
|
||||
}
|
||||
COND_BIT((marioDist < gCurrentObject->oDrawingDistance), gCurrentObject->header.gfx.node.flags, GRAPH_RENDER_ACTIVE);
|
||||
COND_BIT((marioDist < o->oDrawingDistance), o->header.gfx.node.flags, GRAPH_RENDER_ACTIVE);
|
||||
#if PUPPYPRINT_DEBUG
|
||||
collisionTime[perfIteration] += osGetTime()-first;
|
||||
collisionTime[perfIteration] += osGetTime() - first;
|
||||
#endif
|
||||
}
|
||||
Reference in new issue
Block a user