From dc8d4d30931eb77ef3661f3bc6b2c30363b22249 Mon Sep 17 00:00:00 2001 From: Noah McQueen <67965519+Yotona@users.noreply.github.com> Date: Tue, 12 Sep 2023 16:20:08 -0600 Subject: [PATCH] Various fixes in SSystem (#19) * Various fixes in SSystem * Removed unused include in c_xyz.h * Removed unused include in c_xyz.cpp --- configure.py | 8 +++--- include/SSystem/SComponent/c_bg_s_poly_info.h | 10 +++++-- include/SSystem/SComponent/c_data_tbl.h | 6 ++--- src/SSystem/SComponent/c_bg_s_lin_chk.cpp | 12 +++++---- src/SSystem/SComponent/c_lib.cpp | 27 +++++++++---------- src/SSystem/SComponent/c_m3d_g_cyl.cpp | 6 ++--- src/SSystem/SComponent/c_m3d_g_sph.cpp | 6 ++--- src/SSystem/SComponent/c_math.cpp | 4 +-- src/SSystem/SComponent/c_xyz.cpp | 9 +++---- 9 files changed, 47 insertions(+), 41 deletions(-) diff --git a/configure.py b/configure.py index 33c3a6b3f..a52bd174b 100644 --- a/configure.py +++ b/configure.py @@ -238,22 +238,22 @@ LIBS = [ Object(Matching, "SSystem/SComponent/c_tag_iter.cpp"), Object(NonMatching, "SSystem/SComponent/c_xyz.cpp"), Object(Matching, "SSystem/SComponent/c_sxyz.cpp"), - Object(NonMatching, "SSystem/SComponent/c_math.cpp"), + Object(Matching, "SSystem/SComponent/c_math.cpp"), Object(NonMatching, "SSystem/SComponent/c_bg_s.cpp"), Object(Matching, "SSystem/SComponent/c_bg_s_chk.cpp"), Object(NonMatching, "SSystem/SComponent/c_bg_s_gnd_chk.cpp"), - Object(NonMatching, "SSystem/SComponent/c_bg_s_lin_chk.cpp"), + Object(Matching, "SSystem/SComponent/c_bg_s_lin_chk.cpp"), Object(NonMatching, "SSystem/SComponent/c_bg_w.cpp"), Object(NonMatching, "SSystem/SComponent/c_m2d.cpp"), Object(NonMatching, "SSystem/SComponent/c_m2d_g_box.cpp"), Object(Matching, "SSystem/SComponent/c_m3d_g_aab.cpp"), - Object(NonMatching, "SSystem/SComponent/c_m3d_g_cyl.cpp"), + Object(Matching, "SSystem/SComponent/c_m3d_g_cyl.cpp"), Object(Matching, "SSystem/SComponent/c_m3d_g_pla.cpp"), Object(NonMatching, "SSystem/SComponent/c_m3d_g_sph.cpp"), Object(Matching, "SSystem/SComponent/c_m3d_g_tri.cpp"), Object(NonMatching, "SSystem/SComponent/c_lib.cpp"), Object(NonMatching, "SSystem/SComponent/c_angle.cpp"), - Object(NonMatching, "SSystem/SComponent/c_data_tbl.cpp"), + Object(Matching, "SSystem/SComponent/c_data_tbl.cpp"), ], }, { diff --git a/include/SSystem/SComponent/c_bg_s_poly_info.h b/include/SSystem/SComponent/c_bg_s_poly_info.h index 55c265b49..2d2da6493 100644 --- a/include/SSystem/SComponent/c_bg_s_poly_info.h +++ b/include/SSystem/SComponent/c_bg_s_poly_info.h @@ -3,16 +3,22 @@ #include "dolphin/types.h" +class cBgW; class cBgS_PolyInfo { private: /* 0x00 */ u16 mPolyIndex; /* 0x02 */ u16 mBgIndex; - /* 0x04 */ void* unk_0x04; + /* 0x04 */ cBgW* mpBgW; /* 0x08 */ unsigned int mActorId; public: cBgS_PolyInfo(); - void ClearPi(); + void ClearPi() { + mPolyIndex = -1; + mBgIndex = 0x100; + mpBgW = NULL; + mActorId = -1; + } void SetPolyInfo(const cBgS_PolyInfo&); void SetActorInfo(int, void*, unsigned int); bool ChkSafe(const void*, unsigned int) const; diff --git a/include/SSystem/SComponent/c_data_tbl.h b/include/SSystem/SComponent/c_data_tbl.h index f231db125..386e189dc 100644 --- a/include/SSystem/SComponent/c_data_tbl.h +++ b/include/SSystem/SComponent/c_data_tbl.h @@ -4,13 +4,13 @@ #include "dolphin/types.h" struct cDT_NamePTbl { + u32 mCount; + char ** mpNames; + cDT_NamePTbl(); virtual ~cDT_NamePTbl(); int GetIndex(const char *pName, int start) const; void Set(u32 count, char** pNames); - - u32 mCount; - char ** mpNames; }; struct cDT_DataSrc { diff --git a/src/SSystem/SComponent/c_bg_s_lin_chk.cpp b/src/SSystem/SComponent/c_bg_s_lin_chk.cpp index 7a36a650f..e35a2f9fd 100644 --- a/src/SSystem/SComponent/c_bg_s_lin_chk.cpp +++ b/src/SSystem/SComponent/c_bg_s_lin_chk.cpp @@ -8,10 +8,11 @@ /* 80247418-80247480 .text ct__11cBgS_LinChkFv */ void cBgS_LinChk::ct() { - mLin.mStart = cXyz::Zero; - mLin.mEnd = cXyz::Zero; - field_0x40 = cXyz::Zero ; - setActorPid(0xFFFFFFFF); + cXyz zero = cXyz::Zero; + mLin.mStart = zero; + mLin.mEnd = zero; + field_0x40 = zero; + setActorPid(-1); field_0x4c = 0; mFrontFlag = 1; mBackFlag = 0; @@ -19,7 +20,8 @@ void cBgS_LinChk::ct() { /* 80247480-80247500 .text Set2__11cBgS_LinChkFP4cXyzP4cXyzUi */ void cBgS_LinChk::Set2(cXyz* pStart, cXyz* pEnd, unsigned int actorPid) { - mLin.SetStartEnd(*pStart, *pEnd); + mLin.mStart.set(*pStart); + mLin.mEnd.set(*pEnd); field_0x40 = *pEnd; setActorPid(actorPid); field_0x4c &= ~0x10; diff --git a/src/SSystem/SComponent/c_lib.cpp b/src/SSystem/SComponent/c_lib.cpp index 9ddb7366e..3678ef251 100644 --- a/src/SSystem/SComponent/c_lib.cpp +++ b/src/SSystem/SComponent/c_lib.cpp @@ -4,10 +4,11 @@ // #include "SSystem/SComponent/c_lib.h" -#include "SSystem/SComponent/c_math.h" #include "MSL_C/string.h" +#include "SSystem/SComponent/c_math.h" #include "dolphin/mtx/mtxvec.h" + /* 802528A4-802528C4 .text cLib_memCpy__FPvPCvUl */ void cLib_memCpy(void* dst, const void* src, unsigned long size) { memcpy(dst, src, size); @@ -202,35 +203,33 @@ void cLib_addCalcAngleS2(s16* pValue, s16 target, s16 scale, s16 maxStep) { } /* 802532C4-8025335C .text cLib_addCalcAngleL__FPlllll */ -s16 cLib_addCalcAngleL(s32* pValue, s32 target, s32 scale, s32 maxStep, s32 minStep) { +s32 cLib_addCalcAngleL(s32* pValue, s32 target, s32 scale, s32 maxStep, s32 minStep) { s32 diff = target - *pValue; if (*pValue != target) { - s32 step = (diff) / scale; - if (step > minStep || step < -minStep) { - if (step > maxStep) { - step = maxStep; + scale = (diff) / scale; + if (scale > minStep || scale < -minStep) { + if (scale > maxStep) { + scale = maxStep; } - if (step < -maxStep) { - step = -maxStep; + if (scale < -maxStep) { + scale = -maxStep; } - *pValue += step; + *pValue += scale; } else { if (0 <= diff) { *pValue += minStep; - diff = target - *pValue; - if (0 >= diff) { + if (0 >= target - *pValue) { *pValue = target; } } else { *pValue -= minStep; - diff = target - *pValue; - if (0 <= diff) { + if (0 <= target - *pValue) { *pValue = target; } } } } - return target - *pValue; + return diff; } /* 8025335C-802533D0 .text cLib_chaseUC__FPUcUcUc */ diff --git a/src/SSystem/SComponent/c_m3d_g_cyl.cpp b/src/SSystem/SComponent/c_m3d_g_cyl.cpp index 799db4b59..8fe53520d 100644 --- a/src/SSystem/SComponent/c_m3d_g_cyl.cpp +++ b/src/SSystem/SComponent/c_m3d_g_cyl.cpp @@ -8,9 +8,9 @@ #include "JSystem/JUtility/JUTAssert.h" #include "MSL_C/float.h" -#define CHECK_FLOAT_CLASS(line, x) JUT_ASSERT(__FILE__, line, !(((sizeof(x) == sizeof(float)) ? __fpclassifyf((float)(x)) : __fpclassifyd((double)(x)) ) == 1)); -#define CHECK_FLOAT_RANGE(line, x) JUT_ASSERT(__FILE__, line, -1.0e32f < x && x < 1.0e32f); -#define CHECK_VEC3_RANGE(line, v) JUT_ASSERT(__FILE__, line, -1.0e32f < v.x && v.x < 1.0e32f && -1.0e32f < v.y && v.y < 1.0e32f && -1.0e32f < v.z && v.z < 1.0e32f) +#define CHECK_FLOAT_CLASS(line, x) JUT_ASSERT(line, !(((sizeof(x) == sizeof(float)) ? __fpclassifyf((float)(x)) : __fpclassifyd((double)(x)) ) == 1)); +#define CHECK_FLOAT_RANGE(line, x) JUT_ASSERT(line, -1.0e32f < x && x < 1.0e32f); +#define CHECK_VEC3_RANGE(line, v) JUT_ASSERT(line, -1.0e32f < v.x && v.x < 1.0e32f && -1.0e32f < v.y && v.y < 1.0e32f && -1.0e32f < v.z && v.z < 1.0e32f) /* 80251D88-80252020 .text SetC__8cM3dGCylFRC4cXyz */ void cM3dGCyl::SetC(const cXyz& pos) { diff --git a/src/SSystem/SComponent/c_m3d_g_sph.cpp b/src/SSystem/SComponent/c_m3d_g_sph.cpp index e52590819..cd3bd4ae0 100644 --- a/src/SSystem/SComponent/c_m3d_g_sph.cpp +++ b/src/SSystem/SComponent/c_m3d_g_sph.cpp @@ -8,9 +8,9 @@ #include "JSystem/JUtility/JUTAssert.h" #include "MSL_C/float.h" -#define CHECK_FLOAT_CLASS(line, x) JUT_ASSERT(__FILE__, line, !(((sizeof(x) == sizeof(float)) ? __fpclassifyf((float)(x)) : __fpclassifyd((double)(x)) ) == 1)); -#define CHECK_FLOAT_RANGE(line, x) JUT_ASSERT(__FILE__, line, -1.0e32f < x && x < 1.0e32f); -#define CHECK_VEC3_RANGE(line, v) JUT_ASSERT(__FILE__, line, -1.0e32f < v.x && v.x < 1.0e32f && -1.0e32f < v.y && v.y < 1.0e32f && -1.0e32f < v.z && v.z < 1.0e32f) +#define CHECK_FLOAT_CLASS(line, x) JUT_ASSERT(line, !(((sizeof(x) == sizeof(float)) ? __fpclassifyf((float)(x)) : __fpclassifyd((double)(x)) ) == 1)); +#define CHECK_FLOAT_RANGE(line, x) JUT_ASSERT(line, -1.0e32f < x && x < 1.0e32f); +#define CHECK_VEC3_RANGE(line, v) JUT_ASSERT(line, -1.0e32f < v.x && v.x < 1.0e32f && -1.0e32f < v.y && v.y < 1.0e32f && -1.0e32f < v.z && v.z < 1.0e32f) /* 8025238C-80252624 .text SetC__8cM3dGSphFRC4cXyz */ void cM3dGSph::SetC(const cXyz& pos) { diff --git a/src/SSystem/SComponent/c_math.cpp b/src/SSystem/SComponent/c_math.cpp index 6f6638a60..7f9e190c0 100644 --- a/src/SSystem/SComponent/c_math.cpp +++ b/src/SSystem/SComponent/c_math.cpp @@ -10,8 +10,8 @@ /* 80246044-8024609C .text cM_rad2s__Ff */ s16 cM_rad2s(float f0) { - f32 tmpF = fmod(f0, 6.2831854820251465 /* approx. 2 * PI */); - s32 tmp = (tmpF * 10430.378f /* approx. 32768 / PI */); + f64 tmpF = fmod(f0, 6.2831854820251465 /* approx. 2 * PI */); + s32 tmp = (tmpF * 10430.3779296875 /* approx. 32768 / PI */); if (tmp < -0x8000) { tmp += 0x10000; } else if (tmp > 0x7FFF) { diff --git a/src/SSystem/SComponent/c_xyz.cpp b/src/SSystem/SComponent/c_xyz.cpp index 346d984f2..5f2cac9e8 100644 --- a/src/SSystem/SComponent/c_xyz.cpp +++ b/src/SSystem/SComponent/c_xyz.cpp @@ -4,9 +4,9 @@ // #include "SSystem/SComponent/c_xyz.h" -#include "SSystem/SComponent/c_math.h" -#include "MSL_C/float.h" #include "JSystem/JUtility/JUTAssert.h" +#include "MSL_C/float.h" +#include "SSystem/SComponent/c_math.h" const cXyz cXyz::Zero(0, 0, 0); const cXyz cXyz::BaseX(1, 0, 0); @@ -150,7 +150,6 @@ bool cXyz::operator!=(const Vec& vec) const { /* 80245CE4-80245D48 .text isZero__4cXyzCFv */ bool cXyz::isZero(void) const { - return fabsf(this->x) < 3.814697e-06 && - fabsf(this->y) < 3.814697e-06 && - fabsf(this->z) < 3.814697e-06; + return fabsf(this->x) < 3.814697e-06f && fabsf(this->y) < 3.814697e-06f && + fabsf(this->z) < 3.814697e-06f; }