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