Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.5 KiB

  1. //========== Copyright � 2006, Valve Corporation, All rights reserved. ========
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef BONETOWORLDARRAY_H
  7. #define BONETOWORLDARRAY_H
  8. #include "tier0/tslist.h"
  9. #if defined( _WIN32 )
  10. #pragma once
  11. #endif
  12. #include "tier0/memdbgon.h" // for _aligned_malloc usage below
  13. //-----------------------------------------------------------------------------
  14. //
  15. //-----------------------------------------------------------------------------
  16. template <int NUM_ARRAYS>
  17. class CBoneToWorldArrays
  18. {
  19. public:
  20. enum
  21. {
  22. ALIGNMENT = 128,
  23. };
  24. CBoneToWorldArrays()
  25. {
  26. const int SIZE_ARRAY = AlignValue( sizeof(matrix3x4_t) * MAXSTUDIOBONES, ALIGNMENT );
  27. m_pBase = (matrix3x4_t *)_aligned_malloc( SIZE_ARRAY * NUM_ARRAYS, ALIGNMENT );
  28. for ( int i = 0; i < NUM_ARRAYS; i++ )
  29. {
  30. matrix3x4_t *pArray = (matrix3x4_t *)((byte *)m_pBase + SIZE_ARRAY * i);
  31. Assert( (size_t)pArray % ALIGNMENT == 0 );
  32. Free( pArray );
  33. }
  34. }
  35. ~CBoneToWorldArrays()
  36. {
  37. _aligned_free( m_pBase );
  38. }
  39. int NumArrays()
  40. {
  41. return NUM_ARRAYS;
  42. }
  43. matrix3x4_t *Alloc( bool bBlock = true )
  44. {
  45. TSLNodeBase_t *p;
  46. while ( ( p = m_Free.Pop() ) == NULL && bBlock )
  47. {
  48. ThreadPause();
  49. }
  50. return (matrix3x4_t *)p;
  51. }
  52. void Free( matrix3x4_t *p )
  53. {
  54. m_Free.Push( (TSLNodeBase_t *) p );
  55. }
  56. private:
  57. CTSListBase m_Free;
  58. matrix3x4_t *m_pBase;
  59. };
  60. #include "tier0/memdbgoff.h" // for _aligned_malloc usage above
  61. #endif // BONETOWORLDARRAY_H