From 707fceca57d750dd132a5106788cc6b381ac1d35 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Thu, 8 Aug 2024 14:50:10 -0400 Subject: [PATCH] Move fmodf, atan2f, sinf, and cosf to std:: namespace --- src/JSystem/JStudio/JStudio/jstudio-math.cpp | 12 +++++------ src/JSystem/JUtility/JUTGamePad.cpp | 2 +- .../MSL/MSL_C/MSL_Common/Include/math.h | 21 ++++--------------- src/SSystem/SComponent/c_math.cpp | 2 +- src/d/d_com_inf_game.cpp | 4 ++-- src/d/d_drawlist.cpp | 2 +- src/d/d_kankyo.cpp | 6 +++--- src/d/d_kankyo_rain.cpp | 16 +++++++------- 8 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/JSystem/JStudio/JStudio/jstudio-math.cpp b/src/JSystem/JStudio/JStudio/jstudio-math.cpp index 4492624b4..dfe90260c 100644 --- a/src/JSystem/JStudio/JStudio/jstudio-math.cpp +++ b/src/JSystem/JStudio/JStudio/jstudio-math.cpp @@ -11,12 +11,12 @@ namespace math { /* 8026E610-8026E778 .text getRotation_xyz__Q27JStudio4mathFPA4_ffff */ void getRotation_xyz(MtxP param_1, f32 x, f32 y, f32 z) { - f32 cosx = i_cosf(DEG_TO_RAD(x)); - f32 sinx = i_sinf(DEG_TO_RAD(x)); - f32 cosy = i_cosf(DEG_TO_RAD(y)); - f32 siny = i_sinf(DEG_TO_RAD(y)); - f32 cosz = i_cosf(DEG_TO_RAD(z)); - f32 sinz = i_sinf(DEG_TO_RAD(z)); + f32 cosx = std::cosf(DEG_TO_RAD(x)); + f32 sinx = std::sinf(DEG_TO_RAD(x)); + f32 cosy = std::cosf(DEG_TO_RAD(y)); + f32 siny = std::sinf(DEG_TO_RAD(y)); + f32 cosz = std::cosf(DEG_TO_RAD(z)); + f32 sinz = std::sinf(DEG_TO_RAD(z)); f32 cosxcosz = cosx * cosz; f32 cosxsinz = cosx * sinz; f32 sinxcosz = sinx * cosz; diff --git a/src/JSystem/JUtility/JUTGamePad.cpp b/src/JSystem/JUtility/JUTGamePad.cpp index eebc93923..fb9dd1c1a 100644 --- a/src/JSystem/JUtility/JUTGamePad.cpp +++ b/src/JSystem/JUtility/JUTGamePad.cpp @@ -323,7 +323,7 @@ u32 JUTGamePad::CStick::update(s8 x_val, s8 y_val, EStickMode mode, EWhichStick mAngle = -0x4000; } } else { - mAngle = 10430.379f * atan2f(mPosX, -mPosY); + mAngle = 10430.379f * std::atan2f(mPosX, -mPosY); } } diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/math.h b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/math.h index 138b8eb95..0898a54a9 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/math.h +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/math.h @@ -35,9 +35,6 @@ inline double fabs(double f) { double floor(double); double fmod(double, double); -inline float fmodf(float f1, float f2) { - return fmod(f1, f2); -} double frexp(double, int*); double ldexp(double, int); @@ -85,20 +82,6 @@ extern inline double sqrt(double x) { return HUGE_VALF; } -inline float atan2f(float y, float x) { - return (float)atan2(y, x); -} - -// these are duplicated due to sinf/cosf having a symbol, but -// still being used as inlines elsewhere -inline float i_sinf(float x) { - return sin(x); -} - -inline float i_cosf(float x) { - return cos(x); -} - #ifdef __cplusplus }; @@ -106,6 +89,10 @@ inline float i_cosf(float x) { namespace std { inline float fabsf(float f) { return fabs(f); } inline float abs(float f) { return fabsf(f); } +inline float fmodf(float x, float y) { return fmod(x, y); } +inline float atan2f(float y, float x) { return (float)atan2(y, x); } +inline float sinf(float x) { return sin(x); } +inline float cosf(float x) { return cos(x); } }; // namespace std #endif diff --git a/src/SSystem/SComponent/c_math.cpp b/src/SSystem/SComponent/c_math.cpp index 91f43904c..ddfffd9de 100644 --- a/src/SSystem/SComponent/c_math.cpp +++ b/src/SSystem/SComponent/c_math.cpp @@ -178,7 +178,7 @@ float cM_rnd(void) { r0 = (r0 * 0xAB) % 0x763D; r1 = (r1 * 0xAC) % 0x7663; r2 = (r2 * 0xAA) % 0x7673; - return std::fabsf(fmod(r0 / 30269.0f + r1 / 30307.0f + r2 / 30323.0f, 1.0)); + return std::fabsf(std::fmodf(r0 / 30269.0f + r1 / 30307.0f + r2 / 30323.0f, 1.0)); } /* 802463B0-802463E8 .text cM_rndF__Ff */ diff --git a/src/d/d_com_inf_game.cpp b/src/d/d_com_inf_game.cpp index d093a02f7..61487f341 100644 --- a/src/d/d_com_inf_game.cpp +++ b/src/d/d_com_inf_game.cpp @@ -1045,8 +1045,8 @@ int dComIfGd_setShadow(u32 id, s8 param_2, J3DModel* pModel, cXyz* pPos, f32 par int sid = dComIfGd_setRealShadow2(id, param_2, pModel, pPos, param_5, y - param_8, param_10); if (sid == 0) { - cXyz i_pos(pPos->x, y, pPos->z); - dComIfGd_setSimpleShadow2(&i_pos, param_8, param_6, pFloorPoly, rotY, param_12, pTexObj); + cXyz pos(pPos->x, y, pPos->z); + dComIfGd_setSimpleShadow2(&pos, param_8, param_6, pFloorPoly, rotY, param_12, pTexObj); } return sid; } diff --git a/src/d/d_drawlist.cpp b/src/d/d_drawlist.cpp index f97dccf60..5bddb7934 100644 --- a/src/d/d_drawlist.cpp +++ b/src/d/d_drawlist.cpp @@ -700,7 +700,7 @@ f32 cM_rnd_c::get() { m0 = (m0 * 171) % 30269; m4 = (m4 * 172) % 30307; m8 = (m8 * 170) % 30323; - return std::fabsf(fmod((m0 / 30269.0f) + (m4 / 30307.0f) + (m8 / 30323.0f), 1.0f)); + return std::fabsf(std::fmodf((m0 / 30269.0f) + (m4 / 30307.0f) + (m8 / 30323.0f), 1.0f)); } f32 cM_rnd_c::getF(f32 m) { diff --git a/src/d/d_kankyo.cpp b/src/d/d_kankyo.cpp index 3f9d07e32..5e8d241d0 100644 --- a/src/d/d_kankyo.cpp +++ b/src/d/d_kankyo.cpp @@ -583,9 +583,9 @@ void dScnKy_env_light_c::setSunpos() { var_f1 = g_env_light.mCurTime + 345.0f; } - sp8.x = i_sinf(DEG_TO_RAD(var_f1)) * 80000.0f; - sp8.y = i_cosf(DEG_TO_RAD(var_f1)) * 80000.0f; - sp8.z = i_cosf(DEG_TO_RAD(var_f1)) * -48000.0f; + sp8.x = std::sinf(DEG_TO_RAD(var_f1)) * 80000.0f; + sp8.y = std::cosf(DEG_TO_RAD(var_f1)) * 80000.0f; + sp8.z = std::cosf(DEG_TO_RAD(var_f1)) * -48000.0f; if (!dComIfGp_event_runCheck() || g_env_light.mInitAnimTimer != 0) { mSunPos.x = camera_p->mLookat.mEye.x + sp8.x; diff --git a/src/d/d_kankyo_rain.cpp b/src/d/d_kankyo_rain.cpp index 31a359038..86ef24918 100644 --- a/src/d/d_kankyo_rain.cpp +++ b/src/d/d_kankyo_rain.cpp @@ -1477,12 +1477,12 @@ void dKyr_drawSun(Mtx drawMtx, cXyz* pPos, GXColor& reg0, u8** pImg) { dKyr_get_vectle_calc(&pCamera->mLookat.mEye, &pCamera->mLookat.mCenter, &camfwd); f32 cam_distXZ = sqrtf(camfwd.x*camfwd.x + camfwd.z*camfwd.z); - f32 cam_theta = atan2f(camfwd.x, camfwd.z); - f32 cam_phi = atan2f(camfwd.y, cam_distXZ); + f32 cam_theta = std::atan2f(camfwd.x, camfwd.z); + f32 cam_phi = std::atan2f(camfwd.y, cam_distXZ); f32 moon_distXZ = sqrtf(moonPos.x*moonPos.x + moonPos.z*moonPos.z); - f32 moon_theta = atan2f(moonPos.x, moonPos.z); - f32 moon_phi = atan2f(moonPos.y, moon_distXZ); + f32 moon_theta = std::atan2f(moonPos.x, moonPos.z); + f32 moon_phi = std::atan2f(moonPos.y, moon_distXZ); f32 angle = 45.0f + (((moon_theta - cam_theta) / -8.0f) * moon_phi) * 360.0f; MTXRotDeg(rotMtx, 'Z', angle); @@ -1575,14 +1575,14 @@ void dKyr_drawSun(Mtx drawMtx, cXyz* pPos, GXColor& reg0, u8** pImg) { snap_sunmoon_proc(&sunPos, 9); f32 sun_distXZ = sqrtf(sunPos.x*sunPos.x + sunPos.z*sunPos.z); - f32 sun_theta = atan2f(sunPos.x, sunPos.z); - f32 sun_phi = atan2f(sunPos.y, sun_distXZ); + f32 sun_theta = std::atan2f(sunPos.x, sunPos.z); + f32 sun_phi = std::atan2f(sunPos.y, sun_distXZ); dKyr_get_vectle_calc(&pCamera->mLookat.mEye, &pCamera->mLookat.mCenter, &camfwd); f32 cam_distXZ = sqrtf(camfwd.x*camfwd.x + camfwd.z*camfwd.z); - f32 cam_theta = atan2f(camfwd.x, camfwd.z); - f32 cam_phi = atan2f(camfwd.y, cam_distXZ); + f32 cam_theta = std::atan2f(camfwd.x, camfwd.z); + f32 cam_phi = std::atan2f(camfwd.y, cam_distXZ); MTXRotDeg(rotMtx, 'Z', -50.0f + (360.0f * ((sun_theta - cam_theta) / -8.0f))); MTXConcat(camMtx, rotMtx, camMtx);