From 78d32b6bcf66228f1fa981db5a5b8f63e0a1fa30 Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Wed, 21 Aug 2024 21:47:25 +0300 Subject: [PATCH] Use method access --- Client/game_sa/CDummyPoolSA.cpp | 40 ++++++++++++++++++--------------- Client/game_sa/CDummyPoolSA.h | 4 ++++ Client/game_sa/CEntitySA.h | 3 +++ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Client/game_sa/CDummyPoolSA.cpp b/Client/game_sa/CDummyPoolSA.cpp index 5985bcfbf9..1b7bf87d65 100644 --- a/Client/game_sa/CDummyPoolSA.cpp +++ b/Client/game_sa/CDummyPoolSA.cpp @@ -79,28 +79,32 @@ void CDummyPoolSA::UpdateBuildingLods(void* oldPool, void* newPool) const std::uint32_t offset = (std::uint32_t)newPool - (std::uint32_t)oldPool; if (m_pOriginalElementsBackup) + UpdateBackupLodOffset(offset); + else + UpdateLodsOffestInPool(offset); +} + +void CDummyPoolSA::UpdateBackupLodOffset(const std::uint32_t offset) +{ + for (auto i = 0; i < (*m_pOriginalElementsBackup).size(); i++) { - for (auto i = 0; i < (*m_pOriginalElementsBackup).size(); i++) + if ((*m_pOriginalElementsBackup)[i].first) { - if ((*m_pOriginalElementsBackup)[i].first) - { - CEntitySAInterface* object = &(*m_pOriginalElementsBackup)[i].second; - if (object->m_pLod) - { - object->m_pLod = (CEntitySAInterface*)((std::uint32_t)(object->m_pLod) + offset); - } - } + CEntitySAInterface* object = &(*m_pOriginalElementsBackup)[i].second; + CEntitySAInterface* lod = object->GetLod(); + if (lod) + object->SetLod((CEntitySAInterface*)((std::uint32_t)lod + offset)); } } - else +} + +void CDummyPoolSA::UpdateLodsOffestInPool(const std::uint32_t offset) +{ + for (auto i = 0; i < (*m_ppDummyPoolInterface)->Size(); i++) { - for (auto i = 0; i < (*m_ppDummyPoolInterface)->Size(); i++) - { - CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i); - if (object->m_pLod) - { - object->m_pLod = (CEntitySAInterface*)((std::uint32_t)object->m_pLod + offset); - } - } + CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i); + CEntitySAInterface* lod = object->GetLod(); + if (lod) + object->SetLod((CEntitySAInterface*)((std::uint32_t)lod + offset)); } } diff --git a/Client/game_sa/CDummyPoolSA.h b/Client/game_sa/CDummyPoolSA.h index 7971a086d6..1e65676cf7 100644 --- a/Client/game_sa/CDummyPoolSA.h +++ b/Client/game_sa/CDummyPoolSA.h @@ -28,6 +28,10 @@ class CDummyPoolSA final : public CDummyPool void RestoreBackup() override; void UpdateBuildingLods(void* oldPool, void* newPool); +private: + void UpdateBackupLodOffset(const std::uint32_t offest); + void UpdateLodsOffestInPool(const std::uint32_t offset); + private: CPoolSAInterface** m_ppDummyPoolInterface; diff --git a/Client/game_sa/CEntitySA.h b/Client/game_sa/CEntitySA.h index a5a0de0dd9..5a237d0375 100644 --- a/Client/game_sa/CEntitySA.h +++ b/Client/game_sa/CEntitySA.h @@ -202,6 +202,9 @@ class CEntitySAInterface // Functions to hide member variable misuse // + void SetLod(CEntitySAInterface* pLod) noexcept { m_pLod = pLod; }; + CEntitySAInterface* GetLod() const noexcept { return m_pLod; }; + // Sets void SetIsLowLodEntity() { numLodChildrenRendered = 0x40; }