Skip to content

Commit a4d7aac

Browse files
committed
Better checks
1 parent 58247b8 commit a4d7aac

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

Client/game_sa/CGameSA.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,17 +1051,29 @@ bool CGameSA::SetBuildingPoolSize(size_t size)
10511051

10521052
void CGameSA::UnloadUnusedModels()
10531053
{
1054-
for (std::size_t id = 0; id < GetBaseIDforCOL(); id++)
1054+
// Unload DFF's
1055+
// CJ should not be unloaded
1056+
const std::size_t baseIdForTxd = GetBaseIDforTXD();
1057+
for (std::size_t id = 1; id < baseIdForTxd; id++)
10551058
{
10561059
CStreamingInfo* streamingInfo = m_pStreaming->GetStreamingInfo(id);
10571060
if (streamingInfo->loadState != eModelLoadState::LOADSTATE_NOT_LOADED && streamingInfo->sizeInBlocks > 0)
10581061
{
1059-
if (ModelInfo[id].GetRefCount() == 0)
1060-
{
1061-
m_pStreaming->RemoveModel(id);
1062-
}
1062+
CModelInfoSA& model = ModelInfo[id];
1063+
if (model.GetRefCount() == 0)
1064+
model.UnloadUnused();
10631065
};
10641066
}
1067+
// Unload TXD
1068+
for (std::size_t id = baseIdForTxd; id < GetBaseIDforCOL(); id++)
1069+
{
1070+
CStreamingInfo* streamingInfo = m_pStreaming->GetStreamingInfo(id);
1071+
std::size_t refsCount = GetPools()->GetTxdPool().GetRefsCount(id - baseIdForTxd);
1072+
if (streamingInfo->loadState != eModelLoadState::LOADSTATE_NOT_LOADED && streamingInfo->sizeInBlocks > 0 && refsCount == 0)
1073+
{
1074+
GetStreaming()->RemoveModel(id);
1075+
}
1076+
}
10651077
}
10661078

10671079
// Ensure models have the default lod distances

Client/game_sa/CModelInfoSA.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ void CModelInfoSA::Remove()
442442

443443
bool CModelInfoSA::UnloadUnused()
444444
{
445+
m_pInterface = ppModelInfo[m_dwModelID];
446+
445447
if (m_pInterface->usNumberOfRefs == 0 && !m_pCustomClump && !m_pCustomColModel)
446448
{
447449
pGame->GetStreaming()->RemoveModel(m_dwModelID);

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/sdk/game/CTxdPool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ class CTxdPool
1919
virtual bool IsFreeTextureDictonarySlot(std::uint32_t uiTxdID) = 0;
2020

2121
virtual std::uint16_t GetFreeTextureDictonarySlot() = 0;
22+
virtual std::uint16_t GetRefsCount(std::uint16_t slot) const = 0;
2223
};

0 commit comments

Comments
 (0)