diff --git a/Client/game_sa/CBuildingsPoolSA.cpp b/Client/game_sa/CBuildingsPoolSA.cpp index aecd125f59..b8363f6507 100644 --- a/Client/game_sa/CBuildingsPoolSA.cpp +++ b/Client/game_sa/CBuildingsPoolSA.cpp @@ -40,10 +40,10 @@ inline bool CBuildingsPoolSA::AddBuildingToPool(CClientBuilding* pClientBuilding if (dwElementIndexInPool == UINT_MAX) return false; - m_buildingPool.arrayOfClientEntities[dwElementIndexInPool] = {pBuilding, (CClientEntity*)pClientBuilding}; + m_buildingPool.entities[dwElementIndexInPool] = {pBuilding, (CClientEntity*)pClientBuilding}; // Increase the count of objects - ++m_buildingPool.ulCount; + ++m_buildingPool.count; return true; } @@ -108,8 +108,8 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding) modelInfo->RemoveColRef(); // Remove from BuildingSA pool - auto* pBuildingSA = m_buildingPool.arrayOfClientEntities[dwElementIndexInPool].pEntity; - m_buildingPool.arrayOfClientEntities[dwElementIndexInPool] = {nullptr, nullptr}; + auto* pBuildingSA = m_buildingPool.entities[dwElementIndexInPool].pEntity; + m_buildingPool.entities[dwElementIndexInPool] = {nullptr, nullptr}; // Delete it from memory delete pBuildingSA; @@ -118,7 +118,7 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding) (*m_ppBuildingPoolInterface)->Release(dwElementIndexInPool); // Decrease the count of elements in the pool - --m_buildingPool.ulCount; + --m_buildingPool.count; } void CBuildingsPoolSA::RemoveAllBuildings() @@ -191,7 +191,9 @@ void CBuildingsPoolSA::RemoveBuildingFromWorld(CBuildingSAInterface* pBuilding) bool CBuildingsPoolSA::Resize(int size) { auto* pool = (*m_ppBuildingPoolInterface); - const int curretnSize = pool->m_nSize; + const int currentSize = pool->m_nSize; + + m_buildingPool.entities.resize(size); void* oldPool = pool->m_pObjects; @@ -210,7 +212,7 @@ bool CBuildingsPoolSA::Resize(int size) CBuildingSAInterface* newObjects = MemSA::malloc_struct(size); if (newObjects == nullptr) { - Resize(curretnSize); + Resize(currentSize); return false; } @@ -218,7 +220,7 @@ bool CBuildingsPoolSA::Resize(int size) if (newBytemap == nullptr) { MemSA::free(newObjects); - Resize(curretnSize); + Resize(currentSize); return false; } diff --git a/Client/game_sa/CBuildingsPoolSA.h b/Client/game_sa/CBuildingsPoolSA.h index 9f38202243..5ce719bd73 100644 --- a/Client/game_sa/CBuildingsPoolSA.h +++ b/Client/game_sa/CBuildingsPoolSA.h @@ -40,8 +40,8 @@ class CBuildingsPoolSA : public CBuildingsPool void RemovePedsContactEnityLinks(); private: - SPoolData m_buildingPool; - CPoolSAInterface** m_ppBuildingPoolInterface; + SVectorPoolData m_buildingPool{MAX_BUILDINGS}; + CPoolSAInterface** m_ppBuildingPoolInterface; std::unique_ptr, MAX_BUILDINGS>> m_pOriginalBuildingsBackup; }; diff --git a/Client/game_sa/CPoolSAInterface.h b/Client/game_sa/CPoolSAInterface.h index 8b653aefc1..9f48bc63d3 100644 --- a/Client/game_sa/CPoolSAInterface.h +++ b/Client/game_sa/CPoolSAInterface.h @@ -149,3 +149,16 @@ struct SPoolData } } }; + +template +struct SVectorPoolData +{ + std::vector> entities; + size_t count; + +public: + SVectorPoolData(size_t defaultSize) : count(0) + { + entities.resize(defaultSize, {nullptr, nullptr}); + } +};