OpenBarnyard
 
Loading...
Searching...
No Matches
TResource.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TResource.h"
3#include "TRenderInterface.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
14
16{
17 m_State = 0;
18 m_UId = 0;
19 m_pRenderer = TNULL;
20 m_Name[ 0 ] = 0;
21}
22
27
29{
30 TASSERT( TFALSE == IsCreated(), "This resource is already created" );
31
32 m_State |= TResourceState_Created;
33 return TTRUE;
34}
35
37{
38 TASSERT( IsDying() == TFALSE, "Resource is dying and cannot be validated" );
39 TASSERT( Parent() == TNULL || Parent()->IsDying() == TFALSE, "Parent resource is dying" );
40
41 if ( IsDying() ) return TFALSE;
42
43 m_State |= TResourceState_Valid;
44 return TTRUE;
45}
46
48{
49 m_State &= ~TResourceState_Valid;
50}
51
56
61
63{
64 return TTRUE;
65}
66
68{
69 TASSERT( TTRUE == IsCreated(), "Tried to destroy resource that wasn't created" );
70
71 m_State &= ~TResourceState_Created;
72 m_State |= TResourceState_Dying;
73}
74
76{
77 auto pTree = TNode::Tree();
78
79 pTree->Remove( this );
80
81 if ( !a_pParent )
82 {
83 if ( pTree )
84 {
85 pTree->InsertAtRoot( this );
86 }
87 }
88 else
89 {
90 pTree->Insert( a_pParent, this );
91 }
92}
93
94void TResource::SetName( const TCHAR* name )
95{
96 // 006b5350
97 if ( name == TNULL )
98 {
99 name = "res:";
100
101 TCHAR UIdStr[ 12 ];
102 T2String8::IntToString( m_UId, UIdStr, 0xE, 10 );
103 }
104
105 TASSERT( TStringManager::String8Length( name ) <= MAXNAMELEN, "Name is too long" );
106 TStringManager::String8Copy( m_Name, name, -1 );
107}
108
109TBOOL TResource::RecurseSimple( t_RecurseCb a_pCallback, TResource* a_pResource, void* a_pUserData )
110{
111 if ( a_pResource )
112 return Recurse( a_pCallback, a_pResource, TFALSE, a_pUserData );
113 else
114 return Recurse( a_pCallback, Child(), TTRUE, a_pUserData );
115}
116
117TBOOL TResource::Recurse( t_RecurseCb a_pCallback, TResource* a_pResource, TBOOL a_bFlag, void* a_pUserData )
118{
119 TResource* pRes = a_pResource;
120
121 if ( TNULL != a_pResource )
122 {
123 TResource* pNext;
124
125 do
126 {
127 pNext = pRes->Next();
128
129 if ( pNext == a_pResource || pNext == pRes || !a_bFlag )
130 pNext = TNULL;
131
132 if ( !a_pCallback( pRes, a_pUserData ) )
133 return TFALSE;
134
135 if ( pRes->Child() && !Recurse( a_pCallback, pRes->Child(), TTRUE, a_pUserData ) )
136 return TFALSE;
137
138 pRes = pNext;
139
140 } while ( pNext != TNULL );
141 }
142
143 return TTRUE;
144}
145
146Toshi::TRenderInterface* TResource::GetRenderer() const
147{
148 return m_pRenderer;
149}
150
152{
153 m_pRenderer = pRenderer;
154}
155
157{
158 return m_UId;
159}
160
162{
163 m_UId = uid;
164}
165
Rendering system interface for the Toshi engine.
@ TResourceState_Dead
Definition TResource.h:15
@ TResourceState_Valid
Definition TResource.h:11
@ TResourceState_Dying
Definition TResource.h:13
@ TResourceState_Created
Definition TResource.h:12
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define TDEFINE_CLASS(...)
Definition TObject.h:120
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
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
void DestroyResource(TResource *resource)
virtual void DestroyResource()
Definition TResource.cpp:52
TBOOL IsCreated() const
Definition TResource.h:46
static constexpr size_t MAXNAMELEN
Definition TResource.h:25
virtual void OnDestroy()
Definition TResource.cpp:67
void SetUId(TUINT32 uid)
virtual void Invalidate()
Definition TResource.cpp:47
virtual TBOOL Validate()
Definition TResource.cpp:36
void SetRenderer(TRenderInterface *pRenderer)
virtual TBOOL Create()
Definition TResource.cpp:28
void SetParent(TResource *a_pParent)
Definition TResource.cpp:75
TBOOL RecurseSimple(t_RecurseCb a_pCallback, TResource *a_pResource, void *a_pUserData)
virtual TBOOL TryValidate()
Definition TResource.cpp:62
static TBOOL Recurse(t_RecurseCb a_pCallback, TResource *a_pResource, TBOOL a_bFlag, void *a_pUserData)
TUINT32 GetUId() const
TRenderInterface * GetRenderer() const
TBOOL(*)(TResource *a_pResource, void *a_pUserData) t_RecurseCb
Definition TResource.h:28
friend TRenderInterface
Definition TResource.h:26
virtual TBOOL TryInvalidate()
Definition TResource.cpp:57
TBOOL IsDying() const
Definition TResource.h:43
void SetName(const TCHAR *name)
Definition TResource.cpp:94
static void IntToString(TINT value, TCHAR *dst, TINT unused, TINT radix)
T * Parent() const
Definition TNodeTree.h:33
T * Child() const
Definition TNodeTree.h:37
T * Next() const
Definition TNodeTree.h:34
static TSIZE String8Length(const TCHAR *str)
static TCHAR * String8Copy(TCHAR *dst, const TCHAR *src, TSIZE size=-1)