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.

176 lines
8.1 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef IRESOURCESYSTEM_H
  9. #define IRESOURCESYSTEM_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "appframework/iappsystem.h"
  14. #include "resourcefile/resourceintrospection.h"
  15. #include "resourcefile/resourcedictionary.h"
  16. #include "resourcefile/resourcetype.h"
  17. #include "tier2/tier2.h"
  18. //-----------------------------------------------------------------------------
  19. // Forward declarations
  20. //-----------------------------------------------------------------------------
  21. class IResourceTypeManager;
  22. //-----------------------------------------------------------------------------
  23. // A method used to allow clients to construct + destruct resources based
  24. // on raw data. Needs to be installed into resource type managers based on
  25. // resource type
  26. //-----------------------------------------------------------------------------
  27. abstract_class IResourceTypeConstructor
  28. {
  29. public:
  30. virtual bool Init( IResourceTypeManager *pTypeManager ) = 0;
  31. virtual void Shutdown() = 0;
  32. // Returns a structure type associated with the permanent data
  33. virtual void *AllocatePermanentData( const void *pDataFromDisk, size_t nDataSize ) = 0;
  34. virtual void DeallocatePermanentData( void *pData ) = 0;
  35. // Returns the default memory limit
  36. virtual size_t GetDefaultMemoryLimit() = 0;
  37. // Allows the system to compute the actual size of the constructed class
  38. // based on the permanent data in in the resource system. If the system
  39. // doesn't know/care, return 0 here.
  40. virtual size_t ComputeActualSize( void *pPermanentData ) = 0;
  41. // NOTE: Resource references in pResourceData have been fixed up to
  42. // be resource handles at this point
  43. virtual void *Allocate( const void *pPermanentData, const void *pResourceData, size_t nDataSize, ResourceHandle_t hResourceHandle ) = 0;
  44. virtual void Deallocate( void *pClass ) = 0;
  45. // Fallbacks + errors..
  46. virtual void *GetErrorResource( const void *pPermanentData ) = 0;
  47. virtual void *GetFallback( const void *pPermanentData ) = 0;
  48. };
  49. //-----------------------------------------------------------------------------
  50. // A resource dictionary to look up resources
  51. //-----------------------------------------------------------------------------
  52. abstract_class IResourceTypeManager
  53. {
  54. public:
  55. virtual ResourceHandle_t FindOrCreateResource( const char *pFileName, const char *pSubResourceName ) = 0;
  56. virtual ResourceHandle_t FindOrCreateProceduralResource( const char *pGroupName, const char *pResourceName, const void *pPermanentData, size_t nDataSize ) = 0;
  57. virtual void DeleteResource( ResourceHandle_t hResource ) = 0;
  58. virtual ResourceHandle_t FindResource( ResourceId_t nResourceId ) = 0;
  59. virtual ResourceType_t GetResourceType() = 0;
  60. virtual ResourceId_t GetResourceId( ResourceHandle_t hResource ) const = 0;
  61. // To bring resources in or out of memory
  62. virtual void CacheResource( ResourceHandle_t hResource ) = 0;
  63. virtual void UncacheResource( ResourceHandle_t hResource ) = 0;
  64. // Sets the amount of memory to restrict this resource type to using
  65. virtual void SetMemoryLimit( int nMemoryLimit ) = 0;
  66. // Returns the list of cached resources
  67. virtual int GetResourceCount() const = 0;
  68. virtual int GetResources( int nFirst, int nCount, ResourceHandle_t *pResources ) = 0;
  69. };
  70. //-----------------------------------------------------------------------------
  71. // Methods related to managing resources
  72. //-----------------------------------------------------------------------------
  73. abstract_class IResourceSystem : public IAppSystem
  74. {
  75. public:
  76. // Used to indicate globals to update to the current frame counter
  77. // This counter is controlled by the resource system + set to the
  78. // resource system's current frame
  79. virtual void RegisterFrameCounter( uint32 *pFrameCounter ) = 0;
  80. virtual void UnregisterFrameCounter( uint32 *pFrameCounter ) = 0;
  81. // Allows various systems to hook in resource type constructors and class bindings
  82. virtual void InstallResourceConstructor( ResourceType_t nType, const char *pResourceManagerType, IResourceTypeConstructor *pConstructor ) = 0;
  83. virtual void RemoveResourceConstructor( IResourceTypeConstructor *pConstructor ) = 0;
  84. // FIXME: Should this be in IResourceSystem or CResourceSystem?
  85. virtual void InstallSchemaClassBinding( class CSchemaClassBindingBase *pBinding ) = 0;
  86. // Indicates globals controlled by the client which specify the frame
  87. // that the clients have finished with, thereby telling the resource system
  88. // what resources it can free.
  89. virtual void RegisterFinishedFrameCounter( uint32 *pFrameCounter ) = 0;
  90. virtual void UnregisterFinishedFrameCounter( uint32 *pFrameCounter ) = 0;
  91. void MarkFinishedFrameCounter( uint32 *pFrameCounter );
  92. // Methods related to resource introspection. Should these go into a separate interface?
  93. virtual const CResourceStructIntrospection* FindStructIntrospection( ResourceStructureId_t id ) const = 0;
  94. virtual const CResourceStructIntrospection* FindStructIntrospection( const char *pStructName ) const = 0;
  95. virtual const CResourceEnumIntrospection* FindEnumIntrospection( ResourceStructureId_t id ) const = 0;
  96. virtual const CResourceEnumIntrospection* FindEnumIntrospection( const char *pEnumName ) const = 0;
  97. virtual const CResourceTypedefIntrospection* FindTypedefIntrospection( ResourceStructureId_t id ) const = 0;
  98. virtual const CResourceTypedefIntrospection* FindTypedefIntrospection( const char *pTypedefName ) const = 0;
  99. // Returns the value associated with a particular enumeration
  100. virtual bool FindEnumeratedValue( void *pValue, const char *pEnumName, const char *pEnumValueName, int nDefaultValue ) const = 0;
  101. virtual const char *FindEnumerationName( const char *pEnumName, int nValue, const char *pDefaultName ) const = 0;
  102. // TODO: Possibly change this to use a StructIntrospectionHandle_t
  103. virtual const CResourceStructIntrospection* FindStructIntrospectionByBlockType( ResourceBlockId_t nBlockType ) const = 0;
  104. virtual const CResourceStructIntrospection* FindStructIntrospectionForResourceType( ResourceType_t nType ) const = 0;
  105. virtual const CResourceStructIntrospection* FindPermanentStructIntrospectionForResourceType( ResourceType_t nType ) const = 0;
  106. virtual bool UnpackIntrospectedBlock( const void *pResourceData, size_t nSrcDataSize,
  107. const CResourceIntrospection *pSrcIntro, const CResourceStructIntrospection* pSrcStructIntro,
  108. const CResourceStructIntrospection* pDstStructIntro,
  109. void const **pOutResult, int *pOutResultSize, IntrospectionCompatibilityType_t* pOutCompat ) const = 0;
  110. // Utility methods
  111. virtual void GetResourceMapping( const char *pDmeElementType, ResourceType_t *pType, ResourceStructureId_t *pId ) = 0;
  112. virtual int GetFieldSize( ResourceFieldType_t nType ) const = 0;
  113. virtual int GetFieldAlignment( ResourceFieldType_t nType ) const = 0;
  114. virtual const char* GetFieldName( ResourceFieldType_t nType ) const = 0;
  115. // Methods related to a resource dictionary
  116. // NOTE: This will become obsolete at some point I believe? It loads a map
  117. // of resource IDs and possible resource IDs from the specified files.
  118. virtual void LoadResourceManifest( const char *pFileName ) = 0;
  119. // Returns a resource manager for a particular resource type
  120. virtual IResourceTypeManager *GetResourceManager( ResourceType_t nType ) = 0;
  121. // Frame update.. resources are cached in or out here
  122. virtual void FrameUpdate() = 0;
  123. // Block until all type dictionaries are loaded.
  124. // NOTE: This call is not necessary to make if you are running the game
  125. // It's only necessary in tools that use IFileSystem instead of IAsyncFileSystem.
  126. virtual void BlockUntilAllVTDsLoaded() = 0;
  127. // Returns the resource manager associated with a particular resource data type
  128. template < class T > IResourceTypeManager *GetResourceManagerForType( );
  129. };
  130. template < class T >
  131. inline IResourceTypeManager *IResourceSystem::GetResourceManagerForType( )
  132. {
  133. return GetResourceManager( ResourceTypeInfo_t< T >::ResourceType() );
  134. }
  135. inline void IResourceSystem::MarkFinishedFrameCounter( uint32 *pFrameCounter )
  136. {
  137. *pFrameCounter = g_nResourceFrameCount;
  138. }
  139. #endif // IRESOURCESYSTEM_H