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.

260 lines
7.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef IGAMESYSTEM_H
  8. #define IGAMESYSTEM_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. //-----------------------------------------------------------------------------
  13. // Game systems are singleton objects in the client + server codebase responsible for
  14. // various tasks
  15. // The order in which the server systems appear in this list are the
  16. // order in which they are initialized and updated. They are shut down in
  17. // reverse order from which they are initialized.
  18. //-----------------------------------------------------------------------------
  19. #ifdef GAME_DLL
  20. class CBasePlayer;
  21. class CUserCmd;
  22. #endif
  23. // UNDONE: Do these need GameInit/GameShutdown as well?
  24. // UNDONE: Remove the Pre/Post entity semantics and rely on system ordering?
  25. // FIXME: Remove all ifdef CLIENT_DLL if we can...
  26. abstract_class IGameSystem
  27. {
  28. public:
  29. // GameSystems are expected to implement these methods.
  30. virtual char const *Name() = 0;
  31. // Init, shutdown
  32. // return true on success. false to abort DLL init!
  33. virtual bool Init() = 0;
  34. virtual void PostInit() = 0;
  35. virtual void Shutdown() = 0;
  36. // Level init, shutdown
  37. virtual void LevelInitPreEntity() = 0;
  38. // entities are created / spawned / precached here
  39. virtual void LevelInitPostEntity() = 0;
  40. virtual void LevelShutdownPreEntity() = 0;
  41. // Entities are deleted / released here...
  42. virtual void LevelShutdownPostEntity() = 0;
  43. // end of level shutdown
  44. // Called during game save
  45. virtual void OnSave() = 0;
  46. // Called during game restore, after the local player has connected and entities have been fully restored
  47. virtual void OnRestore() = 0;
  48. // Called every frame. It's safe to remove an igamesystem from within this callback.
  49. virtual void SafeRemoveIfDesired() = 0;
  50. virtual bool IsPerFrame() = 0;
  51. // destructor, cleans up automagically....
  52. virtual ~IGameSystem();
  53. // Client systems can use this to get at the map name
  54. static char const* MapName();
  55. // These methods are used to add and remove server systems from the
  56. // main server loop. The systems are invoked in the order in which
  57. // they are added.
  58. static void Add ( IGameSystem* pSys );
  59. static void Remove ( IGameSystem* pSys );
  60. static void RemoveAll ( );
  61. // These methods are used to initialize, shutdown, etc all systems
  62. static bool InitAllSystems();
  63. static void PostInitAllSystems();
  64. static void ShutdownAllSystems();
  65. static void LevelInitPreEntityAllSystems( char const* pMapName );
  66. static void LevelInitPostEntityAllSystems();
  67. static void LevelShutdownPreEntityAllSystems();
  68. static void LevelShutdownPostEntityAllSystems();
  69. static void OnSaveAllSystems();
  70. static void OnRestoreAllSystems();
  71. static void SafeRemoveIfDesiredAllSystems();
  72. #ifdef CLIENT_DLL
  73. static void PreRenderAllSystems();
  74. static void UpdateAllSystems( float frametime );
  75. static void PostRenderAllSystems();
  76. #else
  77. static void FrameUpdatePreEntityThinkAllSystems();
  78. static void FrameUpdatePostEntityThinkAllSystems();
  79. static void PreClientUpdateAllSystems();
  80. // Accessors for the above function
  81. #ifdef GAME_DLL
  82. static CBasePlayer *RunCommandPlayer();
  83. static CUserCmd *RunCommandUserCmd();
  84. #endif
  85. #endif
  86. };
  87. class IGameSystemPerFrame : public IGameSystem
  88. {
  89. public:
  90. // destructor, cleans up automagically....
  91. virtual ~IGameSystemPerFrame();
  92. #ifdef CLIENT_DLL
  93. // Called before rendering
  94. virtual void PreRender() = 0;
  95. // Gets called each frame
  96. virtual void Update( float frametime ) = 0;
  97. // Called after rendering
  98. virtual void PostRender() = 0;
  99. #else
  100. // Called each frame before entities think
  101. virtual void FrameUpdatePreEntityThink() = 0;
  102. // called after entities think
  103. virtual void FrameUpdatePostEntityThink() = 0;
  104. virtual void PreClientUpdate() = 0;
  105. #endif
  106. };
  107. // Quick and dirty server system for users who don't care about precise ordering
  108. // and usually only want to implement a few of the callbacks
  109. class CBaseGameSystem : public IGameSystem
  110. {
  111. public:
  112. virtual char const *Name() { return "unnamed"; }
  113. // Init, shutdown
  114. // return true on success. false to abort DLL init!
  115. virtual bool Init() { return true; }
  116. virtual void PostInit() {}
  117. virtual void Shutdown() {}
  118. // Level init, shutdown
  119. virtual void LevelInitPreEntity() {}
  120. virtual void LevelInitPostEntity() {}
  121. virtual void LevelShutdownPreEntity() {}
  122. virtual void LevelShutdownPostEntity() {}
  123. virtual void OnSave() {}
  124. virtual void OnRestore() {}
  125. virtual void SafeRemoveIfDesired() {}
  126. virtual bool IsPerFrame() { return false; }
  127. private:
  128. // Prevent anyone derived from CBaseGameSystem from implementing these, they need
  129. // to derive from CBaseGameSystemPerFrame below!!!
  130. #ifdef CLIENT_DLL
  131. // Called before rendering
  132. virtual void PreRender() {}
  133. // Gets called each frame
  134. virtual void Update( float frametime ) {}
  135. // Called after rendering
  136. virtual void PostRender() {}
  137. #else
  138. // Called each frame before entities think
  139. virtual void FrameUpdatePreEntityThink() {}
  140. // called after entities think
  141. virtual void FrameUpdatePostEntityThink() {}
  142. virtual void PreClientUpdate() {}
  143. #endif
  144. };
  145. // Quick and dirty server system for users who don't care about precise ordering
  146. // and usually only want to implement a few of the callbacks
  147. class CBaseGameSystemPerFrame : public IGameSystemPerFrame
  148. {
  149. public:
  150. virtual char const *Name() { return "unnamed"; }
  151. // Init, shutdown
  152. // return true on success. false to abort DLL init!
  153. virtual bool Init() { return true; }
  154. virtual void PostInit() {}
  155. virtual void Shutdown() {}
  156. // Level init, shutdown
  157. virtual void LevelInitPreEntity() {}
  158. virtual void LevelInitPostEntity() {}
  159. virtual void LevelShutdownPreEntity() {}
  160. virtual void LevelShutdownPostEntity() {}
  161. virtual void OnSave() {}
  162. virtual void OnRestore() {}
  163. virtual void SafeRemoveIfDesired() {}
  164. virtual bool IsPerFrame() { return true; }
  165. #ifdef CLIENT_DLL
  166. // Called before rendering
  167. virtual void PreRender () { }
  168. // Gets called each frame
  169. virtual void Update( float frametime ) { }
  170. // Called after rendering
  171. virtual void PostRender () { }
  172. #else
  173. // Called each frame before entities think
  174. virtual void FrameUpdatePreEntityThink() { }
  175. // called after entities think
  176. virtual void FrameUpdatePostEntityThink() { }
  177. virtual void PreClientUpdate() { }
  178. #endif
  179. };
  180. // Quick and dirty server system for users who don't care about precise ordering
  181. // and usually only want to implement a few of the callbacks
  182. class CAutoGameSystem : public CBaseGameSystem
  183. {
  184. public:
  185. CAutoGameSystem( char const *name = NULL ); // hooks in at startup, no need to explicitly add
  186. CAutoGameSystem *m_pNext;
  187. virtual char const *Name() { return m_pszName ? m_pszName : "unnamed"; }
  188. private:
  189. char const *m_pszName;
  190. };
  191. //-----------------------------------------------------------------------------
  192. // Purpose: This is a CAutoGameSystem which also cares about the "per frame" hooks
  193. //-----------------------------------------------------------------------------
  194. class CAutoGameSystemPerFrame : public CBaseGameSystemPerFrame
  195. {
  196. public:
  197. CAutoGameSystemPerFrame( char const *name = NULL );
  198. CAutoGameSystemPerFrame *m_pNext;
  199. virtual char const *Name() { return m_pszName ? m_pszName : "unnamed"; }
  200. private:
  201. char const *m_pszName;
  202. };
  203. //-----------------------------------------------------------------------------
  204. // Purpose: This interface is here to add more hooks than IGameSystemPerFrame exposes,
  205. // so we don't pollute it with hooks that only the tool cares about
  206. //-----------------------------------------------------------------------------
  207. class IToolFrameworkServer
  208. {
  209. public:
  210. virtual void PreSetupVisibility() = 0;
  211. };
  212. #endif // IGAMESYSTEM_H