From 9d80cf4824f91c3fba27f709677c96bbe8894c3b Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Tue, 12 Mar 2024 14:11:13 -0400 Subject: [PATCH 1/3] Implement/match LegoAnimNodeData::FUN_100a0990 (#662) --- LEGO1/lego/sources/anim/legoanim.cpp | 24 ++++++++++++++++++++---- LEGO1/lego/sources/anim/legoanim.h | 7 +++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/LEGO1/lego/sources/anim/legoanim.cpp b/LEGO1/lego/sources/anim/legoanim.cpp index c721487a..d11efc4d 100644 --- a/LEGO1/lego/sources/anim/legoanim.cpp +++ b/LEGO1/lego/sources/anim/legoanim.cpp @@ -289,7 +289,7 @@ LegoAnimNodeData::LegoAnimNodeData() m_translationIndex = 0; m_rotationIndex = 0; m_scaleIndex = 0; - m_unk0x30 = 0; + m_morphIndex = 0; } // FUNCTION: LEGO1 0x1009fda0 @@ -605,11 +605,27 @@ inline void LegoAnimNodeData::GetScale( p_matrix.Scale(x, y, z); } -// STUB: LEGO1 0x100a0990 +// FUNCTION: LEGO1 0x100a0990 LegoBool LegoAnimNodeData::FUN_100a0990(LegoFloat p_time) { - // TODO - return TRUE; + LegoU32 i, n; + LegoU32 index = GetMorphIndex(); + LegoBool result; + + n = FindKeys(p_time, m_numMorphKeys, m_morphKeys, sizeof(*m_morphKeys), i, index); + SetMorphIndex(index); + + switch (n) { + case 0: + result = TRUE; + break; + case 1: + case 2: + result = m_morphKeys[i].GetUnknown0x08(); + break; + } + + return result; } // STUB: LEGO1 0x100a0a00 diff --git a/LEGO1/lego/sources/anim/legoanim.h b/LEGO1/lego/sources/anim/legoanim.h index ab0aedc7..960d7c90 100644 --- a/LEGO1/lego/sources/anim/legoanim.h +++ b/LEGO1/lego/sources/anim/legoanim.h @@ -90,9 +90,10 @@ class LegoMorphKey : public LegoAnimKey { public: LegoMorphKey(); LegoResult Read(LegoStorage* p_storage); + LegoBool GetUnknown0x08() { return m_unk0x08; } protected: - undefined m_unk0x08; // 0x08 + LegoBool m_unk0x08; // 0x08 }; // SIZE 0x0c @@ -121,10 +122,12 @@ class LegoAnimNodeData : public LegoTreeNodeData { LegoU32 GetTranslationIndex() { return m_translationIndex; } LegoU32 GetRotationIndex() { return m_rotationIndex; } LegoU32 GetScaleIndex() { return m_scaleIndex; } + LegoU32 GetMorphIndex() { return m_morphIndex; } void SetTranslationIndex(LegoU32 p_translationIndex) { m_translationIndex = p_translationIndex; } void SetRotationIndex(LegoU32 p_rotationIndex) { m_rotationIndex = p_rotationIndex; } void SetScaleIndex(LegoU32 p_scaleIndex) { m_scaleIndex = p_scaleIndex; } + void SetMorphIndex(LegoU32 p_morphIndex) { m_morphIndex = p_morphIndex; } LegoResult CreateLocalTransform(LegoTime p_time, Matrix4& p_matrix) { @@ -188,7 +191,7 @@ class LegoAnimNodeData : public LegoTreeNodeData { LegoU32 m_translationIndex; // 0x24 LegoU32 m_rotationIndex; // 0x28 LegoU32 m_scaleIndex; // 0x2c - undefined4 m_unk0x30; // 0x30 + LegoU32 m_morphIndex; // 0x30 }; // SIZE 0x08 From 62a3f5028784782a1ca73e22b828dc2ea2b9efd6 Mon Sep 17 00:00:00 2001 From: MS Date: Tue, 12 Mar 2024 14:27:24 -0400 Subject: [PATCH 2/3] KeyValueStringParse closer to beta version (#656) * KeyValueStringParse closer to beta version * Line numbers out --- LEGO1/omni/src/common/mxutilities.cpp | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/LEGO1/omni/src/common/mxutilities.cpp b/LEGO1/omni/src/common/mxutilities.cpp index 052ab57c..7030848c 100644 --- a/LEGO1/omni/src/common/mxutilities.cpp +++ b/LEGO1/omni/src/common/mxutilities.cpp @@ -9,6 +9,8 @@ #include "mxpresenterlist.h" #include "mxrect32.h" +#include + // GLOBAL: LEGO1 0x101020e8 void (*g_omniUserMessage)(const char*, int) = NULL; @@ -78,39 +80,37 @@ void MakeSourceName(char* p_output, const char* p_input) } // FUNCTION: LEGO1 0x100b7050 -MxBool KeyValueStringParse(char* p_outputValue, const char* p_key, const char* p_source) +MxBool KeyValueStringParse(char* p_output, const char* p_command, const char* p_string) { MxBool didMatch = FALSE; + assert(p_string); + assert(p_command); - MxS16 len = strlen(p_source); - char* temp = new char[len + 1]; - strcpy(temp, p_source); + MxS16 len = strlen(p_string); + char* string = new char[len + 1]; + assert(string); + strcpy(string, p_string); - char* token = strtok(temp, ", \t\r\n:"); - while (token) { + for (char* token = strtok(string, ", \t\r\n:"); token; token = strtok(NULL, ", \t\r\n:")) { len -= (strlen(token) + 1); - if (strcmpi(token, p_key) == 0) { - if (p_outputValue && len > 0) { - char* cur = &token[strlen(p_key)]; + if (strcmpi(token, p_command) == 0) { + if (p_output && len > 0) { + char* output = p_output; + char* cur = &token[strlen(p_command)]; cur++; - while (*cur != ',') { - if (*cur == ' ' || *cur == '\0' || *cur == '\t' || *cur == '\n' || *cur == '\r') { - break; - } - *p_outputValue++ = *cur++; + while (*cur != ',' && *cur != ' ' && *cur != '\0' && *cur != '\t' && *cur != '\n' && *cur != '\r') { + *output++ = *cur++; } - *p_outputValue = '\0'; + *output = '\0'; } didMatch = TRUE; break; } - - token = strtok(NULL, ", \t\r\n:"); } - delete[] temp; + delete[] string; return didMatch; } From dcc3946a084943480738daecc63eac2efc753a36 Mon Sep 17 00:00:00 2001 From: MS Date: Tue, 12 Mar 2024 14:59:39 -0400 Subject: [PATCH 3/3] Separate MxCore counter (#663) --- LEGO1/define.cpp | 10 ---------- LEGO1/define.h | 1 - LEGO1/omni/include/mxcore.h | 1 + LEGO1/omni/include/mxsoundmanager.h | 2 +- LEGO1/omni/src/audio/mxsoundmanager.cpp | 23 ++++++++++++++++++----- LEGO1/omni/src/audio/mxwavepresenter.cpp | 2 +- LEGO1/omni/src/common/mxcore.cpp | 10 +++++++--- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/LEGO1/define.cpp b/LEGO1/define.cpp index 1e403a50..82dafb7d 100644 --- a/LEGO1/define.cpp +++ b/LEGO1/define.cpp @@ -1,15 +1,5 @@ #include "define.h" -// GLOBAL: LEGO1 0x1010141c -MxS32 g_mxcoreCount[101] = {0, -6643, -5643, -5058, -4643, -4321, -4058, -3836, -3643, -3473, -3321, -3184, -3058, - -2943, -2836, -2736, -2643, -2556, -2473, -2395, -2321, -2251, -2184, -2120, -2058, -2000, - -1943, -1888, -1836, -1785, -1736, -1689, -1643, -1599, -1556, -1514, -1473, -1434, -1395, - -1358, -1321, -1286, -1251, -1217, -1184, -1152, -1120, -1089, -1058, -1029, -1000, -971, - -943, -915, -888, -862, -836, -810, -785, -761, -736, -713, -689, -666, -643, - -621, -599, -577, -556, -535, -514, -494, -473, -454, -434, -415, -395, -377, - -358, -340, -321, -304, -286, -268, -251, -234, -217, -200, -184, -168, -152, - -136, -120, -104, -89, -74, -58, -43, -29, -14, 0}; - // GLOBAL: LEGO1 0x10102048 // STRING: LEGO1 0x10102040 const char* g_strACTION = "ACTION"; diff --git a/LEGO1/define.h b/LEGO1/define.h index d45d02c3..84400d36 100644 --- a/LEGO1/define.h +++ b/LEGO1/define.h @@ -3,7 +3,6 @@ #include "mxtypes.h" -extern MxS32 g_mxcoreCount[101]; extern const char* g_parseExtraTokens; extern const char* g_strWORLD; extern const char* g_strSOUND; diff --git a/LEGO1/omni/include/mxcore.h b/LEGO1/omni/include/mxcore.h index dc167f2b..90fdb7b1 100644 --- a/LEGO1/omni/include/mxcore.h +++ b/LEGO1/omni/include/mxcore.h @@ -38,6 +38,7 @@ class MxCore { // MxCore::`scalar deleting destructor' private: + static MxU32 g_nextCoreId; MxU32 m_id; // 0x04 }; diff --git a/LEGO1/omni/include/mxsoundmanager.h b/LEGO1/omni/include/mxsoundmanager.h index 24e7111a..8d1d573d 100644 --- a/LEGO1/omni/include/mxsoundmanager.h +++ b/LEGO1/omni/include/mxsoundmanager.h @@ -22,7 +22,7 @@ class MxSoundManager : public MxAudioManager { inline LPDIRECTSOUND GetDirectSound() { return m_directSound; } - MxS32 FUN_100aecf0(MxU32 p_undefined); + MxS32 GetAttenuation(MxU32 p_volume); protected: void Init(); diff --git a/LEGO1/omni/src/audio/mxsoundmanager.cpp b/LEGO1/omni/src/audio/mxsoundmanager.cpp index 0d9359e6..583d1dfc 100644 --- a/LEGO1/omni/src/audio/mxsoundmanager.cpp +++ b/LEGO1/omni/src/audio/mxsoundmanager.cpp @@ -1,6 +1,5 @@ #include "mxsoundmanager.h" -#include "define.h" #include "mxautolock.h" #include "mxmisc.h" #include "mxomni.h" @@ -10,6 +9,17 @@ DECOMP_SIZE_ASSERT(MxSoundManager, 0x3c); +// GLOBAL LEGO1 0x10101420 +MxS32 g_volumeAttenuation[100] = {-6643, -5643, -5058, -4643, -4321, -4058, -3836, -3643, -3473, -3321, -3184, -3058, + -2943, -2836, -2736, -2643, -2556, -2473, -2395, -2321, -2251, -2184, -2120, -2058, + -2000, -1943, -1888, -1836, -1785, -1736, -1689, -1643, -1599, -1556, -1514, -1473, + -1434, -1395, -1358, -1321, -1286, -1251, -1217, -1184, -1152, -1120, -1089, -1058, + -1029, -1000, -971, -943, -915, -888, -862, -836, -810, -785, -761, -736, + -713, -689, -666, -643, -621, -599, -577, -556, -535, -514, -494, -473, + -454, -434, -415, -395, -377, -358, -340, -321, -304, -286, -268, -251, + -234, -217, -200, -184, -168, -152, -136, -120, -104, -89, -74, -58, + -43, -29, -14, 0}; + // FUNCTION: LEGO1 0x100ae740 MxSoundManager::MxSoundManager() { @@ -184,12 +194,15 @@ MxPresenter* MxSoundManager::FUN_100aebd0(const MxAtomId& p_atomId, MxU32 p_obje } // FUNCTION: LEGO1 0x100aecf0 -MxS32 MxSoundManager::FUN_100aecf0(MxU32 p_undefined) +MxS32 MxSoundManager::GetAttenuation(MxU32 p_volume) { - if (!p_undefined) { - return -10000; + // The unit for p_volume is percent, rounded to integer. + // Convert to DSOUND attenuation units: -10000 (silent) to 0 (loudest). + if (p_volume == 0) { + return DSBVOLUME_MIN; } - return g_mxcoreCount[p_undefined]; + + return g_volumeAttenuation[p_volume - 1]; } // FUNCTION: LEGO1 0x100aed10 diff --git a/LEGO1/omni/src/audio/mxwavepresenter.cpp b/LEGO1/omni/src/audio/mxwavepresenter.cpp index bd02bf8d..defb20f6 100644 --- a/LEGO1/omni/src/audio/mxwavepresenter.cpp +++ b/LEGO1/omni/src/audio/mxwavepresenter.cpp @@ -297,7 +297,7 @@ void MxWavePresenter::SetVolume(MxS32 p_volume) m_volume = p_volume; if (m_dsBuffer != NULL) { MxS32 volume = p_volume * MxOmni::GetInstance()->GetSoundManager()->GetVolume() / 100; - MxS32 otherVolume = MxOmni::GetInstance()->GetSoundManager()->FUN_100aecf0(volume); + MxS32 otherVolume = MxOmni::GetInstance()->GetSoundManager()->GetAttenuation(volume); m_dsBuffer->SetVolume(otherVolume); } diff --git a/LEGO1/omni/src/common/mxcore.cpp b/LEGO1/omni/src/common/mxcore.cpp index 1266a1cb..c07cc51a 100644 --- a/LEGO1/omni/src/common/mxcore.cpp +++ b/LEGO1/omni/src/common/mxcore.cpp @@ -1,12 +1,15 @@ #include "mxcore.h" -#include "define.h" +#include + +// GLOBAL: LEGO1 0x1010141c +MxU32 MxCore::g_nextCoreId = 0; // FUNCTION: LEGO1 0x100ae1a0 MxCore::MxCore() { - m_id = (MxU32) g_mxcoreCount[0]; - g_mxcoreCount[0]++; + m_id = g_nextCoreId++; + assert(g_nextCoreId); } // FUNCTION: LEGO1 0x100ae1e0 @@ -17,5 +20,6 @@ MxCore::~MxCore() // FUNCTION: LEGO1 0x100ae1f0 MxLong MxCore::Notify(MxParam& p_param) { + assert(0); return 0; }