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.

117 lines
4.0 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. #include <tier2/tier2.h>
  7. #include "tier0/dbg.h"
  8. #include "filesystem.h"
  9. #include "materialsystem/imaterialsystem.h"
  10. #include "materialsystem/imaterialsystemhardwareconfig.h"
  11. #include "materialsystem/IColorCorrection.h"
  12. #include "materialsystem/idebugtextureinfo.h"
  13. #include "materialsystem/ivballoctracker.h"
  14. #include "inputsystem/iinputsystem.h"
  15. #include "networksystem/inetworksystem.h"
  16. #include "p4lib/ip4.h"
  17. #include "mdllib/mdllib.h"
  18. #include "filesystem/IQueuedLoader.h"
  19. //-----------------------------------------------------------------------------
  20. // These tier2 libraries must be set by any users of this library.
  21. // They can be set by calling ConnectTier2Libraries or InitDefaultFileSystem.
  22. // It is hoped that setting this, and using this library will be the common mechanism for
  23. // allowing link libraries to access tier2 library interfaces
  24. //-----------------------------------------------------------------------------
  25. IFileSystem *g_pFullFileSystem = 0;
  26. IMaterialSystem *materials = 0;
  27. IMaterialSystem *g_pMaterialSystem = 0;
  28. IInputSystem *g_pInputSystem = 0;
  29. INetworkSystem *g_pNetworkSystem = 0;
  30. IMaterialSystemHardwareConfig *g_pMaterialSystemHardwareConfig = 0;
  31. IDebugTextureInfo *g_pMaterialSystemDebugTextureInfo = 0;
  32. IVBAllocTracker *g_VBAllocTracker = 0;
  33. IColorCorrectionSystem *colorcorrection = 0;
  34. IP4 *p4 = 0;
  35. IMdlLib *mdllib = 0;
  36. IQueuedLoader *g_pQueuedLoader = 0;
  37. //-----------------------------------------------------------------------------
  38. // Call this to connect to all tier 2 libraries.
  39. // It's up to the caller to check the globals it cares about to see if ones are missing
  40. //-----------------------------------------------------------------------------
  41. void ConnectTier2Libraries( CreateInterfaceFn *pFactoryList, int nFactoryCount )
  42. {
  43. // Don't connect twice..
  44. Assert( !g_pFullFileSystem && !materials && !g_pInputSystem && !g_pNetworkSystem &&
  45. !p4 && !mdllib && !g_pMaterialSystemDebugTextureInfo && !g_VBAllocTracker &&
  46. !g_pMaterialSystemHardwareConfig && !g_pQueuedLoader );
  47. for ( int i = 0; i < nFactoryCount; ++i )
  48. {
  49. if ( !g_pFullFileSystem )
  50. {
  51. g_pFullFileSystem = ( IFileSystem * )pFactoryList[i]( FILESYSTEM_INTERFACE_VERSION, NULL );
  52. }
  53. if ( !materials )
  54. {
  55. g_pMaterialSystem = materials = ( IMaterialSystem * )pFactoryList[i]( MATERIAL_SYSTEM_INTERFACE_VERSION, NULL );
  56. }
  57. if ( !g_pInputSystem )
  58. {
  59. g_pInputSystem = ( IInputSystem * )pFactoryList[i]( INPUTSYSTEM_INTERFACE_VERSION, NULL );
  60. }
  61. if ( !g_pNetworkSystem )
  62. {
  63. g_pNetworkSystem = ( INetworkSystem * )pFactoryList[i]( NETWORKSYSTEM_INTERFACE_VERSION, NULL );
  64. }
  65. if ( !g_pMaterialSystemHardwareConfig )
  66. {
  67. g_pMaterialSystemHardwareConfig = ( IMaterialSystemHardwareConfig * )pFactoryList[i]( MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, NULL );
  68. }
  69. if ( !g_pMaterialSystemDebugTextureInfo )
  70. {
  71. g_pMaterialSystemDebugTextureInfo = (IDebugTextureInfo*)pFactoryList[i]( DEBUG_TEXTURE_INFO_VERSION, 0 );
  72. }
  73. if ( !g_VBAllocTracker )
  74. {
  75. g_VBAllocTracker = (IVBAllocTracker*)pFactoryList[i]( VB_ALLOC_TRACKER_INTERFACE_VERSION, 0 );
  76. }
  77. if ( !colorcorrection )
  78. {
  79. colorcorrection = ( IColorCorrectionSystem * )pFactoryList[i]( COLORCORRECTION_INTERFACE_VERSION, NULL );
  80. }
  81. if ( !p4 )
  82. {
  83. p4 = ( IP4 * )pFactoryList[i]( P4_INTERFACE_VERSION, NULL );
  84. }
  85. if ( !mdllib )
  86. {
  87. mdllib = ( IMdlLib * )pFactoryList[i]( MDLLIB_INTERFACE_VERSION, NULL );
  88. }
  89. if ( !g_pQueuedLoader )
  90. {
  91. g_pQueuedLoader = (IQueuedLoader *)pFactoryList[i]( QUEUEDLOADER_INTERFACE_VERSION, NULL );
  92. }
  93. }
  94. }
  95. void DisconnectTier2Libraries()
  96. {
  97. g_pFullFileSystem = 0;
  98. materials = g_pMaterialSystem = 0;
  99. g_pMaterialSystemHardwareConfig = 0;
  100. g_pMaterialSystemDebugTextureInfo = 0;
  101. g_pInputSystem = 0;
  102. g_pNetworkSystem = 0;
  103. colorcorrection = 0;
  104. p4 = 0;
  105. mdllib = 0;
  106. g_pQueuedLoader = 0;
  107. }