From 79d7b7e4b99ccebfaeb0eed95087bcc19c2543ca Mon Sep 17 00:00:00 2001 From: Arceveti <73617174+Arceveti@users.noreply.github.com> Date: Tue, 28 Sep 2021 12:36:26 -0700 Subject: [PATCH] Add COS defines --- include/sm64.h | 25 +++++++++++++++++++++++++ src/game/mario.c | 28 ++++++++++++++-------------- src/game/mario_actions_airborne.c | 6 +++--- src/game/mario_actions_automatic.c | 2 +- src/game/mario_actions_moving.c | 4 ++-- src/game/mario_actions_stationary.c | 4 ++-- src/game/mario_step.c | 3 +-- src/game/object_helpers.c | 9 +++++++-- 8 files changed, 55 insertions(+), 26 deletions(-) diff --git a/include/sm64.h b/include/sm64.h index efdfe675..ed793c27 100644 --- a/include/sm64.h +++ b/include/sm64.h @@ -29,6 +29,31 @@ #define SET_HIGH_U16_OF_32(var, x) ((var) = ((var) & 0xFFFF) | ((x) << 16)) #define SET_HIGH_S16_OF_32(var, x) ((var) = ((var) & 0xFFFF) | ((x) << 16)) +// Common cos values for degrees, often used for surface Y normals +// These are different than coss() +#define COS1 0.9998477f +#define COS5 0.9961947f +#define COS10 0.9848077f +#define COS15 0.9659258f +#define COS20 0.9396926f +#define COS25 0.9063078f // ledge grabs +#define COS30 0.8660254f +#define COS35 0.85264016f +#define COS36 0.8443279f +#define COS38 0.7880108f // mario_floor_is_slippery default +#define COS40 0.80901699f +#define COS45 0.76040596f +#define COS50 0.70710678f // SURFACE_FLAG_X_PROJECTION +#define COS55 0.64944805f +#define COS60 0.58778525f +#define COS65 0.52249856f +#define COS70 0.4539905f +#define COS73 0.29237169f // common_landing_cancels, check_common_idle_cancels, check_common_hold_idle_cancels +#define COS75 0.38268343f +#define COS78 0.20791169f +#define COS80 0.17364818f // braking action +#define COS85 0.23344536f + enum RenderLayers { LAYER_FORCE, diff --git a/src/game/mario.c b/src/game/mario.c index 273de3b1..b009a256 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -533,15 +533,15 @@ s32 mario_facing_downhill(struct MarioState *m, s32 turnYaw) { u32 mario_floor_is_slippery(struct MarioState *m) { f32 normY; - if ((m->area->terrainType & TERRAIN_MASK) == TERRAIN_SLIDE && m->floor->normal.y < 0.9998477f) { //~cos(1 deg) + if ((m->area->terrainType & TERRAIN_MASK) == TERRAIN_SLIDE && m->floor->normal.y < COS1) { return TRUE; } switch (mario_get_floor_class(m)) { - case SURFACE_VERY_SLIPPERY: normY = 0.9848077f; break; //~cos(10 deg) - case SURFACE_SLIPPERY: normY = 0.9396926f; break; //~cos(20 deg) - default: normY = 0.7880108f; break; //~cos(38 deg) - case SURFACE_NOT_SLIPPERY: normY = 0.0f; break; + case SURFACE_VERY_SLIPPERY: normY = COS10; break; + case SURFACE_SLIPPERY: normY = COS20; break; + default: normY = COS38; break; + case SURFACE_NOT_SLIPPERY: normY = 0.0f; break; } return m->floor->normal.y <= normY; @@ -554,15 +554,15 @@ s32 mario_floor_is_slope(struct MarioState *m) { f32 normY; if ((m->area->terrainType & TERRAIN_MASK) == TERRAIN_SLIDE - && m->floor->normal.y < 0.9998477f) { // ~cos(1 deg) + && m->floor->normal.y < COS1) { return TRUE; } switch (mario_get_floor_class(m)) { - case SURFACE_VERY_SLIPPERY: normY = 0.9961947f; break; // ~cos(5 deg) - case SURFACE_SLIPPERY: normY = 0.9848077f; break; // ~cos(10 deg) - default: normY = 0.9659258f; break; // ~cos(15 deg) - case SURFACE_NOT_SLIPPERY: normY = 0.9396926f; break; // ~cos(20 deg) + case SURFACE_VERY_SLIPPERY: normY = COS5; break; + case SURFACE_SLIPPERY: normY = COS10; break; + default: normY = COS15; break; + case SURFACE_NOT_SLIPPERY: normY = COS20; break; } return m->floor->normal.y <= normY; @@ -586,10 +586,10 @@ s32 mario_floor_is_steep(struct MarioState *m) { // This does not matter in vanilla game practice. if (!mario_facing_downhill(m, FALSE)) { switch (mario_get_floor_class(m)) { - case SURFACE_VERY_SLIPPERY: normY = 0.9659258f; break; // ~cos(15 deg) - case SURFACE_SLIPPERY: normY = 0.9396926f; break; // ~cos(20 deg) - default: normY = 0.8660254f; break; // ~cos(30 deg) - case SURFACE_NOT_SLIPPERY: normY = 0.8660254f; break; // ~cos(30 deg) + case SURFACE_VERY_SLIPPERY: normY = COS15; break; + case SURFACE_SLIPPERY: normY = COS20; break; + default: normY = COS30; break; + case SURFACE_NOT_SLIPPERY: normY = COS30; break; } result = m->floor->normal.y <= normY; diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index 7966975c..23192561 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -128,7 +128,7 @@ s32 should_get_stuck_in_ground(struct MarioState *m) { #else if (floor != NULL && (terrainType == TERRAIN_SNOW || terrainType == TERRAIN_SAND) && type != SURFACE_BURNING && SURFACE_IS_NOT_HARD(type)) { - if (!(flags & 0x01) && m->peakHeight - m->pos[1] > 1000.0f && floor->normal.y >= 0.8660254f) { + if (!(flags & 0x01) && m->peakHeight - m->pos[1] > 1000.0f && floor->normal.y >= COS30) { return TRUE; } } @@ -1445,7 +1445,7 @@ s32 act_butt_slide_air(struct MarioState *m) { switch (perform_air_step(m, 0)) { case AIR_STEP_LANDED: - if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= 0.9848077f) { + if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= COS10) { m->vel[1] = -m->vel[1] / 2.0f; m->actionState = 1; } else { @@ -1484,7 +1484,7 @@ s32 act_hold_butt_slide_air(struct MarioState *m) { switch (perform_air_step(m, 0)) { case AIR_STEP_LANDED: - if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= 0.9848077f) { + if (m->actionState == 0 && m->vel[1] < 0.0f && m->floor->normal.y >= COS10) { m->vel[1] = -m->vel[1] / 2.0f; m->actionState = 1; } else { diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c index 96340613..5cbd080a 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -561,7 +561,7 @@ s32 act_ledge_grab(struct MarioState *m) { m->actionTimer++; } #ifndef NO_FALSE_LEDGEGRABS - if (m->floor->normal.y < 0.9063078f) { + if (m->floor->normal.y < COS25) { return let_go_of_ledge(m); } #endif diff --git a/src/game/mario_actions_moving.c b/src/game/mario_actions_moving.c index db316f5d..ab153e9b 100644 --- a/src/game/mario_actions_moving.c +++ b/src/game/mario_actions_moving.c @@ -538,7 +538,7 @@ s32 begin_braking_action(struct MarioState *m) { return set_mario_action(m, ACT_STANDING_AGAINST_WALL, 0); } - if (m->forwardVel >= 16.0f && m->floor->normal.y >= 0.17364818f) { + if (m->forwardVel >= 16.0f && m->floor->normal.y >= COS80) { return set_mario_action(m, ACT_BRAKING, 0); } @@ -1784,7 +1784,7 @@ s32 common_landing_cancels(struct MarioState *m, struct LandingAction *landingAc //! Everything here, including floor steepness, is checked before checking // if Mario is actually on the floor. This leads to e.g. remote sliding. - if (m->floor->normal.y < 0.2923717f) { + if (m->floor->normal.y < COS73) { return mario_push_off_steep_floor(m, landingAction->verySteepAction, 0); } diff --git a/src/game/mario_actions_stationary.c b/src/game/mario_actions_stationary.c index f6950fc7..4aa2d109 100644 --- a/src/game/mario_actions_stationary.c +++ b/src/game/mario_actions_stationary.c @@ -19,7 +19,7 @@ s32 check_common_idle_cancels(struct MarioState *m) { mario_drop_held_object(m); - if (m->floor->normal.y < 0.29237169f) { + if (m->floor->normal.y < COS73) { return mario_push_off_steep_floor(m, ACT_FREEFALL, 0); } @@ -60,7 +60,7 @@ s32 check_common_idle_cancels(struct MarioState *m) { } s32 check_common_hold_idle_cancels(struct MarioState *m) { - if (m->floor->normal.y < 0.29237169f) { + if (m->floor->normal.y < COS73) { return mario_push_off_steep_floor(m, ACT_HOLD_FREEFALL, 0); } diff --git a/src/game/mario_step.c b/src/game/mario_step.c index 3a2d5002..5bc69cf2 100644 --- a/src/game/mario_step.c +++ b/src/game/mario_step.c @@ -519,8 +519,7 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr set_mario_floor(m, floor, ledgePos[1]); m->faceAngle[0] = 0; m->faceAngle[1] = atan2s(grabbedWall->normal.z, grabbedWall->normal.x) + 0x8000; - } - else { + } else { vec3f_copy(m->pos, nextPos); set_mario_floor(m, floor, floorHeight); } diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index cedeabeb..7f6e9bb6 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -1652,8 +1652,13 @@ void cur_obj_move_standard(s16 steepSlopeAngleDegrees) { careAboutEdgesAndSteepSlopes = TRUE; steepSlopeAngleDegrees = -steepSlopeAngleDegrees; // clang-format on } - - steepSlopeNormalY = coss(steepSlopeAngleDegrees * (0x10000 / 360)); + if (steepSlopeAngleDegrees == 78) { + steepSlopeNormalY = COS78; + } else if (steepSlopeAngleDegrees == -78) { + steepSlopeNormalY = -COS78; + } else { + steepSlopeNormalY = coss(DEGREES(steepSlopeAngleDegrees)); + } cur_obj_compute_vel_xz(); cur_obj_apply_drag_xz(dragStrength);