From 3383ae646f04314f2e8e04a44f71d00b7a61b730 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 15 Nov 2024 14:51:46 -0700 Subject: [PATCH] Implement/match LegoBuildingManager::Tickle (#1156) --- .../legoomni/include/legocachesoundmanager.h | 3 +- LEGO1/lego/legoomni/include/legoracers.h | 2 + .../src/common/legobuildingmanager.cpp | 77 +++++++++++++++++-- LEGO1/lego/legoomni/src/race/legoracers.cpp | 12 +-- LEGO1/tgl/d3drm/renderer.cpp | 6 +- 5 files changed, 81 insertions(+), 19 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legocachesoundmanager.h b/LEGO1/lego/legoomni/include/legocachesoundmanager.h index 9b94de83..51133c7e 100644 --- a/LEGO1/lego/legoomni/include/legocachesoundmanager.h +++ b/LEGO1/lego/legoomni/include/legocachesoundmanager.h @@ -57,11 +57,10 @@ class LegoCacheSoundManager { LegoCacheSound* FindSoundByKey(const char* p_key); 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 Destroy(LegoCacheSound*& p_sound); private: - LegoCacheSound* Play(LegoCacheSound* p_sound, const char* p_name, MxBool p_looping); - Set100d6b4c m_set; // 0x04 List100d6b4c m_list; // 0x14 }; diff --git a/LEGO1/lego/legoomni/include/legoracers.h b/LEGO1/lego/legoomni/include/legoracers.h index add7d795..9b460dee 100644 --- a/LEGO1/lego/legoomni/include/legoracers.h +++ b/LEGO1/lego/legoomni/include/legoracers.h @@ -115,6 +115,8 @@ class LegoRaceCar : public LegoCarRaceActor, public LegoRaceMap { static MxLong g_timeLastSoundPlayed; static MxS32 g_unk0x100f0b88; static MxBool g_unk0x100f0b8c; + static undefined4 g_unk0x100f0bac; + static undefined4 g_unk0x100f0bb0; }; #endif // LEGORACERS_H diff --git a/LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp b/LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp index b2582346..d61313bd 100644 --- a/LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp @@ -13,6 +13,8 @@ #include "mxticklemanager.h" #include "mxtimer.h" +#include + DECOMP_SIZE_ASSERT(LegoBuildingManager, 0x30) DECOMP_SIZE_ASSERT(LegoBuildingInfo, 0x2c) DECOMP_SIZE_ASSERT(LegoBuildingManager::AnimEntry, 0x14) @@ -682,18 +684,77 @@ void LegoBuildingManager::ScheduleAnimation(LegoEntity* p_entity, MxLong p_lengt FUN_100307b0(p_entity, -2); } -// STUB: LEGO1 0x10030220 +// FUNCTION: LEGO1 0x10030220 MxResult LegoBuildingManager::Tickle() { - // WIP, included some of this to understand the AnimEntry array. - LegoTime time = Timer()->GetTime(); + MxLong time = Timer()->GetTime(); if (m_numEntries != 0) { - if (m_numEntries > 0) { - for (MxS32 i = 0; i < m_numEntries; i++) { - AnimEntry* entry = m_entries[i]; - if (entry->m_time <= time) { - // Code to animate and play sounds + for (MxS32 i = 0; i < m_numEntries; i++) { + AnimEntry** ppEntry = &m_entries[i]; + AnimEntry* entry = *ppEntry; + + if (m_world != CurrentWorld() || !entry->m_entity) { + delete entry; + m_numEntries--; + + if (m_numEntries != i) { + m_entries[i] = m_entries[m_numEntries]; + m_entries[m_numEntries] = NULL; + } + + break; + } + + if (entry->m_time - time > 1000) { + break; + } + + if (!entry->m_muted) { + entry->m_muted = TRUE; + SoundManager()->GetCacheSoundManager()->Play(m_sound, entry->m_roi->GetName(), FALSE); + } + + MxMatrix local48; + MxMatrix locald8; + + MxMatrix local120(entry->m_roi->GetLocal2World()); + Mx3DPointFloat local134(local120[3]); + + ZEROVEC3(local120[3]); + + locald8.SetIdentity(); + local48 = local120; + + local134[1] = sin(((entry->m_time - time) * 10) * 0.0062831999f) * 0.4 + (entry->m_unk0x0c -= 0.05); + SET3(local120[3], local134); + + entry->m_roi->UpdateTransformationRelativeToParent(local120); + VideoManager()->Get3DManager()->Moved(*entry->m_roi); + + if (entry->m_time < time) { + LegoBuildingInfo* info = GetInfo(entry->m_entity); + + if (info->m_unk0x11 && !m_unk0x28) { + MxS32 index = info - g_buildingInfo; + AdjustHeight(index); + MxMatrix mat = entry->m_roi->GetLocal2World(); + mat[3][1] = g_buildingInfo[index].m_unk0x014; + entry->m_roi->UpdateTransformationRelativeToParent(mat); + VideoManager()->Get3DManager()->Moved(*entry->m_roi); + } + else { + info->m_unk0x11 = 0; + entry->m_roi->SetVisibility(FALSE); + } + + delete entry; + m_numEntries--; + + if (m_numEntries != i) { + i--; + *ppEntry = m_entries[m_numEntries]; + m_entries[m_numEntries] = NULL; } } } diff --git a/LEGO1/lego/legoomni/src/race/legoracers.cpp b/LEGO1/lego/legoomni/src/race/legoracers.cpp index 472421ec..73a070cd 100644 --- a/LEGO1/lego/legoomni/src/race/legoracers.cpp +++ b/LEGO1/lego/legoomni/src/race/legoracers.cpp @@ -21,12 +21,6 @@ DECOMP_SIZE_ASSERT(EdgeReference, 0x08) DECOMP_SIZE_ASSERT(SkeletonKickPhase, 0x10) DECOMP_SIZE_ASSERT(LegoRaceCar, 0x200) -// GLOBAL: LEGO1 0x100f0bac -static undefined4 g_unk0x100f0bac = 0; - -// GLOBAL: LEGO1 0x100f0bb0 -static undefined4 g_unk0x100f0bb0 = 0; - // GLOBAL: LEGO1 0x100f0a20 // GLOBAL: BETA10 0x101f5e34 EdgeReference LegoRaceCar::g_skBMap[] = { @@ -142,6 +136,12 @@ MxS32 LegoRaceCar::g_unk0x100f0b88 = 0; // GLOBAL: BETA10 0x101f5f98 MxBool LegoRaceCar::g_unk0x100f0b8c = TRUE; +// GLOBAL: LEGO1 0x100f0bac +undefined4 LegoRaceCar::g_unk0x100f0bac = 0; + +// GLOBAL: LEGO1 0x100f0bb0 +undefined4 LegoRaceCar::g_unk0x100f0bb0 = 0; + // Initialized at LEGO1 0x10012db0 // GLOBAL: LEGO1 0x10102af0 // GLOBAL: BETA10 0x102114c0 diff --git a/LEGO1/tgl/d3drm/renderer.cpp b/LEGO1/tgl/d3drm/renderer.cpp index 6a20053a..c310b996 100644 --- a/LEGO1/tgl/d3drm/renderer.cpp +++ b/LEGO1/tgl/d3drm/renderer.cpp @@ -46,12 +46,12 @@ Device* RendererImpl::CreateDevice(const DeviceDirect3DCreateData& data) return device; } -// GLOBAL: LEGO1 0x10101040 -static int g_SetBufferCount = 1; - // FUNCTION: LEGO1 0x100a1900 Device* RendererImpl::CreateDevice(const DeviceDirectDrawCreateData& data) { + // GLOBAL: LEGO1 0x10101040 + static int g_SetBufferCount = 1; + DeviceImpl* device = new DeviceImpl(); HRESULT result = m_data->CreateDeviceFromSurface( const_cast(data.m_driverGUID),