Skip to content

Commit b5932c5

Browse files
committed
More PGUITRTextureFactory progress
1 parent f82919b commit b5932c5

File tree

2 files changed

+104
-4
lines changed

2 files changed

+104
-4
lines changed

Toshi/Plugins/Include/PGUIRenderer/PGUITRTextureFactory.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,28 @@ class PGUIRENDERER_EXPORTS PGUITRTextureFactory : public Toshi::TGUITextureFacto
6565
PGUITRTextureFactory();
6666
~PGUITRTextureFactory();
6767

68+
virtual PGUITextureID GetTextureID(const Toshi::TPCString &a_rTextureName);
69+
virtual PGUITextureID FindTextureID(const Toshi::TPCString &a_rTextureName);
6870
virtual PGUITextureID ReserveTextureID(const Toshi::TPCString &a_rTextureName);
6971

7072
void Create(PGUITRDisplayContext *a_pDisplayContext);
7173

72-
Texture *GetTexture( PGUITextureID a_iID );
74+
Texture *GetTexture(PGUITextureID a_iID);
75+
76+
void DestroyTexture(PGUITextureID a_iID);
77+
78+
protected:
79+
PGUITextureID AllocatedTextureID();
7380

7481
protected:
7582
// [5/26/2025 InfiniteC0re]
7683
// Commented m_oTextureSet since it's probably storing something else, not TextureSet
77-
//Toshi::TArray<TextureSet> m_oTextureSet; // 0x4
78-
Texture **m_ppTextures;
84+
// Toshi::TArray<TextureSet> m_oTextureSet; // 0x4
85+
Texture **m_ppTextures; // 0x0
86+
TINT m_iTextureCapacity; // 0x4
87+
TINT m_iTextureCount; // 0x8
88+
TINT m_iTextureAllocations; // 0xC
89+
7990

8091
// ...
8192
PGUITRDisplayContext *m_pDisplayContext; // 0x1C

Toshi/Plugins/Source/PGUIRenderer/PGUITRTextureFactory.cpp

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ IMPLEMENT_DYNCREATE(PGUITRTextureFactory, Toshi::TGUITextureFactory);
1010

1111
// $PGUIRenderer: FUNCTION 100068e0
1212
PGUITRTextureFactory::PGUITRTextureFactory()
13-
: m_ppTextures( TNULL )
13+
: m_ppTextures(TNULL), m_iTextureCount(0), m_iTextureCapacity(10), m_iTextureAllocations(0)
1414
{
1515
}
1616

@@ -23,6 +23,28 @@ PGUITRTextureFactory::~PGUITRTextureFactory()
2323
void PGUITRTextureFactory::Create(PGUITRDisplayContext *a_pDisplayContext)
2424
{
2525
m_pDisplayContext = a_pDisplayContext;
26+
27+
if (m_iTextureCapacity < 200) {
28+
Texture **newTextures = new Texture *[200];
29+
if (!newTextures) {
30+
if (m_ppTextures) {
31+
delete[] m_ppTextures;
32+
m_ppTextures = TNULL;
33+
}
34+
m_iTextureCount = 0;
35+
m_iTextureCapacity = 0;
36+
return;
37+
}
38+
if (m_ppTextures) {
39+
Toshi::TSystem::MemCopy(newTextures, m_ppTextures, m_iTextureCount * sizeof(Texture *));
40+
delete[] m_ppTextures;
41+
}
42+
m_ppTextures = newTextures;
43+
m_iTextureCapacity = 200;
44+
}
45+
else {
46+
m_iTextureCount = 0;
47+
}
2648
}
2749

2850
// $PGUIRenderer: FUNCTION 10006c40
@@ -33,6 +55,73 @@ PGUITRTextureFactory::Texture *PGUITRTextureFactory::GetTexture(PGUITextureID a_
3355
return m_ppTextures[a_iID];
3456
}
3557

58+
// $PGUIRenderer: FUNCTION 10006a80
59+
void PGUITRTextureFactory::DestroyTexture(PGUITextureID a_iID)
60+
{
61+
Texture *texture = GetTexture(a_iID);
62+
if (texture) {
63+
delete texture;
64+
}
65+
m_ppTextures[a_iID] = TNULL;
66+
}
67+
68+
// $PGUIRenderer: FUNCTION 100070e0
69+
PGUITextureID PGUITRTextureFactory::AllocatedTextureID()
70+
{
71+
for (PGUITextureID id = 0; id < m_iTextureCount; id++) {
72+
if (m_ppTextures[id] == TNULL) {
73+
return id;
74+
}
75+
}
76+
if (m_iTextureCount + 1 > m_iTextureCapacity) {
77+
TINT newCapacity = TMAX(m_iTextureCapacity + m_iTextureAllocations, m_iTextureCount + 1);
78+
Texture **newTextures = new Texture *[newCapacity];
79+
if (!newTextures) {
80+
if (m_ppTextures) {
81+
delete[] m_ppTextures;
82+
}
83+
m_iTextureCount = 0;
84+
m_iTextureCapacity = 0;
85+
m_ppTextures = TNULL;
86+
return -1;
87+
}
88+
if (m_ppTextures) {
89+
Toshi::TSystem::MemCopy(newTextures, m_ppTextures, m_iTextureCount * sizeof(Texture *));
90+
delete[] m_ppTextures;
91+
}
92+
for (TINT i = m_iTextureCount; i < newCapacity; i++) {
93+
newTextures[i] = TNULL;
94+
}
95+
m_ppTextures = newTextures;
96+
m_iTextureCapacity = newCapacity;
97+
}
98+
return m_iTextureCount++;
99+
}
100+
101+
// $PGUIRenderer: FUNCTION 10006b20
102+
PGUITextureID PGUITRTextureFactory::GetTextureID(const Toshi::TPCString &a_rTextureName)
103+
{
104+
PGUITextureID textureID = FindTextureID(a_rTextureName);
105+
if (textureID == -1) {
106+
textureID = AllocatedTextureID();
107+
m_ppTextures[textureID] = new Texture(a_rTextureName, this, false);
108+
}
109+
return textureID;
110+
}
111+
112+
// $PGUIRenderer: FUNCTION 10006b80
113+
PGUITextureID PGUITRTextureFactory::FindTextureID(const Toshi::TPCString &a_rTextureName)
114+
{
115+
PGUITextureID textureID = m_iTextureCount == 0 ? -1 : 0;
116+
for (; textureID < m_iTextureCount; textureID++) {
117+
Texture *texture = m_ppTextures[textureID];
118+
if (texture && texture->GetName() == a_rTextureName) {
119+
break;
120+
}
121+
}
122+
return textureID;
123+
}
124+
36125
// $PGUIRenderer: FUNCTION 10006ac0
37126
PGUITextureID PGUITRTextureFactory::ReserveTextureID(const Toshi::TPCString &a_rTextureName)
38127
{

0 commit comments

Comments
 (0)