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
+303
-221
@@ -15,7 +15,7 @@
|
||||
**************************************************/
|
||||
|
||||
#define CALC_OFFSET(vert, next_step) { \
|
||||
if ((vert)[1] != 0.0f) { \
|
||||
if (FLT_IS_NONZERO((vert)[1])) { \
|
||||
v = (v2[1] / (vert)[1]); \
|
||||
if ((v < 0.0f) || (v > 1.0f)) next_step;\
|
||||
d00 = (((vert)[0] * v) - v2[0]); \
|
||||
@@ -37,105 +37,133 @@ static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode, struc
|
||||
register struct Surface *surf;
|
||||
register f32 offset;
|
||||
register f32 radius = data->radius;
|
||||
register Vec3f pos = { data->x, data->y + data->offsetY, data->z };
|
||||
register Vec3f v0, v1, v2;
|
||||
|
||||
Vec3f pos = { data->x, data->y + data->offsetY, data->z };
|
||||
Vec3f v0, v1, v2;
|
||||
register f32 d00, d01, d11, d20, d21;
|
||||
register f32 invDenom;
|
||||
register f32 v, w;
|
||||
register f32 margin_radius = (radius - 1.0f);
|
||||
register TerrainData type = SURFACE_DEFAULT;
|
||||
s32 numCols = 0;
|
||||
|
||||
// Max collision radius = 200
|
||||
if (radius > 200.0f) {
|
||||
radius = 200.0f;
|
||||
if (radius > 200) {
|
||||
radius = 200;
|
||||
}
|
||||
|
||||
f32 margin_radius = radius - 1.0f;
|
||||
|
||||
// Stay in this loop until out of walls.
|
||||
while (surfaceNode != NULL) {
|
||||
surf = surfaceNode->surface;
|
||||
surfaceNode = surfaceNode->next;
|
||||
type = surf->type;
|
||||
|
||||
// Exclude a large number of walls immediately to optimize.
|
||||
if (SURFACE_IS_NEW_WATER(type)) continue;
|
||||
if (pos[1] < surf->lowerY || pos[1] > surf->upperY) continue;
|
||||
|
||||
// Determine if checking for the camera or not.
|
||||
if (gCheckingSurfaceCollisionsForCamera) {
|
||||
if (gCollisionFlags & COLLISION_FLAG_CAMERA) {
|
||||
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) continue;
|
||||
} else {
|
||||
// Ignore camera only surfaces.
|
||||
if (type == SURFACE_CAMERA_BOUNDARY) continue;
|
||||
|
||||
// If an object can pass through a vanish cap wall, pass through.
|
||||
if (type == SURFACE_VANISH_CAP_WALLS && gCurrentObject != NULL) {
|
||||
if (type == SURFACE_VANISH_CAP_WALLS && o != NULL) {
|
||||
// If an object can pass through a vanish cap wall, pass through.
|
||||
if (gCurrentObject->activeFlags & ACTIVE_FLAG_MOVE_THROUGH_GRATE) continue;
|
||||
if (o->activeFlags & ACTIVE_FLAG_MOVE_THROUGH_GRATE) continue;
|
||||
// If Mario has a vanish cap, pass through the vanish cap wall.
|
||||
if (gCurrentObject == gMarioObject && (gMarioState->flags & MARIO_VANISH_CAP)) continue;
|
||||
if (o == gMarioObject && gMarioState->flags & MARIO_VANISH_CAP) continue;
|
||||
}
|
||||
}
|
||||
if (pos[1] < surf->lowerY || pos[1] > surf->upperY) continue;
|
||||
|
||||
// Dot of normal and pos, + origin offset
|
||||
offset = (surf->normal.x * pos[0]) + (surf->normal.y * pos[1]) + (surf->normal.z * pos[2]) + surf->originOffset;
|
||||
|
||||
// Exclude surfaces outside of the radius.
|
||||
if (offset < -radius || offset > radius) continue;
|
||||
|
||||
vec3_diff(v0, surf->vertex2, surf->vertex1);
|
||||
vec3_diff(v1, surf->vertex3, surf->vertex1);
|
||||
vec3_diff(v2, pos, surf->vertex1);
|
||||
|
||||
// Face
|
||||
d00 = vec3_dot(v0, v0);
|
||||
d01 = vec3_dot(v0, v1);
|
||||
d11 = vec3_dot(v1, v1);
|
||||
d20 = vec3_dot(v2, v0);
|
||||
d21 = vec3_dot(v2, v1);
|
||||
invDenom = 1.0f / ((d00 * d11) - (d01 * d01));
|
||||
|
||||
invDenom = (d00 * d11) - (d01 * d01);
|
||||
if (FLT_IS_NONZERO(invDenom)) invDenom = 1.0f / invDenom;
|
||||
|
||||
v = ((d11 * d20) - (d01 * d21)) * invDenom;
|
||||
if (v < 0.0f || v > 1.0f) goto edge_1_2;
|
||||
|
||||
w = ((d00 * d21) - (d01 * d20)) * invDenom;
|
||||
if (w < 0.0f || w > 1.0f || v + w > 1.0f) goto edge_1_2;
|
||||
|
||||
pos[0] += surf->normal.x * (radius - offset);
|
||||
pos[2] += surf->normal.z * (radius - offset);
|
||||
goto hasCollision;
|
||||
|
||||
edge_1_2:
|
||||
if (offset < 0) continue;
|
||||
CALC_OFFSET(v0, goto edge_1_3);
|
||||
|
||||
edge_1_3:
|
||||
CALC_OFFSET(v1, goto edge_2_3);
|
||||
|
||||
edge_2_3:
|
||||
vec3_diff(v1, surf->vertex3, surf->vertex2);
|
||||
vec3_diff(v2, pos, surf->vertex2);
|
||||
CALC_OFFSET(v1, continue);
|
||||
|
||||
check_collision:
|
||||
invDenom = offset / invDenom;
|
||||
if (FLT_IS_NONZERO(invDenom)) invDenom = (offset / invDenom);
|
||||
pos[0] += (d00 *= invDenom);
|
||||
pos[2] += (d01 *= invDenom);
|
||||
margin_radius += 0.01f;
|
||||
if ((d00 * surf->normal.x) + (d01 * surf->normal.z) < (corner_threshold * offset)) continue;
|
||||
|
||||
hasCollision:
|
||||
// (Unreferenced Walls) Since this only returns the first MAX_REFEREMCED_WALLS walls,
|
||||
// this can lead to wall interaction being missed. Typically unreferenced walls
|
||||
// come from only using one wall, however.
|
||||
if (data->numWalls < MAX_REFEREMCED_WALLS) {
|
||||
if (data->numWalls < MAX_REFERENCED_WALLS) {
|
||||
data->walls[data->numWalls++] = surf;
|
||||
}
|
||||
numCols++;
|
||||
|
||||
if (gCollisionFlags & COLLISION_FLAG_RETURN_FIRST) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
data->x = pos[0];
|
||||
data->z = pos[2];
|
||||
return numCols;
|
||||
}
|
||||
#undef CALC_OFFSET
|
||||
|
||||
/**
|
||||
* Formats the position and wall search for find_wall_collisions.
|
||||
*/
|
||||
s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 radius) {
|
||||
struct WallCollisionData collision;
|
||||
s32 numCollisions = 0;
|
||||
collision.offsetY = offsetY;
|
||||
collision.radius = radius;
|
||||
collision.x = *xPtr;
|
||||
collision.y = *yPtr;
|
||||
collision.z = *zPtr;
|
||||
|
||||
collision.offsetY = offsetY;
|
||||
collision.radius = radius;
|
||||
|
||||
collision.x = *xPtr;
|
||||
collision.y = *yPtr;
|
||||
collision.z = *zPtr;
|
||||
|
||||
collision.numWalls = 0;
|
||||
numCollisions = find_wall_collisions(&collision);
|
||||
*xPtr = collision.x;
|
||||
*yPtr = collision.y;
|
||||
*zPtr = collision.z;
|
||||
|
||||
s32 numCollisions = find_wall_collisions(&collision);
|
||||
|
||||
*xPtr = collision.x;
|
||||
*yPtr = collision.y;
|
||||
*zPtr = collision.z;
|
||||
|
||||
return numCollisions;
|
||||
}
|
||||
|
||||
@@ -144,7 +172,6 @@ s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 ra
|
||||
*/
|
||||
s32 find_wall_collisions(struct WallCollisionData *colData) {
|
||||
struct SurfaceNode *node;
|
||||
s32 cellX, cellZ;
|
||||
s32 numCollisions = 0;
|
||||
s32 x = colData->x;
|
||||
s32 z = colData->z;
|
||||
@@ -155,24 +182,31 @@ s32 find_wall_collisions(struct WallCollisionData *colData) {
|
||||
colData->numWalls = 0;
|
||||
|
||||
if (is_outside_level_bounds(x, z)) {
|
||||
#if PUPPYPRINT_DEBUG
|
||||
collisionTime[perfIteration] += osGetTime() - first;
|
||||
#endif
|
||||
return numCollisions;
|
||||
}
|
||||
|
||||
// World (level) consists of a 16x16 grid. Find where the collision is on the grid (round toward -inf)
|
||||
cellX = GET_CELL_COORD(x);
|
||||
cellZ = GET_CELL_COORD(z);
|
||||
s32 cellX = GET_CELL_COORD(x);
|
||||
s32 cellZ = GET_CELL_COORD(z);
|
||||
|
||||
// Check for surfaces belonging to objects.
|
||||
node = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WALLS].next;
|
||||
numCollisions += find_wall_collisions_from_list(node, colData);
|
||||
if (!(gCollisionFlags & COLLISION_FLAG_EXCLUDE_DYNAMIC)) {
|
||||
// Check for surfaces belonging to objects.
|
||||
node = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WALLS].next;
|
||||
numCollisions += find_wall_collisions_from_list(node, colData);
|
||||
}
|
||||
|
||||
// Check for surfaces that are a part of level geometry.
|
||||
node = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WALLS].next;
|
||||
numCollisions += find_wall_collisions_from_list(node, colData);
|
||||
|
||||
gCollisionFlags &= ~(COLLISION_FLAG_RETURN_FIRST | COLLISION_FLAG_EXCLUDE_DYNAMIC | COLLISION_FLAG_INCLUDE_INTANGIBLE);
|
||||
#ifdef VANILLA_DEBUG
|
||||
// Increment the debug tracker.
|
||||
gNumCalls.wall++;
|
||||
|
||||
#endif
|
||||
#if PUPPYPRINT_DEBUG
|
||||
collisionTime[perfIteration] += osGetTime() - first;
|
||||
#endif
|
||||
@@ -202,61 +236,86 @@ void resolve_and_return_wall_collisions(Vec3f pos, f32 offset, f32 radius, struc
|
||||
**************************************************/
|
||||
|
||||
void add_ceil_margin(s32 *x, s32 *z, Vec3s target1, Vec3s target2, f32 margin) {
|
||||
register f32 diff_x, diff_z, invDenom;
|
||||
diff_x = target1[0] - *x + target2[0] - *x;
|
||||
diff_z = target1[2] - *z + target2[2] - *z;
|
||||
invDenom = margin / sqrtf(sqr(diff_x) + sqr(diff_z));
|
||||
register f32 diff_x = target1[0] - *x + target2[0] - *x;
|
||||
register f32 diff_z = target1[2] - *z + target2[2] - *z;
|
||||
register f32 invDenom = margin / sqrtf(sqr(diff_x) + sqr(diff_z));
|
||||
|
||||
*x += diff_x * invDenom;
|
||||
*z += diff_z * invDenom;
|
||||
}
|
||||
|
||||
static s32 check_within_ceil_triangle_bounds(s32 x, s32 z, struct Surface *surf, f32 margin) {
|
||||
s32 addMargin = surf->type != SURFACE_HANGABLE && !FLT_IS_NONZERO(margin);
|
||||
Vec3i vx, vz;
|
||||
vx[0] = surf->vertex1[0];
|
||||
vz[0] = surf->vertex1[2];
|
||||
if (addMargin) add_ceil_margin(&vx[0], &vz[0], surf->vertex2, surf->vertex3, margin);
|
||||
|
||||
vx[1] = surf->vertex2[0];
|
||||
vz[1] = surf->vertex2[2];
|
||||
if (addMargin) add_ceil_margin(&vx[1], &vz[1], surf->vertex3, surf->vertex1, margin);
|
||||
|
||||
// Checking if point is in bounds of the triangle laterally.
|
||||
if (((vz[0] - z) * (vx[1] - vx[0]) - (vx[0] - x) * (vz[1] - vz[0])) > 0) return FALSE;
|
||||
|
||||
// Slight optimization by checking these later.
|
||||
vx[2] = surf->vertex3[0];
|
||||
vz[2] = surf->vertex3[2];
|
||||
if (addMargin) add_ceil_margin(&vx[2], &vz[2], surf->vertex1, surf->vertex2, margin);
|
||||
|
||||
if (((vz[1] - z) * (vx[2] - vx[1]) - (vx[1] - x) * (vz[2] - vz[1])) > 0) return FALSE;
|
||||
if (((vz[2] - z) * (vx[0] - vx[2]) - (vx[2] - x) * (vz[0] - vz[2])) > 0) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate through the list of ceilings and find the first ceiling over a given point.
|
||||
*/
|
||||
static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32 x, s32 y, s32 z, f32 *pheight) {
|
||||
const f32 margin = 1.5f;
|
||||
register struct Surface *surf, *ceil = NULL;
|
||||
Vec3i vx, vz;
|
||||
f32 height;
|
||||
s16 type;
|
||||
register f32 height;
|
||||
SurfaceType type = SURFACE_DEFAULT;
|
||||
*pheight = CELL_HEIGHT_LIMIT;
|
||||
// Stay in this loop until out of ceilings.
|
||||
while (surfaceNode != NULL) {
|
||||
surf = surfaceNode->surface;
|
||||
surfaceNode = surfaceNode->next;
|
||||
type = surf->type;
|
||||
// Determine if checking for the camera or not.
|
||||
if (SURFACE_IS_NEW_WATER(type)) continue;
|
||||
if (gCheckingSurfaceCollisionsForCamera) {
|
||||
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) continue;
|
||||
|
||||
// Exclude all ceilings below the point
|
||||
if (y > surf->upperY) continue;
|
||||
|
||||
// Determine if checking for the camera or not
|
||||
if (gCollisionFlags & COLLISION_FLAG_CAMERA) {
|
||||
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) {
|
||||
continue;
|
||||
}
|
||||
} else if (type == SURFACE_CAMERA_BOUNDARY) {
|
||||
// Ignore camera only surfaces.
|
||||
// Ignore camera only surfaces
|
||||
continue;
|
||||
}
|
||||
if (y > surf->upperY) continue;
|
||||
vx[0] = surf->vertex1[0];
|
||||
vz[0] = surf->vertex1[2];
|
||||
if (surf->type != SURFACE_HANGABLE) add_ceil_margin(&vx[0], &vz[0], surf->vertex2, surf->vertex3, margin);
|
||||
vx[1] = surf->vertex2[0];
|
||||
vz[1] = surf->vertex2[2];
|
||||
if (surf->type != SURFACE_HANGABLE) add_ceil_margin(&vx[1], &vz[1], surf->vertex3, surf->vertex1, margin);
|
||||
// Checking if point is in bounds of the triangle laterally.
|
||||
if ((vz[0] - z) * (vx[1] - vx[0]) - (vx[0] - x) * (vz[1] - vz[0]) > 0) continue;
|
||||
// Slight optimization by checking these later.
|
||||
vx[2] = surf->vertex3[0];
|
||||
vz[2] = surf->vertex3[2];
|
||||
if (surf->type != SURFACE_HANGABLE) add_ceil_margin(&vx[2], &vz[2], surf->vertex1, surf->vertex2, margin);
|
||||
if ((vz[1] - z) * (vx[2] - vx[1]) - (vx[1] - x) * (vz[2] - vz[1]) > 0) continue;
|
||||
if ((vz[2] - z) * (vx[0] - vx[2]) - (vx[2] - x) * (vz[0] - vz[2]) > 0) continue;
|
||||
// Find the ceil height at the specific point.
|
||||
|
||||
// Check that the point is within the triangle bounds
|
||||
if (!check_within_ceil_triangle_bounds(x, z, surf, 1.5f)) continue;
|
||||
|
||||
// Find the height of the ceil at the given location
|
||||
height = get_surface_height_at_location(x, z, surf);
|
||||
|
||||
// Exclude ceilings above the previous lowest ceiling
|
||||
if (height > *pheight) continue;
|
||||
|
||||
// Checks for ceiling interaction
|
||||
if (y > height) continue;
|
||||
if (y >= surf->upperY) continue;
|
||||
|
||||
|
||||
// Use the current ceiling
|
||||
*pheight = height;
|
||||
ceil = surf;
|
||||
if (height == y) break;
|
||||
|
||||
// Exit the loop if it's not possible for another ceiling to be closer
|
||||
// to the original point, or if COLLISION_FLAG_RETURN_FIRST.
|
||||
if (height == y || (gCollisionFlags & COLLISION_FLAG_RETURN_FIRST)) break;
|
||||
}
|
||||
return ceil;
|
||||
}
|
||||
@@ -265,46 +324,61 @@ static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32
|
||||
* Find the lowest ceiling above a given position and return the height.
|
||||
*/
|
||||
f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil) {
|
||||
s32 cellZ, cellX;
|
||||
struct Surface *ceil, *dynamicCeil;
|
||||
struct SurfaceNode *surfaceList;
|
||||
f32 height = CELL_HEIGHT_LIMIT;
|
||||
f32 height = CELL_HEIGHT_LIMIT;
|
||||
f32 dynamicHeight = CELL_HEIGHT_LIMIT;
|
||||
s32 x, y, z;
|
||||
#if PUPPYPRINT_DEBUG
|
||||
OSTime first = osGetTime();
|
||||
#endif
|
||||
x = posX;
|
||||
y = posY;
|
||||
z = posZ;
|
||||
s32 x = posX;
|
||||
s32 y = posY;
|
||||
s32 z = posZ;
|
||||
*pceil = NULL;
|
||||
|
||||
if (is_outside_level_bounds(x, z)) {
|
||||
#if PUPPYPRINT_DEBUG
|
||||
collisionTime[perfIteration] += (osGetTime() - first);
|
||||
#endif
|
||||
return height;
|
||||
}
|
||||
|
||||
// Each level is split into cells to limit load, find the appropriate cell.
|
||||
cellX = GET_CELL_COORD(x);
|
||||
cellZ = GET_CELL_COORD(z);
|
||||
s32 cellX = GET_CELL_COORD(x);
|
||||
s32 cellZ = GET_CELL_COORD(z);
|
||||
|
||||
// Check for surfaces belonging to objects.
|
||||
surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_CEILS].next;
|
||||
dynamicCeil = find_ceil_from_list(surfaceList, x, y, z, &dynamicHeight);
|
||||
struct SurfaceNode *surfaceList;
|
||||
struct Surface *ceil = NULL;
|
||||
struct Surface *dynamicCeil = NULL;
|
||||
|
||||
s32 includeDynamic = !(gCollisionFlags & COLLISION_FLAG_EXCLUDE_DYNAMIC);
|
||||
|
||||
if (includeDynamic) {
|
||||
// Check for surfaces belonging to objects.
|
||||
surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_CEILS].next;
|
||||
dynamicCeil = find_ceil_from_list(surfaceList, x, y, z, &dynamicHeight);
|
||||
|
||||
// In the next check, only check for ceilings lower than the previous check.
|
||||
height = dynamicHeight;
|
||||
}
|
||||
|
||||
// Check for surfaces that are a part of level geometry.
|
||||
surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_CEILS].next;
|
||||
ceil = find_ceil_from_list(surfaceList, x, y, z, &height);
|
||||
|
||||
if (dynamicHeight < height) {
|
||||
ceil = dynamicCeil;
|
||||
// Use the lower ceiling.
|
||||
if (includeDynamic && height >= dynamicHeight) {
|
||||
ceil = dynamicCeil;
|
||||
height = dynamicHeight;
|
||||
}
|
||||
|
||||
*pceil = ceil;
|
||||
// To prevent accidentally leaving the floor tangible, stop checking for it.
|
||||
gCollisionFlags &= ~(COLLISION_FLAG_RETURN_FIRST | COLLISION_FLAG_EXCLUDE_DYNAMIC | COLLISION_FLAG_INCLUDE_INTANGIBLE);
|
||||
|
||||
// Return the ceiling.
|
||||
*pceil = ceil;
|
||||
#ifdef VANILLA_DEBUG
|
||||
// Increment the debug tracker.
|
||||
gNumCalls.ceil++;
|
||||
|
||||
#endif
|
||||
#if PUPPYPRINT_DEBUG
|
||||
collisionTime[perfIteration] += osGetTime() - first;
|
||||
#endif
|
||||
@@ -316,12 +390,21 @@ f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil) {
|
||||
* FLOORS *
|
||||
**************************************************/
|
||||
|
||||
/**
|
||||
* Find the height of the highest floor below an object.
|
||||
*/
|
||||
f32 unused_obj_find_floor_height(struct Object *obj) {
|
||||
struct Surface *floor;
|
||||
return find_floor(obj->oPosX, obj->oPosY, obj->oPosZ, &floor);
|
||||
static s32 check_within_floor_triangle_bounds(s32 x, s32 z, struct Surface *surf) {
|
||||
Vec3i vx, vz;
|
||||
vx[0] = surf->vertex1[0];
|
||||
vz[0] = surf->vertex1[2];
|
||||
vx[1] = surf->vertex2[0];
|
||||
vz[1] = surf->vertex2[2];
|
||||
|
||||
if (((vz[0] - z) * (vx[1] - vx[0]) - (vx[0] - x) * (vz[1] - vz[0])) < 0) return FALSE;
|
||||
|
||||
vx[2] = surf->vertex3[0];
|
||||
vz[2] = surf->vertex3[2];
|
||||
|
||||
if (((vz[1] - z) * (vx[2] - vx[1]) - (vx[1] - x) * (vz[2] - vz[1])) < 0) return FALSE;
|
||||
if (((vz[2] - z) * (vx[0] - vx[2]) - (vx[2] - x) * (vz[0] - vz[2])) < 0) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,62 +412,61 @@ f32 unused_obj_find_floor_height(struct Object *obj) {
|
||||
*/
|
||||
static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 x, s32 y, s32 z, f32 *pheight) {
|
||||
register struct Surface *surf, *floor = NULL;
|
||||
register Vec3i vx, vz;
|
||||
f32 height;
|
||||
s16 type = SURFACE_DEFAULT;
|
||||
*pheight = FLOOR_LOWER_LIMIT;
|
||||
register SurfaceType type = SURFACE_DEFAULT;
|
||||
register f32 height;
|
||||
register s32 bufferY = y + FIND_FLOOR_BUFFER;
|
||||
|
||||
// Iterate through the list of floors until there are no more floors.
|
||||
while (surfaceNode != NULL) {
|
||||
surf = surfaceNode->surface;
|
||||
surfaceNode = surfaceNode->next;
|
||||
type = surf->type;
|
||||
|
||||
// To prevent the Merry-Go-Round room from loading when Mario passes above the hole that leads
|
||||
// there, SURFACE_INTANGIBLE is used. This prevent the wrong room from loading, but can also allow
|
||||
// Mario to pass through.
|
||||
if (!gFindFloorIncludeSurfaceIntangible && (type == SURFACE_INTANGIBLE)) continue;
|
||||
if (!(gCollisionFlags & COLLISION_FLAG_INCLUDE_INTANGIBLE) && (type == SURFACE_INTANGIBLE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Determine if we are checking for the camera or not.
|
||||
if (gCheckingSurfaceCollisionsForCamera) {
|
||||
if ((surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) || SURFACE_IS_NEW_WATER(type)) continue;
|
||||
} else if (surf->type == SURFACE_CAMERA_BOUNDARY) {
|
||||
if (gCollisionFlags & COLLISION_FLAG_CAMERA) {
|
||||
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) {
|
||||
continue;
|
||||
}
|
||||
} else if (type == SURFACE_CAMERA_BOUNDARY) {
|
||||
continue; // If we are not checking for the camera, ignore camera only floors.
|
||||
}
|
||||
if (y < (surf->lowerY - 30)) continue;
|
||||
vx[0] = surf->vertex1[0];
|
||||
vz[0] = surf->vertex1[2];
|
||||
vx[1] = surf->vertex2[0];
|
||||
vz[1] = surf->vertex2[2];
|
||||
|
||||
// Exclude all floors above the point.
|
||||
if (bufferY < surf->lowerY) continue;
|
||||
// Check that the point is within the triangle bounds.
|
||||
if ((vz[0] - z) * (vx[1] - vx[0]) - (vx[0] - x) * (vz[1] - vz[0]) < 0) continue;
|
||||
// To slightly save on computation time, set this later.
|
||||
vx[2] = surf->vertex3[0];
|
||||
vz[2] = surf->vertex3[2];
|
||||
if ((vz[1] - z) * (vx[2] - vx[1]) - (vx[1] - x) * (vz[2] - vz[1]) < 0) continue;
|
||||
if ((vz[2] - z) * (vx[0] - vx[2]) - (vx[2] - x) * (vz[0] - vz[2]) < 0) continue;
|
||||
// Find the height of the floor at a given location.
|
||||
if (!check_within_floor_triangle_bounds(x, z, surf)) continue;
|
||||
|
||||
// Get the height of the floor under the current location.
|
||||
height = get_surface_height_at_location(x, z, surf);
|
||||
|
||||
// Exclude floors lower than the previous highest floor.
|
||||
if (height < *pheight) continue;
|
||||
// Checks for floor interaction with a 78 unit buffer.
|
||||
if (y < (height - 78.0f)) continue;
|
||||
|
||||
// Checks for floor interaction with a FIND_FLOOR_BUFFER unit buffer.
|
||||
if (bufferY < height) continue;
|
||||
|
||||
// Use the current floor
|
||||
*pheight = height;
|
||||
floor = surf;
|
||||
if ((height - 78.0f) == y) break;
|
||||
|
||||
// Exit the loop if it's not possible for another floor to be closer
|
||||
// to the original point, or if COLLISION_FLAG_RETURN_FIRST.
|
||||
if ((height == bufferY) || (gCollisionFlags & COLLISION_FLAG_RETURN_FIRST)) break;
|
||||
}
|
||||
return floor;
|
||||
}
|
||||
|
||||
|
||||
static s16 check_within_triangle_bounds(s32 x, s32 z, struct Surface *surf) {
|
||||
register Vec3i vx, vz;
|
||||
vx[0] = surf->vertex1[0];
|
||||
vz[0] = surf->vertex1[2];
|
||||
vx[1] = surf->vertex2[0];
|
||||
vz[1] = surf->vertex2[2];
|
||||
if ((vz[0] - z) * (vx[1] - vx[0]) - (vx[0] - x) * (vz[1] - vz[0]) < 0) return FALSE;
|
||||
vx[2] = surf->vertex3[0];
|
||||
vz[2] = surf->vertex3[2];
|
||||
if ((vz[1] - z) * (vx[2] - vx[1]) - (vx[1] - x) * (vz[2] - vz[1]) < 0) return FALSE;
|
||||
if ((vz[2] - z) * (vx[0] - vx[2]) - (vx[2] - x) * (vz[0] - vz[2]) < 0) return FALSE;
|
||||
return TRUE;
|
||||
// Generic triangle bounds func
|
||||
ALWAYS_INLINE static s32 check_within_bounds_y_norm(s32 x, s32 z, struct Surface *surf) {
|
||||
if (surf->normal.y >= NORMAL_FLOOR_THRESHOLD) return check_within_floor_triangle_bounds(x, z, surf);
|
||||
return check_within_ceil_triangle_bounds(x, z, surf, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,29 +478,41 @@ struct Surface *find_water_floor_from_list(struct SurfaceNode *surfaceNode, s32
|
||||
struct SurfaceNode *topSurfaceNode = surfaceNode;
|
||||
struct SurfaceNode *bottomSurfaceNode = surfaceNode;
|
||||
f32 height = FLOOR_LOWER_LIMIT;
|
||||
f32 curHeight = FLOOR_LOWER_LIMIT;
|
||||
f32 bottomHeight = FLOOR_LOWER_LIMIT;
|
||||
f32 curBottomHeight = FLOOR_LOWER_LIMIT;
|
||||
f32 buffer = FIND_FLOOR_BUFFER;
|
||||
|
||||
// Iterate through the list of water floors until there are no more water floors.
|
||||
// SURFACE_NEW_WATER_BOTTOM
|
||||
while (bottomSurfaceNode != NULL) {
|
||||
f32 curBottomHeight = FLOOR_LOWER_LIMIT;
|
||||
surf = bottomSurfaceNode->surface;
|
||||
bottomSurfaceNode = bottomSurfaceNode->next;
|
||||
|
||||
if (surf->type != SURFACE_NEW_WATER_BOTTOM || !check_within_triangle_bounds(x, z, surf)) continue;
|
||||
// skip wall angled water
|
||||
if (surf->type != SURFACE_NEW_WATER_BOTTOM || absf(surf->normal.y) < NORMAL_FLOOR_THRESHOLD) continue;
|
||||
|
||||
if (!check_within_bounds_y_norm(x, z, surf)) continue;
|
||||
|
||||
curBottomHeight = get_surface_height_at_location(x, z, surf);
|
||||
|
||||
if (curBottomHeight < y - 78.0f) continue;
|
||||
if (curBottomHeight >= y - 78.0f) bottomHeight = curBottomHeight;
|
||||
if (curBottomHeight < y + buffer) {
|
||||
continue;
|
||||
} else {
|
||||
bottomHeight = curBottomHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through the list of water tops until there are no more water tops.
|
||||
// SURFACE_NEW_WATER
|
||||
while (topSurfaceNode != NULL) {
|
||||
f32 curHeight = FLOOR_LOWER_LIMIT;
|
||||
surf = topSurfaceNode->surface;
|
||||
topSurfaceNode = topSurfaceNode->next;
|
||||
|
||||
if ((surf->type == SURFACE_NEW_WATER_BOTTOM) || !check_within_triangle_bounds(x, z, surf)) continue;
|
||||
// skip water tops or wall angled water bottoms
|
||||
if (surf->type == SURFACE_NEW_WATER_BOTTOM || absf(surf->normal.y) < NORMAL_FLOOR_THRESHOLD) continue;
|
||||
|
||||
if (!check_within_bounds_y_norm(x, z, surf)) continue;
|
||||
|
||||
curHeight = get_surface_height_at_location(x, z, surf);
|
||||
|
||||
@@ -447,8 +541,6 @@ f32 find_floor_height(f32 x, f32 y, f32 z) {
|
||||
* and dynamic floors were checked separately.
|
||||
*/
|
||||
f32 unused_find_dynamic_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor) {
|
||||
struct SurfaceNode *surfaceList;
|
||||
struct Surface *floor;
|
||||
f32 floorHeight = FLOOR_LOWER_LIMIT;
|
||||
|
||||
// Would normally cause PUs, but dynamic floors unload at that range.
|
||||
@@ -460,10 +552,9 @@ f32 unused_find_dynamic_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfl
|
||||
s32 cellX = GET_CELL_COORD(x);
|
||||
s32 cellZ = GET_CELL_COORD(z);
|
||||
|
||||
surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
|
||||
floor = find_floor_from_list(surfaceList, x, y, z, &floorHeight);
|
||||
struct SurfaceNode *surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
|
||||
|
||||
*pfloor = floor;
|
||||
*pfloor = find_floor_from_list(surfaceList, x, y, z, &floorHeight);
|
||||
|
||||
return floorHeight;
|
||||
}
|
||||
@@ -472,20 +563,16 @@ f32 unused_find_dynamic_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfl
|
||||
* Find the highest floor under a given position and return the height.
|
||||
*/
|
||||
f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor) {
|
||||
s32 cellZ, cellX;
|
||||
#if PUPPYPRINT_DEBUG
|
||||
OSTime first = osGetTime();
|
||||
#endif
|
||||
|
||||
struct Surface *floor, *dynamicFloor;
|
||||
struct SurfaceNode *surfaceList;
|
||||
|
||||
f32 height = FLOOR_LOWER_LIMIT;
|
||||
f32 height = FLOOR_LOWER_LIMIT;
|
||||
f32 dynamicHeight = FLOOR_LOWER_LIMIT;
|
||||
|
||||
//! (Parallel Universes) Because position is casted to an s16, reaching higher
|
||||
// float locations can return floors despite them not existing there.
|
||||
//(Dynamic floors will unload due to the range.)
|
||||
// float locations can return floors despite them not existing there.
|
||||
// (Dynamic floors will unload due to the range.)
|
||||
s32 x = xPos;
|
||||
s32 y = yPos;
|
||||
s32 z = zPos;
|
||||
@@ -494,46 +581,60 @@ f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor) {
|
||||
|
||||
if (is_outside_level_bounds(x, z)) {
|
||||
#if PUPPYPRINT_DEBUG
|
||||
collisionTime[perfIteration] += osGetTime() - first;
|
||||
collisionTime[perfIteration] += (osGetTime() - first);
|
||||
#endif
|
||||
return height;
|
||||
}
|
||||
// Each level is split into cells to limit load, find the appropriate cell.
|
||||
cellX = GET_CELL_COORD(x);
|
||||
cellZ = GET_CELL_COORD(z);
|
||||
// Check for surfaces that are a part of level geometry.
|
||||
surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
|
||||
floor = find_floor_from_list(surfaceList, x, y, z, &height);
|
||||
if (!gFindFloorExcludeDynamic) {
|
||||
// In the next check, only check for floors higher than the previous check
|
||||
dynamicHeight = height;
|
||||
s32 cellX = GET_CELL_COORD(x);
|
||||
s32 cellZ = GET_CELL_COORD(z);
|
||||
|
||||
struct SurfaceNode *surfaceList;
|
||||
struct Surface *floor = NULL;
|
||||
struct Surface *dynamicFloor = NULL;
|
||||
|
||||
s32 includeDynamic = !(gCollisionFlags & COLLISION_FLAG_EXCLUDE_DYNAMIC);
|
||||
|
||||
if (includeDynamic) {
|
||||
// Check for surfaces belonging to objects.
|
||||
surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
|
||||
dynamicFloor = find_floor_from_list(surfaceList, x, y, z, &dynamicHeight);
|
||||
if (dynamicHeight > height) {
|
||||
floor = dynamicFloor;
|
||||
height = dynamicHeight;
|
||||
}
|
||||
|
||||
// In the next check, only check for floors higher than the previous check.
|
||||
height = dynamicHeight;
|
||||
}
|
||||
|
||||
// Check for surfaces that are a part of level geometry.
|
||||
surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
|
||||
floor = find_floor_from_list(surfaceList, x, y, z, &height);
|
||||
|
||||
// Use the higher floor.
|
||||
if (includeDynamic && height <= dynamicHeight) {
|
||||
floor = dynamicFloor;
|
||||
height = dynamicHeight;
|
||||
}
|
||||
|
||||
// To prevent accidentally leaving the floor tangible, stop checking for it.
|
||||
gFindFloorIncludeSurfaceIntangible = FALSE;
|
||||
gFindFloorExcludeDynamic = FALSE;
|
||||
gCollisionFlags &= ~(COLLISION_FLAG_RETURN_FIRST | COLLISION_FLAG_EXCLUDE_DYNAMIC | COLLISION_FLAG_INCLUDE_INTANGIBLE);
|
||||
// If a floor was missed, increment the debug counter.
|
||||
if (floor == NULL) {
|
||||
gNumFindFloorMisses++;
|
||||
}
|
||||
|
||||
// Return the floor.
|
||||
*pfloor = floor;
|
||||
#ifdef VANILLA_DEBUG
|
||||
// Increment the debug tracker.
|
||||
gNumCalls.floor++;
|
||||
#endif
|
||||
#if PUPPYPRINT_DEBUG
|
||||
collisionTime[perfIteration] += osGetTime() - first;
|
||||
collisionTime[perfIteration] += (osGetTime() - first);
|
||||
#endif
|
||||
return height;
|
||||
}
|
||||
|
||||
f32 find_room_floor(f32 x, f32 y, f32 z, struct Surface **pfloor) {
|
||||
gFindFloorIncludeSurfaceIntangible = TRUE;
|
||||
gFindFloorExcludeDynamic = TRUE;
|
||||
gCollisionFlags |= (COLLISION_FLAG_RETURN_FIRST | COLLISION_FLAG_EXCLUDE_DYNAMIC | COLLISION_FLAG_INCLUDE_INTANGIBLE);
|
||||
return find_floor(x, y, z, pfloor);
|
||||
}
|
||||
|
||||
@@ -541,11 +642,6 @@ f32 find_room_floor(f32 x, f32 y, f32 z, struct Surface **pfloor) {
|
||||
* Find the highest water floor under a given position and return the height.
|
||||
*/
|
||||
f32 find_water_floor(s32 xPos, s32 yPos, s32 zPos, struct Surface **pfloor) {
|
||||
s32 cellZ, cellX;
|
||||
|
||||
struct Surface *floor = NULL;
|
||||
struct SurfaceNode *surfaceList;
|
||||
|
||||
f32 height = FLOOR_LOWER_LIMIT;
|
||||
|
||||
s32 x = xPos;
|
||||
@@ -555,19 +651,22 @@ f32 find_water_floor(s32 xPos, s32 yPos, s32 zPos, struct Surface **pfloor) {
|
||||
if (is_outside_level_bounds(x, z)) return height;
|
||||
|
||||
// Each level is split into cells to limit load, find the appropriate cell.
|
||||
cellX = GET_CELL_COORD(x);
|
||||
cellZ = GET_CELL_COORD(z);
|
||||
s32 cellX = GET_CELL_COORD(x);
|
||||
s32 cellZ = GET_CELL_COORD(z);
|
||||
|
||||
// Check for surfaces that are a part of level geometry.
|
||||
surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WATER].next;
|
||||
floor = find_water_floor_from_list(surfaceList, x, y, z, &height);
|
||||
struct SurfaceNode *surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WATER].next;
|
||||
struct Surface *floor = find_water_floor_from_list(surfaceList, x, y, z, &height);
|
||||
|
||||
if (floor == NULL) {
|
||||
height = FLOOR_LOWER_LIMIT;
|
||||
} else {
|
||||
*pfloor = floor;
|
||||
}
|
||||
|
||||
#ifdef VANILLA_DEBUG
|
||||
// Increment the debug tracker.
|
||||
gNumCalls.floor++;
|
||||
#endif
|
||||
return height;
|
||||
}
|
||||
|
||||
@@ -578,23 +677,20 @@ f32 find_water_floor(s32 xPos, s32 yPos, s32 zPos, struct Surface **pfloor) {
|
||||
/**
|
||||
* Finds the height of water at a given location.
|
||||
*/
|
||||
s32 find_water_level_and_floor(s32 x, s32 z, struct Surface **pfloor) {
|
||||
s32 i;
|
||||
s32 numRegions;
|
||||
s32 find_water_level_and_floor(s32 x, s32 y, s32 z, struct Surface **pfloor) {
|
||||
s32 val;
|
||||
s32 loX, hiX, loZ, hiZ;
|
||||
s32 waterLevel = FLOOR_LOWER_LIMIT;
|
||||
TerrainData *p = gEnvironmentRegions;
|
||||
struct Surface *floor = NULL;
|
||||
#if PUPPYPRINT_DEBUG
|
||||
OSTime first = osGetTime();
|
||||
#endif
|
||||
waterLevel = find_water_floor(x, (gCheckingSurfaceCollisionsForCamera ? gLakituState.pos[1] : gMarioState->pos[1]), z, &floor);
|
||||
s32 waterLevel = find_water_floor(x, y, z, &floor);
|
||||
|
||||
if (p != NULL && waterLevel == FLOOR_LOWER_LIMIT) {
|
||||
numRegions = *p++;
|
||||
s32 numRegions = *p++;
|
||||
|
||||
for (i = 0; i < numRegions; i++) {
|
||||
for (s32 i = 0; i < numRegions; i++) {
|
||||
val = *p++;
|
||||
loX = *p++;
|
||||
loZ = *p++;
|
||||
@@ -615,7 +711,7 @@ s32 find_water_level_and_floor(s32 x, s32 z, struct Surface **pfloor) {
|
||||
}
|
||||
|
||||
#if PUPPYPRINT_DEBUG
|
||||
collisionTime[perfIteration] += osGetTime() - first;
|
||||
collisionTime[perfIteration] += (osGetTime() - first);
|
||||
#endif
|
||||
return waterLevel;
|
||||
}
|
||||
@@ -623,28 +719,20 @@ s32 find_water_level_and_floor(s32 x, s32 z, struct Surface **pfloor) {
|
||||
/**
|
||||
* Finds the height of water at a given location.
|
||||
*/
|
||||
s32 find_water_level(s32 x, s32 z) {
|
||||
s32 i;
|
||||
s32 numRegions;
|
||||
s32 find_water_level(s32 x, s32 z) { // TODO: Allow y pos
|
||||
s32 val;
|
||||
s32 loX, hiX, loZ, hiZ;
|
||||
s32 waterLevel = FLOOR_LOWER_LIMIT;
|
||||
TerrainData *p = gEnvironmentRegions;
|
||||
struct Surface *floor;
|
||||
#if PUPPYPRINT_DEBUG
|
||||
struct Surface *floor = NULL;
|
||||
#if PUPPYPRINT_DEBUG
|
||||
OSTime first = osGetTime();
|
||||
#endif
|
||||
#endif
|
||||
s32 waterLevel = find_water_floor(x, ((gCollisionFlags & COLLISION_FLAG_CAMERA) ? gLakituState.pos[1] : gMarioState->pos[1]), z, &floor);
|
||||
|
||||
if (gCheckingSurfaceCollisionsForCamera) {
|
||||
waterLevel = find_water_floor(x, gLakituState.pos[1], z, &floor);
|
||||
} else {
|
||||
waterLevel = find_water_floor(x, gMarioState->pos[1], z, &floor);
|
||||
}
|
||||
if ((p != NULL) && (waterLevel == FLOOR_LOWER_LIMIT)) {
|
||||
s32 numRegions = *p++;
|
||||
|
||||
if (p != NULL && waterLevel == FLOOR_LOWER_LIMIT) {
|
||||
numRegions = *p++;
|
||||
|
||||
for (i = 0; i < numRegions; i++) {
|
||||
for (s32 i = 0; i < numRegions; i++) {
|
||||
val = *p++;
|
||||
loX = *p++;
|
||||
loZ = *p++;
|
||||
@@ -673,8 +761,6 @@ s32 find_water_level(s32 x, s32 z) {
|
||||
* Finds the height of the poison gas (used only in HMC) at a given location.
|
||||
*/
|
||||
s32 find_poison_gas_level(s32 x, s32 z) {
|
||||
s32 i;
|
||||
s32 numRegions;
|
||||
s32 val;
|
||||
s32 loX, hiX, loZ, hiZ;
|
||||
s32 gasLevel = FLOOR_LOWER_LIMIT;
|
||||
@@ -684,9 +770,9 @@ s32 find_poison_gas_level(s32 x, s32 z) {
|
||||
#endif
|
||||
|
||||
if (p != NULL) {
|
||||
numRegions = *p++;
|
||||
s32 numRegions = *p++;
|
||||
|
||||
for (i = 0; i < numRegions; i++) {
|
||||
for (s32 i = 0; i < numRegions; i++) {
|
||||
val = *p;
|
||||
|
||||
if (val >= 50) {
|
||||
@@ -719,6 +805,7 @@ s32 find_poison_gas_level(s32 x, s32 z) {
|
||||
* DEBUG *
|
||||
**************************************************/
|
||||
|
||||
#ifdef VANILLA_DEBUG
|
||||
/**
|
||||
* Finds the length of a surface list for debug purposes.
|
||||
*/
|
||||
@@ -738,13 +825,11 @@ static s32 surface_list_length(struct SurfaceNode *list) {
|
||||
void debug_surface_list_info(f32 xPos, f32 zPos) {
|
||||
struct SurfaceNode *list;
|
||||
s32 numFloors = 0;
|
||||
s32 numWalls = 0;
|
||||
s32 numCeils = 0;
|
||||
s32 x = xPos;
|
||||
s32 z = zPos;
|
||||
s32 numWalls = 0;
|
||||
s32 numCeils = 0;
|
||||
|
||||
s32 cellX = GET_CELL_COORD(x);
|
||||
s32 cellZ = GET_CELL_COORD(z);
|
||||
s32 cellX = GET_CELL_COORD(xPos);
|
||||
s32 cellZ = GET_CELL_COORD(zPos);
|
||||
|
||||
list = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
|
||||
numFloors += surface_list_length(list);
|
||||
@@ -782,12 +867,13 @@ void debug_surface_list_info(f32 xPos, f32 zPos) {
|
||||
// listal- List Allocated?, statbg- Static Background?, movebg- Moving Background?
|
||||
print_debug_top_down_mapinfo("listal %d", gSurfaceNodesAllocated);
|
||||
print_debug_top_down_mapinfo("statbg %d", gNumStaticSurfaces);
|
||||
print_debug_top_down_mapinfo("movebg %d", gSurfacesAllocated - gNumStaticSurfaces);
|
||||
print_debug_top_down_mapinfo("movebg %d", (gSurfacesAllocated - gNumStaticSurfaces));
|
||||
|
||||
gNumCalls.floor = 0;
|
||||
gNumCalls.ceil = 0;
|
||||
gNumCalls.wall = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* An unused function that finds and interacts with any type of surface.
|
||||
@@ -795,11 +881,9 @@ void debug_surface_list_info(f32 xPos, f32 zPos) {
|
||||
*/
|
||||
s32 unused_resolve_floor_or_ceil_collisions(s32 checkCeil, f32 *px, f32 *py, f32 *pz, f32 radius,
|
||||
struct Surface **psurface, f32 *surfaceHeight) {
|
||||
f32 nx, ny, nz, oo;
|
||||
f32 x = *px;
|
||||
f32 y = *py;
|
||||
f32 z = *pz;
|
||||
f32 offset, distance;
|
||||
|
||||
*psurface = NULL;
|
||||
|
||||
@@ -809,23 +893,21 @@ s32 unused_resolve_floor_or_ceil_collisions(s32 checkCeil, f32 *px, f32 *py, f32
|
||||
*surfaceHeight = find_floor(x, y, z, psurface);
|
||||
}
|
||||
|
||||
if (*psurface == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (*psurface == NULL) return -1;
|
||||
|
||||
nx = (*psurface)->normal.x;
|
||||
ny = (*psurface)->normal.y;
|
||||
nz = (*psurface)->normal.z;
|
||||
oo = (*psurface)->originOffset;
|
||||
f32 nx = (*psurface)->normal.x;
|
||||
f32 ny = (*psurface)->normal.y;
|
||||
f32 nz = (*psurface)->normal.z;
|
||||
f32 oo = (*psurface)->originOffset;
|
||||
|
||||
offset = (nx * x) + (ny * y) + (nz * z) + oo;
|
||||
distance = offset >= 0 ? offset : -offset;
|
||||
f32 offset = absf((nx * x) + (ny * y) + (nz * z) + oo);
|
||||
|
||||
// Interesting surface interaction that should be surf type independent.
|
||||
if (distance < radius) {
|
||||
*px += nx * (radius - offset);
|
||||
*py += ny * (radius - offset);
|
||||
*pz += nz * (radius - offset);
|
||||
if (offset < radius) {
|
||||
offset = (radius - offset);
|
||||
*px += (nx * offset);
|
||||
*py += (ny * offset);
|
||||
*pz += (nz * offset);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user