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.

156 lines
3.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <assert.h>
  8. #include "studio.h"
  9. #include "UtlRBTree.h"
  10. extern studiohdr_t *FindOrLoadGroupFile( char const *modelname );
  11. virtualmodel_t *studiohdr_t::GetVirtualModel( void ) const
  12. {
  13. if (numincludemodels == 0)
  14. {
  15. return NULL;
  16. }
  17. virtualmodel_t *pVModel = (virtualmodel_t *)virtualModel;
  18. if (pVModel == NULL)
  19. {
  20. pVModel = new virtualmodel_t;
  21. // !!! Set cache handle? Set pointer to local virtual model??
  22. virtualModel = (void *)pVModel;
  23. int group = pVModel->m_group.AddToTail( );
  24. pVModel->m_group[ group ].cache = (void *)this;
  25. pVModel->AppendModels( 0, this );
  26. }
  27. return pVModel;
  28. }
  29. const studiohdr_t *studiohdr_t::FindModel( void **cache, char const *modelname ) const
  30. {
  31. studiohdr_t *hdr = (studiohdr_t *)(*cache);
  32. if (hdr)
  33. {
  34. return hdr;
  35. }
  36. hdr = FindOrLoadGroupFile( modelname );
  37. *cache = (void *)hdr;
  38. return hdr;
  39. }
  40. const studiohdr_t *virtualgroup_t::GetStudioHdr( void ) const
  41. {
  42. return (studiohdr_t *)cache;
  43. }
  44. byte *studiohdr_t::GetAnimBlock( int i ) const
  45. {
  46. byte *hdr = (byte *)animblockModel;
  47. if (!hdr)
  48. {
  49. hdr = (byte *)FindOrLoadGroupFile( pszAnimBlockName() );
  50. animblockModel = hdr;
  51. }
  52. return hdr + pAnimBlock( i )->datastart;
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Purpose: Builds up a dictionary of autoplay indices by studiohdr_t *
  56. // NOTE: This list never gets freed even if the model gets unloaded, but we're in a tool so we can probably live with that
  57. //-----------------------------------------------------------------------------
  58. struct AutoPlayGeneric_t
  59. {
  60. public:
  61. AutoPlayGeneric_t() :
  62. hdr( 0 )
  63. {
  64. }
  65. // Implement copy constructor
  66. AutoPlayGeneric_t( const AutoPlayGeneric_t& src )
  67. {
  68. hdr = src.hdr;
  69. autoplaylist.EnsureCount( src.autoplaylist.Count() );
  70. autoplaylist.CopyArray( src.autoplaylist.Base(), src.autoplaylist.Count() );
  71. }
  72. static bool AutoPlayGenericLessFunc( const AutoPlayGeneric_t& lhs, const AutoPlayGeneric_t& rhs )
  73. {
  74. return lhs.hdr < rhs.hdr;
  75. }
  76. public:
  77. // Data
  78. const studiohdr_t *hdr;
  79. CUtlVector< unsigned short > autoplaylist;
  80. };
  81. // A global array to track this data
  82. static CUtlRBTree< AutoPlayGeneric_t, int > g_AutoPlayGeneric( 0, 0, AutoPlayGeneric_t::AutoPlayGenericLessFunc );
  83. int studiohdr_t::GetAutoplayList( unsigned short **pAutoplayList ) const
  84. {
  85. virtualmodel_t *pVirtualModel = GetVirtualModel();
  86. if ( pVirtualModel )
  87. {
  88. if ( pAutoplayList && pVirtualModel->m_autoplaySequences.Count() )
  89. {
  90. *pAutoplayList = pVirtualModel->m_autoplaySequences.Base();
  91. }
  92. return pVirtualModel->m_autoplaySequences.Count();
  93. }
  94. AutoPlayGeneric_t *pData = NULL;
  95. // Search for this studiohdr_t ptr in the global list
  96. AutoPlayGeneric_t search;
  97. search.hdr = this;
  98. int index = g_AutoPlayGeneric.Find( search );
  99. if ( index == g_AutoPlayGeneric.InvalidIndex() )
  100. {
  101. // Not there, so add it
  102. index = g_AutoPlayGeneric.Insert( search );
  103. pData = &g_AutoPlayGeneric[ index ];
  104. // And compute the autoplay info this one time
  105. int autoPlayCount = CountAutoplaySequences();
  106. pData->autoplaylist.EnsureCount( autoPlayCount );
  107. CopyAutoplaySequences( pData->autoplaylist.Base(), autoPlayCount );
  108. }
  109. else
  110. {
  111. // Refer to existing data
  112. pData = &g_AutoPlayGeneric[ index ];
  113. }
  114. // Oops!!!
  115. if ( !pData )
  116. {
  117. return 0;
  118. }
  119. // Give back data if it's being requested
  120. if ( pAutoplayList )
  121. {
  122. *pAutoplayList = pData->autoplaylist.Base();
  123. }
  124. return pData->autoplaylist.Count();
  125. }