qcommon.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. // qcommon.h -- definitions common between client and server, but not game.or ref modules
  2. #ifndef __QCOMMON_H__
  3. #define __QCOMMON_H__
  4. #include "stringed_ingame.h"
  5. #include "../qcommon/cm_public.h"
  6. // some zone mem debugging stuff
  7. #ifndef FINAL_BUILD
  8. #ifdef _DEBUG
  9. //
  10. // both of these should be REM'd unless you specifically need them...
  11. //
  12. //#define DEBUG_ZONE_ALLOCS // adds __FILE__ and __LINE__ info to zone blocks, to see who's leaking
  13. //#define DETAILED_ZONE_DEBUG_CODE // this slows things down a LOT, and is only for tracking nasty double-freeing Z_Malloc bugs
  14. #endif
  15. #endif
  16. //============================================================================
  17. //
  18. // msg.c
  19. //
  20. typedef struct {
  21. qboolean allowoverflow; // if false, do a Com_Error
  22. qboolean overflowed; // set to true if the buffer size failed (with allowoverflow set)
  23. byte *data;
  24. int maxsize;
  25. int cursize;
  26. int readcount;
  27. int bit; // for bitwise reads and writes
  28. } msg_t;
  29. void MSG_Init (msg_t *buf, byte *data, int length);
  30. void MSG_Clear (msg_t *buf);
  31. void *MSG_GetSpace (msg_t *buf, int length);
  32. void MSG_WriteData (msg_t *buf, const void *data, int length);
  33. struct usercmd_s;
  34. struct entityState_s;
  35. struct playerState_s;
  36. void MSG_WriteBits( msg_t *msg, int value, int bits );
  37. void MSG_WriteByte (msg_t *sb, int c);
  38. void MSG_WriteShort (msg_t *sb, int c);
  39. void MSG_WriteLong (msg_t *sb, int c);
  40. void MSG_WriteString (msg_t *sb, const char *s);
  41. void MSG_BeginReading (msg_t *sb);
  42. int MSG_ReadBits( msg_t *msg, int bits );
  43. int MSG_ReadByte (msg_t *sb);
  44. int MSG_ReadShort (msg_t *sb);
  45. int MSG_ReadLong (msg_t *sb);
  46. char *MSG_ReadString (msg_t *sb);
  47. char *MSG_ReadStringLine (msg_t *sb);
  48. void MSG_ReadData (msg_t *sb, void *buffer, int size);
  49. void MSG_WriteDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
  50. void MSG_ReadDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
  51. void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entityState_s *to
  52. , qboolean force );
  53. void MSG_ReadDeltaEntity( msg_t *msg, entityState_t *from, entityState_t *to,
  54. int number );
  55. void MSG_ReadEntity( msg_t *msg, entityState_t *to);
  56. void MSG_WriteEntity( msg_t *msg, entityState_t *to, int removeNum);
  57. void MSG_WriteDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
  58. void MSG_ReadDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
  59. //============================================================================
  60. #ifdef _M_IX86
  61. //
  62. // optimised stuff for Intel, since most of our data is in that format anyway...
  63. //
  64. extern short BigShort (short l);
  65. extern int BigLong (int l);
  66. extern float BigFloat (float l);
  67. #define LittleShort(l) l
  68. #define LittleLong(l) l
  69. #define LittleFloat(l) l
  70. //
  71. #else
  72. //
  73. // standard smart-swap code...
  74. //
  75. extern short BigShort (short l);
  76. extern short LittleShort (short l);
  77. extern int BigLong (int l);
  78. extern int LittleLong (int l);
  79. extern float BigFloat (float l);
  80. extern float LittleFloat (float l);
  81. //
  82. #endif
  83. /*
  84. ==============================================================
  85. NET
  86. ==============================================================
  87. */
  88. #ifdef _XBOX
  89. #define PACKET_BACKUP 2
  90. #else
  91. #define PACKET_BACKUP 16 // number of old messages that must be kept on client and
  92. #endif // server for delta comrpession and ping estimation
  93. #define PACKET_MASK (PACKET_BACKUP-1)
  94. #define MAX_PACKET_USERCMDS 32 // max number of usercmd_t in a packet
  95. #define PORT_ANY -1
  96. #define MAX_RELIABLE_COMMANDS 64 // max string commands buffered for restransmit
  97. typedef enum {
  98. NA_BAD, // an address lookup failed
  99. NA_LOOPBACK,
  100. } netadrtype_t;
  101. typedef enum {
  102. NS_CLIENT,
  103. NS_SERVER
  104. } netsrc_t;
  105. typedef struct {
  106. netadrtype_t type;
  107. unsigned short port;
  108. } netadr_t;
  109. void NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to);
  110. void NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...);
  111. qboolean NET_CompareAdr (netadr_t a, netadr_t b);
  112. qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
  113. qboolean NET_IsLocalAddress (netadr_t adr);
  114. qboolean NET_IsLANAddress (netadr_t adr);
  115. const char *NET_AdrToString (netadr_t a);
  116. qboolean NET_StringToAdr ( const char *s, netadr_t *a);
  117. qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
  118. #define MAX_MSGLEN (1*17408) // max length of a message, which may
  119. //#define MAX_MSGLEN (3*16384) // max length of a message, which may
  120. // be fragmented into multiple packets
  121. /*
  122. Netchan handles packet fragmentation and out of order / duplicate suppression
  123. */
  124. typedef struct {
  125. netsrc_t sock;
  126. int dropped; // between last packet and previous
  127. netadr_t remoteAddress;
  128. int qport; // qport value to write when transmitting
  129. // sequencing variables
  130. int incomingSequence;
  131. int incomingAcknowledged;
  132. int outgoingSequence;
  133. // incoming fragment assembly buffer
  134. int fragmentSequence;
  135. int fragmentLength;
  136. byte fragmentBuffer[MAX_MSGLEN];
  137. } netchan_t;
  138. void Netchan_Init( int qport );
  139. void Netchan_Setup( netsrc_t sock, netchan_t *chan, netadr_t adr, int qport );
  140. void Netchan_Transmit( netchan_t *chan, int length, const byte *data );
  141. qboolean Netchan_Process( netchan_t *chan, msg_t *msg );
  142. /*
  143. ==============================================================
  144. PROTOCOL
  145. ==============================================================
  146. */
  147. #define PROTOCOL_VERSION 40
  148. #define PORT_SERVER 27960
  149. // the svc_strings[] array in cl_parse.c should mirror this
  150. //
  151. // server to client
  152. //
  153. enum svc_ops_e {
  154. svc_bad,
  155. svc_nop,
  156. svc_gamestate,
  157. svc_configstring, // [short] [string] only in gamestate messages
  158. svc_baseline, // only in gamestate messages
  159. svc_serverCommand, // [string] to be executed by client game module
  160. svc_download, // [short] size [size bytes]
  161. svc_snapshot
  162. };
  163. //
  164. // client to server
  165. //
  166. enum clc_ops_e {
  167. clc_bad,
  168. clc_nop,
  169. clc_move, // [[usercmd_t]
  170. clc_clientCommand // [string] message
  171. };
  172. /*
  173. ==============================================================
  174. CMD
  175. Command text buffering and command execution
  176. ==============================================================
  177. */
  178. /*
  179. Any number of commands can be added in a frame, from several different sources.
  180. Most commands come from either keybindings or console line input, but entire text
  181. files can be execed.
  182. */
  183. void Cbuf_Init (void);
  184. // allocates an initial text buffer that will grow as needed
  185. void Cbuf_AddText( const char *text );
  186. // Adds command text at the end of the buffer, does NOT add a final \n
  187. void Cbuf_ExecuteText( int exec_when, const char *text );
  188. // this can be used in place of either Cbuf_AddText or Cbuf_InsertText
  189. void Cbuf_Execute (void);
  190. // Pulls off \n terminated lines of text from the command buffer and sends
  191. // them through Cmd_ExecuteString. Stops when the buffer is empty.
  192. // Normally called once per frame, but may be explicitly invoked.
  193. // Do not call inside a command function, or current args will be destroyed.
  194. //===========================================================================
  195. /*
  196. Command execution takes a null terminated string, breaks it into tokens,
  197. then searches for a command or variable that matches the first token.
  198. */
  199. typedef void (*xcommand_t) (void);
  200. void Cmd_Init (void);
  201. void Cmd_AddCommand( const char *cmd_name, xcommand_t function );
  202. // called by the init functions of other parts of the program to
  203. // register commands and functions to call for them.
  204. // The cmd_name is referenced later, so it should not be in temp memory
  205. // if function is NULL, the command will be forwarded to the server
  206. // as a clc_clientCommand instead of executed locally
  207. void Cmd_RemoveCommand( const char *cmd_name );
  208. char *Cmd_CompleteCommand( const char *partial );
  209. // attempts to match a partial command for automatic command line completion
  210. // returns NULL if nothing fits
  211. int Cmd_Argc (void);
  212. char *Cmd_Argv (int arg);
  213. void Cmd_ArgvBuffer( int arg, char *buffer, int bufferLength );
  214. char *Cmd_Args (void);
  215. void Cmd_ArgsBuffer( char *buffer, int bufferLength );
  216. // The functions that execute commands get their parameters with these
  217. // functions. Cmd_Argv () will return an empty string, not a NULL
  218. // if arg > argc, so string operations are allways safe.
  219. void Cmd_TokenizeString( const char *text );
  220. // Takes a null terminated string. Does not need to be /n terminated.
  221. // breaks the string up into arg tokens.
  222. void Cmd_ExecuteString( const char *text );
  223. // Parses a single line of text into arguments and tries to execute it
  224. // as if it was typed at the console
  225. /*
  226. ==============================================================
  227. CVAR
  228. ==============================================================
  229. */
  230. /*
  231. cvar_t variables are used to hold scalar or string variables that can be changed
  232. or displayed at the console or prog code as well as accessed directly
  233. in C code.
  234. The user can access cvars from the console in three ways:
  235. r_draworder prints the current value
  236. r_draworder 0 sets the current value to 0
  237. set r_draworder 0 as above, but creates the cvar if not present
  238. Cvars are restricted from having the same names as commands to keep this
  239. interface from being ambiguous.
  240. The are also occasionally used to communicated information between different
  241. modules of the program.
  242. */
  243. cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
  244. // creates the variable if it doesn't exist, or returns the existing one
  245. // if it exists, the value will not be changed, but flags will be ORed in
  246. // that allows variables to be unarchived without needing bitflags
  247. // if value is "", the value will not override a previously set value.
  248. void Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags );
  249. // basically a slightly modified Cvar_Get for the interpreted modules
  250. void Cvar_Update( vmCvar_t *vmCvar );
  251. // updates an interpreted modules' version of a cvar
  252. void Cvar_Set( const char *var_name, const char *value );
  253. // will create the variable with no flags if it doesn't exist
  254. void Cvar_SetValue( const char *var_name, float value );
  255. // expands value to a string and calls Cvar_Set
  256. float Cvar_VariableValue( const char *var_name );
  257. int Cvar_VariableIntegerValue( const char *var_name );
  258. // returns 0 if not defined or non numeric
  259. char *Cvar_VariableString( const char *var_name );
  260. void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize );
  261. // returns an empty string if not defined
  262. char *Cvar_CompleteVariable( const char *partial );
  263. // attempts to match a partial variable name for command line completion
  264. // returns NULL if nothing fits
  265. void Cvar_Reset( const char *var_name );
  266. void Cvar_SetCheatState( void );
  267. // reset all testing vars to a safe value
  268. qboolean Cvar_Command( void );
  269. // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
  270. // command. Returns true if the command was a variable reference that
  271. // was handled. (print or change)
  272. void Cvar_WriteVariables( fileHandle_t f );
  273. // writes lines containing "set variable value" for all variables
  274. // with the archive flag set to true.
  275. void Cvar_Init( void );
  276. char *Cvar_InfoString( int bit );
  277. // returns an info string containing all the cvars that have the given bit set
  278. // in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
  279. void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
  280. void Cvar_Restart_f( void );
  281. extern int cvar_modifiedFlags;
  282. // whenever a cvar is modifed, its flags will be OR'd into this, so
  283. // a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO,
  284. // etc, variables have been modified since the last check. The bit
  285. // can then be cleared to allow another change detection.
  286. /*
  287. ==============================================================
  288. FILESYSTEM
  289. No stdio calls should be used by any part of the game, because
  290. we need to deal with all sorts of directory and seperator char
  291. issues.
  292. ==============================================================
  293. */
  294. qboolean FS_Initialized();
  295. void FS_InitFilesystem (void);
  296. char **FS_ListFiles( const char *directory, const char *extension, int *numfiles );
  297. // directory should not have either a leading or trailing /
  298. // if extension is "/", only subdirectories will be returned
  299. // the returned files will not include any directories or /
  300. void FS_FreeFileList( char **filelist );
  301. int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
  302. fileHandle_t FS_FOpenFileWrite( const char *qpath );
  303. // will properly create any needed paths and deal with seperater character issues
  304. fileHandle_t FS_FOpenFileAppend( const char *filename ); // this was present already, but no public proto
  305. qboolean FS_GetExtendedInfo_FOpenFileRead(const char *filename, char **ppsFilename, int *piOffset);
  306. //return value is success of opening file, then ppsFilename and piOffset are valid
  307. int FS_FOpenFileRead( const char *qpath, fileHandle_t *file, qboolean uniqueFILE );
  308. // if uniqueFILE is true, then a new FILE will be fopened even if the file
  309. // is found in an already open pak file. If uniqueFILE is false, you must call
  310. // FS_FCloseFile instead of fclose, otherwise the pak FILE would be improperly closed
  311. // It is generally safe to always set uniqueFILE to true, because the majority of
  312. // file IO goes through FS_ReadFile, which Does The Right Thing already.
  313. int FS_FileIsInPAK(const char *filename );
  314. // returns 1 if a file is in the PAK file, otherwise -1
  315. int FS_Write( const void *buffer, int len, fileHandle_t f );
  316. int FS_Read( void *buffer, int len, fileHandle_t f );
  317. // properly handles partial reads and reads from other dlls
  318. void FS_FCloseFile( fileHandle_t f );
  319. // note: you can't just fclose from another DLL, due to MS libc issues
  320. int FS_ReadFile( const char *qpath, void **buffer );
  321. // returns the length of the file
  322. // a null buffer will just return the file length without loading
  323. // as a quick check for existance. -1 length == not present
  324. // A 0 byte will always be appended at the end, so string ops are safe.
  325. // the buffer should be considered read-only, because it may be cached
  326. // for other uses.
  327. void FS_ForceFlush( fileHandle_t f );
  328. // forces flush on files we're writing to.
  329. void FS_FreeFile( void *buffer );
  330. // frees the memory returned by FS_ReadFile
  331. void FS_WriteFile( const char *qpath, const void *buffer, int size );
  332. // writes a complete file, creating any subdirectories needed
  333. int FS_filelength( fileHandle_t f );
  334. // doesn't work for files that are opened from a pack file
  335. int FS_FTell( fileHandle_t f );
  336. // where are we?
  337. void FS_Flush( fileHandle_t f );
  338. void QDECL FS_Printf( fileHandle_t f, const char *fmt, ... );
  339. // like fprintf
  340. int FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode );
  341. // opens a file for reading, writing, or appending depending on the value of mode
  342. int FS_Seek( fileHandle_t f, long offset, int origin );
  343. // seek on a file (doesn't work for zip files!!!!!!!!)
  344. // These 2 are generally only used by the save games, filenames are local (eg "saves/blah.sav")
  345. //
  346. void FS_DeleteUserGenFile( const char *filename );
  347. qboolean FS_MoveUserGenFile ( const char *filename_src, const char *filename_dst );
  348. /*
  349. ==============================================================
  350. MISC
  351. ==============================================================
  352. */
  353. //==========================================================
  354. //
  355. // NOTE NOTE NOTE!!!!!!!!!!!!!
  356. //
  357. // Any CPUID_XXXX defined as higher than CPUID_INTEL_MMX *must* have MMX support (eg like CPUID_AMD_3DNOW (0x30) has),
  358. // this allows convenient MMX capability checking. If you for some reason want to support some new processor that does
  359. // *NOT* have MMX (yeah, right), then define it as a lower number. -slc
  360. //
  361. // ( These values are returned by Sys_GetProcessorId )
  362. //
  363. #define CPUID_GENERIC 0 // any unrecognized processor
  364. #define CPUID_AXP 0x10
  365. #define CPUID_INTEL_UNSUPPORTED 0x20 // Intel 386/486
  366. #define CPUID_INTEL_PENTIUM 0x21 // Intel Pentium or PPro
  367. #define CPUID_INTEL_MMX 0x22 // Intel Pentium/MMX or P2/MMX
  368. #define CPUID_INTEL_KATMAI 0x23 // Intel Katmai
  369. #define CPUID_INTEL_WILLIAMETTE 0x24 // Intel Williamette
  370. #define CPUID_AMD_3DNOW 0x30 // AMD K6 3DNOW!
  371. //
  372. //==========================================================
  373. #define RoundUp(N, M) ((N) + ((unsigned int)(M)) - (((unsigned int)(N)) % ((unsigned int)(M))))
  374. #define RoundDown(N, M) ((N) - (((unsigned int)(N)) % ((unsigned int)(M))))
  375. char *CopyString( const char *in );
  376. void Info_Print( const char *s );
  377. void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *));
  378. void Com_EndRedirect( void );
  379. void QDECL Com_Printf( const char *fmt, ... );
  380. void QDECL Com_PrintfAlways( const char *fmt, ... );
  381. void QDECL Com_DPrintf( const char *fmt, ... );
  382. void QDECL Com_Error( int code, const char *fmt, ... );
  383. void Com_Quit_f( void );
  384. int Com_EventLoop( void );
  385. int Com_Milliseconds( void ); // will be journaled properly
  386. unsigned Com_BlockChecksum( const void *buffer, int length );
  387. int Com_Filter(char *filter, char *name, int casesensitive);
  388. void Com_StartupVariable( const char *match );
  389. // checks for and removes command line "+set var arg" constructs
  390. // if match is NULL, all set commands will be executed, otherwise
  391. // only a set with the exact name. Only used during startup.
  392. extern cvar_t *com_developer;
  393. extern cvar_t *com_speeds;
  394. extern cvar_t *com_timescale;
  395. extern cvar_t *com_sv_running;
  396. extern cvar_t *com_cl_running;
  397. extern cvar_t *com_viewlog; // 0 = hidden, 1 = visible, 2 = minimized
  398. extern cvar_t *com_version;
  399. // both client and server must agree to pause
  400. extern cvar_t *cl_paused;
  401. extern cvar_t *sv_paused;
  402. // com_speeds times
  403. extern int time_game;
  404. extern int time_frontend;
  405. extern int time_backend; // renderer backend time
  406. extern int timeInTrace;
  407. extern int timeInPVSCheck;
  408. extern int numTraces;
  409. extern int com_frameTime;
  410. extern int com_frameMsec;
  411. extern qboolean com_errorEntered;
  412. #ifndef _XBOX
  413. extern fileHandle_t com_journalFile;
  414. extern fileHandle_t com_journalDataFile;
  415. #endif
  416. /*
  417. --- low memory ----
  418. server vm
  419. server clipmap
  420. ---mark---
  421. renderer initialization (shaders, etc)
  422. UI vm
  423. cgame vm
  424. renderer map
  425. renderer models
  426. ---free---
  427. temp file loading
  428. --- high memory ---
  429. */
  430. int Z_Validate( void ); // also used to insure all of these are paged in
  431. int Z_MemSize ( memtag_t eTag );
  432. void Z_TagFree ( memtag_t eTag );
  433. int Z_Free ( void *ptr ); //returns bytes freed
  434. int Z_Size ( void *pvAddress);
  435. void Z_MorphMallocTag( void *pvAddress, memtag_t eDesiredTag );
  436. qboolean Z_IsFromZone(void *pvAddress, memtag_t eTag);
  437. qboolean Z_IsFromTempPool(void *pvAddress);
  438. #ifdef DEBUG_ZONE_ALLOCS
  439. void *_D_Z_Malloc ( int iSize, memtag_t eTag, qboolean bZeroit, const char *psFile, int iLine );
  440. void *_D_S_Malloc ( int iSize, const char *psFile, int iLine );
  441. void _D_Z_Label ( const void *pvAddress, const char *pslabel );
  442. #define Z_Malloc(_iSize, _eTag, _bZeroit) _D_Z_Malloc (_iSize, _eTag, _bZeroit, __FILE__, __LINE__)
  443. #define S_Malloc(_iSize) _D_S_Malloc (_iSize, __FILE__, __LINE__) // NOT 0 filled memory only for small allocations
  444. #define Z_Label(_ptr, _label) _D_Z_Label (_ptr, _label)
  445. #else
  446. void *Z_Malloc ( int iSize, memtag_t eTag, qboolean bZeroit, int iAlign = 4); // return memory NOT zero-filled by default
  447. void *S_Malloc ( int iSize ); // NOT 0 filled memory only for small allocations
  448. #define Z_Label(_ptr, _label) /* */
  449. #endif
  450. void Hunk_Clear( void );
  451. void Hunk_ClearToMark( void );
  452. void Hunk_SetMark( void );
  453. // note the opposite default for 'bZeroIt' in Hunk_Alloc to Z_Malloc, since Hunk_Alloc always used to memset(0)...
  454. //
  455. inline void *Hunk_Alloc( int size, qboolean bZeroIt = qtrue)
  456. {
  457. return Z_Malloc(size, TAG_HUNKALLOC, bZeroIt);
  458. }
  459. // Used to re-tag new/delete allocations:
  460. void Z_PushNewDeleteTag( memtag_t eTag );
  461. void Z_PopNewDeleteTag( void );
  462. void Com_TouchMemory( void );
  463. // commandLine should not include the executable name (argv[0])
  464. void Com_SetOrgAngles(vec3_t org,vec3_t angles);
  465. void Com_Init( char *commandLine );
  466. void Com_Frame( void );
  467. void Com_Shutdown( void );
  468. void Com_ShutdownZoneMemory(void);
  469. void Com_ShutdownHunkMemory(void);
  470. bool Com_ParseTextFile(const char *file, class CGenericParser2 &parser, bool cleanFirst = true);
  471. CGenericParser2 *Com_ParseTextFile(const char *file, bool cleanFirst, bool writeable);
  472. void Com_ParseTextFileDestroy(class CGenericParser2 &parser);
  473. /*
  474. ==============================================================
  475. CLIENT / SERVER SYSTEMS
  476. ==============================================================
  477. */
  478. //
  479. // client interface
  480. //
  481. void CL_InitKeyCommands( void );
  482. // the keyboard binding interface must be setup before execing
  483. // config files, but the rest of client startup will happen later
  484. void CL_Init( void );
  485. void CL_Disconnect( void );
  486. void CL_Shutdown( void );
  487. void CL_Frame( int msec,float fractionMsec );
  488. qboolean CL_GameCommand( void );
  489. void CL_KeyEvent (int key, qboolean down, unsigned time);
  490. void CL_CharEvent( int key );
  491. // char events are for field typing, not game control
  492. void CL_MouseEvent( int dx, int dy, int time );
  493. void CL_JoystickEvent( int axis, int value, int time );
  494. void CL_PacketEvent( netadr_t from, msg_t *msg );
  495. void CL_ConsolePrint( char *text );
  496. void CL_MapLoading( void );
  497. // do a screen update before starting to load a map
  498. // when the server is going to load a new map, the entire hunk
  499. // will be cleared, so the client must shutdown cgame, ui, and
  500. // the renderer
  501. void CL_ForwardCommandToServer( void );
  502. // adds the current command line as a clc_clientCommand to the client message.
  503. // things like godmode, noclip, etc, are commands directed to the server,
  504. // so when they are typed in at the console, they will need to be forwarded.
  505. void CL_FlushMemory( void );
  506. // dump all memory on an error
  507. void CL_StartHunkUsers( void );
  508. void Key_WriteBindings( fileHandle_t f );
  509. // for writing the config files
  510. void S_ClearSoundBuffer( void );
  511. // call before filesystem access
  512. void SCR_DebugGraph (float value, int color); // FIXME: move logging to common?
  513. //
  514. // server interface
  515. //
  516. void SV_Init( void );
  517. void SV_Shutdown( char *finalmsg );
  518. void SV_Frame( int msec,float fractionMsec);
  519. void SV_PacketEvent( netadr_t from, msg_t *msg );
  520. qboolean SV_GameCommand( void );
  521. //
  522. // UI interface
  523. //
  524. qboolean UI_GameCommand( void );
  525. /*
  526. ==============================================================
  527. NON-PORTABLE SYSTEM SERVICES
  528. ==============================================================
  529. */
  530. typedef enum {
  531. AXIS_SIDE,
  532. AXIS_FORWARD,
  533. AXIS_UP,
  534. AXIS_ROLL,
  535. AXIS_YAW,
  536. AXIS_PITCH,
  537. MAX_JOYSTICK_AXIS
  538. } joystickAxis_t;
  539. typedef enum {
  540. SE_NONE, // evTime is still valid
  541. SE_KEY, // evValue is a key code, evValue2 is the down flag
  542. SE_CHAR, // evValue is an ascii char
  543. SE_MOUSE, // evValue and evValue2 are reletive signed x / y moves
  544. SE_JOYSTICK_AXIS, // evValue is an axis number and evValue2 is the current state (-127 to 127)
  545. SE_CONSOLE, // evPtr is a char*
  546. SE_PACKET // evPtr is a netadr_t followed by data bytes to evPtrLength
  547. } sysEventType_t;
  548. typedef struct {
  549. int evTime;
  550. sysEventType_t evType;
  551. int evValue, evValue2;
  552. int evPtrLength; // bytes of data pointed to by evPtr, for journaling
  553. void *evPtr; // this must be manually freed if not NULL
  554. } sysEvent_t;
  555. sysEvent_t Sys_GetEvent( void );
  556. void Sys_Init (void);
  557. char *Sys_GetCurrentUser( void );
  558. void QDECL Sys_Error( const char *error, ...);
  559. void Sys_Quit (void);
  560. char *Sys_GetClipboardData( void ); // note that this isn't journaled...
  561. void Sys_Print( const char *msg );
  562. #ifdef _XBOX
  563. void Sys_Log( const char *file, const char *msg );
  564. void Sys_Log( const char *file, const void *buffer, int size, bool flush );
  565. #endif
  566. // Sys_Milliseconds should only be used for profiling purposes,
  567. // any game related timing information should come from event timestamps
  568. int Sys_Milliseconds (void);
  569. // the system console is shown when a dedicated server is running
  570. void Sys_DisplaySystemConsole( qboolean show );
  571. int Sys_GetProcessorId( void );
  572. void Sys_BeginStreamedFile( fileHandle_t f, int readahead );
  573. void Sys_EndStreamedFile( fileHandle_t f );
  574. int Sys_StreamedRead( void *buffer, int size, int count, fileHandle_t f );
  575. void Sys_StreamSeek( fileHandle_t f, int offset, int origin );
  576. void Sys_ShowConsole( int level, qboolean quitOnClose );
  577. void Sys_SetErrorText( const char *text );
  578. qboolean Sys_CheckCD( void );
  579. void Sys_Mkdir( const char *path );
  580. char *Sys_Cwd( void );
  581. char *Sys_DefaultCDPath(void);
  582. char *Sys_DefaultBasePath(void);
  583. char **Sys_ListFiles( const char *directory, const char *extension, int *numfiles, qboolean wantsubs );
  584. void Sys_FreeFileList( char **filelist );
  585. void Sys_BeginProfiling( void );
  586. void Sys_EndProfiling( void );
  587. qboolean Sys_LowPhysicalMemory();
  588. qboolean Sys_FileOutOfDate( LPCSTR psFinalFileName /* dest */, LPCSTR psDataFileName /* src */ );
  589. qboolean Sys_CopyFile(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, qboolean bOverwrite);
  590. //byte* SCR_GetScreenshot(qboolean *qValid);
  591. //void SCR_SetScreenshot(const byte *pbData, int w, int h);
  592. //byte* SCR_TempRawImage_ReadFromFile(const char *psLocalFilename, int *piWidth, int *piHeight, byte *pbReSampleBuffer, qboolean qbVertFlip);
  593. //void SCR_TempRawImage_CleanUp();
  594. inline int Round(float value)
  595. {
  596. return((int)floorf(value + 0.5f));
  597. }
  598. #ifdef _XBOX
  599. //////////////////////////////
  600. //
  601. // Map Lump Loader
  602. //
  603. struct Lump
  604. {
  605. void* data;
  606. int len;
  607. Lump() : data(NULL), len(0) {}
  608. ~Lump() { clear(); }
  609. void load(const char* map, const char* lump)
  610. {
  611. clear();
  612. char path[MAX_QPATH];
  613. Com_sprintf(path, MAX_QPATH, "%s/%s.mle", map, lump);
  614. len = FS_ReadFile(path, &data);
  615. if (len < 0) len = 0;
  616. }
  617. void clear(void)
  618. {
  619. if (data)
  620. {
  621. FS_FreeFile(data);
  622. data = NULL;
  623. }
  624. }
  625. };
  626. #endif _XBOX
  627. #endif //__QCOMMON_H__