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.

128 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A higher level link library for general use in the game and tools.
  4. //
  5. //===========================================================================//
  6. #ifndef TIER2_H
  7. #define TIER2_H
  8. #if defined( _WIN32 )
  9. #pragma once
  10. #endif
  11. #include "tier1/tier1.h"
  12. //-----------------------------------------------------------------------------
  13. // Forward declarations
  14. //-----------------------------------------------------------------------------
  15. class IFileSystem;
  16. class IMaterialSystem;
  17. class IColorCorrectionSystem;
  18. class IMaterialSystemHardwareConfig;
  19. class IDebugTextureInfo;
  20. class IVBAllocTracker;
  21. class IInputSystem;
  22. class INetworkSystem;
  23. class IP4;
  24. class IMdlLib;
  25. class IQueuedLoader;
  26. //-----------------------------------------------------------------------------
  27. // These tier2 libraries must be set by any users of this library.
  28. // They can be set by calling ConnectTier2Libraries or InitDefaultFileSystem.
  29. // It is hoped that setting this, and using this library will be the common mechanism for
  30. // allowing link libraries to access tier2 library interfaces
  31. //-----------------------------------------------------------------------------
  32. extern IFileSystem *g_pFullFileSystem;
  33. extern IMaterialSystem *materials;
  34. extern IMaterialSystem *g_pMaterialSystem;
  35. extern IInputSystem *g_pInputSystem;
  36. extern INetworkSystem *g_pNetworkSystem;
  37. extern IMaterialSystemHardwareConfig *g_pMaterialSystemHardwareConfig;
  38. extern IDebugTextureInfo *g_pMaterialSystemDebugTextureInfo;
  39. extern IVBAllocTracker *g_VBAllocTracker;
  40. extern IColorCorrectionSystem *colorcorrection;
  41. extern IP4 *p4;
  42. extern IMdlLib *mdllib;
  43. extern IQueuedLoader *g_pQueuedLoader;
  44. //-----------------------------------------------------------------------------
  45. // Call this to connect to/disconnect from all tier 2 libraries.
  46. // It's up to the caller to check the globals it cares about to see if ones are missing
  47. //-----------------------------------------------------------------------------
  48. void ConnectTier2Libraries( CreateInterfaceFn *pFactoryList, int nFactoryCount );
  49. void DisconnectTier2Libraries();
  50. //-----------------------------------------------------------------------------
  51. // Call this to get the file system set up to stdio for utilities, etc:
  52. //-----------------------------------------------------------------------------
  53. void InitDefaultFileSystem(void);
  54. void ShutdownDefaultFileSystem(void);
  55. //-----------------------------------------------------------------------------
  56. // for simple utilities using valve libraries, call the entry point below in main(). It will
  57. // init a filesystem for you, init mathlib, and create the command line.
  58. //-----------------------------------------------------------------------------
  59. void InitCommandLineProgram( int argc, char **argv );
  60. //-----------------------------------------------------------------------------
  61. // Helper empty implementation of an IAppSystem for tier2 libraries
  62. //-----------------------------------------------------------------------------
  63. template< class IInterface, int ConVarFlag = 0 >
  64. class CTier2AppSystem : public CTier1AppSystem< IInterface, ConVarFlag >
  65. {
  66. typedef CTier1AppSystem< IInterface, ConVarFlag > BaseClass;
  67. public:
  68. CTier2AppSystem( bool bIsPrimaryAppSystem = true ) : BaseClass( bIsPrimaryAppSystem )
  69. {
  70. }
  71. virtual bool Connect( CreateInterfaceFn factory )
  72. {
  73. if ( !BaseClass::Connect( factory ) )
  74. return false;
  75. if ( BaseClass::IsPrimaryAppSystem() )
  76. {
  77. ConnectTier2Libraries( &factory, 1 );
  78. }
  79. return true;
  80. }
  81. virtual InitReturnVal_t Init()
  82. {
  83. InitReturnVal_t nRetVal = BaseClass::Init();
  84. if ( nRetVal != INIT_OK )
  85. return nRetVal;
  86. return INIT_OK;
  87. }
  88. virtual void Shutdown()
  89. {
  90. BaseClass::Shutdown();
  91. }
  92. virtual void Disconnect()
  93. {
  94. if ( BaseClass::IsPrimaryAppSystem() )
  95. {
  96. DisconnectTier2Libraries();
  97. }
  98. BaseClass::Disconnect();
  99. }
  100. };
  101. #endif // TIER2_H