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

#include <TIndexPoolResource_DX8.h>

Inheritance diagram for TIndexPoolResource:
TIndexPoolResourceInterface TResource TObject TNodeTree< T >::TNode

Public Member Functions

 TDECLARE_CLASS (TIndexPoolResource, TIndexPoolResourceInterface)
 
 TIndexPoolResource ()
 
 ~TIndexPoolResource ()
 
virtual TBOOL Validate () override
 
virtual void Invalidate () override
 
virtual void OnDestroy () override
 
virtual TBOOL Lock (LockBuffer *a_pLockBuffer) override
 
virtual void Unlock (TUINT16 a_uiNewNumIndices) override
 
virtual TBOOL Create (TIndexFactoryResourceInterface *a_pFactory, TUINT16 a_uiMaxIndices, TUINT16 a_uiFlags) override
 
TUINT16GetIndices ()
 
TResourceGetParent ()
 
TIndexBlockResourceGetIndexBlock ()
 
TBOOL GetHALBuffer (TIndexBlockResource::HALBuffer *a_pHALBuffer)
 
- Public Member Functions inherited from TIndexPoolResourceInterface
 TDECLARE_CLASS (TIndexPoolResourceInterface, TResource)
 
 TIndexPoolResourceInterface ()
 
TIndexFactoryResourceInterfaceGetFactory () const
 
TUINT16 GetFlags () const
 
TUINT16 GetMaxIndices () const
 
TUINT16 GetNumIndices () const
 
TBOOL IsLocked () const
 
- Public Member Functions inherited from TResource
 TDECLARE_CLASS (TResource, TObject)
 
 TResource ()
 
 ~TResource ()
 
virtual TBOOL Create ()
 
virtual void DestroyResource ()
 
virtual TBOOL TryInvalidate ()
 
virtual TBOOL TryValidate ()
 
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
 

Public Attributes

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

Additional Inherited Members

- Public Types inherited from TResource
using t_RecurseCb = TBOOL ( * )( TResource* a_pResource, void* a_pUserData )
 
- Public Types inherited from TObject
enum  { IsTObject = TTRUE }
 
- Static Public Member Functions inherited from TResource
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 ()
 
- Static Public Attributes inherited from TResource
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 ) )
 
- Protected Member Functions inherited from TNodeTree< T >::TNode
 TNode ()
 
- Protected Attributes inherited from TIndexPoolResourceInterface
TIndexFactoryResourceInterfacem_pFactory
 
TUINT16 m_uiFlags
 
TUINT16 m_uiMaxIndices
 
TUINT16 m_uiNumIndices
 
TUINT16 m_uiLockCount
 
- 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 9 of file TIndexPoolResource_DX8.h.

Constructor & Destructor Documentation

◆ TIndexPoolResource()

TIndexPoolResource::TIndexPoolResource ( )

Definition at line 17 of file TIndexPoolResource_DX8.cpp.

18{
19 m_uiIndexOffset = 0;
20 m_pIndices = TNULL;
21 m_uiNumLocksAllTime = 0;
22}
#define TNULL
Definition Typedefs.h:23

◆ ~TIndexPoolResource()

TIndexPoolResource::~TIndexPoolResource ( )

Definition at line 25 of file TIndexPoolResource_DX8.cpp.

26{
27}

Member Function Documentation

◆ Create()

TBOOL TIndexPoolResource::Create ( TIndexFactoryResourceInterface * a_pFactory,
TUINT16 a_uiMaxIndices,
TUINT16 a_uiFlags )
overridevirtual

Reimplemented from TIndexPoolResourceInterface.

Definition at line 185 of file TIndexPoolResource_DX8.cpp.

186{
187 if ( a_uiFlags & 4 )
188 {
189 a_uiFlags = a_uiFlags & 0xfffb | 2;
190 }
191
192 if ( TIndexPoolResourceInterface::Create( a_pFactory, a_uiMaxIndices, a_uiFlags ) )
193 {
194 if ( m_uiFlags & 1 )
195 {
196 m_pIndices = new TIndexType[ a_uiMaxIndices ];
197 TVALIDPTR( m_pIndices );
198 }
199
200 return TTRUE;
201 }
202
203 return TFALSE;
204}
TUINT16 TIndexType
#define TVALIDPTR(PTR)
Definition Defines.h:139
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
virtual TBOOL Create()
Definition TResource.cpp:28

◆ GetHALBuffer()

TBOOL TIndexPoolResource::GetHALBuffer ( TIndexBlockResource::HALBuffer * a_pHALBuffer)

Definition at line 228 of file TIndexPoolResource_DX8.cpp.

229{
230 TVALIDPTR( a_pHALBuffer );
231
232 if ( Validate() )
233 {
234 auto pIndexBlock = GetIndexBlock();
235 TVALIDPTR( pIndexBlock );
236
237 if ( pIndexBlock->Validate() && pIndexBlock->GetHALBuffer( a_pHALBuffer ) )
238 {
239 a_pHALBuffer->uiIndexOffset = m_uiIndexOffset;
240 return TTRUE;
241 }
242 }
243
244 return TFALSE;
245}
TIndexBlockResource * GetIndexBlock()
virtual TBOOL Validate() override

◆ GetIndexBlock()

TIndexBlockResource * TIndexPoolResource::GetIndexBlock ( )

Definition at line 217 of file TIndexPoolResource_DX8.cpp.

218{
220 {
222 }
223
224 return TNULL;
225}
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TGetClass(CLASS)
Definition TObject.h:13
T * Parent() const
Definition TNodeTree.h:33
TBOOL IsExactly(TClass *a_pClass)
Definition TObject.h:191

◆ GetIndices()

TUINT16 * TIndexPoolResource::GetIndices ( )

Definition at line 248 of file TIndexPoolResource_DX8.cpp.

249{
250 return ( m_uiLockCount == 0 ) ? m_pIndices : TNULL;
251}

◆ GetParent()

TResource * TIndexPoolResource::GetParent ( )

Definition at line 206 of file TIndexPoolResource_DX8.cpp.

207{
208 if ( Tree() )
209 {
210 return Parent() == Tree()->GetRoot() ? TNULL : Parent();
211 }
212
213 return Parent();
214}
TNodeTree< T > * Tree() const
Definition TNodeTree.h:36

◆ Invalidate()

void TIndexPoolResource::Invalidate ( )
overridevirtual

Reimplemented from TResource.

Definition at line 81 of file TIndexPoolResource_DX8.cpp.

82{
83 if ( IsCreated() && IsValid() )
84 {
85 TASSERT( m_uiLockCount == 0 );
86
87 auto pIndexBlock = GetIndexBlock();
88 TVALIDPTR( pIndexBlock );
89
90 pIndexBlock->DettachPool( this );
92 }
93}
#define TASSERT(X,...)
Definition Defines.h:138
TBOOL IsCreated() const
Definition TResource.h:46
virtual void Invalidate()
Definition TResource.cpp:47
TBOOL IsValid() const
Definition TResource.h:44

◆ Lock()

TBOOL TIndexPoolResource::Lock ( LockBuffer * a_pLockBuffer)
overridevirtual

Implements TIndexPoolResourceInterface.

Definition at line 108 of file TIndexPoolResource_DX8.cpp.

109{
110 TVALIDPTR( a_pLockBuffer );
111
112 auto uiOldLockCount = m_uiLockCount;
113 m_uiNumLocksAllTime += 1;
114 m_uiLockCount += 1;
115
116 if ( uiOldLockCount == 0 )
117 {
118 TUINT8 uiUnk1 = m_uiFlags & 7;
119
120 if ( uiUnk1 == 1 )
121 {
122 a_pLockBuffer->pBuffer = m_pIndices;
123 return TTRUE;
124 }
125 else if ( uiUnk1 == 2 )
126 {
127 Validate();
128
129 if ( GetIndexBlock()->Lock( a_pLockBuffer, 0 ) )
130 {
131 m_uiIndexOffset = a_pLockBuffer->uiOffset;
132 return TTRUE;
133 }
134 }
135 else if ( uiUnk1 == 4 )
136 {
137 Validate();
138
139 if ( GetIndexBlock()->Lock( a_pLockBuffer, GetMaxIndices() ) )
140 {
141 m_uiIndexOffset = a_pLockBuffer->uiOffset;
142 return TTRUE;
143 }
144 }
145 }
146
147 return TFALSE;
148}
uint8_t TUINT8
Definition Typedefs.h:17
virtual TBOOL Lock(LockBuffer *a_pLockBuffer) override

◆ OnDestroy()

void TIndexPoolResource::OnDestroy ( )
overridevirtual

Reimplemented from TIndexPoolResourceInterface.

Definition at line 96 of file TIndexPoolResource_DX8.cpp.

97{
98 if ( m_uiFlags & 1 && m_pIndices )
99 {
100 delete[] m_pIndices;
101 m_pIndices = TNULL;
102 }
103
105}

◆ TDECLARE_CLASS()

TIndexPoolResource::TDECLARE_CLASS ( TIndexPoolResource ,
TIndexPoolResourceInterface  )

◆ Unlock()

void TIndexPoolResource::Unlock ( TUINT16 a_uiNewNumIndices)
overridevirtual

Implements TIndexPoolResourceInterface.

Definition at line 151 of file TIndexPoolResource_DX8.cpp.

152{
153 TASSERT( m_uiLockCount > 0 );
154
155 if ( m_uiLockCount > 0 && --m_uiLockCount == 0 )
156 {
157 TINT iChange = a_uiNewNumIndices - GetNumIndices();
158
159 if ( iChange != 0 )
160 {
161 if ( GetParent() )
162 {
164 {
165 auto pIndexBlock = TSTATICCAST( TIndexBlockResource, GetParent() );
166 pIndexBlock->ChildIndexUsedChanged( iChange );
167 }
168 }
169 }
170
171 m_uiNumIndices = a_uiNewNumIndices;
172
173 if ( m_uiFlags & 6 )
174 {
176 }
177 else if ( m_uiFlags & 1 )
178 {
179 Validate();
180 }
181 }
182}
int TINT
Definition Typedefs.h:7
virtual Toshi::TClass * GetClass()
Definition TObject.cpp:12
TBOOL IsA(TClass *a_pClass)
Definition TObject.h:192

◆ Validate()

TBOOL TIndexPoolResource::Validate ( )
overridevirtual

Reimplemented from TResource.

Definition at line 30 of file TIndexPoolResource_DX8.cpp.

31{
32 if ( IsCreated() && IsValid() )
33 {
34 return TTRUE;
35 }
36
37 auto pFactory = TSTATICCAST( TIndexFactoryResource, GetFactory() );
38 auto pBlock = pFactory->FindBlockResource( this );
39
40 if ( !pBlock )
41 {
42 TUINT32 uiFlags;
43 TUINT16 uiMaxVertices;
44
45 TUINT8 uiUnk1 = m_uiFlags & 7;
46
47 if ( uiUnk1 == 1 )
48 {
49 uiMaxVertices = pFactory->GetMaxStaticIndices();
50 uiFlags = 1;
51 }
52 else if ( uiUnk1 == 2 )
53 {
54 uiMaxVertices = GetMaxIndices();
55 uiFlags = 2;
56 }
57 else
58 {
59 if ( uiUnk1 != 4 )
60 {
61 return TFALSE;
62 }
63
64 uiMaxVertices = GetMaxIndices();
65 uiFlags = 4;
66 }
67
68 pBlock = pFactory->CreateBlockResource( uiMaxVertices, uiFlags );
69
70 if ( !pBlock )
71 {
72 return TFALSE;
73 }
74 }
75
76 pBlock->AttachPool( this );
77 return TResource::Validate();
78}
uint16_t TUINT16
Definition Typedefs.h:15
uint32_t TUINT32
Definition Typedefs.h:13
TIndexFactoryResourceInterface * GetFactory() const
virtual TBOOL Validate()
Definition TResource.cpp:36

Member Data Documentation

◆ TIndexBlockResource

friend TIndexPoolResource::TIndexBlockResource

Definition at line 15 of file TIndexPoolResource_DX8.h.


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