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.

143 lines
3.0 KiB

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