Common.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 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 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. typedef enum {
  28. EDITOR_NONE = 0,
  29. EDITOR_RADIANT = BIT(1),
  30. EDITOR_GUI = BIT(2),
  31. EDITOR_DEBUGGER = BIT(3),
  32. EDITOR_SCRIPT = BIT(4),
  33. EDITOR_LIGHT = BIT(5),
  34. EDITOR_SOUND = BIT(6),
  35. EDITOR_DECL = BIT(7),
  36. EDITOR_AF = BIT(8),
  37. EDITOR_PARTICLE = BIT(9),
  38. EDITOR_PDA = BIT(10),
  39. EDITOR_AAS = BIT(11),
  40. EDITOR_MATERIAL = BIT(12)
  41. } toolFlag_t;
  42. #define STRTABLE_ID "#str_"
  43. #define STRTABLE_ID_LENGTH 5
  44. extern idCVar com_version;
  45. extern idCVar com_skipRenderer;
  46. extern idCVar com_asyncInput;
  47. extern idCVar com_asyncSound;
  48. extern idCVar com_machineSpec;
  49. extern idCVar com_purgeAll;
  50. extern idCVar com_developer;
  51. extern idCVar com_allowConsole;
  52. extern idCVar com_speeds;
  53. extern idCVar com_showFPS;
  54. extern idCVar com_showMemoryUsage;
  55. extern idCVar com_showAsyncStats;
  56. extern idCVar com_showSoundDecoders;
  57. extern idCVar com_makingBuild;
  58. extern idCVar com_updateLoadSize;
  59. extern idCVar com_videoRam;
  60. extern int time_gameFrame; // game logic time
  61. extern int time_gameDraw; // game present time
  62. extern int time_frontend; // renderer frontend time
  63. extern int time_backend; // renderer backend time
  64. extern int com_frameTime; // time for the current frame in milliseconds
  65. extern volatile int com_ticNumber; // 60 hz tics, incremented by async function
  66. extern int com_editors; // current active editor(s)
  67. extern bool com_editorActive; // true if an editor has focus
  68. #ifdef _WIN32
  69. const char DMAP_MSGID[] = "DMAPOutput";
  70. const char DMAP_DONE[] = "DMAPDone";
  71. extern HWND com_hwndMsg;
  72. extern bool com_outputMsg;
  73. #endif
  74. struct MemInfo_t {
  75. idStr filebase;
  76. int total;
  77. int assetTotals;
  78. // memory manager totals
  79. int memoryManagerTotal;
  80. // subsystem totals
  81. int gameSubsystemTotal;
  82. int renderSubsystemTotal;
  83. // asset totals
  84. int imageAssetsTotal;
  85. int modelAssetsTotal;
  86. int soundAssetsTotal;
  87. };
  88. class idCommon {
  89. public:
  90. virtual ~idCommon( void ) {}
  91. // Initialize everything.
  92. // if the OS allows, pass argc/argv directly (without executable name)
  93. // otherwise pass the command line in a single string (without executable name)
  94. virtual void Init( int argc, const char **argv, const char *cmdline ) = 0;
  95. // Shuts down everything.
  96. virtual void Shutdown( void ) = 0;
  97. // Shuts down everything.
  98. virtual void Quit( void ) = 0;
  99. // Returns true if common initialization is complete.
  100. virtual bool IsInitialized( void ) const = 0;
  101. // Called repeatedly as the foreground thread for rendering and game logic.
  102. virtual void Frame( void ) = 0;
  103. // Called repeatedly by blocking function calls with GUI interactivity.
  104. virtual void GUIFrame( bool execCmd, bool network ) = 0;
  105. // Called 60 times a second from a background thread for sound mixing,
  106. // and input generation. Not called until idCommon::Init() has completed.
  107. virtual void Async( void ) = 0;
  108. // Checks for and removes command line "+set var arg" constructs.
  109. // If match is NULL, all set commands will be executed, otherwise
  110. // only a set with the exact name. Only used during startup.
  111. // set once to clear the cvar from +set for early init code
  112. virtual void StartupVariable( const char *match, bool once ) = 0;
  113. // Initializes a tool with the given dictionary.
  114. virtual void InitTool( const toolFlag_t tool, const idDict *dict ) = 0;
  115. // Activates or deactivates a tool.
  116. virtual void ActivateTool( bool active ) = 0;
  117. // Writes the user's configuration to a file
  118. virtual void WriteConfigToFile( const char *filename ) = 0;
  119. // Writes cvars with the given flags to a file.
  120. virtual void WriteFlaggedCVarsToFile( const char *filename, int flags, const char *setCmd ) = 0;
  121. // Begins redirection of console output to the given buffer.
  122. virtual void BeginRedirect( char *buffer, int buffersize, void (*flush)( const char * ) ) = 0;
  123. // Stops redirection of console output.
  124. virtual void EndRedirect( void ) = 0;
  125. // Update the screen with every message printed.
  126. virtual void SetRefreshOnPrint( bool set ) = 0;
  127. // Prints message to the console, which may cause a screen update if com_refreshOnPrint is set.
  128. virtual void Printf( const char *fmt, ... )id_attribute((format(printf,2,3))) = 0;
  129. // Same as Printf, with a more usable API - Printf pipes to this.
  130. virtual void VPrintf( const char *fmt, va_list arg ) = 0;
  131. // Prints message that only shows up if the "developer" cvar is set,
  132. // and NEVER forces a screen update, which could cause reentrancy problems.
  133. virtual void DPrintf( const char *fmt, ... ) id_attribute((format(printf,2,3))) = 0;
  134. // Prints WARNING %s message and adds the warning message to a queue for printing later on.
  135. virtual void Warning( const char *fmt, ... ) id_attribute((format(printf,2,3))) = 0;
  136. // Prints WARNING %s message in yellow that only shows up if the "developer" cvar is set.
  137. virtual void DWarning( const char *fmt, ...) id_attribute((format(printf,2,3))) = 0;
  138. // Prints all queued warnings.
  139. virtual void PrintWarnings( void ) = 0;
  140. // Removes all queued warnings.
  141. virtual void ClearWarnings( const char *reason ) = 0;
  142. // Issues a C++ throw. Normal errors just abort to the game loop,
  143. // which is appropriate for media or dynamic logic errors.
  144. virtual void Error( const char *fmt, ... ) id_attribute((format(printf,2,3))) = 0;
  145. // Fatal errors quit all the way to a system dialog box, which is appropriate for
  146. // static internal errors or cases where the system may be corrupted.
  147. virtual void FatalError( const char *fmt, ... ) id_attribute((format(printf,2,3))) = 0;
  148. // Returns a pointer to the dictionary with language specific strings.
  149. virtual const idLangDict * GetLanguageDict( void ) = 0;
  150. // Returns key bound to the command
  151. virtual const char * KeysFromBinding( const char *bind ) = 0;
  152. // Returns the binding bound to the key
  153. virtual const char * BindingFromKey( const char *key ) = 0;
  154. // Directly sample a button.
  155. virtual int ButtonState( int key ) = 0;
  156. // Directly sample a keystate.
  157. virtual int KeyState( int key ) = 0;
  158. };
  159. extern idCommon * common;
  160. #endif /* !__COMMON_H__ */