forked from sears2424/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbonetoworldarray.h
71 lines (60 loc) · 1.41 KB
/
bonetoworldarray.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#ifndef BONETOWORLDARRAY_H
#define BONETOWORLDARRAY_H
#include "tier0/tslist.h"
#if defined( _WIN32 )
#pragma once
#endif
#include "tier0/memdbgon.h" // for _aligned_malloc usage below
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
template <int NUM_ARRAYS>
class CBoneToWorldArrays
{
public:
enum
{
ALIGNMENT = 128,
};
CBoneToWorldArrays()
{
const int SIZE_ARRAY = AlignValue( sizeof(matrix3x4_t) * MAXSTUDIOBONES, ALIGNMENT );
m_pBase = (matrix3x4_t *)_aligned_malloc( SIZE_ARRAY * NUM_ARRAYS, ALIGNMENT );
for ( int i = 0; i < NUM_ARRAYS; i++ )
{
matrix3x4_t *pArray = (matrix3x4_t *)((byte *)m_pBase + SIZE_ARRAY * i);
Assert( (size_t)pArray % ALIGNMENT == 0 );
Free( pArray );
}
}
~CBoneToWorldArrays()
{
_aligned_free( m_pBase );
}
int NumArrays()
{
return NUM_ARRAYS;
}
matrix3x4_t *Alloc( bool bBlock = true )
{
TSLNodeBase_t *p;
while ( ( p = m_Free.Pop() ) == NULL && bBlock )
{
ThreadPause();
}
return (matrix3x4_t *)p;
}
void Free( matrix3x4_t *p )
{
m_Free.Push( (TSLNodeBase_t *) p );
}
private:
CTSListBase m_Free;
matrix3x4_t *m_pBase;
};
#endif // BONETOWORLDARRAY_H