From 3bafe2d3a42dbda9ba6da3d1adf9503c7ad40639 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Sat, 6 Apr 2024 11:46:40 -0400 Subject: [PATCH] Implement/match LegoCharacterManager::FUN_10083f10 (#774) * Implement LegoCharacterManager::FUN_10083f10 * style * Match * Fix naming --- .../legoomni/include/legocharactermanager.h | 10 +++++ LEGO1/lego/legoomni/include/legoentity.h | 1 + .../legoomni/include/legounknown100d5778.h | 4 +- .../src/audio/legounknown100d5778.cpp | 8 ++-- .../src/common/legocharactermanager.cpp | 39 ++++++++++++++++++- 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legocharactermanager.h b/LEGO1/lego/legoomni/include/legocharactermanager.h index 53ef5d55..b86a1dab 100644 --- a/LEGO1/lego/legoomni/include/legocharactermanager.h +++ b/LEGO1/lego/legoomni/include/legocharactermanager.h @@ -25,8 +25,17 @@ struct LegoCharacter { m_roi = p_roi; m_refCount = 1; } + ~LegoCharacter() { delete m_roi; } inline void AddRef() { m_refCount++; } + inline MxU32 RemoveRef() + { + if (m_refCount != 0) { + m_refCount--; + } + + return m_refCount; + } LegoROI* m_roi; // 0x00 MxU32 m_refCount; // 0x04 @@ -65,6 +74,7 @@ class LegoCharacterManager { private: LegoROI* CreateROI(const char* p_key); + void RemoveROI(LegoROI* p_roi); LegoROI* FUN_10084cf0(LegoROI* p_roi, const char* p_name); MxResult FUN_10085870(LegoROI* p_roi); diff --git a/LEGO1/lego/legoomni/include/legoentity.h b/LEGO1/lego/legoomni/include/legoentity.h index 775c4f6f..f8de2914 100644 --- a/LEGO1/lego/legoomni/include/legoentity.h +++ b/LEGO1/lego/legoomni/include/legoentity.h @@ -71,6 +71,7 @@ class LegoEntity : public MxEntity { Mx3DPointFloat GetWorldPosition(); inline MxBool GetUnknown0x10IsSet(MxU8 p_flag) { return m_unk0x10 & p_flag; } + inline MxBool GetFlagsIsSet(MxU8 p_flag) { return m_flags & p_flag; } inline MxU8 GetFlags() { return m_flags; } inline MxFloat GetWorldSpeed() { return m_worldSpeed; } inline LegoROI* GetROI() { return m_roi; } diff --git a/LEGO1/lego/legoomni/include/legounknown100d5778.h b/LEGO1/lego/legoomni/include/legounknown100d5778.h index d04c200c..cb4dd25e 100644 --- a/LEGO1/lego/legoomni/include/legounknown100d5778.h +++ b/LEGO1/lego/legoomni/include/legounknown100d5778.h @@ -24,9 +24,9 @@ class LegoUnknown100d5778 { // LegoUnknown100d5778::`scalar deleting destructor' private: - undefined m_unk0x4[4]; // 0x04 + undefined m_unk0x04[4]; // 0x04 LPDIRECTSOUNDBUFFER m_dsBuffer; // 0x08 - LegoROI* m_unk0xc; // 0x0c + LegoROI* m_unk0x0c; // 0x0c undefined4 m_unk0x10; // 0x10 MxBool m_unk0x14; // 0x14 MxBool m_unk0x15; // 0x15 diff --git a/LEGO1/lego/legoomni/src/audio/legounknown100d5778.cpp b/LEGO1/lego/legoomni/src/audio/legounknown100d5778.cpp index ecb39b3b..03fe9752 100644 --- a/LEGO1/lego/legoomni/src/audio/legounknown100d5778.cpp +++ b/LEGO1/lego/legoomni/src/audio/legounknown100d5778.cpp @@ -22,7 +22,7 @@ LegoUnknown100d5778::~LegoUnknown100d5778() void LegoUnknown100d5778::Init() { m_dsBuffer = NULL; - m_unk0xc = NULL; + m_unk0x0c = NULL; m_unk0x10 = 0; m_unk0x18 = 0; m_unk0x14 = FALSE; @@ -57,12 +57,12 @@ void LegoUnknown100d5778::Destroy() m_dsBuffer = NULL; } - if (m_unk0x14 && m_unk0xc && CharacterManager()) { + if (m_unk0x14 && m_unk0x0c && CharacterManager()) { if (m_unk0x15) { - CharacterManager()->FUN_10083db0(m_unk0xc); + CharacterManager()->FUN_10083db0(m_unk0x0c); } else { - CharacterManager()->FUN_10083f10(m_unk0xc); + CharacterManager()->FUN_10083f10(m_unk0x0c); } } diff --git a/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp b/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp index 5928c5c1..766cf205 100644 --- a/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp @@ -242,10 +242,45 @@ void LegoCharacterManager::FUN_10083db0(LegoROI* p_roi) // TODO } -// STUB: LEGO1 0x10083f10 +// FUNCTION: LEGO1 0x10083f10 void LegoCharacterManager::FUN_10083f10(LegoROI* p_roi) { - // TODO + LegoCharacter* character = NULL; + LegoCharacterMap::iterator it; + + for (it = m_characters->begin(); it != m_characters->end(); it++) { + character = (*it).second; + + if (character->m_roi == p_roi) { + if (character->RemoveRef() == 0) { + LegoEntity* entity = character->m_roi->GetEntity(); + + if (entity != NULL) { + entity->SetROI(NULL, FALSE, FALSE); + } + + RemoveROI(character->m_roi); + + delete[] const_cast((*it).first); + delete (*it).second; + + m_characters->erase(it); + + if (entity != NULL && entity->GetFlagsIsSet(LegoEntity::c_bit2)) { + entity->ClearFlag(LegoEntity::c_bit2); + delete entity; + } + } + + return; + } + } +} + +// FUNCTION: LEGO1 0x10084010 +void LegoCharacterManager::RemoveROI(LegoROI* p_roi) +{ + VideoManager()->Get3DManager()->Remove(*p_roi); } // FUNCTION: LEGO1 0x10084030