From b9a1da6a7a229347af744349bd2a8c503908fe36 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Mon, 25 Nov 2024 14:08:57 -0700 Subject: [PATCH] Implement/match Act2Brick (#1169) * Implement/match Act2Brick * Rename functions * Naming --- LEGO1/lego/legoomni/include/act2brick.h | 18 ++-- .../legoomni/include/legocachesoundmanager.h | 1 + LEGO1/lego/legoomni/include/legocachsound.h | 2 +- .../src/audio/legocachesoundmanager.cpp | 44 ++++++++- .../lego/legoomni/src/audio/legocachsound.cpp | 2 +- LEGO1/lego/legoomni/src/entity/act2brick.cpp | 93 ++++++++++++++++--- LEGO1/lego/legoomni/src/entity/legoactor.cpp | 2 +- 7 files changed, 132 insertions(+), 30 deletions(-) diff --git a/LEGO1/lego/legoomni/include/act2brick.h b/LEGO1/lego/legoomni/include/act2brick.h index 332a3cc6..1ff4529e 100644 --- a/LEGO1/lego/legoomni/include/act2brick.h +++ b/LEGO1/lego/legoomni/include/act2brick.h @@ -26,18 +26,22 @@ class Act2Brick : public LegoPathActor { return !strcmp(p_name, Act2Brick::ClassName()) || LegoEntity::IsA(p_name); } - MxResult VTable0x94(LegoPathActor* p_actor, MxBool p_bool) override; // vtable+0x94 + MxResult VTable0x94(LegoPathActor* p_actor, MxBool) override; // vtable+0x94 // SYNTHETIC: LEGO1 0x1007a450 // Act2Brick::`scalar deleting destructor' + void StopSound(); + private: - undefined4 m_unk0x154; // 0x154 - undefined m_unk0x158[0x0c]; // 0x158 - undefined4 m_unk0x164; // 0x164 - Mx3DPointFloat m_unk0x168; // 0x168 - Mx3DPointFloat m_unk0x17c; // 0x17c - undefined4 m_unk0x190; // 0x190 + static MxLong g_lastHitActorTime; + + LegoCacheSound* m_whistleSound; // 0x154 + undefined m_unk0x158[0x0c]; // 0x158 + undefined4 m_unk0x164; // 0x164 + Mx3DPointFloat m_unk0x168; // 0x168 + Mx3DPointFloat m_unk0x17c; // 0x17c + MxS32 m_unk0x190; // 0x190 }; #endif // ACT2BRICK_H diff --git a/LEGO1/lego/legoomni/include/legocachesoundmanager.h b/LEGO1/lego/legoomni/include/legocachesoundmanager.h index 51133c7e..dd9df741 100644 --- a/LEGO1/lego/legoomni/include/legocachesoundmanager.h +++ b/LEGO1/lego/legoomni/include/legocachesoundmanager.h @@ -58,6 +58,7 @@ class LegoCacheSoundManager { LegoCacheSound* ManageSoundEntry(LegoCacheSound* p_sound); LegoCacheSound* Play(const char* p_key, const char* p_name, MxBool p_looping); LegoCacheSound* Play(LegoCacheSound* p_sound, const char* p_name, MxBool p_looping); + void Stop(LegoCacheSound*& p_sound); void Destroy(LegoCacheSound*& p_sound); private: diff --git a/LEGO1/lego/legoomni/include/legocachsound.h b/LEGO1/lego/legoomni/include/legocachsound.h index 593be9d2..196bfb55 100644 --- a/LEGO1/lego/legoomni/include/legocachsound.h +++ b/LEGO1/lego/legoomni/include/legocachsound.h @@ -41,7 +41,7 @@ class LegoCacheSound : public MxCore { LegoCacheSound* Clone(); MxResult Play(const char* p_name, MxBool p_looping); - void FUN_10006b80(); + void Stop(); void FUN_10006be0(); void SetDistance(MxS32 p_min, MxS32 p_max); void Mute(MxBool p_mute); diff --git a/LEGO1/lego/legoomni/src/audio/legocachesoundmanager.cpp b/LEGO1/lego/legoomni/src/audio/legocachesoundmanager.cpp index c18d5dcb..6338b281 100644 --- a/LEGO1/lego/legoomni/src/audio/legocachesoundmanager.cpp +++ b/LEGO1/lego/legoomni/src/audio/legocachesoundmanager.cpp @@ -14,14 +14,14 @@ LegoCacheSoundManager::~LegoCacheSoundManager() while (!m_set.empty()) { sound = (*m_set.begin()).GetSound(); m_set.erase(m_set.begin()); - sound->FUN_10006b80(); + sound->Stop(); delete sound; } while (!m_list.empty()) { sound = (*m_list.begin()).GetSound(); m_list.erase(m_list.begin()); - sound->FUN_10006b80(); + sound->Stop(); // DECOMP: delete should not be inlined here delete sound; } @@ -51,7 +51,7 @@ MxResult LegoCacheSoundManager::Tickle() listIter++; } else { - sound->FUN_10006b80(); + sound->Stop(); m_list.erase(listIter++); delete sound; } @@ -132,6 +132,40 @@ LegoCacheSound* LegoCacheSoundManager::Play(LegoCacheSound* p_sound, const char* return NULL; } +// FUNCTION: LEGO1 0x1003db80 +// FUNCTION: BETA10 0x100656a7 +void LegoCacheSoundManager::Stop(LegoCacheSound*& p_sound) +{ +#ifdef COMPAT_MODE + Set100d6b4c::iterator setIter; + for (setIter = m_set.begin(); setIter != m_set.end(); setIter++) { +#else + for (Set100d6b4c::iterator setIter = m_set.begin(); setIter != m_set.end(); setIter++) { +#endif + if ((*setIter).GetSound() == p_sound) { + p_sound->Stop(); + return; + } + } + +#ifdef COMPAT_MODE + List100d6b4c::iterator listIter; + for (listIter = m_list.begin();; listIter++) { +#else + for (List100d6b4c::iterator listIter = m_list.begin();; listIter++) { +#endif + if (listIter == m_list.end()) { + return; + } + + LegoCacheSound* sound = (*listIter).GetSound(); + if (sound == p_sound) { + p_sound->Stop(); + return; + } + } +} + // FUNCTION: LEGO1 0x1003dc40 void LegoCacheSoundManager::Destroy(LegoCacheSound*& p_sound) { @@ -142,7 +176,7 @@ void LegoCacheSoundManager::Destroy(LegoCacheSound*& p_sound) for (Set100d6b4c::iterator setIter = m_set.begin(); setIter != m_set.end(); setIter++) { #endif if ((*setIter).GetSound() == p_sound) { - p_sound->FUN_10006b80(); + p_sound->Stop(); delete p_sound; m_set.erase(setIter); @@ -162,7 +196,7 @@ void LegoCacheSoundManager::Destroy(LegoCacheSound*& p_sound) LegoCacheSound* sound = (*listIter).GetSound(); if (sound == p_sound) { - p_sound->FUN_10006b80(); + p_sound->Stop(); delete sound; m_list.erase(listIter); diff --git a/LEGO1/lego/legoomni/src/audio/legocachsound.cpp b/LEGO1/lego/legoomni/src/audio/legocachsound.cpp index 7665e5d7..47e9b98c 100644 --- a/LEGO1/lego/legoomni/src/audio/legocachsound.cpp +++ b/LEGO1/lego/legoomni/src/audio/legocachsound.cpp @@ -181,7 +181,7 @@ MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping) } // FUNCTION: LEGO1 0x10006b80 -void LegoCacheSound::FUN_10006b80() +void LegoCacheSound::Stop() { DWORD dwStatus; m_dsBuffer->GetStatus(&dwStatus); diff --git a/LEGO1/lego/legoomni/src/entity/act2brick.cpp b/LEGO1/lego/legoomni/src/entity/act2brick.cpp index fa1408aa..a5811f26 100644 --- a/LEGO1/lego/legoomni/src/entity/act2brick.cpp +++ b/LEGO1/lego/legoomni/src/entity/act2brick.cpp @@ -1,38 +1,101 @@ #include "act2brick.h" +#include "legocachesoundmanager.h" +#include "legosoundmanager.h" +#include "legoworld.h" +#include "misc.h" +#include "mxmisc.h" +#include "mxnotificationmanager.h" +#include "mxnotificationparam.h" +#include "mxticklemanager.h" +#include "mxtimer.h" +#include "roi/legoroi.h" + +#include + DECOMP_SIZE_ASSERT(Act2Brick, 0x194) -// STUB: LEGO1 0x1007a2b0 +// GLOBAL: LEGO1 0x100f7a60 +MxLong Act2Brick::g_lastHitActorTime = 0; + +// FUNCTION: LEGO1 0x1007a2b0 +// FUNCTION: BETA10 0x10012a30 Act2Brick::Act2Brick() { - // TODO + m_whistleSound = NULL; + m_unk0x164 = 0; } -// STUB: LEGO1 0x1007a470 +// FUNCTION: LEGO1 0x1007a470 Act2Brick::~Act2Brick() { - // TODO + TickleManager()->UnregisterClient(this); } -// STUB: LEGO1 0x1007a750 -MxResult Act2Brick::VTable0x94(LegoPathActor* p_actor, MxBool p_bool) +// FUNCTION: LEGO1 0x1007a750 +MxResult Act2Brick::VTable0x94(LegoPathActor* p_actor, MxBool) { - // TODO - return 0; -} + MxLong time = Timer()->GetTime(); + MxLong diff = time - g_lastHitActorTime; -// STUB: LEGO1 0x1007a7f0 -MxResult Act2Brick::Tickle() -{ - // TODO + if (strcmp(p_actor->GetROI()->GetName(), "pepper")) { + return SUCCESS; + } + + g_lastHitActorTime = time; + if (diff > 1000) { + SoundManager()->GetCacheSoundManager()->Play("hitactor", NULL, FALSE); + } return SUCCESS; } -// STUB: LEGO1 0x1007a8c0 +// FUNCTION: LEGO1 0x1007a7f0 +// FUNCTION: BETA10 0x10012d46 +MxResult Act2Brick::Tickle() +{ + MxMatrix local2world(m_roi->GetLocal2World()); + m_unk0x190++; + + if (m_unk0x190 >= 8) { + local2world.SetTranslation(m_unk0x17c[0], m_unk0x17c[1], m_unk0x17c[2]); + m_unk0x164 = 3; + TickleManager()->UnregisterClient(this); + } + else { + VPV3(local2world[3], local2world[3], m_unk0x168); + } + + m_roi->FUN_100a58f0(local2world); + m_roi->VTable0x14(); + return SUCCESS; +} + +// FUNCTION: LEGO1 0x1007a8c0 +// FUNCTION: BETA10 0x10012ec4 MxLong Act2Brick::Notify(MxParam& p_param) { - // TODO + if (((MxNotificationParam&) p_param).GetNotification() == c_notificationClick && m_roi->GetVisibility()) { + m_roi->SetVisibility(FALSE); + + if (m_whistleSound != NULL) { + StopSound(); + } + + MxNotificationParam param(c_notificationType22, this); + NotificationManager()->Send(CurrentWorld(), param); + return 1; + } return 0; } + +// FUNCTION: LEGO1 0x1007a9d0 +// FUNCTION: BETA10 0x1001300f +void Act2Brick::StopSound() +{ + if (m_whistleSound != NULL) { + SoundManager()->GetCacheSoundManager()->Stop(m_whistleSound); + m_whistleSound = NULL; + } +} diff --git a/LEGO1/lego/legoomni/src/entity/legoactor.cpp b/LEGO1/lego/legoomni/src/entity/legoactor.cpp index 927ad4a4..93f7c94b 100644 --- a/LEGO1/lego/legoomni/src/entity/legoactor.cpp +++ b/LEGO1/lego/legoomni/src/entity/legoactor.cpp @@ -26,7 +26,7 @@ LegoActor::LegoActor() LegoActor::~LegoActor() { if (m_sound) { - m_sound->FUN_10006b80(); + m_sound->Stop(); } }