Skip to content

Commit 1f95e2e

Browse files
Synchronize changes from 1.6 master branch [ci skip]
bae4ca9 Make engineRestreamWorld more aggressive (PR #3685)
2 parents 735c185 + bae4ca9 commit 1f95e2e

File tree

11 files changed

+48
-8
lines changed

11 files changed

+48
-8
lines changed

Client/game_sa/CGameSA.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,33 @@ bool CGameSA::SetBuildingPoolSize(size_t size)
11021102
return status;
11031103
}
11041104

1105+
void CGameSA::UnloadUnusedModels()
1106+
{
1107+
// Unload DFF's
1108+
// CJ should not be unloaded
1109+
const std::size_t baseIdForTxd = GetBaseIDforTXD();
1110+
for (std::size_t id = 1; id < baseIdForTxd; id++)
1111+
{
1112+
CStreamingInfo* streamingInfo = m_pStreaming->GetStreamingInfo(id);
1113+
if (streamingInfo->loadState != eModelLoadState::LOADSTATE_NOT_LOADED && streamingInfo->sizeInBlocks > 0)
1114+
{
1115+
CModelInfoSA& model = ModelInfo[id];
1116+
if (model.GetRefCount() == 0)
1117+
model.UnloadUnused();
1118+
};
1119+
}
1120+
// Unload TXD
1121+
for (std::size_t id = baseIdForTxd; id < GetBaseIDforCOL(); id++)
1122+
{
1123+
CStreamingInfo* streamingInfo = m_pStreaming->GetStreamingInfo(id);
1124+
std::size_t refsCount = GetPools()->GetTxdPool().GetRefsCount(id - baseIdForTxd);
1125+
if (streamingInfo->loadState != eModelLoadState::LOADSTATE_NOT_LOADED && streamingInfo->sizeInBlocks > 0 && refsCount == 0)
1126+
{
1127+
GetStreaming()->RemoveModel(id);
1128+
}
1129+
}
1130+
}
1131+
11051132
// Ensure models have the default lod distances
11061133
void CGameSA::ResetModelLodDistances()
11071134
{

Client/game_sa/CGameSA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ class CGameSA : public CGame
312312

313313
bool SetBuildingPoolSize(size_t size);
314314

315+
void UnloadUnusedModels();
316+
315317
private:
316318
std::unique_ptr<CPools> m_Pools;
317319
CPlayerInfo* m_pPlayerInfo;

Client/game_sa/CModelInfoSA.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ void CModelInfoSA::Remove()
452452

453453
bool CModelInfoSA::UnloadUnused()
454454
{
455+
m_pInterface = ppModelInfo[m_dwModelID];
456+
455457
if (m_pInterface->usNumberOfRefs == 0 && !m_pCustomClump && !m_pCustomColModel)
456458
{
457459
pGame->GetStreaming()->RemoveModel(m_dwModelID);
@@ -1094,11 +1096,6 @@ void CModelInfoSA::ModelAddRef(EModelRequestType requestType, const char* szTag)
10941096
m_dwReferences++;
10951097
}
10961098

1097-
int CModelInfoSA::GetRefCount()
1098-
{
1099-
return static_cast<int>(m_dwReferences);
1100-
}
1101-
11021099
void CModelInfoSA::RemoveRef(bool bRemoveExtraGTARef)
11031100
{
11041101
// Decrement the references

Client/game_sa/CModelInfoSA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ class CModelInfoSA : public CModelInfo
397397
static void StaticResetAlphaTransparencies();
398398

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

Client/game_sa/CPoolSAInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class CPoolSAInterface
122122
return !IsEmpty(index);
123123
}
124124

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

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

Client/game_sa/CTxdPoolSA.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ std::uint16_t CTxdPoolSA::GetFreeTextureDictonarySlot()
5555
{
5656
return (*m_ppTxdPoolInterface)->GetFreeSlot();
5757
}
58+
59+
std::uint16_t CTxdPoolSA::GetRefsCount(std::uint16_t slot) const
60+
{
61+
CTextureDictonarySAInterface* pTxd = (*m_ppTxdPoolInterface)->GetObject(slot);
62+
if (!pTxd)
63+
return -1;
64+
65+
return pTxd->usUsagesCount;
66+
}

Client/game_sa/CTxdPoolSA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CTxdPoolSA final : public CTxdPool
2525
bool IsFreeTextureDictonarySlot(std::uint32_t uiTxdId);
2626

2727
std::uint16_t GetFreeTextureDictonarySlot();
28+
std::uint16_t GetRefsCount(std::uint16_t slot) const;
2829

2930
private:
3031
CPoolSAInterface<CTextureDictonarySAInterface>** m_ppTxdPoolInterface;

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6764,6 +6764,8 @@ void CClientGame::RestreamWorld()
67646764

67656765
g_pGame->GetStreaming()->RemoveBigBuildings();
67666766
g_pGame->GetStreaming()->ReinitStreaming();
6767+
6768+
g_pGame->UnloadUnusedModels();
67676769
}
67686770

67696771
void CClientGame::ReinitMarkers()

Client/sdk/game/CGame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,5 @@ class __declspec(novtable) CGame
278278

279279
virtual bool SetBuildingPoolSize(size_t size) = 0;
280280

281+
virtual void UnloadUnusedModels() = 0;
281282
};

Client/sdk/game/CModelInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class CModelInfo
181181

182182
virtual void ModelAddRef(EModelRequestType requestType, const char* szTag /* = NULL*/) = 0;
183183
virtual void RemoveRef(bool bRemoveExtraGTARef = false) = 0;
184-
virtual int GetRefCount() = 0;
184+
virtual int GetRefCount() const = 0;
185185
virtual bool ForceUnload() = 0;
186186
virtual bool UnloadUnused() = 0;
187187
virtual void DeallocateModel() = 0;

0 commit comments

Comments
 (0)