DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

sys_public.h (19518B)


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