qcommon.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. // qcommon.h -- definitions common between client and server, but not game.or ref modules
  19. #ifndef _QCOMMON_H_
  20. #define _QCOMMON_H_
  21. #include "../qcommon/cm_public.h"
  22. //#define PRE_RELEASE_DEMO
  23. //============================================================================
  24. //
  25. // msg.c
  26. //
  27. typedef struct {
  28. qboolean allowoverflow; // if false, do a Com_Error
  29. qboolean overflowed; // set to true if the buffer size failed (with allowoverflow set)
  30. qboolean oob; // set to true if the buffer size failed (with allowoverflow set)
  31. byte *data;
  32. int maxsize;
  33. int cursize;
  34. int readcount;
  35. int bit; // for bitwise reads and writes
  36. } msg_t;
  37. void MSG_Init (msg_t *buf, byte *data, int length);
  38. void MSG_InitOOB( msg_t *buf, byte *data, int length );
  39. void MSG_Clear (msg_t *buf);
  40. void MSG_WriteData (msg_t *buf, const void *data, int length);
  41. void MSG_Bitstream( msg_t *buf );
  42. // TTimo
  43. // copy a msg_t in case we need to store it as is for a bit
  44. // (as I needed this to keep an msg_t from a static var for later use)
  45. // sets data buffer as MSG_Init does prior to do the copy
  46. void MSG_Copy(msg_t *buf, byte *data, int length, msg_t *src);
  47. struct usercmd_s;
  48. struct entityState_s;
  49. struct playerState_s;
  50. void MSG_WriteBits( msg_t *msg, int value, int bits );
  51. void MSG_WriteChar (msg_t *sb, int c);
  52. void MSG_WriteByte (msg_t *sb, int c);
  53. void MSG_WriteShort (msg_t *sb, int c);
  54. void MSG_WriteLong (msg_t *sb, int c);
  55. void MSG_WriteFloat (msg_t *sb, float f);
  56. void MSG_WriteString (msg_t *sb, const char *s);
  57. void MSG_WriteBigString (msg_t *sb, const char *s);
  58. void MSG_WriteAngle16 (msg_t *sb, float f);
  59. void MSG_BeginReading (msg_t *sb);
  60. void MSG_BeginReadingOOB(msg_t *sb);
  61. int MSG_ReadBits( msg_t *msg, int bits );
  62. int MSG_ReadChar (msg_t *sb);
  63. int MSG_ReadByte (msg_t *sb);
  64. int MSG_ReadShort (msg_t *sb);
  65. int MSG_ReadLong (msg_t *sb);
  66. float MSG_ReadFloat (msg_t *sb);
  67. char *MSG_ReadString (msg_t *sb);
  68. char *MSG_ReadBigString (msg_t *sb);
  69. char *MSG_ReadStringLine (msg_t *sb);
  70. float MSG_ReadAngle16 (msg_t *sb);
  71. void MSG_ReadData (msg_t *sb, void *buffer, int size);
  72. void MSG_WriteDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
  73. void MSG_ReadDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
  74. void MSG_WriteDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
  75. void MSG_ReadDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
  76. void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entityState_s *to
  77. , qboolean force );
  78. void MSG_ReadDeltaEntity( msg_t *msg, entityState_t *from, entityState_t *to,
  79. int number );
  80. void MSG_WriteDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
  81. void MSG_ReadDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
  82. void MSG_ReportChangeVectors_f( void );
  83. //============================================================================
  84. /*
  85. ==============================================================
  86. NET
  87. ==============================================================
  88. */
  89. #define PACKET_BACKUP 32 // number of old messages that must be kept on client and
  90. // server for delta comrpession and ping estimation
  91. #define PACKET_MASK (PACKET_BACKUP-1)
  92. #define MAX_PACKET_USERCMDS 32 // max number of usercmd_t in a packet
  93. #define PORT_ANY -1
  94. #define MAX_RELIABLE_COMMANDS 64 // max string commands buffered for restransmit
  95. typedef enum {
  96. NA_BOT,
  97. NA_BAD, // an address lookup failed
  98. NA_LOOPBACK,
  99. NA_BROADCAST,
  100. NA_IP,
  101. NA_IPX,
  102. NA_BROADCAST_IPX
  103. } netadrtype_t;
  104. typedef enum {
  105. NS_CLIENT,
  106. NS_SERVER
  107. } netsrc_t;
  108. typedef struct {
  109. netadrtype_t type;
  110. byte ip[4];
  111. byte ipx[10];
  112. unsigned short port;
  113. } netadr_t;
  114. void NET_Init( void );
  115. void NET_Shutdown( void );
  116. void NET_Restart( void );
  117. void NET_Config( qboolean enableNetworking );
  118. void NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to);
  119. void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...);
  120. void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len );
  121. qboolean NET_CompareAdr (netadr_t a, netadr_t b);
  122. qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
  123. qboolean NET_IsLocalAddress (netadr_t adr);
  124. const char *NET_AdrToString (netadr_t a);
  125. qboolean NET_StringToAdr ( const char *s, netadr_t *a);
  126. qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
  127. void NET_Sleep(int msec);
  128. #define MAX_MSGLEN 16384 // max length of a message, which may
  129. // be fragmented into multiple packets
  130. #define MAX_DOWNLOAD_WINDOW 8 // max of eight download frames
  131. #define MAX_DOWNLOAD_BLKSIZE 2048 // 2048 byte block chunks
  132. /*
  133. Netchan handles packet fragmentation and out of order / duplicate suppression
  134. */
  135. typedef struct {
  136. netsrc_t sock;
  137. int dropped; // between last packet and previous
  138. netadr_t remoteAddress;
  139. int qport; // qport value to write when transmitting
  140. // sequencing variables
  141. int incomingSequence;
  142. int outgoingSequence;
  143. // incoming fragment assembly buffer
  144. int fragmentSequence;
  145. int fragmentLength;
  146. byte fragmentBuffer[MAX_MSGLEN];
  147. // outgoing fragment buffer
  148. // we need to space out the sending of large fragmented messages
  149. qboolean unsentFragments;
  150. int unsentFragmentStart;
  151. int unsentLength;
  152. byte unsentBuffer[MAX_MSGLEN];
  153. } netchan_t;
  154. void Netchan_Init( int qport );
  155. void Netchan_Setup( netsrc_t sock, netchan_t *chan, netadr_t adr, int qport );
  156. void Netchan_Transmit( netchan_t *chan, int length, const byte *data );
  157. void Netchan_TransmitNextFragment( netchan_t *chan );
  158. qboolean Netchan_Process( netchan_t *chan, msg_t *msg );
  159. /*
  160. ==============================================================
  161. PROTOCOL
  162. ==============================================================
  163. */
  164. #define PROTOCOL_VERSION 68
  165. // 1.31 - 67
  166. // maintain a list of compatible protocols for demo playing
  167. // NOTE: that stuff only works with two digits protocols
  168. extern int demo_protocols[];
  169. #define UPDATE_SERVER_NAME "update.quake3arena.com"
  170. // override on command line, config files etc.
  171. #ifndef MASTER_SERVER_NAME
  172. #define MASTER_SERVER_NAME "master.quake3arena.com"
  173. #endif
  174. #ifndef AUTHORIZE_SERVER_NAME
  175. #define AUTHORIZE_SERVER_NAME "authorize.quake3arena.com"
  176. #endif
  177. #define PORT_MASTER 27950
  178. #define PORT_UPDATE 27951
  179. #ifndef PORT_AUTHORIZE
  180. #define PORT_AUTHORIZE 27952
  181. #endif
  182. #define PORT_SERVER 27960
  183. #define NUM_SERVER_PORTS 4 // broadcast scan this many ports after
  184. // PORT_SERVER so a single machine can
  185. // run multiple servers
  186. // the svc_strings[] array in cl_parse.c should mirror this
  187. //
  188. // server to client
  189. //
  190. enum svc_ops_e {
  191. svc_bad,
  192. svc_nop,
  193. svc_gamestate,
  194. svc_configstring, // [short] [string] only in gamestate messages
  195. svc_baseline, // only in gamestate messages
  196. svc_serverCommand, // [string] to be executed by client game module
  197. svc_download, // [short] size [size bytes]
  198. svc_snapshot,
  199. svc_EOF
  200. };
  201. //
  202. // client to server
  203. //
  204. enum clc_ops_e {
  205. clc_bad,
  206. clc_nop,
  207. clc_move, // [[usercmd_t]
  208. clc_moveNoDelta, // [[usercmd_t]
  209. clc_clientCommand, // [string] message
  210. clc_EOF
  211. };
  212. /*
  213. ==============================================================
  214. VIRTUAL MACHINE
  215. ==============================================================
  216. */
  217. typedef struct vm_s vm_t;
  218. typedef enum {
  219. VMI_NATIVE,
  220. VMI_BYTECODE,
  221. VMI_COMPILED
  222. } vmInterpret_t;
  223. typedef enum {
  224. TRAP_MEMSET = 100,
  225. TRAP_MEMCPY,
  226. TRAP_STRNCPY,
  227. TRAP_SIN,
  228. TRAP_COS,
  229. TRAP_ATAN2,
  230. TRAP_SQRT,
  231. TRAP_MATRIXMULTIPLY,
  232. TRAP_ANGLEVECTORS,
  233. TRAP_PERPENDICULARVECTOR,
  234. TRAP_FLOOR,
  235. TRAP_CEIL,
  236. TRAP_TESTPRINTINT,
  237. TRAP_TESTPRINTFLOAT
  238. } sharedTraps_t;
  239. void VM_Init( void );
  240. vm_t *VM_Create( const char *module, int (*systemCalls)(int *),
  241. vmInterpret_t interpret );
  242. // module should be bare: "cgame", not "cgame.dll" or "vm/cgame.qvm"
  243. void VM_Free( vm_t *vm );
  244. void VM_Clear(void);
  245. vm_t *VM_Restart( vm_t *vm );
  246. int QDECL VM_Call( vm_t *vm, int callNum, ... );
  247. void VM_Debug( int level );
  248. void *VM_ArgPtr( int intValue );
  249. void *VM_ExplicitArgPtr( vm_t *vm, int intValue );
  250. /*
  251. ==============================================================
  252. CMD
  253. Command text buffering and command execution
  254. ==============================================================
  255. */
  256. /*
  257. Any number of commands can be added in a frame, from several different sources.
  258. Most commands come from either keybindings or console line input, but entire text
  259. files can be execed.
  260. */
  261. void Cbuf_Init (void);
  262. // allocates an initial text buffer that will grow as needed
  263. void Cbuf_AddText( const char *text );
  264. // Adds command text at the end of the buffer, does NOT add a final \n
  265. void Cbuf_ExecuteText( int exec_when, const char *text );
  266. // this can be used in place of either Cbuf_AddText or Cbuf_InsertText
  267. void Cbuf_Execute (void);
  268. // Pulls off \n terminated lines of text from the command buffer and sends
  269. // them through Cmd_ExecuteString. Stops when the buffer is empty.
  270. // Normally called once per frame, but may be explicitly invoked.
  271. // Do not call inside a command function, or current args will be destroyed.
  272. //===========================================================================
  273. /*
  274. Command execution takes a null terminated string, breaks it into tokens,
  275. then searches for a command or variable that matches the first token.
  276. */
  277. typedef void (*xcommand_t) (void);
  278. void Cmd_Init (void);
  279. void Cmd_AddCommand( const char *cmd_name, xcommand_t function );
  280. // called by the init functions of other parts of the program to
  281. // register commands and functions to call for them.
  282. // The cmd_name is referenced later, so it should not be in temp memory
  283. // if function is NULL, the command will be forwarded to the server
  284. // as a clc_clientCommand instead of executed locally
  285. void Cmd_RemoveCommand( const char *cmd_name );
  286. void Cmd_CommandCompletion( void(*callback)(const char *s) );
  287. // callback with each valid string
  288. int Cmd_Argc (void);
  289. char *Cmd_Argv (int arg);
  290. void Cmd_ArgvBuffer( int arg, char *buffer, int bufferLength );
  291. char *Cmd_Args (void);
  292. char *Cmd_ArgsFrom( int arg );
  293. void Cmd_ArgsBuffer( char *buffer, int bufferLength );
  294. char *Cmd_Cmd (void);
  295. // The functions that execute commands get their parameters with these
  296. // functions. Cmd_Argv () will return an empty string, not a NULL
  297. // if arg > argc, so string operations are allways safe.
  298. void Cmd_TokenizeString( const char *text );
  299. // Takes a null terminated string. Does not need to be /n terminated.
  300. // breaks the string up into arg tokens.
  301. void Cmd_ExecuteString( const char *text );
  302. // Parses a single line of text into arguments and tries to execute it
  303. // as if it was typed at the console
  304. /*
  305. ==============================================================
  306. CVAR
  307. ==============================================================
  308. */
  309. /*
  310. cvar_t variables are used to hold scalar or string variables that can be changed
  311. or displayed at the console or prog code as well as accessed directly
  312. in C code.
  313. The user can access cvars from the console in three ways:
  314. r_draworder prints the current value
  315. r_draworder 0 sets the current value to 0
  316. set r_draworder 0 as above, but creates the cvar if not present
  317. Cvars are restricted from having the same names as commands to keep this
  318. interface from being ambiguous.
  319. The are also occasionally used to communicated information between different
  320. modules of the program.
  321. */
  322. cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
  323. // creates the variable if it doesn't exist, or returns the existing one
  324. // if it exists, the value will not be changed, but flags will be ORed in
  325. // that allows variables to be unarchived without needing bitflags
  326. // if value is "", the value will not override a previously set value.
  327. void Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags );
  328. // basically a slightly modified Cvar_Get for the interpreted modules
  329. void Cvar_Update( vmCvar_t *vmCvar );
  330. // updates an interpreted modules' version of a cvar
  331. void Cvar_Set( const char *var_name, const char *value );
  332. // will create the variable with no flags if it doesn't exist
  333. void Cvar_SetLatched( const char *var_name, const char *value);
  334. // don't set the cvar immediately
  335. void Cvar_SetValue( const char *var_name, float value );
  336. // expands value to a string and calls Cvar_Set
  337. float Cvar_VariableValue( const char *var_name );
  338. int Cvar_VariableIntegerValue( const char *var_name );
  339. // returns 0 if not defined or non numeric
  340. char *Cvar_VariableString( const char *var_name );
  341. void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize );
  342. // returns an empty string if not defined
  343. void Cvar_CommandCompletion( void(*callback)(const char *s) );
  344. // callback with each valid string
  345. void Cvar_Reset( const char *var_name );
  346. void Cvar_SetCheatState( void );
  347. // reset all testing vars to a safe value
  348. qboolean Cvar_Command( void );
  349. // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
  350. // command. Returns true if the command was a variable reference that
  351. // was handled. (print or change)
  352. void Cvar_WriteVariables( fileHandle_t f );
  353. // writes lines containing "set variable value" for all variables
  354. // with the archive flag set to true.
  355. void Cvar_Init( void );
  356. char *Cvar_InfoString( int bit );
  357. char *Cvar_InfoString_Big( int bit );
  358. // returns an info string containing all the cvars that have the given bit set
  359. // in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
  360. void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
  361. void Cvar_Restart_f( void );
  362. extern int cvar_modifiedFlags;
  363. // whenever a cvar is modifed, its flags will be OR'd into this, so
  364. // a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO,
  365. // etc, variables have been modified since the last check. The bit
  366. // can then be cleared to allow another change detection.
  367. /*
  368. ==============================================================
  369. FILESYSTEM
  370. No stdio calls should be used by any part of the game, because
  371. we need to deal with all sorts of directory and seperator char
  372. issues.
  373. ==============================================================
  374. */
  375. // referenced flags
  376. // these are in loop specific order so don't change the order
  377. #define FS_GENERAL_REF 0x01
  378. #define FS_UI_REF 0x02
  379. #define FS_CGAME_REF 0x04
  380. #define FS_QAGAME_REF 0x08
  381. // number of id paks that will never be autodownloaded from baseq3
  382. #define NUM_ID_PAKS 9
  383. #define MAX_FILE_HANDLES 64
  384. #define BASEGAME "baseq3"
  385. qboolean FS_Initialized();
  386. void FS_InitFilesystem (void);
  387. void FS_Shutdown( qboolean closemfp );
  388. qboolean FS_ConditionalRestart( int checksumFeed );
  389. void FS_Restart( int checksumFeed );
  390. // shutdown and restart the filesystem so changes to fs_gamedir can take effect
  391. char **FS_ListFiles( const char *directory, const char *extension, int *numfiles );
  392. // directory should not have either a leading or trailing /
  393. // if extension is "/", only subdirectories will be returned
  394. // the returned files will not include any directories or /
  395. void FS_FreeFileList( char **list );
  396. qboolean FS_FileExists( const char *file );
  397. int FS_LoadStack();
  398. int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
  399. int FS_GetModList( char *listbuf, int bufsize );
  400. fileHandle_t FS_FOpenFileWrite( const char *qpath );
  401. // will properly create any needed paths and deal with seperater character issues
  402. int FS_filelength( fileHandle_t f );
  403. fileHandle_t FS_SV_FOpenFileWrite( const char *filename );
  404. int FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp );
  405. void FS_SV_Rename( const char *from, const char *to );
  406. int FS_FOpenFileRead( const char *qpath, fileHandle_t *file, qboolean uniqueFILE );
  407. // if uniqueFILE is true, then a new FILE will be fopened even if the file
  408. // is found in an already open pak file. If uniqueFILE is false, you must call
  409. // FS_FCloseFile instead of fclose, otherwise the pak FILE would be improperly closed
  410. // It is generally safe to always set uniqueFILE to true, because the majority of
  411. // file IO goes through FS_ReadFile, which Does The Right Thing already.
  412. int FS_FileIsInPAK(const char *filename, int *pChecksum );
  413. // returns 1 if a file is in the PAK file, otherwise -1
  414. int FS_Write( const void *buffer, int len, fileHandle_t f );
  415. int FS_Read2( void *buffer, int len, fileHandle_t f );
  416. int FS_Read( void *buffer, int len, fileHandle_t f );
  417. // properly handles partial reads and reads from other dlls
  418. void FS_FCloseFile( fileHandle_t f );
  419. // note: you can't just fclose from another DLL, due to MS libc issues
  420. int FS_ReadFile( const char *qpath, void **buffer );
  421. // returns the length of the file
  422. // a null buffer will just return the file length without loading
  423. // as a quick check for existance. -1 length == not present
  424. // A 0 byte will always be appended at the end, so string ops are safe.
  425. // the buffer should be considered read-only, because it may be cached
  426. // for other uses.
  427. void FS_ForceFlush( fileHandle_t f );
  428. // forces flush on files we're writing to.
  429. void FS_FreeFile( void *buffer );
  430. // frees the memory returned by FS_ReadFile
  431. void FS_WriteFile( const char *qpath, const void *buffer, int size );
  432. // writes a complete file, creating any subdirectories needed
  433. int FS_filelength( fileHandle_t f );
  434. // doesn't work for files that are opened from a pack file
  435. int FS_FTell( fileHandle_t f );
  436. // where are we?
  437. void FS_Flush( fileHandle_t f );
  438. void QDECL FS_Printf( fileHandle_t f, const char *fmt, ... );
  439. // like fprintf
  440. int FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode );
  441. // opens a file for reading, writing, or appending depending on the value of mode
  442. int FS_Seek( fileHandle_t f, long offset, int origin );
  443. // seek on a file (doesn't work for zip files!!!!!!!!)
  444. qboolean FS_FilenameCompare( const char *s1, const char *s2 );
  445. const char *FS_GamePureChecksum( void );
  446. // Returns the checksum of the pk3 from which the server loaded the qagame.qvm
  447. const char *FS_LoadedPakNames( void );
  448. const char *FS_LoadedPakChecksums( void );
  449. const char *FS_LoadedPakPureChecksums( void );
  450. // Returns a space separated string containing the checksums of all loaded pk3 files.
  451. // Servers with sv_pure set will get this string and pass it to clients.
  452. const char *FS_ReferencedPakNames( void );
  453. const char *FS_ReferencedPakChecksums( void );
  454. const char *FS_ReferencedPakPureChecksums( void );
  455. // Returns a space separated string containing the checksums of all loaded
  456. // AND referenced pk3 files. Servers with sv_pure set will get this string
  457. // back from clients for pure validation
  458. void FS_ClearPakReferences( int flags );
  459. // clears referenced booleans on loaded pk3s
  460. void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames );
  461. void FS_PureServerSetLoadedPaks( const char *pakSums, const char *pakNames );
  462. // If the string is empty, all data sources will be allowed.
  463. // If not empty, only pk3 files that match one of the space
  464. // separated checksums will be checked for files, with the
  465. // sole exception of .cfg files.
  466. qboolean FS_idPak( char *pak, char *base );
  467. qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring );
  468. void FS_Rename( const char *from, const char *to );
  469. /*
  470. ==============================================================
  471. Edit fields and command line history/completion
  472. ==============================================================
  473. */
  474. #define MAX_EDIT_LINE 256
  475. typedef struct {
  476. int cursor;
  477. int scroll;
  478. int widthInChars;
  479. char buffer[MAX_EDIT_LINE];
  480. } field_t;
  481. void Field_Clear( field_t *edit );
  482. void Field_CompleteCommand( field_t *edit );
  483. /*
  484. ==============================================================
  485. MISC
  486. ==============================================================
  487. */
  488. // TTimo
  489. // vsnprintf is ISO/IEC 9899:1999
  490. // abstracting this to make it portable
  491. #ifdef WIN32
  492. #define Q_vsnprintf _vsnprintf
  493. #else
  494. // TODO: do we need Mac define?
  495. #define Q_vsnprintf vsnprintf
  496. #endif
  497. // centralizing the declarations for cl_cdkey
  498. // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470
  499. extern char cl_cdkey[34];
  500. // returnbed by Sys_GetProcessorId
  501. #define CPUID_GENERIC 0 // any unrecognized processor
  502. #define CPUID_AXP 0x10
  503. #define CPUID_INTEL_UNSUPPORTED 0x20 // Intel 386/486
  504. #define CPUID_INTEL_PENTIUM 0x21 // Intel Pentium or PPro
  505. #define CPUID_INTEL_MMX 0x22 // Intel Pentium/MMX or P2/MMX
  506. #define CPUID_INTEL_KATMAI 0x23 // Intel Katmai
  507. #define CPUID_AMD_3DNOW 0x30 // AMD K6 3DNOW!
  508. // TTimo
  509. // centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
  510. #define MAXPRINTMSG 4096
  511. char *CopyString( const char *in );
  512. void Info_Print( const char *s );
  513. void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *));
  514. void Com_EndRedirect( void );
  515. void QDECL Com_Printf( const char *fmt, ... );
  516. void QDECL Com_DPrintf( const char *fmt, ... );
  517. void QDECL Com_Error( int code, const char *fmt, ... );
  518. void Com_Quit_f( void );
  519. int Com_EventLoop( void );
  520. int Com_Milliseconds( void ); // will be journaled properly
  521. unsigned Com_BlockChecksum( const void *buffer, int length );
  522. unsigned Com_BlockChecksumKey (void *buffer, int length, int key);
  523. int Com_HashKey(char *string, int maxlen);
  524. int Com_Filter(char *filter, char *name, int casesensitive);
  525. int Com_FilterPath(char *filter, char *name, int casesensitive);
  526. int Com_RealTime(qtime_t *qtime);
  527. qboolean Com_SafeMode( void );
  528. void Com_StartupVariable( const char *match );
  529. // checks for and removes command line "+set var arg" constructs
  530. // if match is NULL, all set commands will be executed, otherwise
  531. // only a set with the exact name. Only used during startup.
  532. extern cvar_t *com_developer;
  533. extern cvar_t *com_dedicated;
  534. extern cvar_t *com_speeds;
  535. extern cvar_t *com_timescale;
  536. extern cvar_t *com_sv_running;
  537. extern cvar_t *com_cl_running;
  538. extern cvar_t *com_viewlog; // 0 = hidden, 1 = visible, 2 = minimized
  539. extern cvar_t *com_version;
  540. extern cvar_t *com_blood;
  541. extern cvar_t *com_buildScript; // for building release pak files
  542. extern cvar_t *com_journal;
  543. extern cvar_t *com_cameraMode;
  544. // both client and server must agree to pause
  545. extern cvar_t *cl_paused;
  546. extern cvar_t *sv_paused;
  547. // com_speeds times
  548. extern int time_game;
  549. extern int time_frontend;
  550. extern int time_backend; // renderer backend time
  551. extern int com_frameTime;
  552. extern int com_frameMsec;
  553. extern qboolean com_errorEntered;
  554. extern fileHandle_t com_journalFile;
  555. extern fileHandle_t com_journalDataFile;
  556. typedef enum {
  557. TAG_FREE,
  558. TAG_GENERAL,
  559. TAG_BOTLIB,
  560. TAG_RENDERER,
  561. TAG_SMALL,
  562. TAG_STATIC
  563. } memtag_t;
  564. /*
  565. --- low memory ----
  566. server vm
  567. server clipmap
  568. ---mark---
  569. renderer initialization (shaders, etc)
  570. UI vm
  571. cgame vm
  572. renderer map
  573. renderer models
  574. ---free---
  575. temp file loading
  576. --- high memory ---
  577. */
  578. #if defined(_DEBUG) && !defined(BSPC)
  579. #define ZONE_DEBUG
  580. #endif
  581. #ifdef ZONE_DEBUG
  582. #define Z_TagMalloc(size, tag) Z_TagMallocDebug(size, tag, #size, __FILE__, __LINE__)
  583. #define Z_Malloc(size) Z_MallocDebug(size, #size, __FILE__, __LINE__)
  584. #define S_Malloc(size) S_MallocDebug(size, #size, __FILE__, __LINE__)
  585. void *Z_TagMallocDebug( int size, int tag, char *label, char *file, int line ); // NOT 0 filled memory
  586. void *Z_MallocDebug( int size, char *label, char *file, int line ); // returns 0 filled memory
  587. void *S_MallocDebug( int size, char *label, char *file, int line ); // returns 0 filled memory
  588. #else
  589. void *Z_TagMalloc( int size, int tag ); // NOT 0 filled memory
  590. void *Z_Malloc( int size ); // returns 0 filled memory
  591. void *S_Malloc( int size ); // NOT 0 filled memory only for small allocations
  592. #endif
  593. void Z_Free( void *ptr );
  594. void Z_FreeTags( int tag );
  595. int Z_AvailableMemory( void );
  596. void Z_LogHeap( void );
  597. void Hunk_Clear( void );
  598. void Hunk_ClearToMark( void );
  599. void Hunk_SetMark( void );
  600. qboolean Hunk_CheckMark( void );
  601. void Hunk_ClearTempMemory( void );
  602. void *Hunk_AllocateTempMemory( int size );
  603. void Hunk_FreeTempMemory( void *buf );
  604. int Hunk_MemoryRemaining( void );
  605. void Hunk_Log( void);
  606. void Hunk_Trash( void );
  607. void Com_TouchMemory( void );
  608. // commandLine should not include the executable name (argv[0])
  609. void Com_Init( char *commandLine );
  610. void Com_Frame( void );
  611. void Com_Shutdown( void );
  612. /*
  613. ==============================================================
  614. CLIENT / SERVER SYSTEMS
  615. ==============================================================
  616. */
  617. //
  618. // client interface
  619. //
  620. void CL_InitKeyCommands( void );
  621. // the keyboard binding interface must be setup before execing
  622. // config files, but the rest of client startup will happen later
  623. void CL_Init( void );
  624. void CL_Disconnect( qboolean showMainMenu );
  625. void CL_Shutdown( void );
  626. void CL_Frame( int msec );
  627. qboolean CL_GameCommand( void );
  628. void CL_KeyEvent (int key, qboolean down, unsigned time);
  629. void CL_CharEvent( int key );
  630. // char events are for field typing, not game control
  631. void CL_MouseEvent( int dx, int dy, int time );
  632. void CL_JoystickEvent( int axis, int value, int time );
  633. void CL_PacketEvent( netadr_t from, msg_t *msg );
  634. void CL_ConsolePrint( char *text );
  635. void CL_MapLoading( void );
  636. // do a screen update before starting to load a map
  637. // when the server is going to load a new map, the entire hunk
  638. // will be cleared, so the client must shutdown cgame, ui, and
  639. // the renderer
  640. void CL_ForwardCommandToServer( const char *string );
  641. // adds the current command line as a clc_clientCommand to the client message.
  642. // things like godmode, noclip, etc, are commands directed to the server,
  643. // so when they are typed in at the console, they will need to be forwarded.
  644. void CL_CDDialog( void );
  645. // bring up the "need a cd to play" dialog
  646. void CL_ShutdownAll( void );
  647. // shutdown all the client stuff
  648. void CL_FlushMemory( void );
  649. // dump all memory on an error
  650. void CL_StartHunkUsers( void );
  651. // start all the client stuff using the hunk
  652. void Key_WriteBindings( fileHandle_t f );
  653. // for writing the config files
  654. void S_ClearSoundBuffer( void );
  655. // call before filesystem access
  656. void SCR_DebugGraph (float value, int color); // FIXME: move logging to common?
  657. //
  658. // server interface
  659. //
  660. void SV_Init( void );
  661. void SV_Shutdown( char *finalmsg );
  662. void SV_Frame( int msec );
  663. void SV_PacketEvent( netadr_t from, msg_t *msg );
  664. qboolean SV_GameCommand( void );
  665. //
  666. // UI interface
  667. //
  668. qboolean UI_GameCommand( void );
  669. qboolean UI_usesUniqueCDKey();
  670. /*
  671. ==============================================================
  672. NON-PORTABLE SYSTEM SERVICES
  673. ==============================================================
  674. */
  675. typedef enum {
  676. AXIS_SIDE,
  677. AXIS_FORWARD,
  678. AXIS_UP,
  679. AXIS_ROLL,
  680. AXIS_YAW,
  681. AXIS_PITCH,
  682. MAX_JOYSTICK_AXIS
  683. } joystickAxis_t;
  684. typedef enum {
  685. // bk001129 - make sure SE_NONE is zero
  686. SE_NONE = 0, // evTime is still valid
  687. SE_KEY, // evValue is a key code, evValue2 is the down flag
  688. SE_CHAR, // evValue is an ascii char
  689. SE_MOUSE, // evValue and evValue2 are reletive signed x / y moves
  690. SE_JOYSTICK_AXIS, // evValue is an axis number and evValue2 is the current state (-127 to 127)
  691. SE_CONSOLE, // evPtr is a char*
  692. SE_PACKET // evPtr is a netadr_t followed by data bytes to evPtrLength
  693. } sysEventType_t;
  694. typedef struct {
  695. int evTime;
  696. sysEventType_t evType;
  697. int evValue, evValue2;
  698. int evPtrLength; // bytes of data pointed to by evPtr, for journaling
  699. void *evPtr; // this must be manually freed if not NULL
  700. } sysEvent_t;
  701. sysEvent_t Sys_GetEvent( void );
  702. void Sys_Init (void);
  703. // general development dll loading for virtual machine testing
  704. // fqpath param added 7/20/02 by T.Ray - Sys_LoadDll is only called in vm.c at this time
  705. void * QDECL Sys_LoadDll( const char *name, char *fqpath , int (QDECL **entryPoint)(int, ...),
  706. int (QDECL *systemcalls)(int, ...) );
  707. void Sys_UnloadDll( void *dllHandle );
  708. void Sys_UnloadGame( void );
  709. void *Sys_GetGameAPI( void *parms );
  710. void Sys_UnloadCGame( void );
  711. void *Sys_GetCGameAPI( void );
  712. void Sys_UnloadUI( void );
  713. void *Sys_GetUIAPI( void );
  714. //bot libraries
  715. void Sys_UnloadBotLib( void );
  716. void *Sys_GetBotLibAPI( void *parms );
  717. char *Sys_GetCurrentUser( void );
  718. void QDECL Sys_Error( const char *error, ...);
  719. void Sys_Quit (void);
  720. char *Sys_GetClipboardData( void ); // note that this isn't journaled...
  721. void Sys_Print( const char *msg );
  722. // Sys_Milliseconds should only be used for profiling purposes,
  723. // any game related timing information should come from event timestamps
  724. int Sys_Milliseconds (void);
  725. void Sys_SnapVector( float *v );
  726. // the system console is shown when a dedicated server is running
  727. void Sys_DisplaySystemConsole( qboolean show );
  728. int Sys_GetProcessorId( void );
  729. void Sys_BeginStreamedFile( fileHandle_t f, int readahead );
  730. void Sys_EndStreamedFile( fileHandle_t f );
  731. int Sys_StreamedRead( void *buffer, int size, int count, fileHandle_t f );
  732. void Sys_StreamSeek( fileHandle_t f, int offset, int origin );
  733. void Sys_ShowConsole( int level, qboolean quitOnClose );
  734. void Sys_SetErrorText( const char *text );
  735. void Sys_SendPacket( int length, const void *data, netadr_t to );
  736. qboolean Sys_StringToAdr( const char *s, netadr_t *a );
  737. //Does NOT parse port numbers, only base addresses.
  738. qboolean Sys_IsLANAddress (netadr_t adr);
  739. void Sys_ShowIP(void);
  740. qboolean Sys_CheckCD( void );
  741. void Sys_Mkdir( const char *path );
  742. char *Sys_Cwd( void );
  743. void Sys_SetDefaultCDPath(const char *path);
  744. char *Sys_DefaultCDPath(void);
  745. void Sys_SetDefaultInstallPath(const char *path);
  746. char *Sys_DefaultInstallPath(void);
  747. void Sys_SetDefaultHomePath(const char *path);
  748. char *Sys_DefaultHomePath(void);
  749. char **Sys_ListFiles( const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs );
  750. void Sys_FreeFileList( char **list );
  751. void Sys_BeginProfiling( void );
  752. void Sys_EndProfiling( void );
  753. qboolean Sys_LowPhysicalMemory();
  754. unsigned int Sys_ProcessorCount();
  755. int Sys_MonkeyShouldBeSpanked( void );
  756. /* This is based on the Adaptive Huffman algorithm described in Sayood's Data
  757. * Compression book. The ranks are not actually stored, but implicitly defined
  758. * by the location of a node within a doubly-linked list */
  759. #define NYT HMAX /* NYT = Not Yet Transmitted */
  760. #define INTERNAL_NODE (HMAX+1)
  761. typedef struct nodetype {
  762. struct nodetype *left, *right, *parent; /* tree structure */
  763. struct nodetype *next, *prev; /* doubly-linked list */
  764. struct nodetype **head; /* highest ranked node in block */
  765. int weight;
  766. int symbol;
  767. } node_t;
  768. #define HMAX 256 /* Maximum symbol */
  769. typedef struct {
  770. int blocNode;
  771. int blocPtrs;
  772. node_t* tree;
  773. node_t* lhead;
  774. node_t* ltail;
  775. node_t* loc[HMAX+1];
  776. node_t** freelist;
  777. node_t nodeList[768];
  778. node_t* nodePtrs[768];
  779. } huff_t;
  780. typedef struct {
  781. huff_t compressor;
  782. huff_t decompressor;
  783. } huffman_t;
  784. void Huff_Compress(msg_t *buf, int offset);
  785. void Huff_Decompress(msg_t *buf, int offset);
  786. void Huff_Init(huffman_t *huff);
  787. void Huff_addRef(huff_t* huff, byte ch);
  788. int Huff_Receive (node_t *node, int *ch, byte *fin);
  789. void Huff_transmit (huff_t *huff, int ch, byte *fout);
  790. void Huff_offsetReceive (node_t *node, int *ch, byte *fin, int *offset);
  791. void Huff_offsetTransmit (huff_t *huff, int ch, byte *fout, int *offset);
  792. void Huff_putBit( int bit, byte *fout, int *offset);
  793. int Huff_getBit( byte *fout, int *offset);
  794. extern huffman_t clientHuffTables;
  795. #define SV_ENCODE_START 4
  796. #define SV_DECODE_START 12
  797. #define CL_ENCODE_START 12
  798. #define CL_DECODE_START 4
  799. #endif // _QCOMMON_H_