@@ -10,7 +10,7 @@ IMPLEMENT_DYNCREATE(PGUITRTextureFactory, Toshi::TGUITextureFactory);
1010
1111// $PGUIRenderer: FUNCTION 100068e0
1212PGUITRTextureFactory::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()
2323void 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
37126PGUITextureID PGUITRTextureFactory::ReserveTextureID (const Toshi::TPCString &a_rTextureName)
38127{
0 commit comments