OpenBarnyard
 
Loading...
Searching...
No Matches
TTextureFactory.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TTextureFactory.h"
3#include "TTexture.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
11TDEFINE_CLASS_NORUNTIME( Toshi::TTextureFactory );
12
14
16{
17 auto uiNameLen = TStringManager::String8Length( a_szName );
18 TASSERT( uiNameLen < MAX_TEXTURENAMELEN );
19
21 m_pTexture = a_pTexture;
22}
23
28
30{
31 for ( TUINT32 i = 0; i < NUM_LISTS; i++ )
32 {
33 m_aLists[ i ].DeleteAll();
34 }
35}
36
38{
39 TUINT uiTexIndex = 0;
40
41 for ( TUINT32 i = 0; i < NUM_LISTS; i++ )
42 {
43 for ( auto it = m_aLists[ i ].Begin(); it != m_aLists[ i ].End(); it++ )
44 {
45 TTRACE( "[%d] Texture [%s]: W=%d , H=%d\n", uiTexIndex++, it->GetName(), it->GetTexture()->GetWidth(), it->GetTexture()->GetHeight() );
46 }
47 }
48}
49
51{
52 TASSERT( a_uiList < NUM_LISTS );
53 return &m_aLists[ a_uiList ];
54}
55
57{
58 auto pList = &m_aLists[ HashName( a_szName ) ];
59
60 for ( auto it = pList->Begin(); it != pList->End(); it++ )
61 {
62 if ( 0 == TStringManager::String8CompareNoCase( it->GetName(), a_szName ) )
63 {
64 return it->GetTexture();
65 }
66 }
67
68 return TNULL;
69}
70
72{
73 auto pList = &m_aLists[ HashName( a_szName ) ];
74 auto pEntry = new TTextureFactory::NameEntry( a_szName, a_pTexture );
75
76 a_pTexture->m_pNameEntry = pEntry;
77 pList->InsertHead( pEntry );
78
79 return a_pTexture->m_pNameEntry;
80}
81
83{
84 TVALIDPTR( a_pTexture );
85
86 auto pNameEntry = a_pTexture->m_pNameEntry;
87
88 if ( pNameEntry )
89 {
90 pNameEntry->Remove();
91 delete pNameEntry;
92 }
93}
94
96{
97 TUINT32 iHash = 0;
98
99 for ( TSIZE i = 0; i < TStringManager::String8Length( a_szName ); i++ )
100 {
101 iHash += a_szName[ i ];
102 }
103
104 return iHash % NUM_LISTS;
105}
106
Texture system for the Toshi engine.
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TTRACE(...)
Definition Defines.h:155
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define TVALIDPTR(PTR)
Definition Defines.h:139
#define TDEFINE_CLASS_NORUNTIME(...)
Definition TObject.h:138
unsigned int TUINT
Definition Typedefs.h:8
size_t TSIZE
Definition Typedefs.h:9
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
uint32_t TUINT32
Definition Typedefs.h:13
#define TFALSE
Definition Typedefs.h:24
TTextureFactory::NameEntry * m_pNameEntry
Definition TTexture.h:78
TNodeList< NameEntry > * GetList(TUINT a_uiList)
NameEntry * RegisterTexture(const TCHAR *a_szName, TTexture *a_pTexture)
virtual void Dump() const
void DeregisterTexture(TTexture *a_pTexture)
TTexture * FindTexture(const TCHAR *a_szName) const
static TUINT32 HashName(const TCHAR *a_szName)
static constexpr TUINT32 NUM_LISTS
static constexpr TUINT32 MAX_TEXTURENAMELEN
NameEntry(const TCHAR *a_szName, TTexture *a_pTexture)
TBOOL IsLinked() const
Definition TNodeTree.h:32
static TSIZE String8Length(const TCHAR *str)
static TINT String8CompareNoCase(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
static TCHAR * String8Copy(TCHAR *dst, const TCHAR *src, TSIZE size=-1)