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

#include <TIndexBlockResource_DX8.h>

Inheritance diagram for TIndexBlockResource:
TResource TObject TNodeTree< T >::TNode

Classes

struct  HALBuffer
 

Public Member Functions

 TDECLARE_CLASS (TIndexBlockResource, TResource)
 
TFORCEINLINE void * operator new (size_t s)
 
TFORCEINLINE void * operator new (size_t s, void *where)
 
TFORCEINLINE void operator delete (void *ptr)
 
TFORCEINLINE void operator delete (void *ptr, void *where)
 
virtual TBOOL Validate () override
 
virtual void Invalidate () override
 
virtual TBOOL TryInvalidate () override
 
virtual TBOOL TryValidate () override
 
TBOOL AttachPool (TIndexPoolResource *a_pPool)
 
TBOOL DettachPool (TIndexPoolResource *a_pPool)
 
TBOOL CanFit (TIndexPoolResource *a_pPoolResource) const
 
void ChildIndexUsedChanged (TINT a_iChange)
 
TBOOL Lock (TIndexPoolResourceInterface::LockBuffer *a_pLockBuffer, TUINT16 a_uiNumIndices)
 
void Unlock ()
 
TBOOL Create (TIndexFactoryResourceInterface *a_pFactory, TUINT16 a_uiMaxIndices, TUINT32 a_uiFlags)
 
TBOOL CreateHAL ()
 
void DestroyHAL ()
 
TBOOL GetHALBuffer (HALBuffer *a_pHALBuffer) const
 
- Public Member Functions inherited from TResource
 TDECLARE_CLASS (TResource, TObject)
 
 TResource ()
 
 ~TResource ()
 
virtual TBOOL Create ()
 
virtual void DestroyResource ()
 
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 void SetupFreeList (TINT a_iCapacity, TINT a_iGrowSize)
 
static TIndexBlockResourceCreateNew ()
 
- 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 ()
 

Public Attributes

TIndexFactoryResourceInterfacem_pFactory
 
TUINT m_uiFlags
 
TUINT16 m_uiMaxIndices
 
TUINT m_uiOffset
 
TUINT m_uiIndicesUsed
 
TUINT m_uiLockCount
 
TUINT m_Unk1
 
HALBuffer m_HALBuffer
 
- Public Attributes inherited from TResource
friend TRenderInterface
 
- Public Attributes inherited from TNodeTree< T >::TNode
friend TNodeTree
 

Static Public Attributes

static Toshi::TFreeList ms_oFreeList = Toshi::TFreeList( sizeof( TIndexBlockResource ), 0, 8, "TIndexBlockResource" )
 
- 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 ) )
 

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 }
 
- 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 13 of file TIndexBlockResource_DX8.h.

Member Function Documentation

◆ AttachPool()

TBOOL TIndexBlockResource::AttachPool ( TIndexPoolResource * a_pPool)

Definition at line 37 of file TIndexBlockResource_DX8.cpp.

38{
39 TVALIDPTR( a_pPool );
40
41 m_uiIndicesUsed += a_pPool->GetNumIndices();
42 a_pPool->SetParent( this );
43
44 if ( m_uiFlags & 1 )
45 {
46 Invalidate();
47 }
48
49 return TTRUE;
50}
#define TVALIDPTR(PTR)
Definition Defines.h:139
#define TTRUE
Definition Typedefs.h:25
virtual void Invalidate() override
void SetParent(TResource *a_pParent)
Definition TResource.cpp:75

◆ CanFit()

TBOOL TIndexBlockResource::CanFit ( TIndexPoolResource * a_pPoolResource) const

Definition at line 303 of file TIndexBlockResource_DX8.cpp.

304{
305 if ( !HASANYFLAG( m_uiFlags, 1 ) )
306 {
307 if ( HASANYFLAG( m_uiFlags, 4 ) && HASANYFLAG( a_pPoolResource->m_uiFlags, 4 ) )
308 {
309 return TTRUE;
310 }
311 }
312 else if ( HASANYFLAG( a_pPoolResource->m_uiFlags, 1 ) )
313 {
314 return m_uiMaxIndices > a_pPoolResource->GetNumIndices() + m_uiIndicesUsed;
315 }
316
317 return TFALSE;
318}
#define HASANYFLAG(STATE, FLAG)
Definition Defines.h:5
#define TFALSE
Definition Typedefs.h:24

◆ ChildIndexUsedChanged()

void TIndexBlockResource::ChildIndexUsedChanged ( TINT a_iChange)

Definition at line 320 of file TIndexBlockResource_DX8.cpp.

321{
322 if ( a_iChange < 0 )
323 {
324 TASSERT( m_uiIndicesUsed >= TUINT( -a_iChange ) );
325 }
326
327 m_uiIndicesUsed += a_iChange;
328}
#define TASSERT(X,...)
Definition Defines.h:138
unsigned int TUINT
Definition Typedefs.h:8

◆ Create()

TBOOL TIndexBlockResource::Create ( TIndexFactoryResourceInterface * a_pFactory,
TUINT16 a_uiMaxIndices,
TUINT32 a_uiFlags )

Definition at line 294 of file TIndexBlockResource_DX8.cpp.

295{
296 m_pFactory = a_pFactory;
297 m_uiMaxIndices = a_uiMaxIndices;
298 m_uiFlags = a_uiFlags;
299 return TResource::Create();
300}
TIndexFactoryResourceInterface * m_pFactory
virtual TBOOL Create()
Definition TResource.cpp:28

◆ CreateHAL()

TBOOL TIndexBlockResource::CreateHAL ( )

Definition at line 156 of file TIndexBlockResource_DX8.cpp.

157{
158 DestroyHAL();
159
160 TMemory::HALMemInfo memInfoHAL;
161 TMemory::GetHALMemInfo( memInfoHAL );
162
163 auto pRenderer = TRenderD3DInterface::Interface();
164 DWORD usage = D3DUSAGE_WRITEONLY;
165
166 if ( ISZERO( m_uiFlags & 1 ) )
167 {
168 usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY;
169 m_uiOffset = 0;
170 }
171
172 if ( !pRenderer->GetCurrentDevice()->SupportsHardwareTransfomations() )
173 {
174 usage |= D3DUSAGE_SOFTWAREPROCESSING;
175 }
176
177 HRESULT hRes = pRenderer->GetDirect3DDevice()->CreateIndexBuffer(
178 m_uiMaxIndices * sizeof( TIndexType ),
179 usage,
180 D3DFMT_INDEX16,
181 ( m_uiFlags & 1 ) ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT,
182 &m_HALBuffer.pIndexBuffer
183 );
184
185 if ( FAILED( hRes ) )
186 {
187 TRenderD3DInterface::PrintError( hRes, "Unable to create a new index buffer!" );
188 return TFALSE;
189 }
190
191 TMemory::GetHALMemInfo( memInfoHAL );
192 s_iHALMemoryUsage += memInfoHAL.m_uiMemUsage;
193
194 return TTRUE;
195}
TUINT16 TIndexType
#define ISZERO(X)
Definition Defines.h:3
static void GetHALMemInfo(HALMemInfo &a_rHALMemInfo)
Definition TMemory.cpp:956
TSIZE m_uiMemUsage
Total memory usage.
Definition TMemory.h:165
static void PrintError(TINT32 a_eError, const TCHAR *a_szInfo)
Prints error text caused by some directx call.
static TFORCEINLINE TRenderD3DInterface * Interface()
Gets the render interface singleton.

◆ CreateNew()

static TIndexBlockResource * TIndexBlockResource::CreateNew ( )
inlinestatic

Definition at line 19 of file TIndexBlockResource_DX8.h.

20 {
21 return new TIndexBlockResource();
22 }

◆ DestroyHAL()

void TIndexBlockResource::DestroyHAL ( )

Definition at line 198 of file TIndexBlockResource_DX8.cpp.

199{
200 TMemory::HALMemInfo memInfoHAL;
201 TMemory::GetHALMemInfo( memInfoHAL );
202
203 if ( m_HALBuffer.pIndexBuffer )
204 {
205 m_HALBuffer.pIndexBuffer->Release();
206 m_HALBuffer.pIndexBuffer = TNULL;
207 }
208
209 TMemory::GetHALMemInfo( memInfoHAL );
210 s_iHALMemoryUsage = s_iHALMemoryUsage - memInfoHAL.m_uiMemUsage;
211}
#define TNULL
Definition Typedefs.h:23

◆ DettachPool()

TBOOL TIndexBlockResource::DettachPool ( TIndexPoolResource * a_pPool)

Definition at line 52 of file TIndexBlockResource_DX8.cpp.

53{
54 TASSERT( TTRUE == Parent()->IsExactly( &TGetClass( TIndexFactoryResource ) ) );
55 a_pPool->SetParent( Parent() == Tree()->GetRoot() ? TNULL : Parent() );
56
57 m_uiIndicesUsed -= a_pPool->GetNumIndices();
58
59 if ( m_uiIndicesUsed == 0 && Child() == TNULL )
60 {
62 return TTRUE;
63 }
64
65 return TFALSE;
66}
#define TGetClass(CLASS)
Definition TObject.h:13
void DestroyResource(TResource *resource)
TRenderInterface * GetRenderer() const
T * Parent() const
Definition TNodeTree.h:33
T * Child() const
Definition TNodeTree.h:37
TNodeTree< T > * Tree() const
Definition TNodeTree.h:36
TBOOL IsExactly(TClass *a_pClass)
Definition TObject.h:191

◆ GetHALBuffer()

TBOOL TIndexBlockResource::GetHALBuffer ( HALBuffer * a_pHALBuffer) const

Definition at line 330 of file TIndexBlockResource_DX8.cpp.

331{
332 TVALIDPTR( a_pHALBuffer );
333
334 if ( a_pHALBuffer )
335 {
336 *a_pHALBuffer = m_HALBuffer;
337 return TTRUE;
338 }
339
340 return TFALSE;
341}

◆ Invalidate()

void TIndexBlockResource::Invalidate ( )
overridevirtual

Reimplemented from TResource.

Definition at line 124 of file TIndexBlockResource_DX8.cpp.

125{
126 if ( IsValid() && IsCreated() )
127 {
128 TASSERT( m_uiLockCount == 0 );
129
130 DestroyHAL();
132 }
133}
TBOOL IsCreated() const
Definition TResource.h:46
virtual void Invalidate()
Definition TResource.cpp:47
TBOOL IsValid() const
Definition TResource.h:44

◆ Lock()

TBOOL TIndexBlockResource::Lock ( TIndexPoolResourceInterface::LockBuffer * a_pLockBuffer,
TUINT16 a_uiNumIndices )

Definition at line 214 of file TIndexBlockResource_DX8.cpp.

215{
216 TVALIDPTR( a_pLockBuffer );
217
218 DWORD uiFlags;
219 TUINT uiNumIndices = 0;
220 TUINT uiUnk1 = m_uiFlags & 7;
221
222 if ( uiUnk1 == 1 )
223 {
224 uiFlags = D3DLOCK_NOSYSLOCK;
225 a_pLockBuffer->uiOffset = 0;
226 }
227 else
228 {
229 if ( uiUnk1 != 2 )
230 {
231 if ( uiUnk1 != 4 )
232 {
233 return TFALSE;
234 }
235
236 Validate();
237 uiNumIndices = a_uiNumIndices;
238
239 if ( m_uiMaxIndices < m_uiOffset + uiNumIndices )
240 {
241 uiFlags = D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK;
242 a_pLockBuffer->uiOffset = 0;
243 m_uiOffset = uiNumIndices;
244 }
245 else
246 {
247 uiFlags = D3DLOCK_NOOVERWRITE | D3DLOCK_NOSYSLOCK;
248 a_pLockBuffer->uiOffset = m_uiOffset;
249 m_uiOffset += uiNumIndices;
250 }
251 }
252 else
253 {
254 Validate();
255 uiFlags = D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK;
256 a_pLockBuffer->uiOffset = 0;
257 }
258 }
259
260 HRESULT hRes = m_HALBuffer.pIndexBuffer->Lock(
261 a_pLockBuffer->uiOffset * sizeof( TIndexType ),
262 uiNumIndices * sizeof( TIndexType ),
263 (BYTE**)&a_pLockBuffer->pBuffer,
264 uiFlags
265 );
266
267 if ( FAILED( hRes ) )
268 {
269 TRenderD3DInterface::PrintError( hRes, "Couldn\'t lock stream index buffer" );
270 }
271
272 m_uiLockCount += 1;
273 return TTRUE;
274}
virtual TBOOL Validate() override

◆ operator delete() [1/2]

TFORCEINLINE void TIndexBlockResource::operator delete ( void * ptr)
inline

Definition at line 17 of file TIndexBlockResource_DX8.h.

◆ operator delete() [2/2]

TFORCEINLINE void TIndexBlockResource::operator delete ( void * ptr,
void * where )
inline

Definition at line 17 of file TIndexBlockResource_DX8.h.

◆ operator new() [1/2]

TFORCEINLINE void * TIndexBlockResource::operator new ( size_t s)
inline

Definition at line 17 of file TIndexBlockResource_DX8.h.

◆ operator new() [2/2]

TFORCEINLINE void * TIndexBlockResource::operator new ( size_t s,
void * where )
inline

Definition at line 17 of file TIndexBlockResource_DX8.h.

◆ SetupFreeList()

static void TIndexBlockResource::SetupFreeList ( TINT a_iCapacity,
TINT a_iGrowSize )
inlinestatic

Definition at line 17 of file TIndexBlockResource_DX8.h.

◆ TDECLARE_CLASS()

TIndexBlockResource::TDECLARE_CLASS ( TIndexBlockResource ,
TResource  )

◆ TryInvalidate()

TBOOL TIndexBlockResource::TryInvalidate ( )
overridevirtual

Reimplemented from TResource.

Definition at line 135 of file TIndexBlockResource_DX8.cpp.

136{
137 if ( m_uiFlags & 1 )
138 {
139 Invalidate();
140 }
141
142 return TTRUE;
143}

◆ TryValidate()

TBOOL TIndexBlockResource::TryValidate ( )
overridevirtual

Reimplemented from TResource.

Definition at line 145 of file TIndexBlockResource_DX8.cpp.

146{
147 if ( m_uiFlags & 1 )
148 {
149 Validate();
150 }
151
152 return TTRUE;
153}

◆ Unlock()

void TIndexBlockResource::Unlock ( )

Definition at line 277 of file TIndexBlockResource_DX8.cpp.

278{
279 TASSERT( 0 != m_uiLockCount );
280
281 if ( m_uiLockCount > 0 )
282 {
283 HRESULT hRes = m_HALBuffer.pIndexBuffer->Unlock();
284
285 if ( FAILED( hRes ) )
286 {
287 TRenderD3DInterface::PrintError( hRes, "Couldn\'t unlock stream index buffer!" );
288 }
289
290 m_uiLockCount -= 1;
291 }
292}

◆ Validate()

TBOOL TIndexBlockResource::Validate ( )
overridevirtual

Reimplemented from TResource.

Definition at line 69 of file TIndexBlockResource_DX8.cpp.

70{
71 if ( IsValid() && IsCreated() )
72 {
73 return TTRUE;
74 }
75
76 if ( !CreateHAL() )
77 {
78 return TFALSE;
79 }
80
81 if ( m_uiFlags & 1 )
82 {
83 using Pair = T2Pair<TIndexBlockResource*, TIndexPoolResourceInterface::LockBuffer>;
84 Pair pair;
85
86 if ( Lock( &pair.second, 0 ) )
87 {
88 pair.first = this;
89
91 []( TResource* a_pResource, void* a_pUserData ) {
92 if ( a_pResource->IsExactly( &TGetClass( TIndexPoolResource ) ) )
93 {
94 auto pPool = TSTATICCAST( TIndexPoolResource, a_pResource );
95 auto pPair = TSTATICCAST( Pair, a_pUserData );
96
97 if ( pPool->m_uiFlags & 1 )
98 {
99 pPool->m_uiIndexOffset = pPair->second.uiOffset;
100 pPair->second.uiOffset += pPool->GetNumIndices();
101
103 pPair->second.pBuffer + pPool->m_uiIndexOffset,
104 pPool->GetIndices(),
105 pPool->GetNumIndices() * sizeof( TIndexType )
106 );
107 }
108 }
109
110 return TTRUE;
111 },
112 this,
113 &pair
114 );
115
116 Unlock();
117 }
118 }
119
120 return TResource::Validate();
121}
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
TBOOL Lock(TIndexPoolResourceInterface::LockBuffer *a_pLockBuffer, TUINT16 a_uiNumIndices)
virtual TBOOL Validate()
Definition TResource.cpp:36
TBOOL RecurseSimple(t_RecurseCb a_pCallback, TResource *a_pResource, void *a_pUserData)
static void * MemCopy(void *dst, const void *src, TSIZE size)
Definition TUtil.h:90

Member Data Documentation

◆ m_HALBuffer

HALBuffer TIndexBlockResource::m_HALBuffer

Definition at line 69 of file TIndexBlockResource_DX8.h.

◆ m_pFactory

TIndexFactoryResourceInterface* TIndexBlockResource::m_pFactory

Definition at line 62 of file TIndexBlockResource_DX8.h.

◆ m_uiFlags

TUINT TIndexBlockResource::m_uiFlags

Definition at line 63 of file TIndexBlockResource_DX8.h.

◆ m_uiIndicesUsed

TUINT TIndexBlockResource::m_uiIndicesUsed

Definition at line 66 of file TIndexBlockResource_DX8.h.

◆ m_uiLockCount

TUINT TIndexBlockResource::m_uiLockCount

Definition at line 67 of file TIndexBlockResource_DX8.h.

◆ m_uiMaxIndices

TUINT16 TIndexBlockResource::m_uiMaxIndices

Definition at line 64 of file TIndexBlockResource_DX8.h.

◆ m_uiOffset

TUINT TIndexBlockResource::m_uiOffset

Definition at line 65 of file TIndexBlockResource_DX8.h.

◆ m_Unk1

TUINT TIndexBlockResource::m_Unk1

Definition at line 68 of file TIndexBlockResource_DX8.h.

◆ ms_oFreeList

Toshi::TFreeList TIndexBlockResource::ms_oFreeList = Toshi::TFreeList( sizeof( TIndexBlockResource ), 0, 8, "TIndexBlockResource" )
static

Definition at line 17 of file TIndexBlockResource_DX8.h.


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