Team Fortress 2 Source Code as on 22/4/2020
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.

259 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "quakedef.h"
  8. #include "precache.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. //-----------------------------------------------------------------------------
  12. // Purpose: Print out flag names
  13. // Input : flags -
  14. // Output : char const
  15. //-----------------------------------------------------------------------------
  16. char const *GetFlagString( int flags )
  17. {
  18. static char ret[ 512 ];
  19. ret[ 0 ] = 0;
  20. bool first = true;
  21. if ( !flags )
  22. return "None";
  23. if ( flags & RES_FATALIFMISSING )
  24. {
  25. if ( !first )
  26. {
  27. Q_strncat( ret, " | ", sizeof( ret ), COPY_ALL_CHARACTERS );
  28. }
  29. Q_strncat( ret, "RES_FATALIFMISSING", sizeof( ret ), COPY_ALL_CHARACTERS );
  30. first = false;
  31. }
  32. if ( flags & RES_PRELOAD )
  33. {
  34. if ( !first )
  35. {
  36. Q_strncat( ret, " | ", sizeof( ret ), COPY_ALL_CHARACTERS );
  37. }
  38. Q_strncat( ret, "RES_PRELOAD", sizeof( ret ), COPY_ALL_CHARACTERS );
  39. first = false;
  40. }
  41. return ret;
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose:
  45. //-----------------------------------------------------------------------------
  46. CPrecacheItem::CPrecacheItem( void )
  47. {
  48. Init( TYPE_UNK, NULL );
  49. ResetStats();
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. //-----------------------------------------------------------------------------
  54. void CPrecacheItem::ResetStats( void )
  55. {
  56. m_uiRefcount = 0;
  57. #if DEBUG_PRECACHE
  58. m_flFirst = 0.0f;
  59. m_flMostRecent = 0.0f;
  60. #endif
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose:
  64. //-----------------------------------------------------------------------------
  65. void CPrecacheItem::Reference( void )
  66. {
  67. m_uiRefcount++;
  68. #if DEBUG_PRECACHE
  69. m_flMostRecent = realtime;
  70. if ( !m_flFirst )
  71. {
  72. m_flFirst = realtime;
  73. }
  74. #endif
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Purpose:
  78. // Input : type -
  79. // *ptr -
  80. //-----------------------------------------------------------------------------
  81. void CPrecacheItem::Init( int type, void const *ptr )
  82. {
  83. m_nType = type;
  84. u.model = ( model_t * )ptr;
  85. if ( ptr )
  86. {
  87. ResetStats();
  88. }
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. // Output : model_t
  93. //-----------------------------------------------------------------------------
  94. model_t *CPrecacheItem::GetModel( void )
  95. {
  96. if ( !u.model )
  97. return NULL;
  98. Assert( m_nType == TYPE_MODEL );
  99. Reference();
  100. return u.model;
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Purpose:
  104. // Output : char const
  105. //-----------------------------------------------------------------------------
  106. char const *CPrecacheItem::GetGeneric( void )
  107. {
  108. if ( !u.generic )
  109. return NULL;
  110. Assert( m_nType == TYPE_GENERIC );
  111. Reference();
  112. return u.generic;
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose:
  116. // Output : CSfxTable
  117. //-----------------------------------------------------------------------------
  118. CSfxTable *CPrecacheItem::GetSound( void )
  119. {
  120. if ( !u.sound )
  121. return NULL;
  122. Assert( m_nType == TYPE_SOUND );
  123. Reference();
  124. return u.sound;
  125. }
  126. //-----------------------------------------------------------------------------
  127. // Purpose:
  128. // Output : char const
  129. //-----------------------------------------------------------------------------
  130. char const *CPrecacheItem::GetName( void )
  131. {
  132. if ( !u.name )
  133. return NULL;
  134. Assert( m_nType == TYPE_SOUND );
  135. Reference();
  136. return u.name;
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose:
  140. // Output : char const
  141. //-----------------------------------------------------------------------------
  142. char const *CPrecacheItem::GetDecal( void )
  143. {
  144. if ( !u.name )
  145. return NULL;
  146. Assert( m_nType == TYPE_DECAL );
  147. Reference();
  148. return u.name;
  149. }
  150. //-----------------------------------------------------------------------------
  151. // Purpose:
  152. // Input : *pmodel -
  153. //-----------------------------------------------------------------------------
  154. void CPrecacheItem::SetModel( model_t const *pmodel )
  155. {
  156. Init( TYPE_MODEL, pmodel );
  157. }
  158. //-----------------------------------------------------------------------------
  159. // Purpose:
  160. // Input : *pname -
  161. //-----------------------------------------------------------------------------
  162. void CPrecacheItem::SetGeneric( char const *pname )
  163. {
  164. Init( TYPE_GENERIC, pname );
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Purpose:
  168. // Input : *psound -
  169. //-----------------------------------------------------------------------------
  170. void CPrecacheItem::SetSound( CSfxTable const *psound )
  171. {
  172. Init( TYPE_SOUND, psound );
  173. }
  174. //-----------------------------------------------------------------------------
  175. // Purpose:
  176. // Input : *name -
  177. //-----------------------------------------------------------------------------
  178. void CPrecacheItem::SetName( char const *name )
  179. {
  180. Init( TYPE_SOUND, name );
  181. }
  182. //-----------------------------------------------------------------------------
  183. // Purpose:
  184. // Input : *decalname -
  185. //-----------------------------------------------------------------------------
  186. void CPrecacheItem::SetDecal( char const *decalname )
  187. {
  188. Init( TYPE_DECAL, decalname );
  189. }
  190. //-----------------------------------------------------------------------------
  191. // Purpose:
  192. // Output : float
  193. //-----------------------------------------------------------------------------
  194. float CPrecacheItem::GetFirstReference( void )
  195. {
  196. #if DEBUG_PRECACHE
  197. return m_flFirst;
  198. #else
  199. return 0;
  200. #endif
  201. }
  202. //-----------------------------------------------------------------------------
  203. // Purpose:
  204. // Output : float
  205. //-----------------------------------------------------------------------------
  206. float CPrecacheItem::GetMostRecentReference( void )
  207. {
  208. #if DEBUG_PRECACHE
  209. return m_flMostRecent;
  210. #else
  211. return 0;
  212. #endif
  213. }
  214. //-----------------------------------------------------------------------------
  215. // Purpose:
  216. // Output : unsigned int
  217. //-----------------------------------------------------------------------------
  218. unsigned int CPrecacheItem::GetReferenceCount( void )
  219. {
  220. return m_uiRefcount;
  221. }