diff --git a/include/config.h b/include/config.h index 670b367c6..f8c64113d 100644 --- a/include/config.h +++ b/include/config.h @@ -88,11 +88,14 @@ //#define DISABLE_BLJ // -- COLLISION SETTINGS -- +// Reduces some find_floor calls, at the cost of some barely noticeable smoothness in Mario's visual movement in a few actions at higher speeds. +// The defined number is the forward speed threshold before the change is active, since it's only noticeable at lower speeds. +#define FAST_FLOOR_ALIGN 10 // Automatically calculate the optimal collision distance for an object based on its vertices. #define AUTO_COLLISION_DISTANCE // Allow all surfaces types to have force, (doesn't require setting force, just allows it to be optional). #define ALL_SURFACES_HAVE_FORCE -// Number of walls that can push Mario at once. +// Number of walls that can push Mario at once. Vanilla is 4. #define MAX_REFEREMCED_WALLS 4 // Collision data is the type that the collision system uses. All data by default is stored as an s16, but you may change it to s32. // Naturally, that would double the size of all collision data, but would allow you to use 32 bit values instead of 16. diff --git a/src/game/behaviors/metal_box.inc.c b/src/game/behaviors/metal_box.inc.c index 5ff822bcd..e8f569da5 100644 --- a/src/game/behaviors/metal_box.inc.c +++ b/src/game/behaviors/metal_box.inc.c @@ -13,10 +13,10 @@ struct ObjectHitbox sMetalBoxHitbox = { }; s32 check_if_moving_over_floor(f32 maxDist, f32 offset) { - struct Surface *sp24; + struct Surface *floor; f32 xPos = o->oPosX + sins(o->oMoveAngleYaw) * offset; f32 zPos = o->oPosZ + coss(o->oMoveAngleYaw) * offset; - f32 floorHeight = find_floor(xPos, o->oPosY, zPos, &sp24); + f32 floorHeight = find_floor(xPos, o->oPosY, zPos, &floor); if (absf(floorHeight - o->oPosY) < maxDist) // abs return 1; else diff --git a/src/game/mario.c b/src/game/mario.c index 23ec42550..5691c0281 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -655,16 +655,25 @@ f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f * Returns the slope of the floor based off points around Mario. */ s16 find_floor_slope(struct MarioState *m, s16 yawOffset) { - struct Surface *floor; + struct Surface *floor = m->floor; f32 forwardFloorY, backwardFloorY; f32 forwardYDelta, backwardYDelta; s16 result; f32 x = sins(m->faceAngle[1] + yawOffset) * 5.0f; f32 z = coss(m->faceAngle[1] + yawOffset) * 5.0f; - - forwardFloorY = find_floor(m->pos[0] + x, m->pos[1] + 100.0f, m->pos[2] + z, &floor); - backwardFloorY = find_floor(m->pos[0] - x, m->pos[1] + 100.0f, m->pos[2] - z, &floor); +#ifdef FAST_FLOOR_ALIGN + if (ABS(m->forwardVel) > FAST_FLOOR_ALIGN) { + forwardFloorY = get_surface_height_at_location((m->pos[0] + x), (m->pos[2] + z), floor); + backwardFloorY = get_surface_height_at_location((m->pos[0] - x), (m->pos[2] - z), floor); + } else { + forwardFloorY = find_floor((m->pos[0] + x), (m->pos[1] + 100.0f), (m->pos[2] + z), &floor); + backwardFloorY = find_floor((m->pos[0] - x), (m->pos[1] + 100.0f), (m->pos[2] - z), &floor); + } +#else + forwardFloorY = find_floor((m->pos[0] + x), (m->pos[1] + 100.0f), (m->pos[2] + z), &floor); + backwardFloorY = find_floor((m->pos[0] - x), (m->pos[1] + 100.0f), (m->pos[2] - z), &floor); +#endif //! If Mario is near OOB, these floorY's can sometimes be -11000. // This will cause these to be off and give improper slopes. diff --git a/src/game/mario_actions_moving.c b/src/game/mario_actions_moving.c index dda17dcfc..d0f9e055e 100644 --- a/src/game/mario_actions_moving.c +++ b/src/game/mario_actions_moving.c @@ -64,9 +64,7 @@ struct LandingAction sBackflipLandAction = { Mat4 sFloorAlignMatrix[2]; s16 tilt_body_running(struct MarioState *m) { - s16 pitch = find_floor_slope(m, 0); - pitch = pitch * m->forwardVel / 40.0f; - return -pitch; + return -(find_floor_slope(m, 0) * m->forwardVel / 40.0f); } void play_step_sound(struct MarioState *m, s16 frame1, s16 frame2) { @@ -88,9 +86,21 @@ void play_step_sound(struct MarioState *m, s16 frame1, s16 frame2) { } void align_with_floor(struct MarioState *m) { - m->pos[1] = m->floorHeight; - mtxf_align_terrain_triangle(sFloorAlignMatrix[m->playerID], m->pos, m->faceAngle[1], 40.0f); - m->marioObj->header.gfx.throwMatrix = &sFloorAlignMatrix[m->playerID]; + struct Surface *floor = m->floor; + if ((floor != NULL) && (m->pos[1] < (m->floorHeight + 80.0f))) { + m->pos[1] = m->floorHeight; +#ifdef FAST_FLOOR_ALIGN + if (ABS(m->forwardVel) > FAST_FLOOR_ALIGN) { + Vec3f floorNormal = { floor->normal.x, floor->normal.y, floor->normal.z }; + mtxf_align_terrain_normal(sFloorAlignMatrix[m->playerID], floorNormal, m->pos, m->faceAngle[1]); + } else { + mtxf_align_terrain_triangle(sFloorAlignMatrix[m->playerID], m->pos, m->faceAngle[1], 40.0f); + } +#else + mtxf_align_terrain_triangle(sFloorAlignMatrix[m->playerID], m->pos, m->faceAngle[1], 40.0f); +#endif + m->marioObj->header.gfx.throwMatrix = &sFloorAlignMatrix[m->playerID]; + } } s32 begin_walking_action(struct MarioState *m, f32 forwardVel, u32 action, u32 actionArg) {