Skip to content

Commit

Permalink
new functions added
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Aug 4, 2024
1 parent f4e90e4 commit aeecd9e
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 62 deletions.
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:
SVectorPoolData<CBuildingSA> m_buildingPool{MAX_BUILDINGS};
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;
};
4 changes: 2 additions & 2 deletions Client/game_sa/CDummyPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void CDummyPoolSA::UpdateBuildingLods(void* oldPool, void* newPool)

if (m_pOriginalElementsBackup)
{
for (int i = 0; i < MAX_DUMMIES_DEFAULT; i++)
for (int i = 0; i < (*m_pOriginalElementsBackup).size(); i++)
{
if ((*m_pOriginalElementsBackup)[i].first)
{
Expand All @@ -94,7 +94,7 @@ void CDummyPoolSA::UpdateBuildingLods(void* oldPool, void* newPool)
}
else
{
for (int i = 0; i < MAX_DUMMIES_DEFAULT; i++)
for (int i = 0; i < (*m_ppDummyPoolInterface)->Size(); i++)
{
CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i);
if (object->m_pLod)
Expand Down
17 changes: 6 additions & 11 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ void CGameSA::Reset()
CModelInfoSA::StaticResetTextureDictionaries();

// Restore default world state
RestoreGameBuildings();
RestoreGameWorld();
}
}

Expand Down Expand Up @@ -1005,7 +1005,7 @@ void CGameSA::GetShaderReplacementStats(SShaderReplacementStats& outStats)
m_pRenderWare->GetShaderReplacementStats(outStats);
}

void CGameSA::RemoveAllBuildings(bool clearBuildingRemoval)
void CGameSA::RemoveGameWorld()
{
m_pIplStore->SetDynamicIplStreamingEnabled(false);

Expand All @@ -1018,17 +1018,12 @@ void CGameSA::RemoveAllBuildings(bool clearBuildingRemoval)
m_pPools->GetDummyPool().RemoveAllWithBackup();
m_pPools->GetBuildingsPool().RemoveAllWithBackup();

auto pBuildingRemoval = static_cast<CBuildingRemovalSA*>(m_pBuildingRemoval);
if (clearBuildingRemoval)
{
pBuildingRemoval->ClearRemovedBuildingLists();
}
pBuildingRemoval->DropCaches();
static_cast<CBuildingRemovalSA*>(m_pBuildingRemoval)->DropCaches();

m_isBuildingsRemoved = true;
}

void CGameSA::RestoreGameBuildings()
void CGameSA::RestoreGameWorld()
{
m_pPools->GetBuildingsPool().RestoreBackup();
m_pPools->GetDummyPool().RestoreBackup();
Expand All @@ -1042,7 +1037,7 @@ bool CGameSA::SetBuildingPoolSize(size_t size)
const bool shouldRemoveBuilding = !m_isBuildingsRemoved;
if (shouldRemoveBuilding)
{
RemoveAllBuildings(false);
RemoveGameWorld();
}
else
{
Expand All @@ -1053,7 +1048,7 @@ bool CGameSA::SetBuildingPoolSize(size_t size)

if (shouldRemoveBuilding)
{
RestoreGameBuildings();
RestoreGameWorld();
}

return status;
Expand Down
4 changes: 2 additions & 2 deletions Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ class CGameSA : public CGame
PostWeaponFireHandler* m_pPostWeaponFireHandler;
TaskSimpleBeHitHandler* m_pTaskSimpleBeHitHandler;

void RemoveAllBuildings(bool clearBuildingRemoval = true);
void RestoreGameBuildings();
void RemoveGameWorld();
void RestoreGameWorld();

bool SetBuildingPoolSize(size_t size);

Expand Down
5 changes: 3 additions & 2 deletions Client/game_sa/CPoolSAInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ class CPoolSAInterface

void Delete(uint index) { Release(index); }

bool IsEmpty(std::int32_t objectIndex) { return m_byteMap[objectIndex].bEmpty; }
bool IsContains(uint index)
int Size() const noexcept { return m_nSize; };
bool IsEmpty(std::int32_t objectIndex) const { return m_byteMap[objectIndex].bEmpty; }
bool IsContains(uint index) const
{
if (m_nSize <= index)
return false;
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CPoolsSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#define INVALID_POOL_ARRAY_ID 0xFFFFFFFF

class CClientEntity;
class CClientVehicle;
class CClientObject;

class CPoolsSA : public CPools
{
Expand Down
50 changes: 15 additions & 35 deletions Client/mods/deathmatch/logic/CClientBuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ void CClientBuildingManager::RestoreDestroyed()
}
}

void CClientBuildingManager::RestoreDestroyedSafe()
{
// Resize the building pool if we need
const int currentUsed = g_pGame->GetPools()->GetNumberOfUsedSpaces(ePools::BUILDING_POOL) + m_List.size();
const int currentCapacity = g_pGame->GetPools()->GetPoolCapacity(ePools::BUILDING_POOL);

if (currentCapacity - currentUsed < PRESERVED_POOL_SIZE)
{
DoPoolResize(currentUsed + PRESERVED_POOL_SIZE);
}

// Restore
RestoreDestroyed();
}

void CClientBuildingManager::ResizePoolIfNeeds()
{
const int currentUsed = g_pGame->GetPools()->GetNumberOfUsedSpaces(ePools::BUILDING_POOL);
Expand Down Expand Up @@ -164,38 +179,3 @@ bool CClientBuildingManager::DoPoolResize(size_t newCapacity)

return success;
}


void CClientBuildingManager::RemoveAllGameBuildings()
{
// We do not want to remove scripted buildings
// But we need remove them from the buildings pool for a bit...
DestroyAllForABit();

// This function makes buildings backup without scripted buildings
g_pGame->RemoveAllBuildings();

// ... And restore here
RestoreDestroyed();
}

void CClientBuildingManager::RestoreAllGameBuildings()
{
// We want to restore the game buildings to the same positions as they were before the backup.
// Remove scripted buildings for a bit
DestroyAllForABit();

g_pGame->RestoreGameBuildings();

// Resize the building pool if we need
const int currentUsed = g_pGame->GetPools()->GetNumberOfUsedSpaces(ePools::BUILDING_POOL) + m_List.size();
const int currentCapacity = g_pGame->GetPools()->GetPoolCapacity(ePools::BUILDING_POOL);

if (currentCapacity - currentUsed < PRESERVED_POOL_SIZE)
{
DoPoolResize(currentUsed + PRESERVED_POOL_SIZE);
}

// Restore
RestoreDestroyed();
}
6 changes: 2 additions & 4 deletions Client/mods/deathmatch/logic/CClientBuildingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ class CClientBuildingManager
void ResizePoolIfNeeds();
bool SetPoolCapacity(size_t newCapacity);

void RemoveAllGameBuildings();
void RestoreAllGameBuildings();

private:
void DestroyAllForABit();
void RestoreDestroyed();
void RestoreDestroyedSafe();

private:
bool DoPoolResize(size_t newCapacity);
void AddToList(CClientBuilding* pBuilding) { m_List.push_back(pBuilding); }
void RemoveFromList(CClientBuilding* pBuilding);
Expand Down
6 changes: 4 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ CClientBuilding* CLuaBuildingDefs::CreateBuilding(lua_State* const luaVM, uint16
return pBuilding;
}

// Deprecated
void CLuaBuildingDefs::RemoveAllGameBuildings()
{
m_pBuildingManager->RemoveAllGameBuildings();
CLuaWorldDefs::RemoveGameWorld();
}

// Deprecated
void CLuaBuildingDefs::RestoreGameBuildings()
{
m_pBuildingManager->RestoreAllGameBuildings();
CLuaWorldDefs::RestoreGameWorld();
}
29 changes: 29 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ void CLuaWorldDefs::LoadFunctions()
{"setFPSLimit", SetFPSLimit},
{"setCoronaReflectionsEnabled", ArgumentParser<SetCoronaReflectionsEnabled>},
{"setWorldProperty", ArgumentParser<SetWorldProperty>},

// World remove/restore functions
{"removeWorldModel", RemoveWorldBuilding},
{"restoreAllWorldModels", RestoreWorldBuildings},
{"restoreWorldModel", RestoreWorldBuilding},
{"removeGameWorld", ArgumentParser<RemoveGameWorld>},
{"restoreGameWorld", ArgumentParser<RestoreGameWorld>},

// World create funcs
{"createSWATRope", CreateSWATRope},
Expand Down Expand Up @@ -2234,3 +2238,28 @@ bool CLuaWorldDefs::ResetWorldProperty(eWorldProperty property)
}
return false;
}

void CLuaWorldDefs::RemoveGameWorld()
{
// We do not want to remove scripted buildings
// But we need remove them from the buildings pool for a bit...
m_pBuildingManager->DestroyAllForABit();

// This function makes buildings backup without scripted buildings
g_pGame->RemoveGameWorld();

// ... And restore here
m_pBuildingManager->RestoreDestroyed();
}

void CLuaWorldDefs::RestoreGameWorld()
{
// We want to restore the game buildings to the same positions as they were before the backup.
// Remove scripted buildings for a bit
m_pBuildingManager->DestroyAllForABit();

g_pGame->RestoreGameWorld();

// ... And restore here
m_pBuildingManager->RestoreDestroyedSafe();
}
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@ class CLuaWorldDefs : public CLuaDefs
static std::variant<bool, float, CLuaMultiReturn<float, float, float>> GetWorldProperty(eWorldProperty property);
static bool SetWorldProperty(eWorldProperty property, float arg1, std::optional<float> arg2, std::optional<float> arg3);
static bool ResetWorldProperty(eWorldProperty property);

static void RemoveGameWorld();
static void RestoreGameWorld();
};
4 changes: 2 additions & 2 deletions Client/sdk/game/CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ class __declspec(novtable) CGame
virtual int32_t GetBaseIDforSCM() = 0;
virtual int32_t GetCountOfAllFileIDs() = 0;

virtual void RemoveAllBuildings(bool clearBuildingRemoval = true) = 0;
virtual void RestoreGameBuildings() = 0;
virtual void RemoveGameWorld() = 0;
virtual void RestoreGameWorld() = 0;

virtual bool SetBuildingPoolSize(size_t size) = 0;

Expand Down

0 comments on commit aeecd9e

Please sign in to comment.