OpenBarnyard
 
Loading...
Searching...
No Matches
AMaterialLibrary.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "AMaterialLibrary.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12{
13 m_iNumTextures = 0;
14}
15
17{
19
20 TTL* pTTL = TSTATICCAST( TTL, a_pTTLData );
21
22 auto pLibList = AMaterialLibraryManager::List::GetSingleton();
23 TINT iNumTextures = 0;
24
25 if ( ms_bSkipLoadedTextures )
26 {
27 for ( TINT i = 0; i < pTTL->m_iNumTextures; i++ )
28 {
29 if ( !pLibList->FindTexture( pTTL->m_pTextureInfos[ i ].m_szFileName, TNULL, TNULL ) )
30 {
31 iNumTextures++;
32 }
33 }
34 }
35 else
36 {
37 iNumTextures = pTTL->m_iNumTextures;
38 }
39
40 m_pTexturesArray = new ATexture[ iNumTextures ];
41 m_pTextures = m_pTexturesArray;
42 m_iNumTextures = iNumTextures;
43
44 for ( TINT i = 0; i < iNumTextures; i++ )
45 {
46 auto pTexInfo = &pTTL->m_pTextureInfos[ i ];
47
48 if ( !ms_bSkipLoadedTextures || !pLibList->FindTexture( pTexInfo->m_szFileName, TNULL, TNULL ) )
49 {
50 TASSERT( pTexInfo->m_bIsT2Texture == TRUE, "No support of other texture types" );
51 m_pTextures[ i ].Name = pTexInfo->m_szFileName;
52
53 if ( pTexInfo->m_bIsT2Texture == TRUE )
54 {
55 auto pTexture = new Toshi::T2Texture;
56
57 if ( pTexture )
58 {
59 void* pData = TMalloc( pTexInfo->m_uiDataSize );
60
61 Toshi::TUtil::MemCopy( pData, pTexInfo->m_pData, pTexInfo->m_uiDataSize );
62 pTexture->SetData( pData, pTexInfo->m_uiDataSize );
63 pTexture->Load();
64 }
65
66 m_pTextures[ i ].pTexture = pTexture;
67 }
68 }
69 }
70
71 return TTRUE;
72}
73
75{
76 m_TRB.Load( a_szFilePath );
77 LoadTTLData( m_TRB.GetSymbolAddress( "TTL" ) );
78 m_TRB.Close();
79
80 return TTRUE;
81}
82
84{
85 void* pTTL = a_pTRB->GetSymbolAddress( "TTL" );
86 TASSERT( TNULL != pTTL );
87
88 LoadTTLData( pTTL );
89 a_pTRB->Close();
90
91 return TTRUE;
92}
93
95{
96 Node::Remove();
97 DestroyTextures();
98 delete this;
99}
100
101void AMaterialLibrary::DestroyTextures()
102{
103 for ( TINT i = 0; i < m_iNumTextures; i++ )
104 {
105 if ( m_pTextures[ i ].pTexture )
106 {
107 delete m_pTextures[ i ].pTexture;
108 m_pTextures[ i ].pTexture = TNULL;
109 }
110 }
111
112 m_pTextures = TNULL;
113 m_iNumTextures = 0;
114 delete[] m_pTexturesArray;
115 m_pTexturesArray = TNULL;
116}
117
119{
120 for ( TINT i = 0; i < m_iNumTextures; i++ )
121 {
122 if ( Toshi::TStringManager::String8CompareNoCase( m_pTextures[ i ].Name, a_szTextureName ) == 0 )
123 {
124 return i;
125 }
126 }
127
128 return -1;
129}
void * TMalloc(TSIZE a_uiSize, Toshi::TMemory::MemBlock *a_pMemBlock, const TCHAR *a_szFileName, TINT a_iLineNum)
Allocates memory from a specific memory block.
Definition TMemory.cpp:973
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TPROFILER_SCOPE()
Definition Profiler.h:17
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
TBOOL LoadTTLFile(const TCHAR *a_szFilePath)
TBOOL LoadTTLData(void *a_pTTLData)
TINT FindTextureIndex(const TCHAR *a_szTextureName)
TBOOL LoadTRBFile(Toshi::TTRB *a_pTRB)
Toshi::T2Texture * pTexture
Definition ATexture.h:11