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.

106 lines
2.8 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 TIER1_H
  7. #define TIER1_H
  8. #if defined( _WIN32 )
  9. #pragma once
  10. #endif
  11. #include "appframework/IAppSystem.h"
  12. #include "tier1/convar.h"
  13. //-----------------------------------------------------------------------------
  14. // Forward declarations
  15. //-----------------------------------------------------------------------------
  16. class ICvar;
  17. class IProcessUtils;
  18. //-----------------------------------------------------------------------------
  19. // These tier1 libraries must be set by any users of this library.
  20. // They can be set by calling ConnectTier1Libraries.
  21. // It is hoped that setting this, and using this library will be the common mechanism for
  22. // allowing link libraries to access tier1 library interfaces
  23. //-----------------------------------------------------------------------------
  24. // These are marked DLL_EXPORT for Linux.
  25. DLL_EXPORT ICvar *cvar;
  26. extern ICvar *g_pCVar;
  27. extern IProcessUtils *g_pProcessUtils;
  28. //-----------------------------------------------------------------------------
  29. // Call this to connect to/disconnect from all tier 1 libraries.
  30. // It's up to the caller to check the globals it cares about to see if ones are missing
  31. //-----------------------------------------------------------------------------
  32. void ConnectTier1Libraries( CreateInterfaceFn *pFactoryList, int nFactoryCount );
  33. void DisconnectTier1Libraries();
  34. //-----------------------------------------------------------------------------
  35. // Helper empty implementation of an IAppSystem for tier2 libraries
  36. //-----------------------------------------------------------------------------
  37. template< class IInterface, int ConVarFlag = 0 >
  38. class CTier1AppSystem : public CTier0AppSystem< IInterface >
  39. {
  40. typedef CTier0AppSystem< IInterface > BaseClass;
  41. public:
  42. CTier1AppSystem( bool bIsPrimaryAppSystem = true ) : BaseClass( bIsPrimaryAppSystem )
  43. {
  44. }
  45. virtual bool Connect( CreateInterfaceFn factory )
  46. {
  47. if ( !BaseClass::Connect( factory ) )
  48. return false;
  49. if ( BaseClass::IsPrimaryAppSystem() )
  50. {
  51. ConnectTier1Libraries( &factory, 1 );
  52. }
  53. return true;
  54. }
  55. virtual void Disconnect()
  56. {
  57. if ( BaseClass::IsPrimaryAppSystem() )
  58. {
  59. DisconnectTier1Libraries();
  60. }
  61. BaseClass::Disconnect();
  62. }
  63. virtual InitReturnVal_t Init()
  64. {
  65. InitReturnVal_t nRetVal = BaseClass::Init();
  66. if ( nRetVal != INIT_OK )
  67. return nRetVal;
  68. if ( g_pCVar && BaseClass::IsPrimaryAppSystem() )
  69. {
  70. ConVar_Register( ConVarFlag );
  71. }
  72. return INIT_OK;
  73. }
  74. virtual void Shutdown()
  75. {
  76. if ( g_pCVar && BaseClass::IsPrimaryAppSystem() )
  77. {
  78. ConVar_Unregister( );
  79. }
  80. BaseClass::Shutdown( );
  81. }
  82. };
  83. #endif // TIER1_H