OpenBarnyard
 
Loading...
Searching...
No Matches
TResource Class Reference

#include <TResource.h>

Inheritance diagram for TResource:
TObject TNodeTree< T >::TNode TIndexBlockResource TIndexFactoryResourceInterface TIndexPoolResourceInterface TNullResource TTexture TTextureFactory TVertexBlockResource TVertexFactoryResourceInterface TVertexPoolResourceInterface

Public Types

using t_RecurseCb = TBOOL ( * )( TResource* a_pResource, void* a_pUserData )
 
- Public Types inherited from TObject
enum  { IsTObject = TTRUE }
 

Public Member Functions

 TDECLARE_CLASS (TResource, TObject)
 
 TResource ()
 
 ~TResource ()
 
virtual TBOOL Create ()
 
virtual TBOOL Validate ()
 
virtual void Invalidate ()
 
virtual void DestroyResource ()
 
virtual TBOOL TryInvalidate ()
 
virtual TBOOL TryValidate ()
 
virtual void OnDestroy ()
 
TBOOL IsDead () const
 
TBOOL IsDying () const
 
TBOOL IsValid () const
 
TBOOL IsExternal () const
 
TBOOL IsCreated () const
 
TBOOL IsSceneObject () const
 
TBOOL IsInvalid () const
 
void SetState (TResourceState newState)
 
void AddState (TResourceState state)
 
void SetParent (TResource *a_pParent)
 
const TCHARGetName () const
 
void SetName (const TCHAR *name)
 
TBOOL RecurseSimple (t_RecurseCb a_pCallback, TResource *a_pResource, void *a_pUserData)
 
TRenderInterfaceGetRenderer () const
 
void SetRenderer (TRenderInterface *pRenderer)
 
TUINT32 GetUId () const
 
void SetUId (TUINT32 uid)
 
- Public Member Functions inherited from TObject
virtual Toshi::TClass * GetClass ()
 
virtual void Delete ()
 
virtual ~TObject ()
 
TBOOL IsExactly (TClass *a_pClass)
 
TBOOL IsA (TClass *a_pClass)
 
- Public Member Functions inherited from TNodeTree< T >::TNode
TBOOL IsChildOfDefaultRoot () const
 
TBOOL IsLinked () const
 
T * Parent () const
 
T * Next () const
 
T * Prev () const
 
TNodeTree< T > * Tree () const
 
T * Child () const
 

Static Public Member Functions

static TBOOL Recurse (t_RecurseCb a_pCallback, TResource *a_pResource, TBOOL a_bFlag, void *a_pUserData)
 
- Static Public Member Functions inherited from TObject
static Toshi::TObject * CreateTObject ()
 
static Toshi::TObject * CreateTObjectInPlace (void *a_pPtr)
 
static void InitialiseClass ()
 
static void DeinitialiseClass ()
 
static TFORCEINLINE TClassGetClassStatic ()
 

Public Attributes

friend TRenderInterface
 
- Public Attributes inherited from TNodeTree< T >::TNode
friend TNodeTree
 

Static Public Attributes

static constexpr size_t MAXNAMELEN = 14
 
- Static Public Attributes inherited from TObject
static constexpr Toshi::TClass * PARENTCLASS = TNULL
 
static constinit Toshi::TClass ms_oClass = Toshi::TClass( "TObject", TObject::CreateTObject, TObject::CreateTObjectInPlace, TObject::InitialiseClass, TObject::DeinitialiseClass, 0, 2, sizeof( TObject ), alignof( TObject ) )
 

Additional Inherited Members

- Protected Member Functions inherited from TNodeTree< T >::TNode
 TNode ()
 
- Protected Attributes inherited from TNodeTree< T >::TNode
TNodeTree< T > * m_Tree
 
T * m_Next
 
T * m_Prev
 
T * m_Parent
 
T * m_Child
 

Detailed Description

Definition at line 19 of file TResource.h.

Member Typedef Documentation

◆ t_RecurseCb

using TResource::t_RecurseCb = TBOOL ( * )( TResource* a_pResource, void* a_pUserData )

Definition at line 28 of file TResource.h.

Constructor & Destructor Documentation

◆ TResource()

TResource::TResource ( )

Definition at line 15 of file TResource.cpp.

16{
17 m_State = 0;
18 m_UId = 0;
19 m_pRenderer = TNULL;
20 m_Name[ 0 ] = 0;
21}
#define TNULL
Definition Typedefs.h:23

◆ ~TResource()

TResource::~TResource ( )

Definition at line 23 of file TResource.cpp.

24{
25 m_State |= TResourceState_Dead;
26}
@ TResourceState_Dead
Definition TResource.h:15

Member Function Documentation

◆ AddState()

void TResource::AddState ( TResourceState state)
inline

Definition at line 51 of file TResource.h.

51{ m_State |= state; }

◆ Create()

TBOOL TResource::Create ( )
virtual

Definition at line 28 of file TResource.cpp.

29{
30 TASSERT( TFALSE == IsCreated(), "This resource is already created" );
31
32 m_State |= TResourceState_Created;
33 return TTRUE;
34}
@ TResourceState_Created
Definition TResource.h:12
#define TASSERT(X,...)
Definition Defines.h:138
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
TBOOL IsCreated() const
Definition TResource.h:46

◆ DestroyResource()

void TResource::DestroyResource ( )
virtual

Definition at line 52 of file TResource.cpp.

53{
55}
void DestroyResource(TResource *resource)
TRenderInterface * GetRenderer() const

◆ GetName()

const TCHAR * TResource::GetName ( ) const
inline

Definition at line 55 of file TResource.h.

55{ return m_Name; }

◆ GetRenderer()

Toshi::TRenderInterface * TResource::GetRenderer ( ) const

Definition at line 146 of file TResource.cpp.

147{
148 return m_pRenderer;
149}

◆ GetUId()

TUINT32 TResource::GetUId ( ) const

Definition at line 156 of file TResource.cpp.

157{
158 return m_UId;
159}

◆ Invalidate()

void TResource::Invalidate ( )
virtual

Reimplemented in TIndexBlockResource, TIndexPoolResource, TTextureResourceHAL, TVertexBlockResource, and TVertexPoolResource.

Definition at line 47 of file TResource.cpp.

48{
49 m_State &= ~TResourceState_Valid;
50}

◆ IsCreated()

TBOOL TResource::IsCreated ( ) const
inline

Definition at line 46 of file TResource.h.

46{ return m_State & TResourceState_Created; }

◆ IsDead()

TBOOL TResource::IsDead ( ) const
inline

Definition at line 42 of file TResource.h.

42{ return m_State & TResourceState_Dead; }

◆ IsDying()

TBOOL TResource::IsDying ( ) const
inline

Definition at line 43 of file TResource.h.

43{ return m_State & TResourceState_Dying; }
@ TResourceState_Dying
Definition TResource.h:13

◆ IsExternal()

TBOOL TResource::IsExternal ( ) const
inline

Definition at line 45 of file TResource.h.

45{ return m_State & TResourceState_External; }
@ TResourceState_External
Definition TResource.h:14

◆ IsInvalid()

TBOOL TResource::IsInvalid ( ) const
inline

Definition at line 48 of file TResource.h.

48{ return ~m_State & TResourceState_Valid; }
@ TResourceState_Valid
Definition TResource.h:11

◆ IsSceneObject()

TBOOL TResource::IsSceneObject ( ) const
inline

Definition at line 47 of file TResource.h.

47{ return m_State & TResourceState_SceneObject; }
@ TResourceState_SceneObject
Definition TResource.h:16

◆ IsValid()

TBOOL TResource::IsValid ( ) const
inline

Definition at line 44 of file TResource.h.

44{ return m_State & TResourceState_Valid; }

◆ OnDestroy()

void TResource::OnDestroy ( )
virtual

Reimplemented in TIndexPoolResource, TIndexPoolResourceInterface, TVertexPoolResource, and TVertexPoolResourceInterface.

Definition at line 67 of file TResource.cpp.

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}

◆ Recurse()

TBOOL TResource::Recurse ( t_RecurseCb a_pCallback,
TResource * a_pResource,
TBOOL a_bFlag,
void * a_pUserData )
static

Definition at line 117 of file TResource.cpp.

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}
static TBOOL Recurse(t_RecurseCb a_pCallback, TResource *a_pResource, TBOOL a_bFlag, void *a_pUserData)
T * Child() const
Definition TNodeTree.h:37
T * Next() const
Definition TNodeTree.h:34

◆ RecurseSimple()

TBOOL TResource::RecurseSimple ( t_RecurseCb a_pCallback,
TResource * a_pResource,
void * a_pUserData )

Definition at line 109 of file TResource.cpp.

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}

◆ SetName()

void TResource::SetName ( const TCHAR * name)

Definition at line 94 of file TResource.cpp.

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}
char TCHAR
Definition Typedefs.h:20
static constexpr size_t MAXNAMELEN
Definition TResource.h:25
static void IntToString(TINT value, TCHAR *dst, TINT unused, TINT radix)
static TSIZE String8Length(const TCHAR *str)
static TCHAR * String8Copy(TCHAR *dst, const TCHAR *src, TSIZE size=-1)

◆ SetParent()

void TResource::SetParent ( TResource * a_pParent)

Definition at line 75 of file TResource.cpp.

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}

◆ SetRenderer()

void TResource::SetRenderer ( TRenderInterface * pRenderer)

Definition at line 151 of file TResource.cpp.

152{
153 m_pRenderer = pRenderer;
154}

◆ SetState()

void TResource::SetState ( TResourceState newState)
inline

Definition at line 50 of file TResource.h.

50{ m_State = newState; }

◆ SetUId()

void TResource::SetUId ( TUINT32 uid)

Definition at line 161 of file TResource.cpp.

162{
163 m_UId = uid;
164}

◆ TDECLARE_CLASS()

TResource::TDECLARE_CLASS ( TResource ,
TObject  )

◆ TryInvalidate()

TBOOL TResource::TryInvalidate ( )
virtual

Reimplemented in TIndexBlockResource, and TVertexBlockResource.

Definition at line 57 of file TResource.cpp.

58{
59 return TTRUE;
60}

◆ TryValidate()

TBOOL TResource::TryValidate ( )
virtual

Reimplemented in TIndexBlockResource, and TVertexBlockResource.

Definition at line 62 of file TResource.cpp.

63{
64 return TTRUE;
65}

◆ Validate()

TBOOL TResource::Validate ( )
virtual

Reimplemented in TIndexBlockResource, TIndexPoolResource, TTextureResourceHAL, TVertexBlockResource, and TVertexPoolResource.

Definition at line 36 of file TResource.cpp.

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}
TBOOL IsDying() const
Definition TResource.h:43
T * Parent() const
Definition TNodeTree.h:33

Member Data Documentation

◆ MAXNAMELEN

size_t TResource::MAXNAMELEN = 14
staticconstexpr

Definition at line 25 of file TResource.h.

◆ TRenderInterface

friend TResource::TRenderInterface

Definition at line 26 of file TResource.h.


The documentation for this class was generated from the following files: