Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make engineRestreamWorld more aggressive #3685

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,33 @@ bool CGameSA::SetBuildingPoolSize(size_t size)
return status;
}

void CGameSA::UnloadUnusedModels()
{
// Unload DFF's
// CJ should not be unloaded
const std::size_t baseIdForTxd = GetBaseIDforTXD();
for (std::size_t id = 1; id < baseIdForTxd; id++)
{
CStreamingInfo* streamingInfo = m_pStreaming->GetStreamingInfo(id);
if (streamingInfo->loadState != eModelLoadState::LOADSTATE_NOT_LOADED && streamingInfo->sizeInBlocks > 0)
{
CModelInfoSA& model = ModelInfo[id];
if (model.GetRefCount() == 0)
model.UnloadUnused();
};
}
// Unload TXD
for (std::size_t id = baseIdForTxd; id < GetBaseIDforCOL(); id++)
{
CStreamingInfo* streamingInfo = m_pStreaming->GetStreamingInfo(id);
std::size_t refsCount = GetPools()->GetTxdPool().GetRefsCount(id - baseIdForTxd);
if (streamingInfo->loadState != eModelLoadState::LOADSTATE_NOT_LOADED && streamingInfo->sizeInBlocks > 0 && refsCount == 0)
{
GetStreaming()->RemoveModel(id);
}
}
}

// Ensure models have the default lod distances
void CGameSA::ResetModelLodDistances()
{
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ class CGameSA : public CGame

bool SetBuildingPoolSize(size_t size);

void UnloadUnusedModels();

private:
CPools* m_pPools;
CPlayerInfo* m_pPlayerInfo;
Expand Down
7 changes: 2 additions & 5 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ void CModelInfoSA::Remove()

bool CModelInfoSA::UnloadUnused()
{
m_pInterface = ppModelInfo[m_dwModelID];

if (m_pInterface->usNumberOfRefs == 0 && !m_pCustomClump && !m_pCustomColModel)
{
pGame->GetStreaming()->RemoveModel(m_dwModelID);
Expand Down Expand Up @@ -1077,11 +1079,6 @@ void CModelInfoSA::ModelAddRef(EModelRequestType requestType, const char* szTag)
m_dwReferences++;
}

int CModelInfoSA::GetRefCount()
{
return static_cast<int>(m_dwReferences);
}

void CModelInfoSA::RemoveRef(bool bRemoveExtraGTARef)
{
// Decrement the references
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class CModelInfoSA : public CModelInfo
static void StaticResetAlphaTransparencies();

void ModelAddRef(EModelRequestType requestType, const char* szTag);
int GetRefCount();
int GetRefCount() const override { return static_cast<int>(m_dwReferences); };
void RemoveRef(bool bRemoveExtraGTARef = false);
bool ForceUnload();

Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CPoolSAInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class CPoolSAInterface
return !IsEmpty(index);
}

B* GetObject(std::int32_t objectIndex) { return &m_pObjects[objectIndex]; }
B* GetObject(std::int32_t objectIndex) const { return &m_pObjects[objectIndex]; }

uint GetObjectIndex(B* pObject) { return ((DWORD)pObject - (DWORD)m_pObjects) / sizeof(B); }

Expand Down
9 changes: 9 additions & 0 deletions Client/game_sa/CTxdPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ std::uint16_t CTxdPoolSA::GetFreeTextureDictonarySlot()
{
return (*m_ppTxdPoolInterface)->GetFreeSlot();
}

std::uint16_t CTxdPoolSA::GetRefsCount(std::uint16_t slot) const
{
CTextureDictonarySAInterface* pTxd = (*m_ppTxdPoolInterface)->GetObject(slot);
if (!pTxd)
return -1;

return pTxd->usUsagesCount;
}
1 change: 1 addition & 0 deletions Client/game_sa/CTxdPoolSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CTxdPoolSA final : public CTxdPool
bool IsFreeTextureDictonarySlot(std::uint32_t uiTxdId);

std::uint16_t GetFreeTextureDictonarySlot();
TheNormalnij marked this conversation as resolved.
Show resolved Hide resolved
std::uint16_t GetRefsCount(std::uint16_t slot) const;

private:
CPoolSAInterface<CTextureDictonarySAInterface>** m_ppTxdPoolInterface;
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6743,6 +6743,8 @@ void CClientGame::RestreamWorld()

g_pGame->GetStreaming()->RemoveBigBuildings();
g_pGame->GetStreaming()->ReinitStreaming();

g_pGame->UnloadUnusedModels();
}

void CClientGame::ReinitMarkers()
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/game/CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,5 @@ class __declspec(novtable) CGame

virtual bool SetBuildingPoolSize(size_t size) = 0;

virtual void UnloadUnusedModels() = 0;
};
2 changes: 1 addition & 1 deletion Client/sdk/game/CModelInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class CModelInfo

virtual void ModelAddRef(EModelRequestType requestType, const char* szTag /* = NULL*/) = 0;
virtual void RemoveRef(bool bRemoveExtraGTARef = false) = 0;
virtual int GetRefCount() = 0;
virtual int GetRefCount() const = 0;
virtual bool ForceUnload() = 0;
virtual bool UnloadUnused() = 0;
virtual void DeallocateModel() = 0;
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/game/CTxdPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ class CTxdPool
virtual bool IsFreeTextureDictonarySlot(std::uint32_t uiTxdID) = 0;

virtual std::uint16_t GetFreeTextureDictonarySlot() = 0;
virtual std::uint16_t GetRefsCount(std::uint16_t slot) const = 0;
};
Loading