Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DeclarationManager.cs
Go to the documentation of this file.
1using System;
7using std;
8
10
11internal class DeclarationManager : IEqualityComparer<VertexElement[]>
12{
14
16
18
20
28
29 internal void ReleaseAllDeclarations()
30 {
31 bool lockTaken = false;
32 try
33 {
37 while (enumerator.MoveNext())
38 {
39 DeclarationBinding current = enumerator.Current;
40 current.root.RecursiveRelease();
41 current.indirectOffspring.Clear();
42 }
43 }
44 finally
45 {
46 if (lockTaken)
47 {
48 Monitor.Exit(this);
49 }
50 }
51 }
52
54 {
56 bool lockTaken = false;
57 try
58 {
60 VertexElement[] elements = declaration._elements;
61 if (bindings.TryGetValue(elements, out value))
62 {
63 value.referenceCount++;
64 return value;
65 }
66 value = new DeclarationBinding(elements);
67 bindings.Add(elements, value);
68 return value;
69 }
70 finally
71 {
72 if (lockTaken)
73 {
74 Monitor.Exit(this);
75 }
76 }
77 }
78
80 {
81 bool lockTaken = false;
82 try
83 {
85 if (--binding.referenceCount <= 0)
86 {
87 binding.root.RecursiveRelease();
88 List<DeclarationBinding.BindingNode>.Enumerator enumerator = new List<DeclarationBinding.BindingNode>(binding.indirectOffspring.Keys).GetEnumerator();
89 while (enumerator.MoveNext())
90 {
91 enumerator.Current.RemoveChild(binding);
92 }
93 bindings.Remove(binding.elements);
94 }
95 }
96 finally
97 {
98 if (lockTaken)
99 {
100 Monitor.Exit(this);
101 }
102 }
103 }
104
105 internal unsafe void SetVertexDeclaration(VertexBufferBinding* vertexBuffers, int count)
106 {
107 int num = (int)stackalloc byte[_003CModule_003E.__CxxQueryExceptionSize()];
108 bool lockTaken = false;
109 try
110 {
111 Monitor.Enter(this, ref lockTaken);
112 bool flag = false;
113 for (int i = 0; i < count; i++)
114 {
115 VertexDeclaration vertexDeclaration = ((VertexBufferBinding*)(System.Runtime.CompilerServices.Unsafe.SizeOf<VertexBufferBinding>() * i + (byte*)vertexBuffers))->_vertexBuffer._vertexDeclaration;
118 {
119 if (binding == null || vertexDeclaration.GraphicsDevice != device)
120 {
122 binding = vertexDeclaration._binding;
123 }
125 flag = true;
126 }
127 }
128 for (int j = count; j < currentDeclarationCount; j++)
129 {
130 currentDeclarations[j] = null;
131 flag = true;
132 }
134 if (flag)
135 {
137 }
138 }
139 catch when (((Func<bool>)delegate
140 {
141 // Could not convert BlockContainer to single expression
143 return (byte)_003CModule_003E.__CxxExceptionFilter((void*)Marshal.GetExceptionPointers(), null, 0, null) != 0;
144 }).Invoke())
145 {
146 uint num2 = 0u;
147 _003CModule_003E.__CxxRegisterExceptionObject((void*)Marshal.GetExceptionPointers(), (void*)num);
148 try
149 {
150 try
151 {
152 ClearCurrent();
153 _003CModule_003E._CxxThrowException(null, null);
154 return;
155 }
156 catch when (((Func<bool>)delegate
157 {
158 // Could not convert BlockContainer to single expression
159 num2 = (uint)_003CModule_003E.__CxxDetectRethrow((void*)Marshal.GetExceptionPointers());
160 return (byte)num2 != 0;
161 }).Invoke())
162 {
163 }
164 if (num2 != 0)
165 {
166 throw;
167 }
168 }
169 finally
170 {
171 _003CModule_003E.__CxxUnregisterExceptionObject((void*)num, (int)num2);
172 }
173 }
174 finally
175 {
176 if (lockTaken)
177 {
178 Monitor.Exit(this);
179 }
180 }
181 }
182
184 {
185 int num = (int)stackalloc byte[_003CModule_003E.__CxxQueryExceptionSize()];
186 bool lockTaken = false;
187 try
188 {
189 Monitor.Enter(this, ref lockTaken);
191 {
192 if (declaration._binding == null || declaration.GraphicsDevice != device)
193 {
194 declaration.Bind(device);
195 }
196 currentDeclarations[0] = declaration._binding;
197 for (int i = 1; i < currentDeclarationCount; i++)
198 {
199 currentDeclarations[i] = null;
200 }
203 }
204 }
205 catch when (((Func<bool>)delegate
206 {
207 // Could not convert BlockContainer to single expression
209 return (byte)_003CModule_003E.__CxxExceptionFilter((void*)Marshal.GetExceptionPointers(), null, 0, null) != 0;
210 }).Invoke())
211 {
212 uint num2 = 0u;
213 _003CModule_003E.__CxxRegisterExceptionObject((void*)Marshal.GetExceptionPointers(), (void*)num);
214 try
215 {
216 try
217 {
218 ClearCurrent();
219 _003CModule_003E._CxxThrowException(null, null);
220 return;
221 }
222 catch when (((Func<bool>)delegate
223 {
224 // Could not convert BlockContainer to single expression
225 num2 = (uint)_003CModule_003E.__CxxDetectRethrow((void*)Marshal.GetExceptionPointers());
226 return (byte)num2 != 0;
227 }).Invoke())
228 {
229 }
230 if (num2 != 0)
231 {
232 throw;
233 }
234 }
235 finally
236 {
237 _003CModule_003E.__CxxUnregisterExceptionObject((void*)num, (int)num2);
238 }
239 }
240 finally
241 {
242 if (lockTaken)
243 {
244 Monitor.Exit(this);
245 }
246 }
247 }
248
249 private void ClearCurrent()
250 {
251 int num = 0;
253 {
254 do
255 {
256 currentDeclarations[num] = null;
257 num++;
258 }
259 while (num < currentDeclarationCount);
260 }
262 }
263
264 private unsafe void SetNativeDeclaration()
265 {
267 int num = 1;
269 {
270 do
271 {
273 if (bindingNode2 == null)
274 {
278 }
280 num++;
281 }
282 while (num < currentDeclarationCount);
283 }
284 if (bindingNode.pDecl == null)
285 {
287 }
288 int num2 = _003CModule_003E.Microsoft_002EXna_002EFramework_002EGraphics_002EStateTrackerDevice_002ESetVertexDeclaration(device.pStateTracker, bindingNode.pDecl, bindingNode.pSemantics);
289 if (num2 < 0)
290 {
292 }
293 }
294
296 {
297 int num = 0;
298 int num2 = 0;
300 if (0 < num3)
301 {
303 do
304 {
305 num = (int)((nint)array[num2].elements.LongLength + num);
306 num2++;
307 }
308 while (num2 < num3);
309 }
311 if (num > maxVertexStreams)
312 {
314 }
315 int num4 = num + 1;
316 _D3DVERTEXELEMENT9* ptr = (_D3DVERTEXELEMENT9*)_003CModule_003E.new_005B_005D(((uint)num4 > 536870911u) ? uint.MaxValue : ((uint)(num4 << 3)), (nothrow_t*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref _003CModule_003E.std_002Enothrow));
317 if (ptr == null)
318 {
319 throw new OutOfMemoryException();
320 }
321 try
322 {
323 int num5 = 0;
324 for (int i = 0; i < currentDeclarationCount; i++)
325 {
327 for (int j = 0; j < (nint)elements.LongLength; j++)
328 {
330 *(short*)ptr2 = (short)i;
331 *(short*)((byte*)ptr2 + 2) = (short)elements[j].Offset;
332 ((byte*)ptr2)[4] = _003CModule_003E.ConvertXnaVertexElementFormatToDx(elements[j].VertexElementFormat);
333 ((byte*)ptr2)[5] = 0;
334 ((byte*)ptr2)[6] = _003CModule_003E.ConvertXnaVertexElementUsageToDx(elements[j].VertexElementUsage);
335 ((byte*)ptr2)[7] = (byte)elements[j].UsageIndex;
336 while (IsDuplicateElement(ptr, num5))
337 {
338 byte b = (byte)(((byte*)ptr2)[7] + 1);
339 ((byte*)ptr2)[7] = b;
341 {
342 throw new ArgumentException(string.Format(args: new object[2]
343 {
344 elements[j].VertexElementUsage,
345 elements[j].UsageIndex
347 }
348 }
349 num5++;
350 }
351 }
353 *(short*)(&d3DVERTEXELEMENT) = 255;
359 // IL cpblk instruction
363 int num6 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DVERTEXELEMENT9*, IDirect3DVertexDeclaration9**, int>)(int)(*(uint*)(*(int*)pComPtr + 344)))((nint)pComPtr, ptr, &ptr3);
364 if (num6 < 0)
365 {
367 }
370 try
371 {
372 ptr5 = ((ptr4 == null) ? null : _003CModule_003E.Microsoft_002EXna_002EFramework_002EGraphics_002EVertexShaderInputSemantics_002E_007Bctor_007D(ptr4, ptr, (uint)num));
374 }
375 catch
376 {
377 //try-fault
379 throw;
380 }
381 node.pSemantics = ptr5;
382 if (ptr5 == null)
383 {
385 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr + 8)))((nint)intPtr);
386 throw new OutOfMemoryException();
387 }
388 node.pDecl = ptr3;
389 }
390 finally
391 {
392 _003CModule_003E.delete_005B_005D(ptr);
393 }
394 }
395
396 [return: MarshalAs(UnmanagedType.U1)]
397 private unsafe static bool IsDuplicateElement(_D3DVERTEXELEMENT9* elements, int pos)
398 {
399 int num = 0;
400 if (0 < pos)
401 {
402 byte b = (pos * 8 + (byte*)elements)[6];
403 _D3DVERTEXELEMENT9* ptr = (_D3DVERTEXELEMENT9*)((byte*)elements + 7);
404 do
405 {
406 if (b != *((byte*)ptr - 1) || (pos * 8 + (byte*)elements)[7] != *(byte*)ptr)
407 {
408 num++;
409 ptr = (_D3DVERTEXELEMENT9*)((byte*)ptr + 8);
410 continue;
411 }
412 return true;
413 }
414 while (num < pos);
415 }
416 return false;
417 }
418
420 {
421 int num = 0;
422 int num2 = 0;
423 if (0 < (nint)obj.LongLength)
424 {
425 do
426 {
427 num ^= obj[num2].GetHashCode();
428 num2++;
429 }
430 while (num2 < (nint)obj.LongLength);
431 }
432 return num;
433 }
434
436 {
437 //ILSpy generated this explicit interface implementation from .override directive in GetHashCode
438 return this.GetHashCode(obj);
439 }
440
441 [return: MarshalAs(UnmanagedType.U1)]
442 private bool Equals(VertexElement[] x, VertexElement[] y)
443 {
444 int num = x.Length;
445 if ((nint)num != (nint)y.LongLength)
446 {
447 return false;
448 }
449 int num2 = 0;
450 if (0 < num)
451 {
452 do
453 {
454 if (!(x[num2] != y[num2]))
455 {
456 num2++;
457 continue;
458 }
459 return false;
460 }
461 while (num2 < (nint)x.LongLength);
462 }
463 return true;
464 }
465
467 {
468 //ILSpy generated this explicit interface implementation from .override directive in Equals
469 return this.Equals(x, y);
470 }
471}
unsafe void CreateNativeDeclaration(DeclarationBinding.BindingNode node)
DeclarationBinding CreateBinding(VertexDeclaration declaration)
bool Equals(VertexElement[] x, VertexElement[] y)
unsafe void SetVertexDeclaration(VertexBufferBinding *vertexBuffers, int count)
static unsafe bool IsDuplicateElement(_D3DVERTEXELEMENT9 *elements, int pos)
Dictionary< VertexElement[], DeclarationBinding > bindings
unsafe void SetVertexDeclaration(VertexDeclaration declaration)
static Exception GetExceptionFromResult(uint result)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static CultureInfo CurrentCulture
static unsafe void CopyBlockUnaligned(void *destination, void *source, uint byteCount)
Definition Unsafe.cs:101
static void Exit(object obj)
static void Enter(object obj)