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.

241 lines
10 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef IVMODELINFO_H
  8. #define IVMODELINFO_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier0/platform.h"
  13. #include "datacache/imdlcache.h"
  14. //-----------------------------------------------------------------------------
  15. // Forward declarations
  16. //-----------------------------------------------------------------------------
  17. class IMaterial;
  18. class KeyValues;
  19. struct vcollide_t;
  20. struct model_t;
  21. class Vector;
  22. class QAngle;
  23. class CGameTrace;
  24. struct cplane_t;
  25. typedef CGameTrace trace_t;
  26. struct studiohdr_t;
  27. struct virtualmodel_t;
  28. typedef unsigned char byte;
  29. struct virtualterrainparams_t;
  30. class CPhysCollide;
  31. typedef unsigned short MDLHandle_t;
  32. class CUtlBuffer;
  33. class IClientRenderable;
  34. //-----------------------------------------------------------------------------
  35. // Indicates the type of translucency of an unmodulated renderable
  36. //-----------------------------------------------------------------------------
  37. enum RenderableTranslucencyType_t
  38. {
  39. RENDERABLE_IS_OPAQUE = 0,
  40. RENDERABLE_IS_TRANSLUCENT,
  41. RENDERABLE_IS_TWO_PASS, // has both translucent and opaque sub-partsa
  42. };
  43. //-----------------------------------------------------------------------------
  44. // Purpose: a callback class that is notified when a model has finished loading
  45. //-----------------------------------------------------------------------------
  46. abstract_class IModelLoadCallback
  47. {
  48. public:
  49. virtual void OnModelLoadComplete( const model_t* pModel ) = 0;
  50. protected:
  51. // Protected destructor so that nobody tries to delete via this interface.
  52. // Automatically unregisters if the callback is destroyed while still pending.
  53. ~IModelLoadCallback();
  54. };
  55. //-----------------------------------------------------------------------------
  56. // Purpose: Automate refcount tracking on a model index
  57. //-----------------------------------------------------------------------------
  58. class CRefCountedModelIndex
  59. {
  60. private:
  61. int m_nIndex;
  62. public:
  63. CRefCountedModelIndex() : m_nIndex( -1 ) { }
  64. ~CRefCountedModelIndex() { Set( -1 ); }
  65. CRefCountedModelIndex( const CRefCountedModelIndex& src ) : m_nIndex( -1 ) { Set( src.m_nIndex ); }
  66. CRefCountedModelIndex& operator=( const CRefCountedModelIndex& src ) { Set( src.m_nIndex ); return *this; }
  67. explicit CRefCountedModelIndex( int i ) : m_nIndex( -1 ) { Set( i ); }
  68. CRefCountedModelIndex& operator=( int i ) { Set( i ); return *this; }
  69. int Get() const { return m_nIndex; }
  70. void Set( int i );
  71. void Clear() { Set( -1 ); }
  72. operator int () const { return m_nIndex; }
  73. };
  74. //-----------------------------------------------------------------------------
  75. // Model info interface
  76. //-----------------------------------------------------------------------------
  77. // change this when the new version is incompatable with the old
  78. #define VMODELINFO_CLIENT_INTERFACE_VERSION "VModelInfoClient004"
  79. #define VMODELINFO_SERVER_INTERFACE_VERSION "VModelInfoServer002"
  80. // MODEL INDEX RULES
  81. // If index >= 0, then index references the precached model string table
  82. // If index == -1, then the model is invalid
  83. // If index < -1, then the model is DYNAMIC and has a DYNAMIC INDEX of (-2 - index)
  84. // - if the dynamic index is ODD, then the model is CLIENT ONLY
  85. // and has a m_LocalDynamicModels lookup index of (dynamic index)>>1
  86. // - if the dynamic index is EVEN, then the model is NETWORKED
  87. // and has a dynamic model string table index of (dynamic index)>>1
  88. inline bool IsDynamicModelIndex( int modelindex ) { return modelindex < -1; }
  89. inline bool IsClientOnlyModelIndex( int modelindex ) { return modelindex < -1 && (modelindex & 1); }
  90. class IVModelInfo
  91. {
  92. public:
  93. virtual ~IVModelInfo( void ) { }
  94. virtual const model_t *GetModel( int modelindex ) const = 0;
  95. // Returns index of model by name
  96. virtual int GetModelIndex( const char *name ) const = 0;
  97. // Returns name of model
  98. virtual const char *GetModelName( const model_t *model ) const = 0;
  99. virtual vcollide_t *GetVCollide( const model_t *model ) const = 0;
  100. virtual vcollide_t *GetVCollide( int modelindex ) const = 0;
  101. virtual void GetModelBounds( const model_t *model, Vector& mins, Vector& maxs ) const = 0;
  102. virtual void GetModelRenderBounds( const model_t *model, Vector& mins, Vector& maxs ) const = 0;
  103. virtual int GetModelFrameCount( const model_t *model ) const = 0;
  104. virtual int GetModelType( const model_t *model ) const = 0;
  105. virtual void *GetModelExtraData( const model_t *model ) = 0;
  106. virtual bool ModelHasMaterialProxy( const model_t *model ) const = 0;
  107. virtual bool IsTranslucent( model_t const* model ) const = 0;
  108. virtual bool IsTranslucentTwoPass( const model_t *model ) const = 0;
  109. virtual void Unused0() {};
  110. virtual RenderableTranslucencyType_t ComputeTranslucencyType( const model_t *model, int nSkin, int nBody ) = 0;
  111. virtual int GetModelMaterialCount( const model_t* model ) const = 0;
  112. virtual int GetModelMaterials( const model_t *model, int count, IMaterial** ppMaterial ) = 0;
  113. virtual bool IsModelVertexLit( const model_t *model ) const = 0;
  114. virtual const char *GetModelKeyValueText( const model_t *model ) = 0;
  115. virtual bool GetModelKeyValue( const model_t *model, CUtlBuffer &buf ) = 0; // supports keyvalue blocks in submodels
  116. virtual float GetModelRadius( const model_t *model ) = 0;
  117. virtual const studiohdr_t *FindModel( const studiohdr_t *pStudioHdr, void **cache, const char *modelname ) const = 0;
  118. virtual const studiohdr_t *FindModel( void *cache ) const = 0;
  119. virtual virtualmodel_t *GetVirtualModel( const studiohdr_t *pStudioHdr ) const = 0;
  120. virtual byte *GetAnimBlock( const studiohdr_t *pStudioHdr, int nBlock, bool bPreloadIfMissing ) const = 0;
  121. virtual bool HasAnimBlockBeenPreloaded( const studiohdr_t *pStudioHdr, int nBlock ) const = 0;
  122. // Available on client only!!!
  123. virtual void GetModelMaterialColorAndLighting( const model_t *model, Vector const& origin,
  124. QAngle const& angles, trace_t* pTrace,
  125. Vector& lighting, Vector& matColor ) = 0;
  126. virtual void GetIlluminationPoint( const model_t *model, IClientRenderable *pRenderable, Vector const& origin,
  127. QAngle const& angles, Vector* pLightingCenter ) = 0;
  128. virtual int GetModelContents( int modelIndex ) const = 0;
  129. virtual studiohdr_t *GetStudiomodel( const model_t *mod ) = 0;
  130. virtual int GetModelSpriteWidth( const model_t *model ) const = 0;
  131. virtual int GetModelSpriteHeight( const model_t *model ) const = 0;
  132. // Sets/gets a map-specified fade range (client only)
  133. virtual void SetLevelScreenFadeRange( float flMinSize, float flMaxSize ) = 0;
  134. virtual void GetLevelScreenFadeRange( float *pMinArea, float *pMaxArea ) const = 0;
  135. // Sets/gets a map-specified per-view fade range (client only)
  136. virtual void SetViewScreenFadeRange( float flMinSize, float flMaxSize ) = 0;
  137. // Computes fade alpha based on distance fade + screen fade (client only)
  138. virtual unsigned char ComputeLevelScreenFade( const Vector &vecAbsOrigin, float flRadius, float flFadeScale ) const = 0;
  139. virtual unsigned char ComputeViewScreenFade( const Vector &vecAbsOrigin, float flRadius, float flFadeScale ) const = 0;
  140. // both client and server
  141. virtual int GetAutoplayList( const studiohdr_t *pStudioHdr, unsigned short **pAutoplayList ) const = 0;
  142. // Gets a virtual terrain collision model (creates if necessary)
  143. // NOTE: This may return NULL if the terrain model cannot be virtualized
  144. virtual CPhysCollide *GetCollideForVirtualTerrain( int index ) = 0;
  145. virtual bool IsUsingFBTexture( const model_t *model, int nSkin, int nBody, void /*IClientRenderable*/ *pClientRenderable ) const = 0;
  146. virtual const model_t *FindOrLoadModel( const char *name ) const = 0;
  147. virtual MDLHandle_t GetCacheHandle( const model_t *model ) const = 0;
  148. // Returns planes of non-nodraw brush model surfaces
  149. virtual int GetBrushModelPlaneCount( const model_t *model ) const = 0;
  150. virtual void GetBrushModelPlane( const model_t *model, int nIndex, cplane_t &plane, Vector *pOrigin ) const = 0;
  151. virtual int GetSurfacepropsForVirtualTerrain( int index ) = 0;
  152. virtual bool UsesEnvCubemap( const model_t *model ) const = 0;
  153. virtual bool UsesStaticLighting( const model_t *model ) const = 0;
  154. // Returns index of model by name, dynamically registered if not already known.
  155. virtual int RegisterDynamicModel( const char *name, bool bClientSide ) = 0;
  156. virtual int RegisterCombinedDynamicModel( const char *pszName, MDLHandle_t Handle ) = 0;
  157. virtual void UpdateCombinedDynamicModel( int nModelIndex, MDLHandle_t Handle ) = 0;
  158. virtual int BeginCombinedModel( const char *pszName, bool bReuseExisting ) = 0;
  159. virtual bool SetCombineModels( int nModelIndex, const CUtlVector< SCombinerModelInput_t > &vecModelsToCombine ) = 0;
  160. virtual bool FinishCombinedModel( int nModelIndex, CombinedModelLoadedCallback pFunc, void *pUserData = NULL ) = 0;
  161. virtual void ReleaseCombinedModel( int nModelIndex ) = 0;
  162. virtual bool IsDynamicModelLoading( int modelIndex ) = 0;
  163. virtual void AddRefDynamicModel( int modelIndex ) = 0;
  164. virtual void ReleaseDynamicModel( int modelIndex ) = 0;
  165. // Registers callback for when dynamic model has finished loading.
  166. virtual bool RegisterModelLoadCallback( int modelindex, IModelLoadCallback* pCallback, bool bCallImmediatelyIfLoaded = true ) = 0;
  167. virtual void UnregisterModelLoadCallback( int modelindex, IModelLoadCallback* pCallback ) = 0;
  168. // Poked by engine
  169. virtual void OnLevelChange() = 0;
  170. virtual KeyValues *GetModelKeyValues( const model_t *pModel ) = 0;
  171. virtual void UpdateViewWeaponModelCache( const char **ppWeaponModels, int nWeaponModels ) = 0;
  172. virtual void TouchWorldWeaponModelCache( const char **ppWeaponModels, int nWeaponModels ) = 0;
  173. };
  174. class IVModelInfoClient : public IVModelInfo
  175. {
  176. public:
  177. // Returns a model as a client-side index which is stable across server changes
  178. virtual int GetModelClientSideIndex( const char *name ) const = 0;
  179. // Poked by engine
  180. virtual void OnDynamicModelStringTableChanged( int nStringIndex, const char *pString, const void *pData ) = 0;
  181. // Reference and Unload
  182. // Don't assume Reference flags - doing this for now
  183. virtual model_t *ReferenceModel( const char *name ) = 0;
  184. virtual void UnreferenceModel( model_t *model ) = 0;
  185. virtual void UnloadUnreferencedModels( void ) = 0;
  186. };
  187. struct virtualterrainparams_t
  188. {
  189. // UNDONE: Add grouping here, specified in BSP file? (test grouping to see if this is necessary)
  190. int index;
  191. };
  192. #endif // IVMODELINFO_H