OpenBarnyard
 
Loading...
Searching...
No Matches
TVertexPoolResource_DX8.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
5
6//-----------------------------------------------------------------------------
7// Enables memory debugging.
8// Note: Should be the last include!
9//-----------------------------------------------------------------------------
10#include "Core/TMemoryDebugOn.h"
11
13
15
16// $Barnyard: FUNCTION 006d63d0
18{
19 m_uiVertexOffset = 0;
20 m_uiNumLocksAllTime = 0;
21 m_apManagedStreams[ 0 ] = TNULL;
22 m_apManagedStreams[ 1 ] = TNULL;
23 m_apManagedStreams[ 2 ] = TNULL;
24 m_apManagedStreams[ 3 ] = TNULL;
25 m_apManagedStreams[ 4 ] = TNULL;
26 m_apManagedStreams[ 5 ] = TNULL;
27 m_apManagedStreams[ 6 ] = TNULL;
28 m_apManagedStreams[ 7 ] = TNULL;
29}
30
31// $Barnyard: FUNCTION 006d62d0
33{
34 if ( IsCreated() && IsValid() )
35 {
36 return TTRUE;
37 }
38
39 auto pFactory = TSTATICCAST( TVertexFactoryResource, GetFactory() );
40 auto pBlock = pFactory->FindBlockResource( this );
41
42 if ( !pBlock )
43 {
44 TUINT32 uiFlags;
45 TUINT16 uiMaxVertices;
46
47 TUINT8 uiUnk1 = m_uiFlags & 7;
48
49 if ( uiUnk1 == 1 )
50 {
51 uiMaxVertices = pFactory->GetMaxStaticVertices();
52 uiFlags = 1;
53 }
54 else if ( uiUnk1 == 2 )
55 {
56 uiMaxVertices = GetMaxVertices();
57 uiFlags = 2;
58 }
59 else
60 {
61 if ( uiUnk1 != 4 )
62 {
63 return TFALSE;
64 }
65
66 uiMaxVertices = GetMaxVertices();
67 uiFlags = 4;
68 }
69
70 pBlock = pFactory->CreateBlockResource( uiMaxVertices, uiFlags );
71
72 if ( !pBlock )
73 {
74 return TFALSE;
75 }
76 }
77
78 pBlock->AttachPool( this );
79 return TResource::Validate();
80}
81
82// $Barnyard: FUNCTION 006d6490
84{
85 if ( IsCreated() && IsValid() )
86 {
87 TASSERT( m_uiLockCount == 0 );
88
89 auto pVertexBlock = GetVertexBlock();
90 TVALIDPTR( pVertexBlock );
91
92 pVertexBlock->DettachPool( this );
94 }
95}
96
97// $Barnyard: FUNCTION 006d6280
99{
100 if ( m_uiFlags & 1 )
101 {
102 auto& vertexFormat = m_pFactory->GetVertexFormat();
103
104 for ( TUINT i = 0; i < vertexFormat.m_uiNumStreams; i++ )
105 {
106 if ( m_apManagedStreams[ i ] )
107 {
108 delete[] m_apManagedStreams[ i ];
109 m_apManagedStreams[ i ] = TNULL;
110 }
111 }
112 }
113
115}
116
117// $Barnyard: FUNCTION 006d64f0
119{
120 TVALIDPTR( a_pLockBuffer );
121
122 auto uiOldLockCount = m_uiLockCount;
123 m_uiNumLocksAllTime += 1;
124 m_uiLockCount += 1;
125
126 if ( uiOldLockCount == 0 )
127 {
128 TUINT8 uiUnk1 = m_uiFlags & 7;
129
130 if ( uiUnk1 == 1 )
131 {
133
134 for ( TUINT i = 0; i < a_pLockBuffer->uiNumStreams; i++ )
135 {
136 a_pLockBuffer->apStreams[ i ] = m_apManagedStreams[ i ];
137 }
138
139 return TTRUE;
140 }
141 else if ( uiUnk1 == 2 )
142 {
143 Validate();
144
145 if ( GetVertexBlock()->Lock( a_pLockBuffer, 0 ) )
146 {
147 m_uiVertexOffset = a_pLockBuffer->uiOffset;
148 return TTRUE;
149 }
150 }
151 else if ( uiUnk1 == 4 )
152 {
153 Validate();
154
155 if ( GetVertexBlock()->Lock( a_pLockBuffer, GetMaxVertices() ) )
156 {
157 m_uiVertexOffset = a_pLockBuffer->uiOffset;
158 return TTRUE;
159 }
160 }
161 }
162
163 return TFALSE;
164}
165
166// $Barnyard: FUNCTION 006d65d0
167void TVertexPoolResource::Unlock( TUINT16 a_uiNewNumVertices )
168{
169 TASSERT( m_uiLockCount > 0 );
170
171 if ( m_uiLockCount > 0 && --m_uiLockCount == 0 )
172 {
173 TINT iChange = a_uiNewNumVertices - GetNumVertices();
174
175 if ( iChange != 0 )
176 {
177 if ( GetParent() )
178 {
180 {
181 auto pVertexBlock = TSTATICCAST( TVertexBlockResource, GetParent() );
182 pVertexBlock->ChildVertexUsedChanged( iChange );
183 }
184 }
185 }
186
187 m_uiNumVertices = a_uiNewNumVertices;
188
189 if ( m_uiFlags & 6 )
190 {
192 }
193 else if ( m_uiFlags & 1 )
194 {
195 Validate();
196 }
197 }
198}
199
200// $Barnyard: FUNCTION 006d61f0
202{
203 if ( a_uiFlags & 4 )
204 {
205 a_uiFlags = a_uiFlags & 0xfffb | 2;
206 }
207
208 if ( TVertexPoolResourceInterface::Create( a_pFactory, a_uiMaxVertices, a_uiFlags ) )
209 {
210 if ( m_uiFlags & 1 )
211 {
212 auto& vertexFormat = m_pFactory->GetVertexFormat();
213
214 for ( TUINT i = 0; i < vertexFormat.m_uiNumStreams; i++ )
215 {
216 m_apManagedStreams[ i ] = new TBYTE[ a_uiMaxVertices * vertexFormat.m_aStreamFormats[ i ].m_uiVertexSize ];
217 TVALIDPTR( m_apManagedStreams[ i ] );
218 }
219 }
220
221 return TTRUE;
222 }
223
224 return TFALSE;
225}
226
227// $Barnyard: FUNCTION 006d6360
229{
230 TASSERT( a_uiStream < m_pFactory->GetVertexFormat().GetNumStreams() );
231
232 if ( !IsLocked() && a_uiStream < m_pFactory->GetVertexFormat().GetNumStreams() )
233 {
234 return m_apManagedStreams[ a_uiStream ];
235 }
236
237 return TNULL;
238}
239
240// $Barnyard: FUNCTION 006d6450
250
251// $Barnyard: FUNCTION 006bebf0
253{
254 if ( Tree() )
255 {
256 return Parent() == Tree()->GetRoot() ? TNULL : Parent();
257 }
258
259 return Parent();
260}
261
262// $Barnyard: FUNCTION 006d6660
264{
265 TVALIDPTR( a_pHALBuffer );
266
267 if ( Validate() )
268 {
269 auto pVertexBlock = GetVertexBlock();
270 TVALIDPTR( pVertexBlock );
271
272 if ( pVertexBlock->Validate() && pVertexBlock->GetHALBuffer( a_pHALBuffer ) )
273 {
274 a_pHALBuffer->uiVertexOffset = m_uiVertexOffset;
275 return TTRUE;
276 }
277 }
278
279 return TFALSE;
280}
281
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define TVALIDPTR(PTR)
Definition Defines.h:139
#define TGetClass(CLASS)
Definition TObject.h:13
#define TDEFINE_CLASS(...)
Definition TObject.h:120
uint16_t TUINT16
Definition Typedefs.h:15
unsigned int TUINT
Definition Typedefs.h:8
uint8_t TUINT8
Definition Typedefs.h:17
#define TNULL
Definition Typedefs.h:23
uint32_t TUINT32
Definition Typedefs.h:13
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
uint8_t TBYTE
Definition Typedefs.h:19
virtual void Invalidate() override
virtual TBOOL Lock(LockBuffer *a_pLockBuffer) override
virtual void Unlock(TUINT16 a_uiNewNumVertices) override
TVertexBlockResource * GetVertexBlock()
virtual TBOOL Validate() override
TBYTE * GetManagedStream(TUINT a_uiStream)
TBOOL GetHALBuffer(TVertexBlockResource::HALBuffer *a_pHALBuffer)
virtual void OnDestroy() override
TBOOL IsCreated() const
Definition TResource.h:46
virtual void Invalidate()
Definition TResource.cpp:47
virtual TBOOL Validate()
Definition TResource.cpp:36
TBOOL IsValid() const
Definition TResource.h:44
virtual TBOOL Create()
Definition TResource.cpp:28
const TVertexFactoryFormat & GetVertexFormat() const
TVertexFactoryResourceInterface * m_pFactory
virtual TBOOL Create(TVertexFactoryResourceInterface *a_pFactory, TUINT16 a_uiMaxVertices, TUINT16 a_uiFlags)
TVertexFactoryResourceInterface * GetFactory() const
TBYTE * apStreams[TVertexFactoryFormat::MAX_NUM_STREAMS]
T * Parent() const
Definition TNodeTree.h:33
TNodeTree< T > * Tree() const
Definition TNodeTree.h:36
virtual Toshi::TClass * GetClass()
Definition TObject.cpp:12
TBOOL IsA(TClass *a_pClass)
Definition TObject.h:192
TBOOL IsExactly(TClass *a_pClass)
Definition TObject.h:191