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.

261 lines
11 KiB

  1. //========= Copyright 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 "platform.h"
  13. #include "dbg.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. // Purpose: a callback class that is notified when a model has finished loading
  36. //-----------------------------------------------------------------------------
  37. abstract_class IModelLoadCallback
  38. {
  39. public:
  40. virtual void OnModelLoadComplete( const model_t* pModel ) = 0;
  41. protected:
  42. // Protected destructor so that nobody tries to delete via this interface.
  43. // Automatically unregisters if the callback is destroyed while still pending.
  44. ~IModelLoadCallback();
  45. };
  46. //-----------------------------------------------------------------------------
  47. // Purpose: Automate refcount tracking on a model index
  48. //-----------------------------------------------------------------------------
  49. class CRefCountedModelIndex
  50. {
  51. private:
  52. int m_nIndex;
  53. public:
  54. CRefCountedModelIndex() : m_nIndex( -1 ) { }
  55. ~CRefCountedModelIndex() { Set( -1 ); }
  56. CRefCountedModelIndex( const CRefCountedModelIndex& src ) : m_nIndex( -1 ) { Set( src.m_nIndex ); }
  57. CRefCountedModelIndex& operator=( const CRefCountedModelIndex& src ) { Set( src.m_nIndex ); return *this; }
  58. explicit CRefCountedModelIndex( int i ) : m_nIndex( -1 ) { Set( i ); }
  59. CRefCountedModelIndex& operator=( int i ) { Set( i ); return *this; }
  60. int Get() const { return m_nIndex; }
  61. void Set( int i );
  62. void Clear() { Set( -1 ); }
  63. operator int () const { return m_nIndex; }
  64. };
  65. //-----------------------------------------------------------------------------
  66. // Model info interface
  67. //-----------------------------------------------------------------------------
  68. // change this when the new version is incompatable with the old
  69. #define VMODELINFO_CLIENT_INTERFACE_VERSION "VModelInfoClient006"
  70. #define VMODELINFO_SERVER_INTERFACE_VERSION_3 "VModelInfoServer003"
  71. #define VMODELINFO_SERVER_INTERFACE_VERSION "VModelInfoServer004"
  72. // MODEL INDEX RULES
  73. // If index >= 0, then index references the precached model string table
  74. // If index == -1, then the model is invalid
  75. // If index < -1, then the model is DYNAMIC and has a DYNAMIC INDEX of (-2 - index)
  76. // - if the dynamic index is ODD, then the model is CLIENT ONLY
  77. // and has a m_LocalDynamicModels lookup index of (dynamic index)>>1
  78. // - if the dynamic index is EVEN, then the model is NETWORKED
  79. // and has a dynamic model string table index of (dynamic index)>>1
  80. inline bool IsDynamicModelIndex( int modelindex ) { return modelindex < -1; }
  81. inline bool IsClientOnlyModelIndex( int modelindex ) { return modelindex < -1 && (modelindex & 1); }
  82. abstract_class IVModelInfo
  83. {
  84. public:
  85. virtual ~IVModelInfo( void ) { }
  86. // Returns model_t* pointer for a model given a precached or dynamic model index.
  87. virtual const model_t *GetModel( int modelindex ) = 0;
  88. // Returns index of model by name for precached or known dynamic models.
  89. // Does not adjust reference count for dynamic models.
  90. virtual int GetModelIndex( const char *name ) const = 0;
  91. // Returns name of model
  92. virtual const char *GetModelName( const model_t *model ) const = 0;
  93. virtual vcollide_t *GetVCollide( const model_t *model ) = 0;
  94. virtual vcollide_t *GetVCollide( int modelindex ) = 0;
  95. virtual void GetModelBounds( const model_t *model, Vector& mins, Vector& maxs ) const = 0;
  96. virtual void GetModelRenderBounds( const model_t *model, Vector& mins, Vector& maxs ) const = 0;
  97. virtual int GetModelFrameCount( const model_t *model ) const = 0;
  98. virtual int GetModelType( const model_t *model ) const = 0;
  99. virtual void *GetModelExtraData( const model_t *model ) = 0;
  100. virtual bool ModelHasMaterialProxy( const model_t *model ) const = 0;
  101. virtual bool IsTranslucent( model_t const* model ) const = 0;
  102. virtual bool IsTranslucentTwoPass( const model_t *model ) const = 0;
  103. virtual void RecomputeTranslucency( const model_t *model, int nSkin, int nBody, void /*IClientRenderable*/ *pClientRenderable, float fInstanceAlphaModulate=1.0f) = 0;
  104. virtual int GetModelMaterialCount( const model_t* model ) const = 0;
  105. virtual void GetModelMaterials( const model_t *model, int count, IMaterial** ppMaterial ) = 0;
  106. virtual bool IsModelVertexLit( const model_t *model ) const = 0;
  107. virtual const char *GetModelKeyValueText( const model_t *model ) = 0;
  108. virtual bool GetModelKeyValue( const model_t *model, CUtlBuffer &buf ) = 0; // supports keyvalue blocks in submodels
  109. virtual float GetModelRadius( const model_t *model ) = 0;
  110. virtual const studiohdr_t *FindModel( const studiohdr_t *pStudioHdr, void **cache, const char *modelname ) const = 0;
  111. virtual const studiohdr_t *FindModel( void *cache ) const = 0;
  112. virtual virtualmodel_t *GetVirtualModel( const studiohdr_t *pStudioHdr ) const = 0;
  113. virtual byte *GetAnimBlock( const studiohdr_t *pStudioHdr, int iBlock ) const = 0;
  114. // Available on client only!!!
  115. virtual void GetModelMaterialColorAndLighting( const model_t *model, Vector const& origin,
  116. QAngle const& angles, trace_t* pTrace,
  117. Vector& lighting, Vector& matColor ) = 0;
  118. virtual void GetIlluminationPoint( const model_t *model, IClientRenderable *pRenderable, Vector const& origin,
  119. QAngle const& angles, Vector* pLightingCenter ) = 0;
  120. virtual int GetModelContents( int modelIndex ) = 0;
  121. virtual studiohdr_t *GetStudiomodel( const model_t *mod ) = 0;
  122. virtual int GetModelSpriteWidth( const model_t *model ) const = 0;
  123. virtual int GetModelSpriteHeight( const model_t *model ) const = 0;
  124. // Sets/gets a map-specified fade range (client only)
  125. virtual void SetLevelScreenFadeRange( float flMinSize, float flMaxSize ) = 0;
  126. virtual void GetLevelScreenFadeRange( float *pMinArea, float *pMaxArea ) const = 0;
  127. // Sets/gets a map-specified per-view fade range (client only)
  128. virtual void SetViewScreenFadeRange( float flMinSize, float flMaxSize ) = 0;
  129. // Computes fade alpha based on distance fade + screen fade (client only)
  130. virtual unsigned char ComputeLevelScreenFade( const Vector &vecAbsOrigin, float flRadius, float flFadeScale ) const = 0;
  131. virtual unsigned char ComputeViewScreenFade( const Vector &vecAbsOrigin, float flRadius, float flFadeScale ) const = 0;
  132. // both client and server
  133. virtual int GetAutoplayList( const studiohdr_t *pStudioHdr, unsigned short **pAutoplayList ) const = 0;
  134. // Gets a virtual terrain collision model (creates if necessary)
  135. // NOTE: This may return NULL if the terrain model cannot be virtualized
  136. virtual CPhysCollide *GetCollideForVirtualTerrain( int index ) = 0;
  137. virtual bool IsUsingFBTexture( const model_t *model, int nSkin, int nBody, void /*IClientRenderable*/ *pClientRenderable ) const = 0;
  138. // Obsolete methods. These are left in to maintain binary compatibility with clients using the IVModelInfo old version.
  139. virtual const model_t *FindOrLoadModel( const char *name ) { Warning( "IVModelInfo::FindOrLoadModel is now obsolte.\n" ); return NULL; }
  140. virtual void InitDynamicModels( ) { Warning( "IVModelInfo::InitDynamicModels is now obsolte.\n" ); }
  141. virtual void ShutdownDynamicModels( ) { Warning( "IVModelInfo::ShutdownDynamicModels is now obsolte.\n" ); }
  142. virtual void AddDynamicModel( const char *name, int nModelIndex = -1 ) { Warning( "IVModelInfo::AddDynamicModel is now obsolte.\n" ); }
  143. virtual void ReferenceModel( int modelindex ) { Warning( "IVModelInfo::ReferenceModel is now obsolte.\n" ); }
  144. virtual void UnreferenceModel( int modelindex ) { Warning( "IVModelInfo::UnreferenceModel is now obsolte.\n" ); }
  145. virtual void CleanupDynamicModels( bool bForce = false ) { Warning( "IVModelInfo::CleanupDynamicModels is now obsolte.\n" ); }
  146. virtual MDLHandle_t GetCacheHandle( const model_t *model ) const = 0;
  147. // Returns planes of non-nodraw brush model surfaces
  148. virtual int GetBrushModelPlaneCount( const model_t *model ) const = 0;
  149. virtual void GetBrushModelPlane( const model_t *model, int nIndex, cplane_t &plane, Vector *pOrigin ) const = 0;
  150. virtual int GetSurfacepropsForVirtualTerrain( int index ) = 0;
  151. // Poked by engine host system
  152. virtual void OnLevelChange() = 0;
  153. virtual int GetModelClientSideIndex( const char *name ) 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 bool IsDynamicModelLoading( int modelIndex ) = 0;
  157. virtual void AddRefDynamicModel( int modelIndex ) = 0;
  158. virtual void ReleaseDynamicModel( int modelIndex ) = 0;
  159. // Registers callback for when dynamic model has finished loading.
  160. // Automatically adds reference, pair with ReleaseDynamicModel.
  161. virtual bool RegisterModelLoadCallback( int modelindex, IModelLoadCallback* pCallback, bool bCallImmediatelyIfLoaded = true ) = 0;
  162. virtual void UnregisterModelLoadCallback( int modelindex, IModelLoadCallback* pCallback ) = 0;
  163. };
  164. typedef IVModelInfo IVModelInfo003;
  165. abstract_class IVModelInfoClient : public IVModelInfo
  166. {
  167. public:
  168. virtual void OnDynamicModelsStringTableChange( int nStringIndex, const char *pString, const void *pData ) = 0;
  169. // For tools only!
  170. virtual const model_t *FindOrLoadModel( const char *name ) = 0;
  171. };
  172. struct virtualterrainparams_t
  173. {
  174. // UNDONE: Add grouping here, specified in BSP file? (test grouping to see if this is necessary)
  175. int index;
  176. };
  177. //-----------------------------------------------------------------------------
  178. // Purpose: Force removal from callback list on destruction to avoid crashes.
  179. //-----------------------------------------------------------------------------
  180. inline IModelLoadCallback::~IModelLoadCallback()
  181. {
  182. #ifdef CLIENT_DLL
  183. extern IVModelInfoClient *modelinfo;
  184. #else
  185. extern IVModelInfo *modelinfo;
  186. #endif
  187. if ( modelinfo )
  188. {
  189. modelinfo->UnregisterModelLoadCallback( -1, this );
  190. }
  191. }
  192. //-----------------------------------------------------------------------------
  193. // Purpose: Automate refcount tracking on a model index
  194. //-----------------------------------------------------------------------------
  195. inline void CRefCountedModelIndex::Set( int i )
  196. {
  197. #ifdef CLIENT_DLL
  198. extern IVModelInfoClient *modelinfo;
  199. #else
  200. extern IVModelInfo *modelinfo;
  201. #endif
  202. if ( i == m_nIndex )
  203. return;
  204. modelinfo->AddRefDynamicModel( i );
  205. modelinfo->ReleaseDynamicModel( m_nIndex );
  206. m_nIndex = i;
  207. }
  208. #endif // IVMODELINFO_H