sys_public.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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 __SYS_PUBLIC__
  21. #define __SYS_PUBLIC__
  22. #include "../idlib/CmdArgs.h"
  23. /*
  24. ===============================================================================
  25. Non-portable system services.
  26. ===============================================================================
  27. */
  28. enum cpuid_t {
  29. CPUID_NONE = 0x00000,
  30. CPUID_UNSUPPORTED = 0x00001, // unsupported (386/486)
  31. CPUID_GENERIC = 0x00002, // unrecognized processor
  32. CPUID_INTEL = 0x00004, // Intel
  33. CPUID_AMD = 0x00008, // AMD
  34. CPUID_MMX = 0x00010, // Multi Media Extensions
  35. CPUID_3DNOW = 0x00020, // 3DNow!
  36. CPUID_SSE = 0x00040, // Streaming SIMD Extensions
  37. CPUID_SSE2 = 0x00080, // Streaming SIMD Extensions 2
  38. CPUID_SSE3 = 0x00100, // Streaming SIMD Extentions 3 aka Prescott's New Instructions
  39. CPUID_ALTIVEC = 0x00200, // AltiVec
  40. CPUID_HTT = 0x01000, // Hyper-Threading Technology
  41. CPUID_CMOV = 0x02000, // Conditional Move (CMOV) and fast floating point comparison (FCOMI) instructions
  42. CPUID_FTZ = 0x04000, // Flush-To-Zero mode (denormal results are flushed to zero)
  43. CPUID_DAZ = 0x08000, // Denormals-Are-Zero mode (denormal source operands are set to zero)
  44. CPUID_XENON = 0x10000, // Xbox 360
  45. CPUID_CELL = 0x20000 // PS3
  46. };
  47. enum fpuExceptions_t {
  48. FPU_EXCEPTION_INVALID_OPERATION = 1,
  49. FPU_EXCEPTION_DENORMALIZED_OPERAND = 2,
  50. FPU_EXCEPTION_DIVIDE_BY_ZERO = 4,
  51. FPU_EXCEPTION_NUMERIC_OVERFLOW = 8,
  52. FPU_EXCEPTION_NUMERIC_UNDERFLOW = 16,
  53. FPU_EXCEPTION_INEXACT_RESULT = 32
  54. };
  55. enum fpuPrecision_t {
  56. FPU_PRECISION_SINGLE = 0,
  57. FPU_PRECISION_DOUBLE = 1,
  58. FPU_PRECISION_DOUBLE_EXTENDED = 2
  59. };
  60. enum fpuRounding_t {
  61. FPU_ROUNDING_TO_NEAREST = 0,
  62. FPU_ROUNDING_DOWN = 1,
  63. FPU_ROUNDING_UP = 2,
  64. FPU_ROUNDING_TO_ZERO = 3
  65. };
  66. enum joystickAxis_t {
  67. AXIS_LEFT_X,
  68. AXIS_LEFT_Y,
  69. AXIS_RIGHT_X,
  70. AXIS_RIGHT_Y,
  71. AXIS_LEFT_TRIG,
  72. AXIS_RIGHT_TRIG,
  73. MAX_JOYSTICK_AXIS
  74. };
  75. enum sysEventType_t {
  76. SE_NONE, // evTime is still valid
  77. SE_KEY, // evValue is a key code, evValue2 is the down flag
  78. SE_CHAR, // evValue is an ascii char
  79. SE_MOUSE, // evValue and evValue2 are reletive signed x / y moves
  80. SE_MOUSE_ABSOLUTE, // evValue and evValue2 are absolute coordinates in the window's client area.
  81. SE_MOUSE_LEAVE, // evValue and evValue2 are meaninless, this indicates the mouse has left the client area.
  82. SE_JOYSTICK, // evValue is an axis number and evValue2 is the current state (-127 to 127)
  83. SE_CONSOLE // evPtr is a char*, from typing something at a non-game console
  84. };
  85. enum sys_mEvents {
  86. M_ACTION1,
  87. M_ACTION2,
  88. M_ACTION3,
  89. M_ACTION4,
  90. M_ACTION5,
  91. M_ACTION6,
  92. M_ACTION7,
  93. M_ACTION8,
  94. M_DELTAX,
  95. M_DELTAY,
  96. M_DELTAZ,
  97. M_INVALID
  98. };
  99. enum sys_jEvents {
  100. J_ACTION1,
  101. J_ACTION2,
  102. J_ACTION3,
  103. J_ACTION4,
  104. J_ACTION5,
  105. J_ACTION6,
  106. J_ACTION7,
  107. J_ACTION8,
  108. J_ACTION9,
  109. J_ACTION10,
  110. J_ACTION11,
  111. J_ACTION12,
  112. J_ACTION13,
  113. J_ACTION14,
  114. J_ACTION15,
  115. J_ACTION16,
  116. J_ACTION17,
  117. J_ACTION18,
  118. J_ACTION19,
  119. J_ACTION20,
  120. J_ACTION21,
  121. J_ACTION22,
  122. J_ACTION23,
  123. J_ACTION24,
  124. J_ACTION25,
  125. J_ACTION26,
  126. J_ACTION27,
  127. J_ACTION28,
  128. J_ACTION29,
  129. J_ACTION30,
  130. J_ACTION31,
  131. J_ACTION32,
  132. J_ACTION_MAX = J_ACTION32,
  133. J_AXIS_MIN,
  134. J_AXIS_LEFT_X = J_AXIS_MIN + AXIS_LEFT_X,
  135. J_AXIS_LEFT_Y = J_AXIS_MIN + AXIS_LEFT_Y,
  136. J_AXIS_RIGHT_X = J_AXIS_MIN + AXIS_RIGHT_X,
  137. J_AXIS_RIGHT_Y = J_AXIS_MIN + AXIS_RIGHT_Y,
  138. J_AXIS_LEFT_TRIG = J_AXIS_MIN + AXIS_LEFT_TRIG,
  139. J_AXIS_RIGHT_TRIG = J_AXIS_MIN + AXIS_RIGHT_TRIG,
  140. J_AXIS_MAX = J_AXIS_MIN + MAX_JOYSTICK_AXIS - 1,
  141. J_DPAD_UP,
  142. J_DPAD_DOWN,
  143. J_DPAD_LEFT,
  144. J_DPAD_RIGHT,
  145. MAX_JOY_EVENT
  146. };
  147. /*
  148. ================================================
  149. The first part of this table maps directly to Direct Input scan codes (DIK_* from dinput.h)
  150. But they are duplicated here for console portability
  151. ================================================
  152. */
  153. enum keyNum_t {
  154. K_NONE,
  155. K_ESCAPE,
  156. K_1,
  157. K_2,
  158. K_3,
  159. K_4,
  160. K_5,
  161. K_6,
  162. K_7,
  163. K_8,
  164. K_9,
  165. K_0,
  166. K_MINUS,
  167. K_EQUALS,
  168. K_BACKSPACE,
  169. K_TAB,
  170. K_Q,
  171. K_W,
  172. K_E,
  173. K_R,
  174. K_T,
  175. K_Y,
  176. K_U,
  177. K_I,
  178. K_O,
  179. K_P,
  180. K_LBRACKET,
  181. K_RBRACKET,
  182. K_ENTER,
  183. K_LCTRL,
  184. K_A,
  185. K_S,
  186. K_D,
  187. K_F,
  188. K_G,
  189. K_H,
  190. K_J,
  191. K_K,
  192. K_L,
  193. K_SEMICOLON,
  194. K_APOSTROPHE,
  195. K_GRAVE,
  196. K_LSHIFT,
  197. K_BACKSLASH,
  198. K_Z,
  199. K_X,
  200. K_C,
  201. K_V,
  202. K_B,
  203. K_N,
  204. K_M,
  205. K_COMMA,
  206. K_PERIOD,
  207. K_SLASH,
  208. K_RSHIFT,
  209. K_KP_STAR,
  210. K_LALT,
  211. K_SPACE,
  212. K_CAPSLOCK,
  213. K_F1,
  214. K_F2,
  215. K_F3,
  216. K_F4,
  217. K_F5,
  218. K_F6,
  219. K_F7,
  220. K_F8,
  221. K_F9,
  222. K_F10,
  223. K_NUMLOCK,
  224. K_SCROLL,
  225. K_KP_7,
  226. K_KP_8,
  227. K_KP_9,
  228. K_KP_MINUS,
  229. K_KP_4,
  230. K_KP_5,
  231. K_KP_6,
  232. K_KP_PLUS,
  233. K_KP_1,
  234. K_KP_2,
  235. K_KP_3,
  236. K_KP_0,
  237. K_KP_DOT,
  238. K_F11 = 0x57,
  239. K_F12 = 0x58,
  240. K_F13 = 0x64,
  241. K_F14 = 0x65,
  242. K_F15 = 0x66,
  243. K_KANA = 0x70,
  244. K_CONVERT = 0x79,
  245. K_NOCONVERT = 0x7B,
  246. K_YEN = 0x7D,
  247. K_KP_EQUALS = 0x8D,
  248. K_CIRCUMFLEX = 0x90,
  249. K_AT = 0x91,
  250. K_COLON = 0x92,
  251. K_UNDERLINE = 0x93,
  252. K_KANJI = 0x94,
  253. K_STOP = 0x95,
  254. K_AX = 0x96,
  255. K_UNLABELED = 0x97,
  256. K_KP_ENTER = 0x9C,
  257. K_RCTRL = 0x9D,
  258. K_KP_COMMA = 0xB3,
  259. K_KP_SLASH = 0xB5,
  260. K_PRINTSCREEN = 0xB7,
  261. K_RALT = 0xB8,
  262. K_PAUSE = 0xC5,
  263. K_HOME = 0xC7,
  264. K_UPARROW = 0xC8,
  265. K_PGUP = 0xC9,
  266. K_LEFTARROW = 0xCB,
  267. K_RIGHTARROW = 0xCD,
  268. K_END = 0xCF,
  269. K_DOWNARROW = 0xD0,
  270. K_PGDN = 0xD1,
  271. K_INS = 0xD2,
  272. K_DEL = 0xD3,
  273. K_LWIN = 0xDB,
  274. K_RWIN = 0xDC,
  275. K_APPS = 0xDD,
  276. K_POWER = 0xDE,
  277. K_SLEEP = 0xDF,
  278. //------------------------
  279. // K_JOY codes must be contiguous, too
  280. //------------------------
  281. K_JOY1 = 256,
  282. K_JOY2,
  283. K_JOY3,
  284. K_JOY4,
  285. K_JOY5,
  286. K_JOY6,
  287. K_JOY7,
  288. K_JOY8,
  289. K_JOY9,
  290. K_JOY10,
  291. K_JOY11,
  292. K_JOY12,
  293. K_JOY13,
  294. K_JOY14,
  295. K_JOY15,
  296. K_JOY16,
  297. K_JOY_STICK1_UP,
  298. K_JOY_STICK1_DOWN,
  299. K_JOY_STICK1_LEFT,
  300. K_JOY_STICK1_RIGHT,
  301. K_JOY_STICK2_UP,
  302. K_JOY_STICK2_DOWN,
  303. K_JOY_STICK2_LEFT,
  304. K_JOY_STICK2_RIGHT,
  305. K_JOY_TRIGGER1,
  306. K_JOY_TRIGGER2,
  307. K_JOY_DPAD_UP,
  308. K_JOY_DPAD_DOWN,
  309. K_JOY_DPAD_LEFT,
  310. K_JOY_DPAD_RIGHT,
  311. //------------------------
  312. // K_MOUSE enums must be contiguous (no char codes in the middle)
  313. //------------------------
  314. K_MOUSE1,
  315. K_MOUSE2,
  316. K_MOUSE3,
  317. K_MOUSE4,
  318. K_MOUSE5,
  319. K_MOUSE6,
  320. K_MOUSE7,
  321. K_MOUSE8,
  322. K_MWHEELDOWN,
  323. K_MWHEELUP,
  324. K_LAST_KEY
  325. };
  326. struct sysEvent_t {
  327. sysEventType_t evType;
  328. int evValue;
  329. int evValue2;
  330. int evPtrLength; // bytes of data pointed to by evPtr, for journaling
  331. void * evPtr; // this must be manually freed if not NULL
  332. int inputDevice;
  333. bool IsKeyEvent() const { return evType == SE_KEY; }
  334. bool IsMouseEvent() const { return evType == SE_MOUSE; }
  335. bool IsCharEvent() const { return evType == SE_CHAR; }
  336. bool IsJoystickEvent() const { return evType == SE_JOYSTICK; }
  337. bool IsKeyDown() const { return evValue2 != 0; }
  338. keyNum_t GetKey() const { return static_cast< keyNum_t >( evValue ); }
  339. int GetXCoord() const { return evValue; }
  340. int GetYCoord() const { return evValue2; }
  341. };
  342. struct sysMemoryStats_t {
  343. int memoryLoad;
  344. int totalPhysical;
  345. int availPhysical;
  346. int totalPageFile;
  347. int availPageFile;
  348. int totalVirtual;
  349. int availVirtual;
  350. int availExtendedVirtual;
  351. };
  352. typedef unsigned long address_t;
  353. void Sys_Init();
  354. void Sys_Shutdown();
  355. void Sys_Error( const char *error, ...);
  356. const char * Sys_GetCmdLine();
  357. void Sys_ReLaunch( void * launchData, unsigned int launchDataSize );
  358. void Sys_Launch( const char * path, idCmdArgs & args, void * launchData, unsigned int launchDataSize );
  359. void Sys_SetLanguageFromSystem();
  360. const char * Sys_DefaultLanguage();
  361. void Sys_Quit();
  362. bool Sys_AlreadyRunning();
  363. // note that this isn't journaled...
  364. char * Sys_GetClipboardData();
  365. void Sys_SetClipboardData( const char *string );
  366. // will go to the various text consoles
  367. // NOT thread safe - never use in the async paths
  368. void Sys_Printf( VERIFY_FORMAT_STRING const char *msg, ... );
  369. // guaranteed to be thread-safe
  370. void Sys_DebugPrintf( VERIFY_FORMAT_STRING const char *fmt, ... );
  371. void Sys_DebugVPrintf( const char *fmt, va_list arg );
  372. // a decent minimum sleep time to avoid going below the process scheduler speeds
  373. #define SYS_MINSLEEP 20
  374. // allow game to yield CPU time
  375. // NOTE: due to SYS_MINSLEEP this is very bad portability karma, and should be completely removed
  376. void Sys_Sleep( int msec );
  377. // Sys_Milliseconds should only be used for profiling purposes,
  378. // any game related timing information should come from event timestamps
  379. int Sys_Milliseconds();
  380. uint64 Sys_Microseconds();
  381. // for accurate performance testing
  382. double Sys_GetClockTicks();
  383. double Sys_ClockTicksPerSecond();
  384. // returns a selection of the CPUID_* flags
  385. cpuid_t Sys_GetProcessorId();
  386. const char * Sys_GetProcessorString();
  387. // returns true if the FPU stack is empty
  388. bool Sys_FPU_StackIsEmpty();
  389. // empties the FPU stack
  390. void Sys_FPU_ClearStack();
  391. // returns the FPU state as a string
  392. const char * Sys_FPU_GetState();
  393. // enables the given FPU exceptions
  394. void Sys_FPU_EnableExceptions( int exceptions );
  395. // sets the FPU precision
  396. void Sys_FPU_SetPrecision( int precision );
  397. // sets the FPU rounding mode
  398. void Sys_FPU_SetRounding( int rounding );
  399. // sets Flush-To-Zero mode (only available when CPUID_FTZ is set)
  400. void Sys_FPU_SetFTZ( bool enable );
  401. // sets Denormals-Are-Zero mode (only available when CPUID_DAZ is set)
  402. void Sys_FPU_SetDAZ( bool enable );
  403. // returns amount of system ram
  404. int Sys_GetSystemRam();
  405. // returns amount of video ram
  406. int Sys_GetVideoRam();
  407. // returns amount of drive space in path
  408. int Sys_GetDriveFreeSpace( const char *path );
  409. // returns amount of drive space in path in bytes
  410. int64 Sys_GetDriveFreeSpaceInBytes( const char * path );
  411. // returns memory stats
  412. void Sys_GetCurrentMemoryStatus( sysMemoryStats_t &stats );
  413. void Sys_GetExeLaunchMemoryStatus( sysMemoryStats_t &stats );
  414. // lock and unlock memory
  415. bool Sys_LockMemory( void *ptr, int bytes );
  416. bool Sys_UnlockMemory( void *ptr, int bytes );
  417. // set amount of physical work memory
  418. void Sys_SetPhysicalWorkMemory( int minBytes, int maxBytes );
  419. // allows retrieving the call stack at execution points
  420. void Sys_GetCallStack( address_t *callStack, const int callStackSize );
  421. const char * Sys_GetCallStackStr( const address_t *callStack, const int callStackSize );
  422. const char * Sys_GetCallStackCurStr( int depth );
  423. const char * Sys_GetCallStackCurAddressStr( int depth );
  424. void Sys_ShutdownSymbols();
  425. // DLL loading, the path should be a fully qualified OS path to the DLL file to be loaded
  426. int Sys_DLL_Load( const char *dllName );
  427. void * Sys_DLL_GetProcAddress( int dllHandle, const char *procName );
  428. void Sys_DLL_Unload( int dllHandle );
  429. // event generation
  430. void Sys_GenerateEvents();
  431. sysEvent_t Sys_GetEvent();
  432. void Sys_ClearEvents();
  433. // input is tied to windows, so it needs to be started up and shut down whenever
  434. // the main window is recreated
  435. void Sys_InitInput();
  436. void Sys_ShutdownInput();
  437. // keyboard input polling
  438. int Sys_PollKeyboardInputEvents();
  439. int Sys_ReturnKeyboardInputEvent( const int n, int &ch, bool &state );
  440. void Sys_EndKeyboardInputEvents();
  441. // mouse input polling
  442. static const int MAX_MOUSE_EVENTS = 256;
  443. int Sys_PollMouseInputEvents( int mouseEvents[MAX_MOUSE_EVENTS][2] );
  444. // joystick input polling
  445. void Sys_SetRumble( int device, int low, int hi );
  446. int Sys_PollJoystickInputEvents( int deviceNum );
  447. int Sys_ReturnJoystickInputEvent( const int n, int &action, int &value );
  448. void Sys_EndJoystickInputEvents();
  449. // when the console is down, or the game is about to perform a lengthy
  450. // operation like map loading, the system can release the mouse cursor
  451. // when in windowed mode
  452. void Sys_GrabMouseCursor( bool grabIt );
  453. void Sys_ShowWindow( bool show );
  454. bool Sys_IsWindowVisible();
  455. void Sys_ShowConsole( int visLevel, bool quitOnClose );
  456. // This really isn't the right place to have this, but since this is the 'top level' include
  457. // and has a function signature with 'FILE' in it, it kinda needs to be here =/
  458. typedef HANDLE idFileHandle;
  459. ID_TIME_T Sys_FileTimeStamp( idFileHandle fp );
  460. // NOTE: do we need to guarantee the same output on all platforms?
  461. const char * Sys_TimeStampToStr( ID_TIME_T timeStamp );
  462. const char * Sys_SecToStr( int sec );
  463. const char * Sys_DefaultBasePath();
  464. const char * Sys_DefaultSavePath();
  465. // know early if we are performing a fatal error shutdown so the error message doesn't get lost
  466. void Sys_SetFatalError( const char *error );
  467. // Execute the specified process and wait until it's done, calling workFn every waitMS milliseconds.
  468. // If showOutput == true, std IO from the executed process will be output to the console.
  469. // Note that the return value is not an indication of the exit code of the process, but is false
  470. // only if the process could not be created at all. If you wish to check the exit code of the
  471. // spawned process, check the value returned in exitCode.
  472. typedef bool ( *execProcessWorkFunction_t )();
  473. typedef void ( *execOutputFunction_t)( const char * text );
  474. bool Sys_Exec( const char * appPath, const char * workingPath, const char * args,
  475. execProcessWorkFunction_t workFn, execOutputFunction_t outputFn, const int waitMS,
  476. unsigned int & exitCode );
  477. // localization
  478. #define ID_LANG_ENGLISH "english"
  479. #define ID_LANG_FRENCH "french"
  480. #define ID_LANG_ITALIAN "italian"
  481. #define ID_LANG_GERMAN "german"
  482. #define ID_LANG_SPANISH "spanish"
  483. #define ID_LANG_JAPANESE "japanese"
  484. int Sys_NumLangs();
  485. const char * Sys_Lang( int idx );
  486. /*
  487. ==============================================================
  488. Networking
  489. ==============================================================
  490. */
  491. typedef enum {
  492. NA_BAD, // an address lookup failed
  493. NA_LOOPBACK,
  494. NA_BROADCAST,
  495. NA_IP
  496. } netadrtype_t;
  497. typedef struct {
  498. netadrtype_t type;
  499. unsigned char ip[4];
  500. unsigned short port;
  501. } netadr_t;
  502. #define PORT_ANY -1
  503. /*
  504. ================================================
  505. idUDP
  506. ================================================
  507. */
  508. class idUDP {
  509. public:
  510. // this just zeros netSocket and port
  511. idUDP();
  512. virtual ~idUDP();
  513. // if the InitForPort fails, the idUDP.port field will remain 0
  514. bool InitForPort( int portNumber );
  515. int GetPort() const { return bound_to.port; }
  516. netadr_t GetAdr() const { return bound_to; }
  517. uint32 GetUIntAdr() const { return ( bound_to.ip[0] | bound_to.ip[1] << 8 | bound_to.ip[2] << 16 | bound_to.ip[3] << 24 ); }
  518. void Close();
  519. bool GetPacket( netadr_t &from, void *data, int &size, int maxSize );
  520. bool GetPacketBlocking( netadr_t &from, void *data, int &size, int maxSize,
  521. int timeout );
  522. void SendPacket( const netadr_t to, const void *data, int size );
  523. void SetSilent( bool silent ) { this->silent = silent; }
  524. bool GetSilent() const { return silent; }
  525. int packetsRead;
  526. int bytesRead;
  527. int packetsWritten;
  528. int bytesWritten;
  529. bool IsOpen() const { return netSocket > 0; }
  530. private:
  531. netadr_t bound_to; // interface and port
  532. int netSocket; // OS specific socket
  533. bool silent; // don't emit anything ( black hole )
  534. };
  535. // parses the port number
  536. // can also do DNS resolve if you ask for it.
  537. // NOTE: DNS resolve is a slow/blocking call, think before you use
  538. // ( could be exploited for server DoS )
  539. bool Sys_StringToNetAdr( const char *s, netadr_t *a, bool doDNSResolve );
  540. const char * Sys_NetAdrToString( const netadr_t a );
  541. bool Sys_IsLANAddress( const netadr_t a );
  542. bool Sys_CompareNetAdrBase( const netadr_t a, const netadr_t b );
  543. int Sys_GetLocalIPCount();
  544. const char * Sys_GetLocalIP( int i );
  545. void Sys_InitNetworking();
  546. void Sys_ShutdownNetworking();
  547. /*
  548. ================================================
  549. idJoystick is managed by each platform's local Sys implementation, and
  550. provides full *Joy Pad* support (the most common device, these days).
  551. ================================================
  552. */
  553. class idJoystick {
  554. public:
  555. virtual ~idJoystick() { }
  556. virtual bool Init() { return false; }
  557. virtual void Shutdown() { }
  558. virtual void Deactivate() { }
  559. virtual void SetRumble( int deviceNum, int rumbleLow, int rumbleHigh ) { }
  560. virtual int PollInputEvents( int inputDeviceNum ) { return 0; }
  561. virtual int ReturnInputEvent( const int n, int &action, int &value ) { return 0; }
  562. virtual void EndInputEvents() { }
  563. };
  564. /*
  565. ==============================================================
  566. idSys
  567. ==============================================================
  568. */
  569. class idSys {
  570. public:
  571. virtual void DebugPrintf( VERIFY_FORMAT_STRING const char *fmt, ... ) = 0;
  572. virtual void DebugVPrintf( const char *fmt, va_list arg ) = 0;
  573. virtual double GetClockTicks() = 0;
  574. virtual double ClockTicksPerSecond() = 0;
  575. virtual cpuid_t GetProcessorId() = 0;
  576. virtual const char * GetProcessorString() = 0;
  577. virtual const char * FPU_GetState() = 0;
  578. virtual bool FPU_StackIsEmpty() = 0;
  579. virtual void FPU_SetFTZ( bool enable ) = 0;
  580. virtual void FPU_SetDAZ( bool enable ) = 0;
  581. virtual void FPU_EnableExceptions( int exceptions ) = 0;
  582. virtual bool LockMemory( void *ptr, int bytes ) = 0;
  583. virtual bool UnlockMemory( void *ptr, int bytes ) = 0;
  584. virtual void GetCallStack( address_t *callStack, const int callStackSize ) = 0;
  585. virtual const char * GetCallStackStr( const address_t *callStack, const int callStackSize ) = 0;
  586. virtual const char * GetCallStackCurStr( int depth ) = 0;
  587. virtual void ShutdownSymbols() = 0;
  588. virtual int DLL_Load( const char *dllName ) = 0;
  589. virtual void * DLL_GetProcAddress( int dllHandle, const char *procName ) = 0;
  590. virtual void DLL_Unload( int dllHandle ) = 0;
  591. virtual void DLL_GetFileName( const char *baseName, char *dllName, int maxLength ) = 0;
  592. virtual sysEvent_t GenerateMouseButtonEvent( int button, bool down ) = 0;
  593. virtual sysEvent_t GenerateMouseMoveEvent( int deltax, int deltay ) = 0;
  594. virtual void OpenURL( const char *url, bool quit ) = 0;
  595. virtual void StartProcess( const char *exePath, bool quit ) = 0;
  596. };
  597. extern idSys * sys;
  598. bool Sys_LoadOpenAL();
  599. void Sys_FreeOpenAL();
  600. #endif /* !__SYS_PUBLIC__ */