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.

283 lines
11 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #if !defined( MOD_LOADER_H )
  8. #define MOD_LOADER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. struct model_t;
  13. class IMaterial;
  14. class IFileList;
  15. #include "tier1/utlmemory.h"
  16. #include "engine/ivmodelinfo.h"
  17. //-----------------------------------------------------------------------------
  18. // Purpose:
  19. //-----------------------------------------------------------------------------
  20. abstract_class IModelLoader
  21. {
  22. public:
  23. enum REFERENCETYPE
  24. {
  25. // The name is allocated, but nothing else is in memory or being referenced
  26. FMODELLOADER_NOTLOADEDORREFERENCED = 0,
  27. // The model has been loaded into memory
  28. FMODELLOADER_LOADED = (1<<0),
  29. // The model is being referenced by the server code
  30. FMODELLOADER_SERVER = (1<<1),
  31. // The model is being referenced by the client code
  32. FMODELLOADER_CLIENT = (1<<2),
  33. // The model is being referenced in the client .dll
  34. FMODELLOADER_CLIENTDLL = (1<<3),
  35. // The model is being referenced by static props
  36. FMODELLOADER_STATICPROP = (1<<4),
  37. // The model is a detail prop
  38. FMODELLOADER_DETAILPROP = (1<<5),
  39. // The model is the simple version of the world geometry
  40. FMODELLOADER_SIMPLEWORLD = (1<<6),
  41. // The model is dynamically loaded
  42. FMODELLOADER_DYNSERVER = (1<<7),
  43. FMODELLOADER_DYNCLIENT = (1<<8),
  44. FMODELLOADER_COMBINED = (1<<9),
  45. FMODELLOADER_DYNAMIC = FMODELLOADER_DYNSERVER | FMODELLOADER_DYNCLIENT | FMODELLOADER_COMBINED,
  46. FMODELLOADER_REFERENCEMASK = (FMODELLOADER_SERVER | FMODELLOADER_CLIENT | FMODELLOADER_CLIENTDLL | FMODELLOADER_STATICPROP | FMODELLOADER_DETAILPROP | FMODELLOADER_DYNAMIC | FMODELLOADER_SIMPLEWORLD ),
  47. // The model was touched by the preload method
  48. FMODELLOADER_TOUCHED_BY_PRELOAD = (1<<15),
  49. // The model was loaded by the preload method, a postload fixup is required
  50. FMODELLOADER_LOADED_BY_PRELOAD = (1<<16),
  51. // The model touched its materials as part of its load
  52. FMODELLOADER_TOUCHED_MATERIALS = (1<<17),
  53. };
  54. enum ReloadType_t
  55. {
  56. RELOAD_LOD_CHANGED = 0,
  57. RELOAD_EVERYTHING,
  58. RELOAD_REFRESH_MODELS,
  59. };
  60. // Start up modelloader subsystem
  61. virtual void Init( void ) = 0;
  62. virtual void Shutdown( void ) = 0;
  63. virtual int GetCount( void ) = 0;
  64. virtual model_t *GetModelForIndex( int i ) = 0;
  65. // Look up name for model
  66. virtual const char *GetName( const model_t *model ) = 0;
  67. // Check for extra data, reload studio model if needed
  68. virtual void *GetExtraData( model_t *model ) = 0;
  69. // Get disk size for model
  70. virtual int GetModelFileSize( const char *name ) = 0;
  71. // Finds the model, and loads it if it isn't already present. Updates reference flags
  72. virtual model_t *GetModelForName( const char *name, REFERENCETYPE referencetype ) = 0;
  73. virtual model_t *ReferenceModel( const char *name, REFERENCETYPE referencetype ) = 0;
  74. // Unmasks the referencetype field for the model
  75. virtual void UnreferenceModel( model_t *model, REFERENCETYPE referencetype ) = 0;
  76. // Unmasks the specified reference type across all models
  77. virtual void UnreferenceAllModels( REFERENCETYPE referencetype ) = 0;
  78. // For any models with referencetype blank, frees all memory associated with the model
  79. // and frees up the models slot
  80. virtual void UnloadUnreferencedModels( void ) = 0;
  81. virtual void PurgeUnusedModels( void ) = 0;
  82. virtual void UnMountCompatibilityPaths( void ) = 0;
  83. virtual void AddCompatibilityPath( const char *szNewCompatibilityPath ) = 0;
  84. // On the client only, there is some information that is computed at the time we are just
  85. // about to render the map the first time. If we don't change/unload the map, then we
  86. // shouldn't have to recompute it each time we reconnect to the same map
  87. virtual bool Map_GetRenderInfoAllocated( void ) = 0;
  88. virtual void Map_SetRenderInfoAllocated( bool allocated ) = 0;
  89. // Load all the displacements for rendering. Set bRestoring to true if we're recovering from an alt+tab.
  90. virtual void Map_LoadDisplacements( model_t *model, bool bRestoring ) = 0;
  91. // Print which models are in the cache/known
  92. virtual void Print( void ) = 0;
  93. // Validate version/header of a .bsp file
  94. virtual bool Map_IsValid( char const *pBaseMapName, bool bQuiet = false ) = 0;
  95. // Recomputes surface flags
  96. virtual void RecomputeSurfaceFlags( model_t *mod ) = 0;
  97. // Reloads all models
  98. virtual void Studio_ReloadModels( ReloadType_t reloadType ) = 0;
  99. // Is a model loaded?
  100. virtual bool IsLoaded( const model_t *mod ) = 0;
  101. virtual bool LastLoadedMapHasHDRLighting( void ) = 0;
  102. virtual bool LastLoadedMapHasLightmapAlphaData( void ) = 0;
  103. // See CL_HandlePureServerWhitelist for what this is for.
  104. virtual void ReloadFilesInList( IFileList *pFilesToReload ) = 0;
  105. // Called by app system once per frame to poll and update dynamic models
  106. virtual void UpdateDynamicModels() = 0;
  107. // Called by server and client engine code to flush unreferenced dynamic models
  108. virtual void FlushDynamicModels() = 0;
  109. // Called by server and client engine code to flush unreferenced dynamic models
  110. virtual void ForceUnloadNonClientDynamicModels() = 0;
  111. // Called by client code to load dynamic models, instead of GetModelForName.
  112. virtual model_t *GetDynamicModel( const char *name, bool bClientOnly ) = 0;
  113. virtual model_t *GetDynamicCombinedModel( const char *name, bool bClientOnly ) = 0;
  114. virtual void UpdateDynamicCombinedModel( model_t *pModel, MDLHandle_t Handle, bool bClientSide ) = 0;
  115. virtual bool SetCombineModels( model_t *pModel, const CUtlVector< SCombinerModelInput_t > &vecModelsToCombine ) = 0;
  116. virtual bool FinishCombinedModel( model_t *pModel, CombinedModelLoadedCallback pFunc, void *pUserData = NULL ) = 0;
  117. // Called by client code to query dynamic model state
  118. virtual bool IsDynamicModelLoading( model_t *pModel ) = 0;
  119. // Called by client code to refcount dynamic models
  120. virtual void AddRefDynamicModel( model_t *pModel, bool bClientSideRef ) = 0;
  121. virtual void ReleaseDynamicModel( model_t *pModel, bool bClientSideRef ) = 0;
  122. // Called by client code
  123. virtual bool RegisterModelLoadCallback( model_t *pModel, IModelLoadCallback *pCallback, bool bCallImmediatelyIfLoaded = true ) = 0;
  124. // Called by client code or IModelLoadCallback destructor
  125. virtual void UnregisterModelLoadCallback( model_t *pModel, IModelLoadCallback *pCallback ) = 0;
  126. // Called by client engine code when server indicates that a model has finished loading or has been unloaded
  127. virtual void Client_OnServerModelStateChanged( model_t *pModel, bool bServerLoaded ) = 0;
  128. virtual void UpdateViewWeaponModelCache( const char **ppWeaponModels, int nWeaponModels ) = 0;
  129. virtual void TouchWorldWeaponModelCache( const char **ppWeaponModels, int nWeaponModels ) = 0;
  130. virtual bool IsModelInWeaponCache( const model_t *pModel ) = 0;
  131. virtual void EvictAllWeaponsFromModelCache( bool bLoadingComplete ) = 0;
  132. virtual bool IsViewWeaponModelResident( const model_t *pModel ) = 0;
  133. };
  134. extern IModelLoader *modelloader;
  135. //-----------------------------------------------------------------------------
  136. // Purpose: Loads the lump to temporary memory and automatically cleans up the
  137. // memory when it goes out of scope.
  138. //-----------------------------------------------------------------------------
  139. class CMapLoadHelper
  140. {
  141. public:
  142. CMapLoadHelper( int lumpToLoad, bool bUncompress = true );
  143. ~CMapLoadHelper( void );
  144. // Get raw memory pointer
  145. byte *LumpBase( void );
  146. int LumpSize( void );
  147. int LumpOffset( void );
  148. int LumpVersion() const;
  149. const char *GetMapPathName( void );
  150. char *GetLoadName( void );
  151. char *GetDiskName( void );
  152. struct worldbrushdata_t *GetMap( void );
  153. // use these to explicitly manage compressed lumps (by default, decompression is done transparently):
  154. int UncompressedLumpSize( void );
  155. void UncompressLump( void *pExternalBuffer = NULL );
  156. // Global setup/shutdown
  157. static void Init( model_t *pMapModel, const char *pLoadname );
  158. static void InitFromMemory( model_t *pMapModel, const void *pData, int nDataSize );
  159. static void Shutdown( void );
  160. static int GetRefCount( void );
  161. // Free the lighting lump (increases free memory during loading on 360)
  162. static void FreeLightingLump();
  163. // Returns the size of a particular lump without loading it
  164. static int LumpSize( int lumpId );
  165. static int LumpOffset( int lumpId );
  166. // Loads one element in a lump.
  167. void LoadLumpElement( int nElemIndex, int nElemSize, void *pData );
  168. void LoadLumpData( int offset, int size, void *pData );
  169. private:
  170. int m_nLumpSize;
  171. int m_nLumpOffset;
  172. int m_nLumpVersion;
  173. byte *m_pRawData;
  174. byte *m_pData;
  175. byte *m_pUncompressedData;
  176. int m_nUncompressedLumpSize;
  177. bool m_bUncompressedDataExternal;
  178. // Handling for lump files
  179. int m_nLumpID;
  180. char m_szLumpFilename[MAX_PATH];
  181. };
  182. //-----------------------------------------------------------------------------
  183. // Recomputes translucency for the model...
  184. //-----------------------------------------------------------------------------
  185. RenderableTranslucencyType_t Mod_ComputeTranslucencyType( model_t* mod, int nSkin, int nBody );
  186. //-----------------------------------------------------------------------------
  187. // game lumps
  188. //-----------------------------------------------------------------------------
  189. int Mod_GameLumpSize( int lumpId );
  190. int Mod_GameLumpVersion( int lumpId );
  191. bool Mod_LoadGameLump( int lumpId, void* pBuffer, int size );
  192. // returns the material count...
  193. int Mod_GetMaterialCount( model_t* mod );
  194. // returns the first n materials.
  195. int Mod_GetModelMaterials( model_t* mod, int count, IMaterial** ppMaterial );
  196. bool Mod_MarkWaterSurfaces( model_t *pModel );
  197. //-----------------------------------------------------------------------------
  198. // Hooks the cache notify into the MDL cache system
  199. //-----------------------------------------------------------------------------
  200. void ConnectMDLCacheNotify( );
  201. void DisconnectMDLCacheNotify( );
  202. //-----------------------------------------------------------------------------
  203. // Initialize studiomdl state
  204. //-----------------------------------------------------------------------------
  205. void InitStudioModelState( model_t *pModel );
  206. //-----------------------------------------------------------------------------
  207. // Convert the full bsp name into the actual platform bsp name
  208. //-----------------------------------------------------------------------------
  209. char *GetMapPathNameOnDisk( char *pDiskName, const char *pFullMapName, unsigned int nDiskNameSize );
  210. // has the lightstyle lighting changed since last updated?
  211. bool Mod_NeedsLightstyleUpdate( model_t *pModel );
  212. // set the material system config for hdr or not
  213. void EnableHDR( bool bEnable );
  214. void DeallocateLightingData( worldbrushdata_t *pBrushData );
  215. extern bool g_bLoadedMapHasBakedPropLighting;
  216. extern bool g_bBakedPropLightingNoSeparateHDR;
  217. extern bool g_bHasLightmapAlphaData;
  218. extern bool g_bBakedPropLightingStreams3;
  219. extern bool g_bHasLightmapAlphaData3;
  220. #endif // MOD_LOADER_H