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.

222 lines
6.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #if !defined( HOST_H )
  10. #define HOST_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "convar.h"
  15. #ifdef _PS3
  16. #include "tls_ps3.h"
  17. #endif
  18. #define SCRIPT_DIR "scripts/"
  19. struct model_t;
  20. struct AudioState_t;
  21. class KeyValues;
  22. class CMsg_CVars;
  23. class CCommonHostState
  24. {
  25. public:
  26. CCommonHostState() : worldmodel( NULL ), worldbrush( NULL ), interval_per_tick( 0.0f ), max_splitscreen_players( 1 ), max_splitscreen_players_clientdll( 1 ) {}
  27. // cl_entitites[0].model
  28. model_t *worldmodel;
  29. struct worldbrushdata_t *worldbrush;
  30. // Tick interval for game
  31. float interval_per_tick;
  32. // 1, unless a game supports split screen, then probably 2 or 4 (4 is the max allowable)
  33. int max_splitscreen_players;
  34. // This is the # the client .dll thinks is the max, it might be > max_splitscreen_players in -tools mode, etc.
  35. int max_splitscreen_players_clientdll;
  36. void SetWorldModel( model_t *pModel );
  37. };
  38. extern CCommonHostState host_state;
  39. //=============================================================================
  40. // the host system specifies the base of the directory tree, the mod + base mod
  41. // and the amount of memory available for the program to use
  42. struct engineparms_t
  43. {
  44. engineparms_t() : basedir( NULL ), mod( NULL ), game( NULL ), memsize( 0u ) {}
  45. char *basedir; // Executable directory ("c:/program files/half-life 2", for example)
  46. char *mod; // Mod name ("cstrike", for example)
  47. char *game; // Root game name ("hl2", for example, in the case of cstrike)
  48. unsigned int memsize;
  49. };
  50. extern engineparms_t host_parms;
  51. //-----------------------------------------------------------------------------
  52. // Human readable methods to get at engineparms info
  53. //-----------------------------------------------------------------------------
  54. inline const char *GetCurrentMod()
  55. {
  56. return host_parms.mod;
  57. }
  58. inline const char *GetCurrentGame()
  59. {
  60. return host_parms.game;
  61. }
  62. inline const char *GetBaseDirectory()
  63. {
  64. return host_parms.basedir;
  65. }
  66. //=============================================================================
  67. //
  68. // host
  69. // FIXME, move all this crap somewhere else
  70. //
  71. // when we are using -fork, and we are the parent controlling process, we want to avoid a bunch of stuff, such as registering ourselves with the xlsp master or steam, etc
  72. #define FORK_ID_PARENT_PROCESS -1
  73. extern int g_nForkID;
  74. extern int g_nSocketToParentProcess; // -1 if we are not a child, otherwise its a socket that talks to the parent process
  75. FORCEINLINE bool IsChildProcess( void )
  76. {
  77. return g_nForkID > 0;
  78. }
  79. #ifdef _LINUX
  80. void SendStringToParentProcess( char const *pMsg );
  81. #endif
  82. extern ConVar developer;
  83. extern bool host_initialized; // true if into command execution
  84. extern float host_frametime;
  85. extern float host_frametime_unbounded;
  86. extern float host_frametime_unscaled;
  87. extern float host_frametime_stddeviation;
  88. extern float host_framestarttime_stddeviation;
  89. extern float host_frameendtime_computationduration;
  90. extern int host_framecount; // incremented every frame, never reset
  91. extern double realtime; // not bounded in any way, changed at
  92. // start of every frame, never reset
  93. void Host_Error (PRINTF_FORMAT_STRING const char *error, ...) FMTFUNCTION( 1, 2 );
  94. void Host_EndGame (bool bShowMainMenu, PRINTF_FORMAT_STRING const char *message, ...) FMTFUNCTION( 2, 3 );
  95. // user message
  96. #define MAX_USER_MSG_BITS 12
  97. #define MAX_USER_MSG_DATA ( ( 1 << ( MAX_USER_MSG_BITS - 3 ) ) - 1 )
  98. // build info
  99. // day counter from Sep 30 2003
  100. extern int build_number( void );
  101. // Choke local client's/server's packets?
  102. extern ConVar host_limitlocal;
  103. // Print a debug message when the client or server cache is missed
  104. extern ConVar host_showcachemiss;
  105. //#if !defined( LINUX )
  106. extern bool g_bInEditMode;
  107. extern bool g_bInCommentaryMode;
  108. //#endif
  109. extern bool g_bLowViolence;
  110. extern KeyValues* g_pLaunchOptions;
  111. // Returns true if host is not single stepping/pausing through code/
  112. // FIXME: Remove from final, retail version of code.
  113. bool Host_ShouldRun( void );
  114. void Host_FreeToLowMark( bool server );
  115. void Host_FreeStateAndWorld( bool server );
  116. void Host_Disconnect( bool bShowMainMenu );
  117. void Host_RunFrame( float time );
  118. void Host_DumpMemoryStats( void );
  119. void Host_UpdateMapList( void );
  120. float Host_GetSoundDuration( const char *pSample );
  121. bool Host_IsSinglePlayerGame( void );
  122. bool Host_IsLocalServer();
  123. int Host_GetServerCount( void );
  124. bool Host_AllowQueuedMaterialSystem( bool bAllow );
  125. void Host_EnsureHostNameSet();
  126. void Host_BeginThreadedSound();
  127. // Force the voice stuff to send a packet out.
  128. // bFinal is true when the user is done talking.
  129. void CL_SendVoicePacket(bool bFinal);
  130. bool Host_IsSecureServerAllowed();
  131. void Host_DisallowSecureServers();
  132. bool Host_AllowLoadModule( const char *pFilename, const char *pPathID, bool bAllowUnknown );
  133. // Accumulated filtered time on machine ( i.e., host_framerate can alter host_time )
  134. extern float host_time;
  135. struct NetMessageCvar_t;
  136. void Host_BuildConVarUpdateMessage( CMsg_CVars *rCvarList, int flags, bool nonDefault );
  137. void Host_BuildUserInfoUpdateMessage( int nSplitScreenSlot, CMsg_CVars *rCvarList, bool nonDefault );
  138. char const *Host_CleanupConVarStringValue( char const *invalue );
  139. void Host_SetAudioState( const AudioState_t &audioState );
  140. bool CheckVarRange_Generic( ConVar *pVar, int minVal, int maxVal );
  141. // Total ticks run
  142. extern int host_tickcount;
  143. // Number of ticks being run this frame
  144. extern int host_frameticks;
  145. // Which tick are we currently on for this frame
  146. extern int host_currentframetick;
  147. // PERFORMANCE INFO
  148. #define MIN_FPS 0.1 // Host minimum fps value for maxfps.
  149. #define MAX_FPS 1000.0 // Upper limit for maxfps.
  150. #define MAX_FRAMETIME 0.1
  151. #define MIN_FRAMETIME 0.001
  152. #define MAX_TOOLS_FRAMETIME 2.0
  153. #define MIN_TOOLS_FRAMETIME 0.001
  154. #define TIME_TO_TICKS( dt ) ( (int)( 0.5f + (float)(dt) / host_state.interval_per_tick ) )
  155. #define TICKS_TO_TIME( dt ) ( host_state.interval_per_tick * (float)(dt) )
  156. // Set by the game DLL to tell us to do the same timing tricks as timedemo.
  157. extern bool g_bDedicatedServerBenchmarkMode;
  158. extern uint GetSteamAppID();
  159. #include "steam/steamclientpublic.h"
  160. extern EUniverse GetSteamUniverse();
  161. //
  162. // \return true iff PS3 (and only PS3) and Quitting (on user request or disk eject or other critical condition when we absolutely must quit within 10 seconds)
  163. //
  164. //
  165. // \return true iff PS3 (and only PS3) and Quitting (on user request or disk eject or other critical condition when we absolutely must quit within 10 seconds)
  166. //
  167. inline bool IsPS3QuitRequested()
  168. {
  169. #ifdef _PS3
  170. return GetTLSGlobals()->bNormalQuitRequested;
  171. #else
  172. // if not on PS3, do not disturb the old logic of host_state which has a lot of dependencies, because other platforms do not require the game to quit cleanly
  173. return false;
  174. #endif
  175. }
  176. #endif // HOST_H