OpenBarnyard
 
Loading...
Searching...
No Matches
AMaterialLibraryManager.h
Go to the documentation of this file.
1#pragma once
2#include "AMaterialLibrary.h"
3
4#include <Toshi/TPString8.h>
6#include <Render/TTexture.h>
7#include <Toshi/T2Map.h>
8#include <Toshi/T2SList.h>
9
11 : public Toshi::TObject
12 , public Toshi::TSingleton<AMaterialLibraryManager>
13{
14public:
16
17public:
18 class List : public Toshi::TSingleton<List>
19 {
20 public:
21 AMaterialLibrary* CreateLibraryFromTRB( Toshi::TTRB* a_pTRB, const TCHAR* a_szFilePath );
22 AMaterialLibrary* CreateLibraryFromAsset( const TCHAR* a_szFilePath, Toshi::TTRB* a_pTRB );
23 void DestroyLibrary( AMaterialLibrary* a_pLibrary );
24 ATexture* FindTexture( const TCHAR* a_szTextureName, AMaterialLibrary** a_ppMaterialLibrary, TINT* a_pTextureIndex );
25
26 private:
27 Toshi::T2DList<AMaterialLibrary> m_Libraries;
28 };
29
30 class TextureSlot : public Toshi::T2SList<TextureSlot>::Node
31 {
32 public:
33 TextureSlot() = default;
34
35 void SetTexture( Toshi::TTexture* a_pTexture )
36 {
37 m_pTexture = a_pTexture;
38 }
39
40 Toshi::TTexture* GetTexture() const
41 {
42 return m_pTexture;
43 }
44
45 void SetName( const Toshi::TString8& a_Name )
46 {
47 m_Name = a_Name;
48 m_Name.MakeLower();
49 }
50
51 void ResetName()
52 {
53 m_Name = "";
54 }
55
56 const Toshi::TString8& GetName()
57 {
58 return m_Name;
59 }
60
62 {
63 return m_pMaterialLibrary;
64 }
65
66 void SetLibrary( AMaterialLibrary* a_pLibrary )
67 {
68 m_pMaterialLibrary = a_pLibrary;
69 }
70
71 private:
72 Toshi::TTexture* m_pTexture;
73 Toshi::TString8 m_Name;
74 AMaterialLibrary* m_pMaterialLibrary;
75 };
76
77 using LibrariesMap = Toshi::T2Map<Toshi::TPString8, AMaterialLibrary*, Toshi::TPString8::Comparator>;
78
79 static constexpr TUINT MAX_NUM_TEXTURES = 600;
80
81public:
83
84 void LoadLibrariesFromProperties( const PBPropertyValue* a_pProperty, Toshi::TTRB* a_pTRB, TBOOL a_bUpdateGUIMaterials );
85 void LoadLibrary( const Toshi::TPString8& a_rLibName, Toshi::TTRB* a_pTRB, TBOOL a_bIsGUI );
86 void UnloadLibrary( const Toshi::TPString8& a_rLibName, TBOOL a_bUnused );
87
88 void CreateTextures( AMaterialLibrary* a_pMatLibrary );
89 void OnLibraryLoaded( TBOOL a_bIsGUI );
90
91 Toshi::TTexture* FindTexture( const TCHAR* a_szTextureName );
92 TINT GetNumUsedTextures() const { return m_iNumUsedTextures; }
93 TINT GetNumFreeTextures() const { return m_iNumFreeTextures; }
94
95 void UnloadTexturesOfLibrary( AMaterialLibrary* a_pMaterialLibrary );
96
97private:
98 void DestroyLibrary( LibrariesMap::Iterator& a_rcMaterialLibraryNode, TBOOL a_bUpdateGUIMaterials );
99
100private:
101 Toshi::T2Map<Toshi::TPString8, int, Toshi::TPString8::Comparator> m_NumRefLibraries;
102 LibrariesMap m_LoadedLibraries;
103 TextureSlot m_aSlots[ MAX_NUM_TEXTURES ];
104 Toshi::T2SList<TextureSlot> m_UsedTextures;
105 Toshi::T2SList<TextureSlot> m_FreeTextures;
106 TINT m_iNumUsedTextures;
107 TINT m_iNumFreeTextures;
108};
Texture system for the Toshi engine.
#define TDECLARE_CLASS(THIS_CLASS, PARENT_CLASS)
Definition TObject.h:38
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
int TINT
Definition Typedefs.h:7
bool TBOOL
Definition Typedefs.h:6
Toshi::T2Map< Toshi::TPString8, AMaterialLibrary *, Toshi::TPString8::Comparator > LibrariesMap
void UnloadLibrary(const Toshi::TPString8 &a_rLibName, TBOOL a_bUnused)
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)
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)
void SetTexture(Toshi::TTexture *a_pTexture)
void SetName(const Toshi::TString8 &a_Name)
void SetLibrary(AMaterialLibrary *a_pLibrary)