Skip to content

Commit

Permalink
Merge branch 'master' into Buildings/fix_physical
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutchman101 authored Jun 16, 2024
2 parents 7141e78 + ba4f730 commit 160c18c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
18 changes: 10 additions & 8 deletions Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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;

Expand All @@ -210,15 +212,15 @@ bool CBuildingsPoolSA::Resize(int size)
CBuildingSAInterface* newObjects = MemSA::malloc_struct<CBuildingSAInterface>(size);
if (newObjects == nullptr)
{
Resize(curretnSize);
Resize(currentSize);
return false;
}

tPoolObjectFlags* newBytemap = MemSA::malloc_struct<tPoolObjectFlags>(size);
if (newBytemap == nullptr)
{
MemSA::free(newObjects);
Resize(curretnSize);
Resize(currentSize);
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions Client/game_sa/CBuildingsPoolSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class CBuildingsPoolSA : public CBuildingsPool
void RemovePedsContactEnityLinks();

private:
SPoolData<CBuildingSA, CBuildingSAInterface, MAX_BUILDINGS> m_buildingPool;
CPoolSAInterface<CBuildingSAInterface>** m_ppBuildingPoolInterface;
SVectorPoolData<CBuildingSA> m_buildingPool{MAX_BUILDINGS};
CPoolSAInterface<CBuildingSAInterface>** m_ppBuildingPoolInterface;

std::unique_ptr<std::array<std::pair<bool, CBuildingSAInterface>, MAX_BUILDINGS>> m_pOriginalBuildingsBackup;
};
13 changes: 13 additions & 0 deletions Client/game_sa/CPoolSAInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,16 @@ struct SPoolData
}
}
};

template <class T>
struct SVectorPoolData
{
std::vector<SClientEntity<T>> entities;
size_t count;

public:
SVectorPoolData(size_t defaultSize) : count(0)
{
entities.resize(defaultSize, {nullptr, nullptr});
}
};

0 comments on commit 160c18c

Please sign in to comment.