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.

138 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #include "cbase.h"
  9. #include "igamesystem.h"
  10. #include "toolframework/iserverenginetools.h"
  11. #include "init_factory.h"
  12. //-----------------------------------------------------------------------------
  13. // Purpose: This is an autogame system which is used to call back into the engine at appropriate points
  14. // so that IToolSystems can get these hooks at the correct time
  15. //-----------------------------------------------------------------------------
  16. class CToolFrameworkServer : public CAutoGameSystemPerFrame, public IToolFrameworkServer
  17. {
  18. public:
  19. virtual bool Init();
  20. // Level init, shutdown
  21. virtual void LevelInitPreEntity();
  22. // entities are created / spawned / precached here
  23. virtual void LevelInitPostEntity();
  24. virtual void LevelShutdownPreEntity();
  25. // Entities are deleted / released here...
  26. virtual void LevelShutdownPostEntity();
  27. // Called each frame before entities think
  28. virtual void FrameUpdatePreEntityThink();
  29. // called after entities think
  30. virtual void FrameUpdatePostEntityThink();
  31. virtual void PreClientUpdate();
  32. virtual void PreSetupVisibility();
  33. IServerEngineTools *m_pTools;
  34. };
  35. // Singleton
  36. static CToolFrameworkServer g_ToolFrameworkServer;
  37. IToolFrameworkServer *g_pToolFrameworkServer = &g_ToolFrameworkServer;
  38. #ifndef NO_TOOLFRAMEWORK
  39. bool ToolsEnabled()
  40. {
  41. return g_ToolFrameworkServer.m_pTools && g_ToolFrameworkServer.m_pTools->InToolMode() && !engine->IsDedicatedServer();
  42. }
  43. #endif
  44. bool CToolFrameworkServer::Init()
  45. {
  46. factorylist_t list;
  47. FactoryList_Retrieve( list );
  48. // Latch onto internal interface
  49. m_pTools = ( IServerEngineTools * )list.engineFactory( VSERVERENGINETOOLS_INTERFACE_VERSION, NULL );
  50. if ( !m_pTools && !engine->IsDedicatedServer() )
  51. {
  52. return false;
  53. }
  54. return true;
  55. }
  56. void CToolFrameworkServer::LevelInitPreEntity()
  57. {
  58. if ( !m_pTools )
  59. {
  60. return;
  61. }
  62. m_pTools->LevelInitPreEntityAllTools();
  63. }
  64. void CToolFrameworkServer::LevelInitPostEntity()
  65. {
  66. if ( !m_pTools )
  67. {
  68. return;
  69. }
  70. m_pTools->LevelInitPostEntityAllTools();
  71. }
  72. void CToolFrameworkServer::LevelShutdownPreEntity()
  73. {
  74. if ( !m_pTools )
  75. {
  76. return;
  77. }
  78. m_pTools->LevelShutdownPreEntityAllTools();
  79. }
  80. void CToolFrameworkServer::LevelShutdownPostEntity()
  81. {
  82. if ( !m_pTools )
  83. {
  84. return;
  85. }
  86. m_pTools->LevelShutdownPostEntityAllTools();
  87. }
  88. void CToolFrameworkServer::FrameUpdatePreEntityThink()
  89. {
  90. if ( !m_pTools )
  91. {
  92. return;
  93. }
  94. m_pTools->FrameUpdatePreEntityThinkAllTools();
  95. }
  96. void CToolFrameworkServer::FrameUpdatePostEntityThink()
  97. {
  98. if ( !m_pTools )
  99. {
  100. return;
  101. }
  102. m_pTools->FrameUpdatePostEntityThinkAllTools();
  103. }
  104. void CToolFrameworkServer::PreClientUpdate()
  105. {
  106. if ( !m_pTools )
  107. {
  108. return;
  109. }
  110. m_pTools->PreClientUpdateAllTools();
  111. }
  112. void CToolFrameworkServer::PreSetupVisibility()
  113. {
  114. if ( !m_pTools )
  115. {
  116. return;
  117. }
  118. m_pTools->PreSetupVisibilityAllTools();
  119. }