Common.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __COMMON_H__
  21. #define __COMMON_H__
  22. /*
  23. ==============================================================
  24. Common
  25. ==============================================================
  26. */
  27. extern idCVar com_engineHz;
  28. extern float com_engineHz_latched;
  29. extern int64 com_engineHz_numerator;
  30. extern int64 com_engineHz_denominator;
  31. // Returns the msec the frame starts on
  32. ID_INLINE int FRAME_TO_MSEC( int64 frame ) {
  33. return (int)( ( frame * com_engineHz_numerator ) / com_engineHz_denominator );
  34. }
  35. // Rounds DOWN to the nearest frame
  36. ID_INLINE int MSEC_TO_FRAME_FLOOR( int msec ) {
  37. return (int)( ( ( (int64)msec * com_engineHz_denominator ) + ( com_engineHz_denominator - 1 ) ) / com_engineHz_numerator );
  38. }
  39. // Rounds UP to the nearest frame
  40. ID_INLINE int MSEC_TO_FRAME_CEIL( int msec ) {
  41. return (int)( ( ( (int64)msec * com_engineHz_denominator ) + ( com_engineHz_numerator - 1 ) ) / com_engineHz_numerator );
  42. }
  43. // Aligns msec so it starts on a frame bondary
  44. ID_INLINE int MSEC_ALIGN_TO_FRAME( int msec ) {
  45. return FRAME_TO_MSEC( MSEC_TO_FRAME_CEIL( msec ) );
  46. }
  47. class idGame;
  48. class idRenderWorld;
  49. class idSoundWorld;
  50. class idSession;
  51. class idCommonDialog;
  52. class idDemoFile;
  53. class idUserInterface;
  54. class idSaveLoadParms;
  55. class idMatchParameters;
  56. struct lobbyConnectInfo_t;
  57. ID_INLINE void BeginProfileNamedEventColor( uint32 color, VERIFY_FORMAT_STRING const char * szName ) {
  58. }
  59. ID_INLINE void EndProfileNamedEvent() {
  60. }
  61. ID_INLINE void BeginProfileNamedEvent( VERIFY_FORMAT_STRING const char * szName ) {
  62. BeginProfileNamedEventColor( (uint32) 0xFF00FF00, szName );
  63. }
  64. class idScopedProfileEvent {
  65. public:
  66. idScopedProfileEvent( const char * name ) { BeginProfileNamedEvent( name ); }
  67. ~idScopedProfileEvent() { EndProfileNamedEvent(); }
  68. };
  69. #define SCOPED_PROFILE_EVENT( x ) idScopedProfileEvent scopedProfileEvent_##__LINE__( x )
  70. ID_INLINE bool BeginTraceRecording( char * szName ) {
  71. return false;
  72. }
  73. ID_INLINE bool EndTraceRecording() {
  74. return false;
  75. }
  76. typedef enum {
  77. EDITOR_NONE = 0,
  78. EDITOR_RADIANT = BIT(1),
  79. EDITOR_GUI = BIT(2),
  80. EDITOR_DEBUGGER = BIT(3),
  81. EDITOR_SCRIPT = BIT(4),
  82. EDITOR_LIGHT = BIT(5),
  83. EDITOR_SOUND = BIT(6),
  84. EDITOR_DECL = BIT(7),
  85. EDITOR_AF = BIT(8),
  86. EDITOR_PARTICLE = BIT(9),
  87. EDITOR_PDA = BIT(10),
  88. EDITOR_AAS = BIT(11),
  89. EDITOR_MATERIAL = BIT(12)
  90. } toolFlag_t;
  91. #define STRTABLE_ID "#str_"
  92. #define STRTABLE_ID_LENGTH 5
  93. extern idCVar com_version;
  94. extern idCVar com_developer;
  95. extern idCVar com_allowConsole;
  96. extern idCVar com_speeds;
  97. extern idCVar com_showFPS;
  98. extern idCVar com_showMemoryUsage;
  99. extern idCVar com_updateLoadSize;
  100. extern idCVar com_productionMode;
  101. struct MemInfo_t {
  102. idStr filebase;
  103. int total;
  104. int assetTotals;
  105. // memory manager totals
  106. int memoryManagerTotal;
  107. // subsystem totals
  108. int gameSubsystemTotal;
  109. int renderSubsystemTotal;
  110. // asset totals
  111. int imageAssetsTotal;
  112. int modelAssetsTotal;
  113. int soundAssetsTotal;
  114. };
  115. struct mpMap_t {
  116. void operator=( const mpMap_t & src ) {
  117. mapFile = src.mapFile;
  118. mapName = src.mapName;
  119. supportedModes = src.supportedModes;
  120. }
  121. idStr mapFile;
  122. idStr mapName;
  123. uint32 supportedModes;
  124. };
  125. static const int MAX_LOGGED_STATS = 60 * 120; // log every half second
  126. enum currentGame_t {
  127. DOOM_CLASSIC,
  128. DOOM2_CLASSIC,
  129. DOOM3_BFG
  130. };
  131. class idCommon {
  132. public:
  133. virtual ~idCommon() {}
  134. // Initialize everything.
  135. // if the OS allows, pass argc/argv directly (without executable name)
  136. // otherwise pass the command line in a single string (without executable name)
  137. virtual void Init( int argc, const char * const * argv, const char *cmdline ) = 0;
  138. // Shuts down everything.
  139. virtual void Shutdown() = 0;
  140. virtual bool IsShuttingDown() const = 0;
  141. virtual void CreateMainMenu() = 0;
  142. // Shuts down everything.
  143. virtual void Quit() = 0;
  144. // Returns true if common initialization is complete.
  145. virtual bool IsInitialized() const = 0;
  146. // Called repeatedly as the foreground thread for rendering and game logic.
  147. virtual void Frame() = 0;
  148. // Redraws the screen, handling games, guis, console, etc
  149. // in a modal manner outside the normal frame loop
  150. virtual void UpdateScreen( bool captureToImage ) = 0;
  151. virtual void UpdateLevelLoadPacifier() = 0;
  152. // Checks for and removes command line "+set var arg" constructs.
  153. // If match is NULL, all set commands will be executed, otherwise
  154. // only a set with the exact name.
  155. virtual void StartupVariable( const char * match ) = 0;
  156. // Begins redirection of console output to the given buffer.
  157. virtual void BeginRedirect( char *buffer, int buffersize, void (*flush)( const char * ) ) = 0;
  158. // Stops redirection of console output.
  159. virtual void EndRedirect() = 0;
  160. // Update the screen with every message printed.
  161. virtual void SetRefreshOnPrint( bool set ) = 0;
  162. // Prints message to the console, which may cause a screen update if com_refreshOnPrint is set.
  163. virtual void Printf( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
  164. // Same as Printf, with a more usable API - Printf pipes to this.
  165. virtual void VPrintf( const char *fmt, va_list arg ) = 0;
  166. // Prints message that only shows up if the "developer" cvar is set,
  167. // and NEVER forces a screen update, which could cause reentrancy problems.
  168. virtual void DPrintf( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
  169. // Prints WARNING %s message and adds the warning message to a queue for printing later on.
  170. virtual void Warning( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
  171. // Prints WARNING %s message in yellow that only shows up if the "developer" cvar is set.
  172. virtual void DWarning( VERIFY_FORMAT_STRING const char *fmt, ...) = 0;
  173. // Prints all queued warnings.
  174. virtual void PrintWarnings() = 0;
  175. // Removes all queued warnings.
  176. virtual void ClearWarnings( const char *reason ) = 0;
  177. // Issues a C++ throw. Normal errors just abort to the game loop,
  178. // which is appropriate for media or dynamic logic errors.
  179. virtual void Error( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
  180. // Fatal errors quit all the way to a system dialog box, which is appropriate for
  181. // static internal errors or cases where the system may be corrupted.
  182. virtual void FatalError( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
  183. // Returns key bound to the command
  184. virtual const char * KeysFromBinding( const char *bind ) = 0;
  185. // Returns the binding bound to the key
  186. virtual const char * BindingFromKey( const char *key ) = 0;
  187. // Directly sample a button.
  188. virtual int ButtonState( int key ) = 0;
  189. // Directly sample a keystate.
  190. virtual int KeyState( int key ) = 0;
  191. // Returns true if a multiplayer game is running.
  192. // CVars and commands are checked differently in multiplayer mode.
  193. virtual bool IsMultiplayer() = 0;
  194. virtual bool IsServer() = 0;
  195. virtual bool IsClient() = 0;
  196. // Returns true if the player has ever enabled the console
  197. virtual bool GetConsoleUsed() = 0;
  198. // Returns the rate (in ms between snaps) that we want to generate snapshots
  199. virtual int GetSnapRate() = 0;
  200. virtual void NetReceiveReliable( int peer, int type, idBitMsg & msg ) = 0;
  201. virtual void NetReceiveSnapshot( class idSnapShot & ss ) = 0;
  202. virtual void NetReceiveUsercmds( int peer, idBitMsg & msg ) = 0;
  203. // Processes the given event.
  204. virtual bool ProcessEvent( const sysEvent_t * event ) = 0;
  205. virtual bool LoadGame( const char * saveName ) = 0;
  206. virtual bool SaveGame( const char * saveName ) = 0;
  207. virtual idDemoFile * ReadDemo() = 0;
  208. virtual idDemoFile * WriteDemo() = 0;
  209. virtual idGame * Game() = 0;
  210. virtual idRenderWorld * RW() = 0;
  211. virtual idSoundWorld * SW() = 0;
  212. virtual idSoundWorld * MenuSW() = 0;
  213. virtual idSession * Session() = 0;
  214. virtual idCommonDialog & Dialog() = 0;
  215. virtual void OnSaveCompleted( idSaveLoadParms & parms ) = 0;
  216. virtual void OnLoadCompleted( idSaveLoadParms & parms ) = 0;
  217. virtual void OnLoadFilesCompleted( idSaveLoadParms & parms ) = 0;
  218. virtual void OnEnumerationCompleted( idSaveLoadParms & parms ) = 0;
  219. virtual void OnDeleteCompleted( idSaveLoadParms & parms ) = 0;
  220. virtual void TriggerScreenWipe( const char * _wipeMaterial, bool hold ) = 0;
  221. virtual void OnStartHosting( idMatchParameters & parms ) = 0;
  222. virtual int GetGameFrame() = 0;
  223. virtual void LaunchExternalTitle( int titleIndex, int device, const lobbyConnectInfo_t * const connectInfo ) = 0;
  224. virtual void InitializeMPMapsModes() = 0;
  225. virtual const idStrList & GetModeList() const = 0;
  226. virtual const idStrList & GetModeDisplayList() const = 0;
  227. virtual const idList<mpMap_t> & GetMapList() const = 0;
  228. virtual void ResetPlayerInput( int playerIndex ) = 0;
  229. virtual bool JapaneseCensorship() const = 0;
  230. virtual void QueueShowShell() = 0; // Will activate the shell on the next frame.
  231. virtual currentGame_t GetCurrentGame() const = 0;
  232. virtual void SwitchToGame( currentGame_t newGame ) = 0;
  233. };
  234. extern idCommon * common;
  235. #endif /* !__COMMON_H__ */