Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 733683d

Browse files
Extract TXD pool class (#3684)
1 parent aa0591c commit 733683d

File tree

9 files changed

+120
-60
lines changed

9 files changed

+120
-60
lines changed

‎Client/game_sa/CModelInfoSA.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ CBoundingBox* CModelInfoSA::GetBoundingBox()
743743
bool CModelInfoSA::IsValid()
744744
{
745745
if (m_dwModelID >= MODELINFO_DFF_MAX && m_dwModelID < MODELINFO_TXD_MAX)
746-
return !pGame->GetPools()->IsFreeTextureDictonarySlot(m_dwModelID - MODELINFO_DFF_MAX);
746+
return !pGame->GetPools()->GetTxdPool().IsFreeTextureDictonarySlot(m_dwModelID - MODELINFO_DFF_MAX);
747747

748748
if (m_dwModelID >= pGame->GetBaseIDforTXD() && m_dwModelID < pGame->GetCountOfAllFileIDs())
749749
return true;

‎Client/game_sa/CPoolsSA.cpp‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
#include "CTrailerSA.h"
2525
#include "CTrainSA.h"
2626
#include "CWorldSA.h"
27-
#include "CKeyGenSA.h"
28-
#include "CFileLoaderSA.h"
29-
#include "CPtrNodeSingleListSA.h"
3027

3128
extern CGameSA* pGame;
3229

@@ -35,7 +32,6 @@ CPoolsSA::CPoolsSA()
3532
m_ppPedPoolInterface = (CPoolSAInterface<CPedSAInterface>**)0xB74490;
3633
m_ppObjectPoolInterface = (CPoolSAInterface<CObjectSAInterface>**)0xB7449C;
3734
m_ppVehiclePoolInterface = (CPoolSAInterface<CVehicleSAInterface>**)0xB74494;
38-
m_ppTxdPoolInterface = (CPoolSAInterface<CTextureDictonarySAInterface>**)0xC8800C;
3935

4036
m_bGetVehicleEnabled = true;
4137
}
@@ -1107,40 +1103,3 @@ void CPoolsSA::InvalidateLocalPlayerClientEntity()
11071103
{
11081104
m_pedPool.arrayOfClientEntities[0] = {m_pedPool.arrayOfClientEntities[0].pEntity, nullptr};
11091105
}
1110-
1111-
unsigned int CPoolsSA::AllocateTextureDictonarySlot(uint uiSlotId, std::string& strTxdName)
1112-
{
1113-
CTextureDictonarySAInterface* pTxd = (*m_ppTxdPoolInterface)->AllocateAt(uiSlotId);
1114-
if (!pTxd)
1115-
return -1;
1116-
1117-
strTxdName.resize(24);
1118-
1119-
pTxd->usUsagesCount = 0;
1120-
pTxd->hash = pGame->GetKeyGen()->GetUppercaseKey(strTxdName.c_str());
1121-
pTxd->rwTexDictonary = nullptr;
1122-
pTxd->usParentIndex = -1;
1123-
1124-
return (*m_ppTxdPoolInterface)->GetObjectIndex(pTxd);
1125-
}
1126-
1127-
void CPoolsSA::RemoveTextureDictonarySlot(uint uiTxdId)
1128-
{
1129-
if (!(*m_ppTxdPoolInterface)->IsContains(uiTxdId))
1130-
return;
1131-
1132-
typedef uint(__cdecl * Function_TxdReleaseSlot)(uint uiTxdId);
1133-
((Function_TxdReleaseSlot)(0x731E90))(uiTxdId);
1134-
1135-
(*m_ppTxdPoolInterface)->Release(uiTxdId);
1136-
}
1137-
1138-
bool CPoolsSA::IsFreeTextureDictonarySlot(uint uiTxdId)
1139-
{
1140-
return (*m_ppTxdPoolInterface)->IsEmpty(uiTxdId);
1141-
}
1142-
1143-
ushort CPoolsSA::GetFreeTextureDictonarySlot()
1144-
{
1145-
return (*m_ppTxdPoolInterface)->GetFreeSlot();
1146-
}

‎Client/game_sa/CPoolsSA.h‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include "CVehicleSA.h"
1616
#include "CObjectSA.h"
1717
#include "CBuildingSA.h"
18-
#include "CTextureDictonarySA.h"
1918
#include "CBuildingsPoolSA.h"
2019
#include "CDummyPoolSA.h"
20+
#include "CTxdPoolSA.h"
2121

2222
#define INVALID_POOL_ARRAY_ID 0xFFFFFFFF
2323

@@ -91,14 +91,9 @@ class CPoolsSA : public CPools
9191
void ResetPedPoolCount() { m_pedPool.ulCount = 0; }
9292
void InvalidateLocalPlayerClientEntity();
9393

94-
uint AllocateTextureDictonarySlot(uint uiSlotID, std::string& strTxdName);
95-
void RemoveTextureDictonarySlot(uint uiTxdId);
96-
bool IsFreeTextureDictonarySlot(uint uiTxdId);
97-
98-
ushort GetFreeTextureDictonarySlot();
99-
10094
CBuildingsPool& GetBuildingsPool() noexcept override { return m_BuildingsPool; };
10195
CDummyPool& GetDummyPool() noexcept { return m_DummyPool; };
96+
CTxdPool& GetTxdPool() noexcept { return m_TxdPool; };
10297

10398
private:
10499
// Pools
@@ -109,10 +104,10 @@ class CPoolsSA : public CPools
109104
CPoolSAInterface<CPedSAInterface>** m_ppPedPoolInterface;
110105
CPoolSAInterface<CObjectSAInterface>** m_ppObjectPoolInterface;
111106
CPoolSAInterface<CVehicleSAInterface>** m_ppVehiclePoolInterface;
112-
CPoolSAInterface<CTextureDictonarySAInterface>** m_ppTxdPoolInterface;
113107

114108
CBuildingsPoolSA m_BuildingsPool;
115109
CDummyPoolSA m_DummyPool;
110+
CTxdPoolSA m_TxdPool;
116111

117112
bool m_bGetVehicleEnabled;
118113
};

‎Client/game_sa/CTxdPoolSA.cpp‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
*
6+
* Multi Theft Auto is available from https://www.multitheftauto.com/
7+
*
8+
*****************************************************************************/
9+
10+
#include "StdInc.h"
11+
#include "CTxdPoolSA.h"
12+
#include "CGameSA.h"
13+
#include "CKeyGenSA.h"
14+
15+
extern CGameSA* pGame;
16+
17+
CTxdPoolSA::CTxdPoolSA()
18+
{
19+
m_ppTxdPoolInterface = (CPoolSAInterface<CTextureDictonarySAInterface>**)0xC8800C;
20+
}
21+
22+
std::uint32_t CTxdPoolSA::AllocateTextureDictonarySlot(std::uint32_t uiSlotId, std::string& strTxdName)
23+
{
24+
CTextureDictonarySAInterface* pTxd = (*m_ppTxdPoolInterface)->AllocateAt(uiSlotId);
25+
if (!pTxd)
26+
return -1;
27+
28+
strTxdName.resize(24);
29+
30+
pTxd->usUsagesCount = 0;
31+
pTxd->hash = pGame->GetKeyGen()->GetUppercaseKey(strTxdName.c_str());
32+
pTxd->rwTexDictonary = nullptr;
33+
pTxd->usParentIndex = -1;
34+
35+
return (*m_ppTxdPoolInterface)->GetObjectIndex(pTxd);
36+
}
37+
38+
void CTxdPoolSA::RemoveTextureDictonarySlot(std::uint32_t uiTxdId)
39+
{
40+
if (!(*m_ppTxdPoolInterface)->IsContains(uiTxdId))
41+
return;
42+
43+
typedef std::uint32_t(__cdecl * Function_TxdReleaseSlot)(std::uint32_t uiTxdId);
44+
((Function_TxdReleaseSlot)(0x731E90))(uiTxdId);
45+
46+
(*m_ppTxdPoolInterface)->Release(uiTxdId);
47+
}
48+
49+
bool CTxdPoolSA::IsFreeTextureDictonarySlot(std::uint32_t uiTxdId)
50+
{
51+
return (*m_ppTxdPoolInterface)->IsEmpty(uiTxdId);
52+
}
53+
54+
std::uint16_t CTxdPoolSA::GetFreeTextureDictonarySlot()
55+
{
56+
return (*m_ppTxdPoolInterface)->GetFreeSlot();
57+
}

‎Client/game_sa/CTxdPoolSA.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
*
6+
* Multi Theft Auto is available from https://www.multitheftauto.com/
7+
*
8+
*****************************************************************************/
9+
10+
#pragma once
11+
12+
#include <game/CTxdPool.h>
13+
#include "CPoolSAInterface.h"
14+
#include "CBuildingSA.h"
15+
#include "CTextureDictonarySA.h"
16+
17+
class CTxdPoolSA final : public CTxdPool
18+
{
19+
public:
20+
CTxdPoolSA();
21+
~CTxdPoolSA() = default;
22+
23+
std::uint32_t AllocateTextureDictonarySlot(std::uint32_t uiSlotID, std::string& strTxdName);
24+
void RemoveTextureDictonarySlot(std::uint32_t uiTxdId);
25+
bool IsFreeTextureDictonarySlot(std::uint32_t uiTxdId);
26+
27+
std::uint16_t GetFreeTextureDictonarySlot();
28+
29+
private:
30+
CPoolSAInterface<CTextureDictonarySAInterface>** m_ppTxdPoolInterface;
31+
};

‎Client/mods/deathmatch/logic/CClientModel.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void CClientModel::RestoreDFF(CModelInfo* pModelInfo)
213213

214214
bool CClientModel::AllocateTXD(std::string &strTxdName)
215215
{
216-
uint uiSlotID = g_pGame->GetPools()->AllocateTextureDictonarySlot(m_iModelID - MAX_MODEL_DFF_ID, strTxdName);
216+
std::uint32_t uiSlotID = g_pGame->GetPools()->GetTxdPool().AllocateTextureDictonarySlot(m_iModelID - MAX_MODEL_DFF_ID, strTxdName);
217217
if (uiSlotID != -1)
218218
{
219219
m_bAllocatedByUs = true;
@@ -234,6 +234,6 @@ void CClientModel::RestoreTXD(CModelInfo* pModelInfo)
234234
pModelInfo->SetTextureDictionaryID(0);
235235
}
236236

237-
g_pGame->GetPools()->RemoveTextureDictonarySlot(uiTextureDictonarySlotID);
237+
g_pGame->GetPools()->GetTxdPool().RemoveTextureDictonarySlot(uiTextureDictonarySlotID);
238238
g_pGame->GetStreaming()->SetStreamingInfo(pModelInfo->GetModel(), 0, 0, 0, -1);
239239
}

‎Client/mods/deathmatch/logic/CClientModelManager.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int CClientModelManager::GetFirstFreeModelID(void)
7676

7777
int CClientModelManager::GetFreeTxdModelID()
7878
{
79-
ushort usTxdId = g_pGame->GetPools()->GetFreeTextureDictonarySlot();
79+
std::uint16_t usTxdId = g_pGame->GetPools()->GetTxdPool().GetFreeTextureDictonarySlot();
8080
if (usTxdId == -1)
8181
return INVALID_MODEL_ID;
8282
return MAX_MODEL_DFF_ID + usTxdId;

‎Client/sdk/game/CPools.h‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Common.h"
1515
#include "CBuildingsPool.h"
1616
#include "CDummyPool.h"
17+
#include "CTxdPool.h"
1718

1819
class CClientEntity;
1920
class CEntity;
@@ -107,12 +108,7 @@ class CPools
107108
virtual void ResetPedPoolCount() = 0;
108109
virtual void InvalidateLocalPlayerClientEntity() = 0;
109110

110-
virtual uint AllocateTextureDictonarySlot(uint uiSlotID, std::string& strTxdName) = 0;
111-
virtual void RemoveTextureDictonarySlot(uint uiTxdID) = 0;
112-
virtual bool IsFreeTextureDictonarySlot(uint uiTxdID) = 0;
113-
114-
virtual ushort GetFreeTextureDictonarySlot() = 0;
115-
116111
virtual CBuildingsPool& GetBuildingsPool() noexcept = 0;
117-
virtual CDummyPool& GetDummyPool() noexcept = 0;
112+
virtual CDummyPool& GetDummyPool() noexcept = 0;
113+
virtual CTxdPool& GetTxdPool() noexcept = 0;
118114
};

‎Client/sdk/game/CTxdPool.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
*
6+
* Multi Theft Auto is available from https://www.multitheftauto.com/
7+
*
8+
*****************************************************************************/
9+
10+
#pragma once
11+
12+
#include "Common.h"
13+
14+
class CTxdPool
15+
{
16+
public:
17+
virtual std::uint32_t AllocateTextureDictonarySlot(std::uint32_t uiSlotID, std::string& strTxdName) = 0;
18+
virtual void RemoveTextureDictonarySlot(std::uint32_t uiTxdID) = 0;
19+
virtual bool IsFreeTextureDictonarySlot(std::uint32_t uiTxdID) = 0;
20+
21+
virtual std::uint16_t GetFreeTextureDictonarySlot() = 0;
22+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /