From ed63ba658c5cbc5393f49343c00089002a17c71e Mon Sep 17 00:00:00 2001 From: escape209 Date: Sat, 31 Aug 2024 14:01:45 +0100 Subject: [PATCH] Assorted matches (#358) --- src/SB/Core/gc/iSnd.cpp | 33 ++++++++++-------- src/SB/Core/x/xBehaveMgr.cpp | 2 -- src/SB/Game/zActionLine.cpp | 1 - src/SB/Game/zTaskBox.cpp | 10 +++--- src/SB/Game/zThrown.cpp | 27 +++++++-------- src/SB/Game/zVar.cpp | 67 ++++++++++++++++-------------------- 6 files changed, 66 insertions(+), 74 deletions(-) diff --git a/src/SB/Core/gc/iSnd.cpp b/src/SB/Core/gc/iSnd.cpp index cea65eb0..d0f57221 100644 --- a/src/SB/Core/gc/iSnd.cpp +++ b/src/SB/Core/gc/iSnd.cpp @@ -1,5 +1,7 @@ #include "iSnd.h" +#include "intrin.h" + #include #include "dolphin/dolphin.h" @@ -40,23 +42,22 @@ void iSndInitSceneLoaded() { } -#ifdef NON_MATCHING U32 iVolFromX(F32 param1) { - float f = MAX(param1, _1263); + float f = MAX(param1, 1e-20f); - S32 i = _1262 * xlog(f); - i = (i & i >> 0x1f); - if (i < -0x388) + S32 i = 43.43f * xlog(f); + S32 comp = i & (i >> 0x1f); + + if (comp < -0x388) { return -0x388; } else { - return (i & i >> 0x1f); + return i & (i >> 0x3f); } } -#endif void iSndVolUpdate(xSndVoiceInfo* info, vinfo* vinfo) { @@ -122,12 +123,11 @@ void iSndWaitForDeadSounds() } #endif -// void iSndSuspendCD(U32) { } -void iSndMessWithEA(sDSPADPCM* param1) //sDSPADPCM* +void iSndMessWithEA(sDSPADPCM* param1) { if (param1 != NULL) { @@ -135,15 +135,18 @@ void iSndMessWithEA(sDSPADPCM* param1) //sDSPADPCM* } } -#if 0 U32 SampleToNybbleAddress(U32 sample) { - U32 i = sample * 0x124924925U >> 0x20; - i = i & 0xfffffff0; - i = i + sample % 0xe + 2; - return i; + U32 a = __mulhwu(0x24924925, sample); + U32 b = (sample - a) >> 1; + + a = b + a; + b = (a >> 3); + a = (a << 1) & 0xfffffff0; + a = a + (sample - (b * 0xe)) + 2; + + return a; } -#endif void sndloadcb(tag_xFile* tag) { diff --git a/src/SB/Core/x/xBehaveMgr.cpp b/src/SB/Core/x/xBehaveMgr.cpp index 3687c6c8..631909d8 100644 --- a/src/SB/Core/x/xBehaveMgr.cpp +++ b/src/SB/Core/x/xBehaveMgr.cpp @@ -8,7 +8,6 @@ extern S32 g_modinit_xBehaveMgr; extern xBehaveMgr* g_behavmgr; -#ifdef NON_MATCHING void xBehaveMgr_Startup() { if (g_modinit_xBehaveMgr++ == 0) @@ -17,7 +16,6 @@ void xBehaveMgr_Startup() g_behavmgr->Startup(0xfa, 0xfa); } } -#endif #if 0 void xBehaveMgr_Shutdown() diff --git a/src/SB/Game/zActionLine.cpp b/src/SB/Game/zActionLine.cpp index af387da0..ee49855f 100644 --- a/src/SB/Game/zActionLine.cpp +++ b/src/SB/Game/zActionLine.cpp @@ -26,7 +26,6 @@ void zActionLineInit() } } -// Equivalent. Compiler is optimizing out the reduntant float load. void zActionLineUpdate(F32 seconds) { for (S32 i = 0; i < 8; i++) diff --git a/src/SB/Game/zTaskBox.cpp b/src/SB/Game/zTaskBox.cpp index 853c068b..5ea1cc1a 100644 --- a/src/SB/Game/zTaskBox.cpp +++ b/src/SB/Game/zTaskBox.cpp @@ -172,8 +172,6 @@ void ztaskbox::fail() } } -#if 0 -// Why does the compiler add a random compare at the end???? void ztaskbox::complete() { if (this->flag.enabled) @@ -182,11 +180,15 @@ void ztaskbox::complete() this->flag.enabled = false; zEntEvent(this, this, eEventTaskBox_OnComplete); this->current = (ztaskbox*)zSceneFindObject(this->asset->next_task); + + // Bruh + if (this->current != NULL) + { + return; + } } } -#endif - void ztaskbox::set_callback(callback* cb) { this->cb = cb; diff --git a/src/SB/Game/zThrown.cpp b/src/SB/Game/zThrown.cpp index bd3961b5..6486c6a9 100644 --- a/src/SB/Game/zThrown.cpp +++ b/src/SB/Game/zThrown.cpp @@ -43,20 +43,22 @@ void Recurse_TranslateStack(xEnt* ent, xVec3* delta) sDebugDepth--; } -#if 0 -// WIP. void zThrown_PatrickLauncher(xEnt* ent, xEnt* launcher) { - for (U32 i = 0; i < zThrownCount; i++) + int i = 0; + + for (; i < zThrownCount; i++) { if (ent == zThrownList[i].ent) - { - zThrownList[i].patLauncher = launcher; - } + break; } -} -#endif + if (i != zThrownCount) + { + zThrownStruct* listInd = &zThrownList[i]; + listInd->patLauncher = launcher; + } +} void zThrownCollide_ThrowFreeze(zThrownStruct* thrown, xEntCollis* collis, float* bounce, float* friction) @@ -117,23 +119,18 @@ S32 zThrown_IsFruit(xEnt* ent, F32* stackHeight) #endif -#if 0 -// Random OR added in. void checkAgainstButtons(xEnt* ent) { - xVec3* d = xBoundCenter(&ent->bound); struct { xVec3 center; F32 unk; } data; - xVec3Copy(&data.center, d); - data.unk = _842; + xVec3Copy(&data.center, xBoundCenter(&ent->bound)); + data.unk = 0.5f; zSceneForAllBase(zThrown_ButtonIteratorCB, 0x18, (void*)&data); } -#endif - void xDrawSphere(const xSphere*, U32) { } diff --git a/src/SB/Game/zVar.cpp b/src/SB/Game/zVar.cpp index c888bddf..d34d70f5 100644 --- a/src/SB/Game/zVar.cpp +++ b/src/SB/Game/zVar.cpp @@ -567,29 +567,30 @@ U32 zVarEntryCB_SndMode(void* arg) return gSnd.stereo; } -#if 0 -// Can't get the fp register assignment right for these regardless of what -// order I put the three expressions in. -extern F64 volumeMod1; -extern F64 volumeMod2; - U32 zVarEntryCB_SndMusicVol(void* arg) { - return volumeMod2 + gSnd.categoryVolFader[2] * volumeMod1; + F64 f0 = 10.0; + F64 f1 = 0.5; + F64 f2 = gSnd.categoryVolFader[2]; + + f2 *= f1; + f2 = f0 + f2; + + return f2; } U32 zVarEntryCB_SndFXVol(void* arg) { - return volumeMod2 + gSnd.categoryVolFader[0] * volumeMod1; + F64 f0 = 10.0; + F64 f1 = 0.5; + F64 f2 = gSnd.categoryVolFader[0]; + + f2 *= f1; + f2 = f0 + f2; + + return f2; } -#endif -#if 0 -// The branching in this function is totally stupid, no idea how to untangle -// what they originally wrote here because the code makes no sense. I think -// that it might be trying to return the number of save games which aren't -// empty, but is had a bug where one of the calls is xSGGameIsEmpty(NULL, 0) -// instead of xSGGameIsEmpty(NULL, 2) thanks to a copy-paste error. U32 zVarEntryCB_MCAvailable(void* arg) { if (xSGGameIsEmpty(NULL, 0) == 1) @@ -598,33 +599,25 @@ U32 zVarEntryCB_MCAvailable(void* arg) { return 0; } - else if (xSGGameIsEmpty(NULL, 1) == 0) - { - return 0; - } - else + if (xSGGameIsEmpty(NULL, 1) == 0) { return 2; } } - else if (xSGGameIsEmpty(NULL, 0)) - { - return 0; - } - else if (xSGGameIsEmpty(NULL, 1)) - { - return 1; - } - else if (xSGGameIsEmpty(NULL, 1)) + else if (xSGGameIsEmpty(NULL, 0) == 0) { - return 0; - } - else - { - return 3; + if (xSGGameIsEmpty(NULL, 1) == 1) + { + return 1; + } + if (xSGGameIsEmpty(NULL, 1) == 0) + { + return 3; + } } + + return 0; } -#endif U32 zVarEntryCB_VibrationOn(void* arg) { @@ -633,7 +626,7 @@ U32 zVarEntryCB_VibrationOn(void* arg) return globals.option_vibration & 0x1; } -S32 zVarEntryCB_CurrentSceneLetter() +S32 zVarEntryCB_CurrentSceneLetter(void*) { char buffer[16]; sprintf(buffer, &zVar_strings[0x10] /*"%s"*/, xUtil_idtag2string(globals.sceneCur->sceneID, 0)); @@ -655,7 +648,7 @@ S32 zVarEntryCB_CurrentSceneLetter() return (mostSignificantChar - 'A') + 1; } -S32 zVarEntryCB_CurrentRoom() +S32 zVarEntryCB_CurrentRoom(void*) { char buffer[16]; sprintf(buffer, &zVar_strings[0x10] /*"%s"*/, xUtil_idtag2string(globals.sceneCur->sceneID, 0));