24 List::CreateSingleton();
26 m_iNumUsedTextures = 0;
27 m_iNumFreeTextures = 0;
31 m_FreeTextures.PushFront( &m_aSlots[ i ] );
40 auto pArray = a_pProperty->
GetArray();
42 for (
TUINT i = 0; i < pArray->GetSize(); i++ )
44 auto matlibName = pArray->GetValue( i )->GetTPString8();
45 auto eLangId = ALocaleManager::GetSingleton()->GetLanguage();
55 bLocaliseAsset =
TPString8(
"gui_loc" ) == matlibName;
60 TString8 localisedAssetName = matlibName.GetString8();
61 localisedAssetName +=
"_";
65 matlibName =
TPString8( localisedAssetName );
75 if ( a_bUpdateGUIMaterials && AGUISystem::GetSingleton() )
88 if ( !m_LoadedLibraries.IsValid( m_LoadedLibraries.Find( a_rLibName ) ) )
93 if ( !pRenderer->Supports32BitTextures() )
98 TCHAR matlibPath[ 128 ];
101 sizeof( matlibPath ),
102 "data/matlibs/%s%s%s.ttl",
108 AMaterialLibrary* pLibrary = List::GetSingleton()->CreateLibraryFromAsset( matlibPath, a_pTRB );
112 m_LoadedLibraries.Insert( a_rLibName, pLibrary );
114 m_NumRefLibraries.Insert( a_rLibName, 1 );
126 auto pRefCount = m_NumRefLibraries.Find( a_rLibName );
127 pRefCount->GetSecond() += 1;
134 auto eLangId = ALocaleManager::GetSingleton()->GetLanguage();
136 TBOOL bLocaliseAsset;
144 bLocaliseAsset =
TPString8(
"gui_loc" ) == matlibName;
147 if ( bLocaliseAsset )
150 localisedAssetName +=
"_";
154 matlibName =
TPString8( localisedAssetName );
159 auto pMatlibNode = m_LoadedLibraries.Find( matlibName );
161 if ( pMatlibNode != m_LoadedLibraries.End() )
163 auto pRefCountNode = m_NumRefLibraries.Find( matlibName );
165 if ( m_NumRefLibraries.IsValid( pRefCountNode ) )
167 pRefCountNode->GetSecond() -= 1;
169 if ( pRefCountNode->GetSecond() == 0 )
171 DestroyLibrary( pMatlibNode, a_bUnused );
172 m_NumRefLibraries.Remove( pRefCountNode );
178void AMaterialLibraryManager::DestroyLibrary( LibrariesMap::Iterator& a_rcMaterialLibraryNode,
TBOOL a_bUpdateGUIMaterials )
180 auto pMaterialLibrary = a_rcMaterialLibraryNode->GetSecond();
183 pMaterialLibrary->Destroy();
184 m_LoadedLibraries.Remove( a_rcMaterialLibraryNode );
189 if ( a_bUpdateGUIMaterials && AGUISystem::GetSingleton() )
197 for (
auto it = m_UsedTextures.Begin(); it != m_UsedTextures.End(); )
199 auto pNextNode = it->Next();
201 if ( it->GetLibrary() == a_pMaterialLibrary )
203 auto removedSlot = m_UsedTextures.Erase( it );
204 m_iNumUsedTextures -= 1;
206 removedSlot->GetTexture()->DestroyResource();
207 removedSlot->SetTexture(
TNULL );
208 removedSlot->ResetName();
210 m_FreeTextures.PushFront( removedSlot );
211 m_iNumFreeTextures += 1;
218 TTODO(
"FUN_006120e0" );
227 auto pMatlibTexture = a_pMatLibrary->
GetTexture( i );
229 auto pTexSlot = m_FreeTextures.PopFront();
230 m_iNumFreeTextures -= 1;
232 pTexSlot->SetName( pMatlibTexture->Name );
233 pTexSlot->SetLibrary( a_pMatLibrary );
234 pTexSlot->SetTexture( pTextureFactory->CreateFromT2Texture( pMatlibTexture->pTexture ) );
236 m_UsedTextures.PushFront( pTexSlot );
237 m_iNumUsedTextures += 1;
246 if ( a_bUpdateGUIMaterials && AGUISystem::GetSingleton() )
254 for (
auto it = m_UsedTextures.Begin(); it != m_UsedTextures.End(); it = it->Next() )
258 return it->GetTexture();
270 pLibrary->
SetPath( a_szFilePath );
272 if ( !pLibrary->LoadTRBFile( a_pTRB ) )
278 m_Libraries.PushBack( pLibrary );
287 pLibrary->
SetPath( a_szFilePath );
294 auto iFileNamePos = iFilePathLength - 1;
296 while ( a_szFilePath[ iFileNamePos ] !=
'\\' && a_szFilePath[ iFileNamePos ] !=
'/' )
301 TCHAR symbolName[ 132 ];
302 auto iLen = iFilePathLength - iFileNamePos - 4;
305 symbolName[ iLen ] =
'_';
306 symbolName[ iLen + 1 ] =
'\0';
314 bSuccess = pLibrary->LoadTTLData( pTTLData );
318 bSuccess = pLibrary->LoadTTLFile( a_szFilePath );
323 bSuccess = pLibrary->LoadTTLFile( a_szFilePath );
336 m_Libraries.PushBack( pLibrary );
352 auto it = m_Libraries.Begin();
356 if ( it == m_Libraries.End() )
361 iIndex = it->FindTextureIndex( a_szTextureName );
362 if ( iIndex != -1 )
break;
367 if ( a_ppMaterialLibrary )
369 *a_ppMaterialLibrary = it;
372 if ( a_pTextureIndex )
374 *a_pTextureIndex = iIndex;
377 return it->GetTexture( iIndex );
TRB (Toshi Relocatable Binary) resource system for the Toshi engine.
@ SYSRESOURCE_TEXTUREFACTORY
Rendering system interface for the Toshi engine.
#define TOSHI_NAMESPACE_USING
#define TPROFILER_SCOPE()
#define TDEFINE_CLASS(...)
ALoadScreen g_oLoadScreen
void * GetSymbolAddress(const TCHAR *symbName)
const class PBPropertyValueArray * GetArray() const
void FlushDyingResources()
T * GetSystemResource(SYSRESOURCE systemResource)
const TString8 & GetString8() const
TFORCEINLINE const TString8 & GetString8() const
TFORCEINLINE const TPooledString8 * GetPooledString() const
static TFORCEINLINE TRenderInterface * GetSingleton()
TINT Find(TCHAR character, TINT pos=0) const
const TCHAR * GetString(TINT a_iIndex=0) const
static void String8ToLowerCase(TCHAR *str)
static TSIZE String8Length(const TCHAR *str)
static TINT String8CompareNoCase(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
static void String8Format(TCHAR *str, TINT size, const TCHAR *format,...)
static TCHAR * String8Copy(TCHAR *dst, const TCHAR *src, TSIZE size=-1)
void SetPath(const TCHAR *a_szFilePath)
ATexture * GetTexture(TINT a_uiIndex)
TINT GetNumTextures() const
void UnloadLibrary(const Toshi::TPString8 &a_rLibName, TBOOL a_bUnused)
void OnLibraryLoaded(TBOOL a_bIsGUI)
void UnloadTexturesOfLibrary(AMaterialLibrary *a_pMaterialLibrary)
void LoadLibrariesFromProperties(const PBPropertyValue *a_pProperty, Toshi::TTRB *a_pTRB, TBOOL a_bUpdateGUIMaterials)
static constexpr TUINT MAX_NUM_TEXTURES
Toshi::TTexture * FindTexture(const TCHAR *a_szTextureName)
void CreateTextures(AMaterialLibrary *a_pMatLibrary)
void LoadLibrary(const Toshi::TPString8 &a_rLibName, Toshi::TTRB *a_pTRB, TBOOL a_bIsGUI)
AMaterialLibraryManager()
AMaterialLibrary * CreateLibraryFromAsset(const TCHAR *a_szFilePath, Toshi::TTRB *a_pTRB)
ATexture * FindTexture(const TCHAR *a_szTextureName, AMaterialLibrary **a_ppMaterialLibrary, TINT *a_pTextureIndex)
void DestroyLibrary(AMaterialLibrary *a_pLibrary)
AMaterialLibrary * CreateLibraryFromTRB(Toshi::TTRB *a_pTRB, const TCHAR *a_szFilePath)
static void UpdateMaterials()
static ALocaleManager * Interface()
const TCHAR * GetCurrentLanguageName()