From ce70fc74af048861ba16ed10de6787a72a5d3fd3 Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Sat, 9 Nov 2024 15:49:29 -0600 Subject: [PATCH] Properly fix sqrtf constants --- configure.py | 6 +++--- include/math.h | 24 +++++++++++++----------- include/rel_sqrt_consts.h | 3 --- src/REL/_minigameDLL/_minigameDLL.c | 2 +- src/REL/board_executor.c | 2 +- src/REL/bootDll/main.c | 1 - src/REL/m437Dll/main.c | 2 +- src/REL/m446Dll/main.c | 2 +- src/REL/m447dll/main.c | 2 +- src/REL/modeltestDll/main.c | 3 +-- src/REL/mstory4Dll/main.c | 2 +- src/REL/option/scene.c | 2 +- src/REL/present/init.c | 2 +- src/REL/safDll/main.c | 2 +- src/REL/selmenuDll/main.c | 2 +- src/REL/staffDll/main.c | 2 +- src/REL/subchrselDll/main.c | 2 +- 17 files changed, 29 insertions(+), 32 deletions(-) diff --git a/configure.py b/configure.py index 933a7b2b..339a9dfe 100644 --- a/configure.py +++ b/configure.py @@ -1089,7 +1089,7 @@ config.libs = [ "m435Dll", # Darts of Doom objects={ Object(NonMatching, "REL/m435Dll/main.c"), - Object(Matching, "REL/m435Dll/sequence.c"), + Object(NonMatching, "REL/m435Dll/sequence.c"), }, ), Rel( @@ -1103,7 +1103,7 @@ config.libs = [ "m437Dll", # Balloon of Doom objects={ Object(NonMatching, "REL/m437Dll/main.c"), - Object(Matching, "REL/m437Dll/sequence.c"), + Object(NonMatching, "REL/m437Dll/sequence.c"), }, ), Rel( @@ -1230,7 +1230,7 @@ config.libs = [ "m456Dll", # Take a Breather objects={ Object(NonMatching, "REL/m456Dll/main.c"), - Object(Matching, "REL/m456Dll/stage.c"), + Object(NonMatching, "REL/m456Dll/stage.c"), }, ), Rel( diff --git a/include/math.h b/include/math.h index 8549b25f..389629df 100644 --- a/include/math.h +++ b/include/math.h @@ -10,17 +10,19 @@ #ifdef __MWERKS__ extern inline float sqrtf(float x) { - volatile float y; - if(x > 0.0f) - { - double guess = __frsqrte((double)x); // returns an approximation to - guess = 0.5*guess*(3.0 - guess*guess*x); // now have 12 sig bits - guess = 0.5*guess*(3.0 - guess*guess*x); // now have 24 sig bits - guess = 0.5*guess*(3.0 - guess*guess*x); // now have 32 sig bits - y=(float)(x*guess); - return y; - } - return x; + static const double _half = .5; + static const double _three = 3.0; + volatile float y; + if (x > 0.0f) + { + double guess = __frsqrte((double)x); // returns an approximation to + guess = _half*guess*(_three - guess*guess*x); // now have 12 sig bits + guess = _half*guess*(_three - guess*guess*x); // now have 24 sig bits + guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits + y = (float)(x*guess); + return y ; + } + return x; } #else float sqrtf(float x); diff --git a/include/rel_sqrt_consts.h b/include/rel_sqrt_consts.h index 23ae61cd..fd06a9e9 100644 --- a/include/rel_sqrt_consts.h +++ b/include/rel_sqrt_consts.h @@ -1,8 +1,5 @@ #ifndef _REL_SQRT_CONSTS #define _REL_SQRT_CONSTS -const double __fakeHalf = 0.5; -const double __fakeThree = 3.0; - #endif diff --git a/src/REL/_minigameDLL/_minigameDLL.c b/src/REL/_minigameDLL/_minigameDLL.c index d252a50b..1b4730ee 100644 --- a/src/REL/_minigameDLL/_minigameDLL.c +++ b/src/REL/_minigameDLL/_minigameDLL.c @@ -1,6 +1,6 @@ #include "REL/executor.h" #include "dolphin/os.h" -#include "rel_sqrt_consts.h" +#include "math.h" void ObjectSetup(void) { OSReport("minigame dll setup\n"); diff --git a/src/REL/board_executor.c b/src/REL/board_executor.c index 04e59a3a..3d838c77 100644 --- a/src/REL/board_executor.c +++ b/src/REL/board_executor.c @@ -1,5 +1,5 @@ #include "REL/board_executor.h" -#include "rel_sqrt_consts.h" +#include "math.h" static void ObjectSetup(void) { BoardObjectSetup(BoardCreate, BoardDestroy); diff --git a/src/REL/bootDll/main.c b/src/REL/bootDll/main.c index ce1d563d..b525067a 100644 --- a/src/REL/bootDll/main.c +++ b/src/REL/bootDll/main.c @@ -15,7 +15,6 @@ #include "game/wipe.h" #include "math.h" -#include "rel_sqrt_consts.h" #include "data_num/title.h" diff --git a/src/REL/m437Dll/main.c b/src/REL/m437Dll/main.c index 54af13d9..7b67a481 100755 --- a/src/REL/m437Dll/main.c +++ b/src/REL/m437Dll/main.c @@ -16,7 +16,7 @@ #include "game/wipe.h" #include "dolphin.h" -#include "rel_sqrt_consts.h" +#include "math.h" #include "string.h" typedef struct { diff --git a/src/REL/m446Dll/main.c b/src/REL/m446Dll/main.c index 1988e32d..b73f19e3 100644 --- a/src/REL/m446Dll/main.c +++ b/src/REL/m446Dll/main.c @@ -1,5 +1,5 @@ #include "REL/m446Dll.h" -#include "rel_sqrt_consts.h" +#include "math.h" #include "game/audio.h" #include "game/frand.h" diff --git a/src/REL/m447dll/main.c b/src/REL/m447dll/main.c index a8389fa0..eeb86fd4 100755 --- a/src/REL/m447dll/main.c +++ b/src/REL/m447dll/main.c @@ -11,7 +11,7 @@ #include "game/window.h" #include "game/wipe.h" -#include "rel_sqrt_consts.h" +#include "math.h" typedef struct { /* 0x00 */ s16 unk00; diff --git a/src/REL/modeltestDll/main.c b/src/REL/modeltestDll/main.c index 91b89102..a871df64 100644 --- a/src/REL/modeltestDll/main.c +++ b/src/REL/modeltestDll/main.c @@ -14,6 +14,7 @@ #include "math.h" #include "REL/modeltestDll.h" +#include "math.h" // -------------------------------------------------------------------------- // @@ -28,8 +29,6 @@ s32 lbl_1_data_0[8] = { DATA_MAKE_NUM(DATADIR_MARIOMOT, 0x04), }; -const f64 unk_rodata_0 = 0.5; -const f64 unk_rodata_8 = 3.0; omObjData *lbl_1_bss_9A4; omObjData *lbl_1_bss_9A0; diff --git a/src/REL/mstory4Dll/main.c b/src/REL/mstory4Dll/main.c index ab56c8a5..1bb809d0 100644 --- a/src/REL/mstory4Dll/main.c +++ b/src/REL/mstory4Dll/main.c @@ -8,7 +8,7 @@ #include "game/gamework_data.h" #include "game/flag.h" #include "game/chrman.h" -#include "rel_sqrt_consts.h" +#include "math.h" #include "REL/executor.h" #include "game/board/main.h" diff --git a/src/REL/option/scene.c b/src/REL/option/scene.c index 0edd9959..4eeb4d2b 100755 --- a/src/REL/option/scene.c +++ b/src/REL/option/scene.c @@ -12,7 +12,7 @@ #include "game/sprite.h" #include "game/wipe.h" -#include "rel_sqrt_consts.h" +#include "math.h" typedef struct { /* 0x00 */ s16 id; diff --git a/src/REL/present/init.c b/src/REL/present/init.c index 71813938..2b2d57a5 100644 --- a/src/REL/present/init.c +++ b/src/REL/present/init.c @@ -5,7 +5,7 @@ #include "game/pad.h" #include "game/process.h" #include "game/wipe.h" -#include "rel_sqrt_consts.h" +#include "math.h" #include "REL/present.h" diff --git a/src/REL/safDll/main.c b/src/REL/safDll/main.c index 6b58f683..dfb34d70 100644 --- a/src/REL/safDll/main.c +++ b/src/REL/safDll/main.c @@ -3,7 +3,7 @@ #include "game/gamework_data.h" #include "game/printfunc.h" #include "game/pad.h" -#include "rel_sqrt_consts.h" +#include "math.h" s32 lbl_1_data_0 = 100; s32 lbl_1_bss_0[192]; diff --git a/src/REL/selmenuDll/main.c b/src/REL/selmenuDll/main.c index fda7916f..ad413ed8 100644 --- a/src/REL/selmenuDll/main.c +++ b/src/REL/selmenuDll/main.c @@ -14,8 +14,8 @@ #include "game/pad.h" #include "game/printfunc.h" #include "game/wipe.h" +#include "math.h" -#include "rel_sqrt_consts.h" // MSM Definitions static s8 *msmSeGetIndexPtr(s16 datano); diff --git a/src/REL/staffDll/main.c b/src/REL/staffDll/main.c index 28f1fbc4..0580c6a1 100644 --- a/src/REL/staffDll/main.c +++ b/src/REL/staffDll/main.c @@ -9,7 +9,7 @@ #include "game/window.h" #include "game/wipe.h" -#include "rel_sqrt_consts.h" +#include "math.h" typedef struct StaffData { /* 0x00 */ u32 unk_00; diff --git a/src/REL/subchrselDll/main.c b/src/REL/subchrselDll/main.c index 71911750..7c16e272 100644 --- a/src/REL/subchrselDll/main.c +++ b/src/REL/subchrselDll/main.c @@ -5,7 +5,7 @@ #include "game/pad.h" #include "game/wipe.h" -#include "rel_sqrt_consts.h" +#include "math.h" static void SubchrMain(void);