From ca13b56cbe823ee38d78a04f5c3b357ed33b059a Mon Sep 17 00:00:00 2001 From: Altimor Date: Thu, 12 Oct 2023 20:19:24 -0400 Subject: [PATCH] use COS constants --- src/engine/math_util.h | 13 +++++++++++++ src/game/mario.c | 29 ++++++++++++++--------------- src/game/mario_actions_airborne.c | 6 +++--- src/game/mario_actions_automatic.c | 2 +- src/game/mario_actions_cutscene.c | 4 ++-- src/game/mario_actions_moving.c | 8 ++++---- src/game/mario_actions_stationary.c | 4 ++-- src/game/mario_actions_submerged.c | 2 +- 8 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/engine/math_util.h b/src/engine/math_util.h index 22f86f86..3dbf5fb8 100644 --- a/src/engine/math_util.h +++ b/src/engine/math_util.h @@ -5,6 +5,19 @@ #include "types.h" +#define COS_1 0.99984770f +#define COS_5 0.99619470f +#define COS_10 0.98480770f +#define COS_15 0.96592580f +#define COS_20 0.93969260f +#define COS_25 0.90630780f +#define COS_30 0.86602540f +#define COS_38 0.78801080f +#define COS_60 0.50000000f +#define COS_73 0.29237170f +#define COS_80 0.17364818f +#define COS_90 0.00000000f + /** * Converts an angle in degrees to sm64's s16 angle units. For example, DEGREES(90) == 0x4000 * This should be used mainly to make math, physics, action, and camera code clearer at first glance. diff --git a/src/game/mario.c b/src/game/mario.c index 71f29d6f..2ee07fca 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -574,26 +574,25 @@ 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) - ) { + && m->floor->normal.y < COS_1) { // ~cos(1 deg) return TRUE; } switch (mario_get_floor_class(m)) { case SURFACE_VERY_SLIPPERY: - normY = 0.9848077f; //~cos(10 deg) + normY = COS_10; //~cos(10 deg) break; case SURFACE_SLIPPERY: - normY = 0.9396926f; //~cos(20 deg) + normY = COS_20; //~cos(20 deg) break; default: - normY = 0.7880108f; //~cos(38 deg) + normY = COS_38; //~cos(38 deg) break; case SURFACE_NOT_SLIPPERY: - normY = 0.0f; + normY = COS_90; break; } @@ -607,25 +606,25 @@ 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 < COS_1) { // ~cos(1 deg) return TRUE; } switch (mario_get_floor_class(m)) { case SURFACE_VERY_SLIPPERY: - normY = 0.9961947f; // ~cos(5 deg) + normY = COS_5; // ~cos(5 deg) break; case SURFACE_SLIPPERY: - normY = 0.9848077f; // ~cos(10 deg) + normY = COS_10; // ~cos(10 deg) break; default: - normY = 0.9659258f; // ~cos(15 deg) + normY = COS_15; // ~cos(15 deg) break; case SURFACE_NOT_SLIPPERY: - normY = 0.9396926f; // ~cos(20 deg) + normY = COS_20; // ~cos(20 deg) break; } @@ -646,19 +645,19 @@ s32 mario_floor_is_steep(struct MarioState *m) { if (!mario_facing_downhill(m, FALSE)) { switch (mario_get_floor_class(m)) { case SURFACE_VERY_SLIPPERY: - normY = 0.9659258f; // ~cos(15 deg) + normY = COS_15; // ~cos(15 deg) break; case SURFACE_SLIPPERY: - normY = 0.9396926f; // ~cos(20 deg) + normY = COS_20; // ~cos(20 deg) break; default: - normY = 0.8660254f; // ~cos(30 deg) + normY = COS_30; // ~cos(30 deg) break; case SURFACE_NOT_SLIPPERY: - normY = 0.8660254f; // ~cos(30 deg) + normY = COS_30; // ~cos(30 deg) break; } diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index c097561e..56d4b096 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -120,7 +120,7 @@ s32 should_get_stuck_in_ground(struct MarioState *m) { 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 >= COS_30) { return TRUE; } } @@ -1441,7 +1441,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 >= COS_10) { m->vel[1] = -m->vel[1] / 2.0f; m->actionState = 1; } else { @@ -1480,7 +1480,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 >= COS_10) { 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 cf57c708..e5e645a2 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -549,7 +549,7 @@ s32 act_ledge_grab(struct MarioState *m) { m->actionTimer++; } - if (m->floor->normal.y < 0.9063078f) { + if (m->floor->normal.y < COS_25) { return let_go_of_ledge(m); } diff --git a/src/game/mario_actions_cutscene.c b/src/game/mario_actions_cutscene.c index 466382a2..c9e418be 100644 --- a/src/game/mario_actions_cutscene.c +++ b/src/game/mario_actions_cutscene.c @@ -1545,12 +1545,12 @@ s32 act_squished(struct MarioState *m) { } // steep floor - if (m->floor != NULL && m->floor->normal.y < 0.5f) { + if (m->floor != NULL && m->floor->normal.y < COS_60) { surfAngle = atan2s(m->floor->normal.z, m->floor->normal.x); underSteepSurf = TRUE; } // steep ceiling - if (m->ceil != NULL && -0.5f < m->ceil->normal.y) { + if (m->ceil != NULL && -COS_60 < m->ceil->normal.y) { surfAngle = atan2s(m->ceil->normal.z, m->ceil->normal.x); underSteepSurf = TRUE; } diff --git a/src/game/mario_actions_moving.c b/src/game/mario_actions_moving.c index 3bb11f70..fa3a0c32 100644 --- a/src/game/mario_actions_moving.c +++ b/src/game/mario_actions_moving.c @@ -375,7 +375,7 @@ void update_shell_speed(struct MarioState *m) { m->forwardVel += 1.1f; } else if (m->forwardVel <= targetSpeed) { m->forwardVel += 1.1f - m->forwardVel / 58.0f; - } else if (m->floor->normal.y >= 0.95f) { + } else if (m->floor->normal.y >= 0.95f) { // ~cos(18.194872 deg) m->forwardVel -= 1.0f; } @@ -451,7 +451,7 @@ void update_walking_speed(struct MarioState *m) { m->forwardVel += 1.1f; } else if (m->forwardVel <= targetSpeed) { m->forwardVel += 1.1f - m->forwardVel / 43.0f; - } else if (m->floor->normal.y >= 0.95f) { + } else if (m->floor->normal.y >= 0.95f) { // ~cos(18.194872 deg) m->forwardVel -= 1.0f; } @@ -506,7 +506,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 >= COS_80) { return set_mario_action(m, ACT_BRAKING, 0); } @@ -1760,7 +1760,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 < COS_73) { 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 d587944f..8c28a682 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 < COS_73) { 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 < COS_73) { return mario_push_off_steep_floor(m, ACT_HOLD_FREEFALL, 0); } diff --git a/src/game/mario_actions_submerged.c b/src/game/mario_actions_submerged.c index 19912f0a..a6c512ad 100644 --- a/src/game/mario_actions_submerged.c +++ b/src/game/mario_actions_submerged.c @@ -1122,7 +1122,7 @@ static void update_metal_water_walking_speed(struct MarioState *m) { m->forwardVel += 1.1f; } else if (m->forwardVel <= val) { m->forwardVel += 1.1f - m->forwardVel / 43.0f; - } else if (m->floor->normal.y >= 0.95f) { + } else if (m->floor->normal.y >= 0.95f) { // ~cos(18.194872 deg) m->forwardVel -= 1.0f; }