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.

195 lines
7.3 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Utilities for setting vproject settings
  4. //
  5. //===========================================================================//
  6. #ifndef _RESOURCEPRECACHER_H
  7. #define _RESOURCEPRECACHER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. //-----------------------------------------------------------------------------
  12. // Resource list
  13. //-----------------------------------------------------------------------------
  14. FORWARD_DECLARE_HANDLE( ResourceList_t );
  15. #define RESOURCE_LIST_INVALID ( (ResourceList_t)-1 )
  16. //-----------------------------------------------------------------------------
  17. // Resource 'systems', which use other resources
  18. // NOTE: If you add types here, be sure to fix s_pResourceSystemName
  19. //-----------------------------------------------------------------------------
  20. enum PrecacheSystem_t
  21. {
  22. CLIENTGLOBAL = 0, // Always precache these
  23. SERVERGLOBAL,
  24. VGUI_PANEL, // What to precache when using a vgui panel
  25. DISPATCH_EFFECT, // What to precache when using a dispatch effect
  26. SHARED_SYSTEM, // Precache lists which are reused and can be referenced as a resource type
  27. PRECACHE_SYSTEM_COUNT,
  28. #if defined( GAME_DLL )
  29. GLOBAL = SERVERGLOBAL,
  30. #elif defined( CLIENT_DLL ) || defined( GAMEUI_EXPORTS )
  31. GLOBAL = CLIENTGLOBAL,
  32. #endif
  33. };
  34. //-----------------------------------------------------------------------------
  35. // Resource types
  36. // NOTE: If you add a type here, modify s_pResourceTypeName in resourceaccesscontrol.cpp
  37. //-----------------------------------------------------------------------------
  38. enum ResourceTypeOld_t // called 'Old' to disambiguate with ResourceSystem
  39. {
  40. RESOURCE_VGUI_PANEL = 0, // .res file
  41. RESOURCE_MATERIAL, // .vmt file
  42. RESOURCE_MODEL, // .mdl file
  43. RESOURCE_PARTICLE_SYSTEM, // particle system
  44. RESOURCE_GAMESOUND, // game sound
  45. RESOURCE_TYPE_OLD_COUNT,
  46. };
  47. //-----------------------------------------------------------------------------
  48. // Resource types
  49. // NOTE: If you add types here, be sure to fix s_pPrecacheResourceTypeName
  50. // A compile-time assert will trigger if you don't.
  51. //-----------------------------------------------------------------------------
  52. enum PrecacheResourceType_t
  53. {
  54. VGUI_RESOURCE = 0, // .res file
  55. MATERIAL, // .vmt file
  56. MODEL, // .mdl file
  57. GAMESOUND, // sound
  58. PARTICLE_SYSTEM, // particle system
  59. ENTITY, // Other entity
  60. DECAL, // A decal
  61. PARTICLE_MATERIAL, // A particle system material (old-style, obsolete)
  62. KV_DEP_FILE, // keyvalues file containing a resource dependency list
  63. GAME_MATERIAL_DECALS, // All decals related to game materials ( resource name is ignored )
  64. PHYSICS_GAMESOUNDS, // Resource names are either "BulletSounds", "StepSounds", or "PhysicsImpactSounds"
  65. SHARED, // a shared precache group (see PrecacheSystem_t SHARED)
  66. PRECACHE_RESOURCE_TYPE_COUNT,
  67. };
  68. //-----------------------------------------------------------------------------
  69. // Callback interface for handler who knows how to precache particular kinds of resources
  70. //-----------------------------------------------------------------------------
  71. abstract_class IPrecacheHandler
  72. {
  73. public:
  74. virtual void CacheResource( PrecacheResourceType_t nType, const char *pName,
  75. bool bPrecache, ResourceList_t hResourceList, int *pIndex = NULL ) = 0;
  76. };
  77. //-----------------------------------------------------------------------------
  78. // Interface to automated system for precaching resources
  79. //-----------------------------------------------------------------------------
  80. abstract_class IResourcePrecacher
  81. {
  82. public:
  83. virtual void Cache( IPrecacheHandler *pPrecacheHandler, bool bPrecache, ResourceList_t hResourceList, bool bIgnoreConditionals ) = 0;
  84. virtual PrecacheSystem_t GetSystem() = 0;
  85. virtual const char *GetName() = 0;
  86. virtual IResourcePrecacher *GetNext() = 0;
  87. virtual void SetNext( IResourcePrecacher * pNext ) = 0;
  88. };
  89. //-----------------------------------------------------------------------------
  90. // Actually does the precaching
  91. //-----------------------------------------------------------------------------
  92. class CBaseResourcePrecacher : public IResourcePrecacher
  93. {
  94. // Other public methods
  95. public:
  96. CBaseResourcePrecacher( PrecacheSystem_t nSystem, const char *pName )
  97. {
  98. m_nSystem = nSystem;
  99. m_pName = pName;
  100. m_pNext = sm_pFirst[nSystem];
  101. sm_pFirst[nSystem] = this;
  102. }
  103. static void RegisterAll();
  104. PrecacheSystem_t GetSystem() { return m_nSystem; }
  105. const char *GetName() { return m_pName; }
  106. IResourcePrecacher *GetNext() { return m_pNext; }
  107. void SetNext( IResourcePrecacher * pNext ) { m_pNext = pNext; }
  108. static CBaseResourcePrecacher *sm_pFirst[PRECACHE_SYSTEM_COUNT];
  109. PrecacheSystem_t m_nSystem;
  110. const char *m_pName;
  111. IResourcePrecacher *m_pNext;
  112. friend class CPrecacheRegister;
  113. };
  114. //-----------------------------------------------------------------------------
  115. // Automatic precache macros
  116. //-----------------------------------------------------------------------------
  117. // Beginning
  118. #define PRECACHE_REGISTER_BEGIN_CONDITIONAL( _system, _className, _condition ) \
  119. namespace _className ## Precache \
  120. { \
  121. class CResourcePrecacher : public CBaseResourcePrecacher\
  122. { \
  123. public: \
  124. CResourcePrecacher() : CBaseResourcePrecacher( _system, #_className ) {} \
  125. public: \
  126. virtual void Cache( IPrecacheHandler *pPrecacheHandler, bool bPrecache, ResourceList_t hResourceList, bool bIgnoreConditionals ); \
  127. }; \
  128. void CResourcePrecacher::Cache( IPrecacheHandler *pPrecacheHandler, bool bPrecache, ResourceList_t hResourceList, bool bIgnoreConditionals ) \
  129. { \
  130. if ( !bIgnoreConditionals && !( _condition ) ) \
  131. return;
  132. #define PRECACHE_REGISTER_BEGIN( _system, _className ) \
  133. PRECACHE_REGISTER_BEGIN_CONDITIONAL( _system, _className, true )
  134. // Resource precache definitions
  135. #define PRECACHE( _type, _name ) pPrecacheHandler->CacheResource( _type, _name, bPrecache, hResourceList, NULL );
  136. // NOTE: PRECACHE_INDEX_CONDITIONAL doesn't initialize the index to 0
  137. // on the assumption that some other conditional will
  138. //MCCLEANUP //NOTE: PRECACHE_INDEX and PRECACHE_INDEX_CONDITIONAL won't work in 64 bit because the old-school particle mgr is sending ptr data types into here. Hopefully the old-school particle mgr will die before this is an issue.
  139. #define PRECACHE_INDEX( _type, _name, _index ) pPrecacheHandler->CacheResource( _type, _name, bPrecache, hResourceList, (int*)( &(_index) ) );
  140. #define PRECACHE_CONDITIONAL( _type, _name, _condition ) \
  141. if ( !bIgnoreConditionals && ( _condition ) ) \
  142. pPrecacheHandler->CacheResource( _type, _name, bPrecache, hResourceList, NULL );
  143. #define PRECACHE_INDEX_CONDITIONAL( _type, _name, _index, _func ) \
  144. if ( bIgnoreConditionals || ( _condition ) ) \
  145. { \
  146. pPrecacheHandler->CacheResource( _type, _name, bPrecache, hResourceList, (int*)( &(_index) ) ); \
  147. }
  148. //End
  149. #define PRECACHE_REGISTER_END( ) \
  150. } \
  151. CResourcePrecacher s_ResourcePrecacher; \
  152. }
  153. // FIXME: Remove! Backward compat
  154. #define PRECACHE_WEAPON_REGISTER( _className ) \
  155. PRECACHE_REGISTER_BEGIN( GLOBAL, _className ) \
  156. PRECACHE( ENTITY, #_className ) \
  157. PRECACHE_REGISTER_END()
  158. #define PRECACHE_REGISTER( _className ) \
  159. PRECACHE_REGISTER_BEGIN( GLOBAL, _className ) \
  160. PRECACHE( ENTITY, #_className ) \
  161. PRECACHE_REGISTER_END()
  162. #endif // _RESOURCEPRECACHER_H