OpenMoHAA 0.83.0
Loading...
Searching...
No Matches
qcommon.h
1/*
2===========================================================================
3Copyright (C) 1999-2005 Id Software, Inc.
4
5This file is part of Quake III Arena source code.
6
7Quake III Arena source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12Quake III Arena source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with Quake III Arena source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22// qcommon.h -- definitions common between client and server, but not game.or ref modules
23#ifndef _QCOMMON_H_
24#define _QCOMMON_H_
25
26#include "cm_public.h"
27#include "alias.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33//#define PRE_RELEASE_DEMO
34
35//============================================================================
36
37//
38// msg.c
39//
40typedef struct msg_s {
41 qboolean allowoverflow; // if false, do a Com_Error
42 qboolean overflowed; // set to true if the buffer size failed (with allowoverflow set)
43 qboolean oob; // set to true if the buffer size failed (with allowoverflow set)
44 byte *data;
45 size_t maxsize;
46 size_t cursize;
47 int readcount;
48 int bit; // for bitwise reads and writes
49} msg_t;
50
51void MSG_Init (msg_t *buf, byte *data, size_t length);
52void MSG_InitOOB( msg_t *buf, byte *data, size_t length );
53void MSG_Clear (msg_t *buf);
54void MSG_WriteData (msg_t *buf, const void *data, size_t length);
55void MSG_Bitstream(msg_t* buf);
56qboolean MSG_IsProtocolVersion15();
57
58// TTimo
59// copy a msg_t in case we need to store it as is for a bit
60// (as I needed this to keep an msg_t from a static var for later use)
61// sets data buffer as MSG_Init does prior to do the copy
62void MSG_Copy(msg_t *buf, byte *data, int length, msg_t *src);
63
64struct usercmd_s;
65struct entityState_s;
66struct playerState_s;
67
68void MSG_WriteBits( msg_t *msg, int value, int bits );
69
70void MSG_WriteChar (msg_t *sb, int c);
71void MSG_WriteByte (msg_t *sb, int c);
72void MSG_WriteShort (msg_t *sb, int c);
73
74void MSG_WriteSVC( msg_t *sb, int c );
75
76void MSG_WriteLong (msg_t *sb, int c);
77void MSG_WriteFloat (msg_t *sb, float f);
78void MSG_WriteString (msg_t *sb, const char *s);
79void MSG_WriteBigString (msg_t *sb, const char *s);
80void MSG_WriteScrambledString(msg_t* sb, const char* s);
81void MSG_WriteScrambledBigString(msg_t* sb, const char* s);
82void MSG_WriteAngle16 (msg_t *sb, float f);
83int MSG_HashKey(const char *string, int maxlen);
84void MSG_WriteEntityNum(msg_t* sb, short number);
85
86void MSG_BeginReading (msg_t *sb);
87void MSG_BeginReadingOOB(msg_t *sb);
88
89int MSG_ReadBits( msg_t *msg, int bits );
90
91int MSG_ReadChar (msg_t *sb);
92int MSG_ReadByte (msg_t *sb);
93int MSG_ReadSVC (msg_t *sb);
94int MSG_ReadShort (msg_t *sb);
95int MSG_ReadLong (msg_t *sb);
96
97void MSG_ReadDir( msg_t *msg, vec3_t dir );
98float MSG_ReadCoord( msg_t *msg );
99void MSG_GetNullEntityState(entityState_t *nullState);
100
101float MSG_ReadFloat (msg_t *sb);
102char *MSG_ReadString (msg_t *sb);
103char *MSG_ReadBigString (msg_t *sb);
104char *MSG_ReadStringLine( msg_t *sb );
105char* MSG_ReadScrambledString(msg_t* msg);
106char* MSG_ReadScrambledBigString(msg_t* msg);
107float MSG_ReadAngle8( msg_t *sb );
108float MSG_ReadAngle16 (msg_t *sb);
109void MSG_ReadData (msg_t *sb, void *buffer, int size);
110unsigned short MSG_ReadEntityNum(msg_t* sb);
111
112
113void MSG_WriteDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
114void MSG_ReadDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
115
116void MSG_WriteDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
117void MSG_ReadDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
118
119void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entityState_s *to
120 , qboolean force, float frameTime);
121
122void MSG_ReadSounds (msg_t *msg, server_sound_t *sounds, int *snapshot_number_of_sounds);
123void MSG_WriteSounds (msg_t *msg, server_sound_t *sounds, int snapshot_number_of_sounds);
124
125void MSG_ReadDeltaEyeInfo(msg_t *msg, usereyes_t *from, usereyes_t *to);
126
127void MSG_ReadDeltaEntity(msg_t* msg, entityState_t* from, entityState_t* to,
128 int number, float frameTime);
129
130void MSG_WriteDeltaEyeInfo (msg_t *msg, usereyes_t *from, usereyes_t *to);
131
132void MSG_WriteDeltaPlayerstate(msg_t* msg, struct playerState_s* from, struct playerState_s* to, float frameTime);
133void MSG_ReadDeltaPlayerstate(msg_t* msg, struct playerState_s* from, struct playerState_s* to, float frameTime);
134
135float MSG_ReadServerFrameTime(msg_t* msg, gameState_t* gameState);
136void MSG_WriteServerFrameTime(msg_t* msg, float value);
137
138void MSG_ReportChangeVectors_f( void );
139
140//====================
141// TA features
142//====================
143
144int MSG_PackAngle(float angle, int bits);
145int MSG_PackAnimTime(float time, int bits);
146int MSG_PackAnimWeight(float weight, int bits);
147int MSG_PackScale(float scale, int bits);
148int MSG_PackAlpha(float alpha, int bits);
149int MSG_PackCoord(float coord);
150int MSG_PackCoordExtra(float coord);
151qboolean MSG_DeltaNeeded(const void* fromField, const void* toField, int fieldType, int bits, int size);
152
153void MSG_WritePackedAngle(msg_t* msg, float value, int bits);
154void MSG_WritePackedAnimTime(msg_t* msg, float fromValue, float toValue, float frameTime, int bits);
155void MSG_WritePackedAnimWeight(msg_t* msg, float value, int bits);
156void MSG_WritePackedScale(msg_t* msg, float value, int bits);
157void MSG_WritePackedAlpha(msg_t* msg, float value, int bits);
158void MSG_WritePackedCoord(msg_t* msg, float fromValue, float toValue, int bits);
159void MSG_WritePackedCoordExtra(msg_t* msg, float fromValue, float toValue, int bits);
160void MSG_WritePackedVelocity(msg_t* msg, float value, int bits);
161void MSG_WritePackedSimple(msg_t* msg, int value, int bits);
162
163float MSG_UnpackAngle(int value, int bits);
164float MSG_UnpackAnimTime(int packed);
165float MSG_UnpackAnimWeight(int result, int bits);
166float MSG_UnpackScale(int packed);
167float MSG_UnpackAlpha(int packed, int bits);
168float MSG_UnpackCoord(int packed, int bits);
169float MSG_UnpackCoordExtra(int packed, int bits);
170
171//============================================================================
172
173/*
174==============================================================
175
176NET
177
178==============================================================
179*/
180
181#define NET_ENABLEV4 0x01
182#define NET_ENABLEV6 0x02
183// if this flag is set, always attempt ipv6 connections instead of ipv4 if a v6 address is found.
184#define NET_PRIOV6 0x04
185// disables ipv6 multicast support if set.
186#define NET_DISABLEMCAST 0x08
187
188#define PACKET_BACKUP 32 // number of old messages that must be kept on client and
189 // server for delta comrpession and ping estimation
190#define PACKET_MASK (PACKET_BACKUP-1)
191
192#define MAX_PACKET_USERCMDS 32 // max number of usercmd_t in a packet
193
194#define PORT_ANY -1
195
196#define MAX_RELIABLE_COMMANDS 512 // max string commands buffered for restransmit
197
198typedef enum {
199 NA_BAD, // an address lookup failed
200 NA_BOT,
201 NA_LOOPBACK,
202 NA_BROADCAST,
203 NA_IP,
204 NA_IPX,
205 NA_BROADCAST_IPX,
206 NA_IP6,
207 NA_MULTICAST6,
208 NA_UNSPEC
209} netadrtype_t;
210
211typedef enum {
212 //NS_MASTER,
213 NS_CLIENT,
214 NS_SERVER
215} netsrc_t;
216
217#define NET_ADDRSTRMAXLEN 48 // maximum length of an IPv6 address string including trailing '\0'
218typedef struct {
219 netadrtype_t type;
220
221 byte ip[4];
222 byte ip6[16];
223 byte ipx[10];
224
225 unsigned short port;
226 unsigned long scope_id; // Needed for IPv6 link-local addresses
227} netadr_t;
228
229void NET_Init( void );
230void NET_Shutdown( void );
231void NET_Restart_f( void );
232void NET_Config( qboolean enableNetworking );
233void NET_FlushPacketQueue(void);
234void NET_SendPacket (netsrc_t sock, size_t length, const void *data, netadr_t to);
235void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...) Q_PRINTF_FUNC(3, 4);
236void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len );
237
238qboolean NET_CompareAdr (netadr_t a, netadr_t b);
239qboolean NET_CompareBaseAdrMask(netadr_t a, netadr_t b, int netmask);
240qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
241qboolean NET_IsLocalAddress (netadr_t adr);
242const char *NET_AdrToString (netadr_t a);
243const char *NET_AdrToStringwPort (netadr_t a);
244int NET_StringToAdr ( const char *s, netadr_t *a, netadrtype_t family);
245qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
246void NET_JoinMulticast6(void);
247void NET_LeaveMulticast6(void);
248void NET_Sleep(int msec);
249
250
251#define MAX_MSGLEN 49152 // max length of a message, which may
252 // be fragmented into multiple packets
253
254#define MAX_DOWNLOAD_WINDOW 48 // ACK window of 48 download chunks. Cannot set this higher, or clients
255 // will overflow the reliable commands buffer
256#define MAX_DOWNLOAD_BLKSIZE 1024 // 896 byte block chunks
257
258#define NETCHAN_GENCHECKSUM(challenge, sequence) ((challenge) ^ ((sequence) * (challenge)))
259
260
261/*
262Netchan handles packet fragmentation and out of order / duplicate suppression
263*/
264
265typedef struct {
266 netsrc_t sock;
267
268 int dropped; // between last packet and previous
269
270 netadr_t remoteAddress;
271 int qport; // qport value to write when transmitting
272
273 // sequencing variables
274 int incomingSequence;
275 int outgoingSequence;
276
277 // incoming fragment assembly buffer
278 int fragmentSequence;
279 int fragmentLength;
280 byte fragmentBuffer[MAX_MSGLEN];
281
282 // outgoing fragment buffer
283 // we need to space out the sending of large fragmented messages
284 qboolean unsentFragments;
285 size_t unsentFragmentStart;
286 size_t unsentLength;
287 byte unsentBuffer[MAX_MSGLEN];
288
289 int challenge;
290 int lastSentTime;
291 int lastSentSize;
292
293#ifdef LEGACY_PROTOCOL
294 qboolean compat;
295#endif
296} netchan_t;
297
298/*
299Packet profiling
300*/
301
302#define NETPROF_PACKET_FRAGMENTED 1
303#define NETPROF_PACKET_DROPPED 2
304#define NETPROF_PACKET_MESSAGE 4
305
306#define NETPROX_MAX_PACKETS 64
307
308typedef struct {
309 int updateTime;
310 int size;
311 int flags;
313
314typedef struct {
315 int updateTime;
316 int index;
317 netprofpacket_t packets[NETPROX_MAX_PACKETS];
318 int lastCalcTime;
319 int lowestUpdateTime;
320 int highestUpdateTime;
321 int totalProcessed;
322 int totalSize;
323 int numFragmented;
324 int numDropped;
325 int numConnectionLess;
326 int totalLengthConnectionLess;
327 int packetsPerSec;
328 int bytesPerSec;
329 int percentFragmented;
330 int percentDropped;
331 int percentConnectionLess;
332 float latency;
334
335typedef struct {
336 qboolean initialized;
337 int rate;
338 netprofpacketlist_t outPackets;
339 netprofpacketlist_t inPackets;
341
342void Netchan_Init( int qport );
343void Netchan_Setup(netsrc_t sock, netchan_t *chan, netadr_t adr, int qport, int challenge, qboolean compat);
344
345void Netchan_Transmit( netchan_t *chan, size_t length, const byte *data, netprofpacketlist_t *packetlist );
346void Netchan_TransmitNextFragment( netchan_t *chan, netprofpacketlist_t *packetlist );
347
348qboolean Netchan_Process( netchan_t *chan, msg_t *msg, netprofpacketlist_t *packetlist );
349
350void NetProfileAddPacket(netprofpacketlist_t* list, size_t size, int flags);
351void NetProfileSetPacketFlags(netprofpacketlist_t* list, int flags);
352void NetProfileCalcStats(netprofpacketlist_t* list, int time);
353
354/*
355==============================================================
356
357PROTOCOL
358
359==============================================================
360*/
361
362#define PROTOCOL_VERSION 17
363#define PROTOCOL_LEGACY_VERSION PROTOCOL_VERSION
364// su44: MoHAA v 1.00 uses protocol version 6
365
366// maintain a list of compatible protocols for demo playing
367// NOTE: that stuff only works with two digits protocols
368extern int demo_protocols[];
369
370// fixme : we need a new master server address
371
372#define UPDATE_SERVER_NAME "updatemoh.2015.com"
373// override on command line, config files etc.
374#ifndef MASTER_SERVER_NAME
375#define MASTER_SERVER_NAME "master.2015.com"
376#endif
377#ifndef AUTHORIZE_SERVER_NAME
378#define AUTHORIZE_SERVER_NAME "authorize.2015.com"
379#endif
380
381#define PORT_MASTER 27950
382#define PORT_UPDATE 27951
383#ifndef PORT_AUTHORIZE
384#define PORT_AUTHORIZE 27952
385#endif
386#define PORT_SERVER 12203
387#define NUM_SERVER_PORTS 4 // broadcast scan this many ports after
388 // PORT_SERVER so a single machine can
389 // run multiple servers
390
391
392// the svc_strings[] array in cl_parse.c should mirror this
393//
394// server to client
395//
396enum svc_ops_e {
397 svc_bad,
398 svc_nop,
399 svc_gamestate,
400 svc_configstring, // [short] [string] only in gamestate messages
401 svc_baseline, // only in gamestate messages
402 svc_serverCommand, // [string] to be executed by client game module
403 svc_download, // [short] size [size bytes]
404 svc_snapshot,
405 svc_centerprint,
406 svc_locprint,
407 svc_cgameMessage,
408 svc_EOF,
409
410// new commands, supported only by ioquake3 protocol but not legacy
411 svc_voipSpeex, // not wrapped in USE_VOIP, so this value is reserved.
412 svc_voipOpus, //
413};
414
415//
416// client to server
417//
418enum clc_ops_e {
419 clc_bad,
420 clc_nop,
421 clc_move, // [[usercmd_t]
422 clc_moveNoDelta, // [[usercmd_t]
423 clc_clientCommand, // [string] message
424 clc_EOF,
425
426// new commands, supported only by ioquake3 protocol but not legacy
427 clc_voipSpeex, // not wrapped in USE_VOIP, so this value is reserved.
428 clc_voipOpus, //
429};
430
431/*
432==============================================================
433
434VIRTUAL MACHINE
435
436==============================================================
437*/
438
439typedef struct vm_s vm_t;
440
441typedef enum {
442 VMI_NATIVE,
443 VMI_BYTECODE,
444 VMI_COMPILED
445} vmInterpret_t;
446
447typedef enum {
448 TRAP_MEMSET = 100,
449 TRAP_MEMCPY,
450 TRAP_STRNCPY,
451 TRAP_SIN,
452 TRAP_COS,
453 TRAP_ATAN2,
454 TRAP_SQRT,
455 TRAP_MATRIXMULTIPLY,
456 TRAP_ANGLEVECTORS,
457 TRAP_PERPENDICULARVECTOR,
458 TRAP_FLOOR,
459 TRAP_CEIL,
460
461 TRAP_TESTPRINTINT,
462 TRAP_TESTPRINTFLOAT
463} sharedTraps_t;
464
465typedef intptr_t (QDECL *vmMainProc)(int callNum, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11);
466
467void VM_Init( void );
468vm_t *VM_Create( const char *module, intptr_t (*systemCalls)(intptr_t *),
469 vmInterpret_t interpret );
470// module should be bare: "cgame", not "cgame.dll" or "vm/cgame.qvm"
471
472void VM_Free( vm_t *vm );
473void VM_Clear(void);
474void VM_Forced_Unload_Start(void);
475void VM_Forced_Unload_Done(void);
476vm_t *VM_Restart(vm_t *vm, qboolean unpure);
477
478intptr_t QDECL VM_Call( vm_t *vm, int callNum, ... );
479
480void VM_Debug( int level );
481
482void *VM_ArgPtr( intptr_t intValue );
483void *VM_ExplicitArgPtr( vm_t *vm, intptr_t intValue );
484
485#define VMA(x) VM_ArgPtr(args[x])
486static ID_INLINE float _vmf(intptr_t x)
487{
488 floatint_t fi;
489 fi.i = (int)x;
490 return fi.f;
491}
492#define VMF(x) _vmf(args[x])
493
494
495/*
496==============================================================
497
498CMD
499
500Command text buffering and command execution
501
502==============================================================
503*/
504
505/*
506
507Any number of commands can be added in a frame, from several different sources.
508Most commands come from either keybindings or console line input, but entire text
509files can be execed.
510
511*/
512
513void Cbuf_Init (void);
514// allocates an initial text buffer that will grow as needed
515
516void Cbuf_AddText( const char *text );
517// Adds command text at the end of the buffer, does NOT add a final \n
518
519void Cbuf_ExecuteText(int exec_when, const char *text );
520// this can be used in place of either Cbuf_AddText or Cbuf_InsertText
521
522void Cbuf_Execute (int msec);
523// Pulls off \n terminated lines of text from the command buffer and sends
524// them through Cmd_ExecuteString. Stops when the buffer is empty.
525// Normally called once per frame, but may be explicitly invoked.
526// Do not call inside a command function, or current args will be destroyed.
527
528void Cmd_WriteAliases( fileHandle_t f );
529
530//===========================================================================
531
532/*
533
534Command execution takes a null terminated string, breaks it into tokens,
535then searches for a command or variable that matches the first token.
536
537*/
538
539typedef void (*xcommand_t) (void);
540
541void Cmd_Init (void);
542
543void Cmd_AddCommand( const char *cmd_name, xcommand_t function );
544// called by the init functions of other parts of the program to
545// register commands and functions to call for them.
546// The cmd_name is referenced later, so it should not be in temp memory
547// if function is NULL, the command will be forwarded to the server
548// as a clc_clientCommand instead of executed locally
549
550void Cmd_RemoveCommand( const char *cmd_name );
551
552typedef void (*completionFunc_t)( const char *args, int argNum );
553
554// don't allow VMs to remove system commands
555void Cmd_RemoveCommandSafe( const char *cmd_name );
556
557void Cmd_CommandCompletion( void(*callback)(const char *s) );
558// callback with each valid string
559void Cmd_SetCommandCompletionFunc( const char *command,
560 completionFunc_t complete );
561void Cmd_CompleteArgument( const char *command, char *args, int argNum );
562void Cmd_CompleteCfgName( const char *args, int argNum );
563void Cmd_CommandCompletion( void(*callback)(const char *s) );
564const char* Cmd_CompleteCommandByNumber(const char* partial, int number);
565// callback with each valid string
566
567int Cmd_Argc (void);
568char *Cmd_Argv (int arg);
569void Cmd_ArgvBuffer( int arg, char *buffer, int bufferLength );
570char *Cmd_Args (void);
571char *Cmd_ArgsFrom( int arg );
572void Cmd_ArgsBuffer( char *buffer, int bufferLength );
573char *Cmd_Cmd (void);
574void Cmd_Args_Sanitize( void );
575// The functions that execute commands get their parameters with these
576// functions. Cmd_Argv () will return an empty string, not a NULL
577// if arg > argc, so string operations are allways safe.
578
579void Cmd_TokenizeString( const char *text );
580void Cmd_TokenizeStringIgnoreQuotes( const char *text_in );
581// Takes a null terminated string. Does not need to be /n terminated.
582// breaks the string up into arg tokens.
583
584void Cmd_ExecuteString( const char *text );
585// Parses a single line of text into arguments and tries to execute it
586// as if it was typed at the console
587
588
589/*
590==============================================================
591
592CVAR
593
594==============================================================
595*/
596
597/*
598
599cvar_t variables are used to hold scalar or string variables that can be changed
600or displayed at the console or prog code as well as accessed directly
601in C code.
602
603The user can access cvars from the console in three ways:
604r_draworder prints the current value
605r_draworder 0 sets the current value to 0
606set r_draworder 0 as above, but creates the cvar if not present
607
608Cvars are restricted from having the same names as commands to keep this
609interface from being ambiguous.
610
611The are also occasionally used to communicated information between different
612modules of the program.
613
614*/
615
616// sets the default value of a variable
617void Cvar_SetDefault( cvar_t *var, const char *var_value );
618
619cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
620// creates the variable if it doesn't exist, or returns the existing one
621// if it exists, the value will not be changed, but flags will be ORed in
622// that allows variables to be unarchived without needing bitflags
623// if value is "", the value will not override a previously set value.
624
625void Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags );
626// basically a slightly modified Cvar_Get for the interpreted modules
627
628void Cvar_Update( vmCvar_t *vmCvar );
629// updates an interpreted modules' version of a cvar
630
631void Cvar_Set( const char *var_name, const char *value );
632// will create the variable with no flags if it doesn't exist
633
634cvar_t *Cvar_Set2( const char *var_name, const char *value, qboolean force );
635// will create the variable with no flags if it doesn't exist
636// can force
637
638cvar_t *Cvar_Next( cvar_t *var );
639// gets the next var
640
641void Cvar_SetLatched( const char *var_name, const char *value);
642// don't set the cvar immediately
643
644void Cvar_SetValue( const char *var_name, float value );
645// expands value to a string and calls Cvar_Set
646
647cvar_t *Cvar_FindVar( const char *var_name );
648float Cvar_VariableValue( const char *var_name );
649int Cvar_VariableIntegerValue(const char* var_name);
650float Cvar_VariableFloatValue(const char* var_name);
651// returns 0 if not defined or non numeric
652
653char *Cvar_VariableString( const char *var_name );
654void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize );
655
656// find a compelte variable
657const char *Cvar_CompleteVariable( const char *partial );
658const char *Cvar_CompleteVariableByNumber( const char *partial, int number );
659// returns an empty string if not defined
660
661int Cvar_Flags(const char *var_name);
662// returns CVAR_NONEXISTENT if cvar doesn't exist or the flags of that particular CVAR.
663
664void Cvar_CommandCompletion( void(*callback)(const char *s) );
665// callback with each valid string
666
667void Cvar_Reset( const char *var_name );
668void Cvar_ForceReset(const char *var_name);
669
670void Cvar_SetCheatState( void );
671// reset all testing vars to a safe value
672
673qboolean Cvar_Command( void );
674// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
675// command. Returns true if the command was a variable reference that
676// was handled. (print or change)
677
678void Cvar_WriteVariables( fileHandle_t f );
679// writes lines containing "set variable value" for all variables
680// with the archive flag set to true.
681
682void Cvar_Init( void );
683
684char *Cvar_InfoString( int bit );
685char *Cvar_InfoString_Big( int bit );
686// returns an info string containing all the cvars that have the given bit set
687// in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
688void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
689void Cvar_CheckRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral );
690void Cvar_SetDescription( cvar_t *var, const char *var_description );
691
692void Cvar_Restart(qboolean unsetVM);
693void Cvar_Restart_f( void );
694void Cvar_SaveGameRestart_f( void );
695
696void Cvar_CompleteCvarName(const char* args, int argNum);
697
698cvar_t *Cvar_Unset(cvar_t *cv);
699
700extern int cvar_modifiedFlags;
701extern qboolean cvar_global_force;
702// whenever a cvar is modifed, its flags will be OR'd into this, so
703// a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO,
704// etc, variables have been modified since the last check. The bit
705// can then be cleared to allow another change detection.
706
707/*
708==============================================================
709
710FILESYSTEM
711
712No stdio calls should be used by any part of the game, because
713we need to deal with all sorts of directory and seperator char
714issues.
715==============================================================
716*/
717
718// referenced flags
719// these are in loop specific order so don't change the order
720#define FS_GENERAL_REF 0x01
721#define FS_UI_REF 0x02
722#define FS_CGAME_REF 0x04
723#define FS_QAGAME_REF 0x08
724// number of id paks that will never be autodownloaded from baseq3
725#define NUM_ID_PAKS 5
726
727#define MAX_FILE_HANDLES 64
728
729#ifdef DEDICATED
730# define Q3CONFIG_CFG "q3config_server.cfg"
731#else
732# define Q3CONFIG_CFG "q3config.cfg"
733#endif
734
735qboolean FS_Initialized( void );
736
737void FS_InitFilesystem( void );
738void FS_Shutdown( qboolean closemfp );
739
740qboolean FS_ConditionalRestart( int checksumFeed, qboolean disconnect );
741void FS_Restart( int checksumFeed );
742// shutdown and restart the filesystem so changes to fs_gamedir can take effect
743
744char **FS_ListFilteredFiles( const char *path, const char *extension, const char *filter, qboolean wantSubs, int *numfiles, qboolean allowNonPureFilesOnDisk );
745char **FS_ListFiles( const char *directory, const char *extension, qboolean wantSubs, int *numfiles );
746// directory should not have either a leading or trailing /
747// if extension is "/", only subdirectories will be returned
748// the returned files will not include any directories or /
749
750void FS_FreeFileList( char **list );
751
752qboolean FS_FileExists( const char *file );
753
754void FS_CorrectCase(char* path);
755qboolean FS_CreatePath (const char *OSPath);
756
757char *FS_BaseDir_BuildOSPath( const char *base, const char *qpath );
758char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
759
760int FS_LoadStack( void );
761
762int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
763int FS_GetModList( char *listbuf, int bufsize );
764
765void FS_GetModDescription(const char* modDir, char* description, int descriptionLen);
766
767fileHandle_t FS_FOpenFileWrite( const char *qpath );
768fileHandle_t FS_FOpenFileAppend( const char *filename );
769fileHandle_t FS_FCreateOpenPipeFile( const char *filename );
770fileHandle_t FS_FOpenTextFileWrite(const char* qpath);
771// will properly create any needed paths and deal with seperater character issues
772
773fileHandle_t FS_BaseDir_FOpenFileWrite( const char *filename );
774long FS_BaseDir_FOpenFileRead( const char *filename, fileHandle_t *fp );
775void FS_BaseDir_Rename( const char *from, const char *to, qboolean safe );
776void FS_DeleteFile( const char *filename );
777void FS_CanonicalFilename( char *filename );
778
779long FS_FOpenFileRead(const char* filename, fileHandle_t* file, qboolean uniqueFILE, qboolean quiet);
780// if uniqueFILE is true, then a new FILE will be fopened even if the file
781// is found in an already open pak file. If uniqueFILE is false, you must call
782// FS_FCloseFile instead of fclose, otherwise the pak FILE would be improperly closed
783// It is generally safe to always set uniqueFILE to true, because the majority of
784// file IO goes through FS_ReadFile, which Does The Right Thing already.
785
786int FS_FileIsInPAK(const char *filename, int *pChecksum );
787// returns 1 if a file is in the PAK file, otherwise -1
788
789size_t FS_Write( const void *buffer, size_t len, fileHandle_t f );
790
791size_t FS_Read( void *buffer, size_t len, fileHandle_t f );
792// properly handles partial reads and reads from other dlls
793
794void FS_FCloseFile( fileHandle_t f );
795// note: you can't just fclose from another DLL, due to MS libc issues
796
797long FS_ReadFileEx(const char* qpath, void** buffer, qboolean quiet);
798long FS_ReadFile(const char* qpath, void** buffer);
799const char *FS_Gamedir( void );
800// returns the length of the file
801// a null buffer will just return the file length without loading
802// as a quick check for existance. -1 length == not present
803// A 0 byte will always be appended at the end, so string ops are safe.
804// the buffer should be considered read-only, because it may be cached
805// for other uses.
806
807void FS_ForceFlush( fileHandle_t f );
808// forces flush on files we're writing to.
809
810void FS_FreeFile( void *buffer );
811// frees the memory returned by FS_ReadFile
812
813
814const char *FS_PrepFileWrite( const char *filename );
815// prepares the file to be written
816
817int FS_WriteFile( const char *qpath, const void *buffer, int size );
818// writes a complete file, creating any subdirectories needed
819
820void FS_WriteTextFile( const char *qpath, const void *buffer, int size );
821// writes a complete text file, creating any subdirectories needed
822
823long FS_filelength(fileHandle_t f);
824// doesn't work for files that are opened from a pack file
825
826int FS_FTell( fileHandle_t f );
827// where are we?
828
829void FS_Flush( fileHandle_t f );
830
831void QDECL FS_Printf( fileHandle_t f, const char *fmt, ... ) Q_PRINTF_FUNC(2, 3);
832// like fprintf
833
834int FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode );
835// opens a file for reading, writing, or appending depending on the value of mode
836
837int FS_Seek( fileHandle_t f, long offset, int origin );
838// seek on a file (doesn't work for zip files!!!!!!!!)
839
840qboolean FS_FilenameCompare( const char *s1, const char *s2 );
841qboolean FS_FileNewer( const char *source, const char *destination );
842
843const char *FS_GamePureChecksum( void );
844// Returns the checksum of the pk3 from which the server loaded the qagame.qvm
845
846const char *FS_LoadedPakNames( void );
847const char *FS_LoadedPakChecksums( void );
848const char *FS_LoadedPakPureChecksums( void );
849// Returns a space separated string containing the checksums of all loaded pk3 files.
850// Servers with sv_pure set will get this string and pass it to clients.
851
852const char *FS_ReferencedPakNames( void );
853const char *FS_ReferencedPakChecksums( void );
854const char *FS_ReferencedPakPureChecksums( void );
855// Returns a space separated string containing the checksums of all loaded
856// AND referenced pk3 files. Servers with sv_pure set will get this string
857// back from clients for pure validation
858
859void FS_ClearPakReferences( int flags );
860// clears referenced booleans on loaded pk3s
861
862void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames );
863void FS_PureServerSetLoadedPaks( const char *pakSums, const char *pakNames );
864// If the string is empty, all data sources will be allowed.
865// If not empty, only pk3 files that match one of the space
866// separated checksums will be checked for files, with the
867// sole exception of .cfg files.
868
869qboolean FS_CheckDirTraversal(const char *checkdir);
870qboolean FS_idPak(const char *pak, const char *base);
871qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring );
872
873void FS_Remove( const char *osPath );
874
875void FS_FilenameCompletion( const char *dir, const char *ext,
876 qboolean stripExt, void(*callback)(const char *s), qboolean allowNonPureFilesOnDisk );
877
878const char* FS_GetCurrentGameDir();
879void FS_GetRelativeFilename( const char *currentDirectory, const char *absoluteFilename, char *out, size_t destlen );
880
881void FS_FileTime(const char* filename, char* date, char* size);
882
883void FS_CorrectCase(char* path);
884
885extern cvar_t* fs_debug;
886extern cvar_t* fs_mapdir;
887
888/*
889==============================================================
890
891Edit fields and command line history/completion
892
893==============================================================
894*/
895
896#define MAX_EDIT_LINE 256
897typedef struct {
898 int cursor;
899 int scroll;
900 int widthInChars;
901 char buffer[MAX_EDIT_LINE];
902} field_t;
903
904void Field_Clear( field_t *edit );
905void Field_AutoComplete( field_t *edit );
906void Field_CompleteKeyname( void );
907void Field_CompleteFilename( const char *dir,
908 const char *ext, qboolean stripExt, qboolean allowNonPureFilesOnDisk );
909void Field_CompleteCommand( char *cmd,
910 qboolean doCommands, qboolean doCvars );
911void Field_CompletePlayerName( const char **names, int count );
912/*
913==============================================================
914
915MISC
916
917==============================================================
918*/
919
920// returnbed by Sys_GetProcessorId
921#define CPUID_GENERIC 0 // any unrecognized processor
922
923#define CPUID_AXP 0x10
924
925#define CPUID_INTEL_UNSUPPORTED 0x20 // Intel 386/486
926#define CPUID_INTEL_PENTIUM 0x21 // Intel Pentium or PPro
927#define CPUID_INTEL_MMX 0x22 // Intel Pentium/MMX or P2/MMX
928#define CPUID_INTEL_KATMAI 0x23 // Intel Katmai
929
930#define CPUID_AMD_3DNOW 0x30 // AMD K6 3DNOW!
931
932/*
933==============================================================
934
935MISC
936
937==============================================================
938*/
939
940// vsnprintf is ISO/IEC 9899:1999
941// abstracting this to make it portable
942#ifdef _WIN32
943#define Q_vsnprintf _vsnprintf
944#define Q_snprintf _snprintf
945#else
946#define Q_vsnprintf vsnprintf
947#define Q_snprintf snprintf
948#endif
949
950// centralizing the declarations for cl_cdkey
951// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470
952extern char cl_cdkey[34];
953
954// returned by Sys_GetProcessorFeatures
955typedef enum
956{
957 CF_RDTSC = 1 << 0,
958 CF_MMX = 1 << 1,
959 CF_MMX_EXT = 1 << 2,
960 CF_3DNOW = 1 << 3,
961 CF_3DNOW_EXT = 1 << 4,
962 CF_SSE = 1 << 5,
963 CF_SSE2 = 1 << 6,
964 CF_ALTIVEC = 1 << 7
965} cpuFeatures_t;
966
967// centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
968#define MAXPRINTMSG 4096
969
970
971#define MAX_RENDER_STRINGS 8
972#define MAX_RENDER_STRING_LENGTH 32
973
974char *CopyString( const char *in );
975void Info_Print( const char *s );
976
977void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *));
978void Com_EndRedirect( void );
979void QDECL Com_Printf( const char *fmt, ... ) Q_PRINTF_FUNC(1, 2);
980void QDECL Com_DPrintf( const char *fmt, ... ) Q_PRINTF_FUNC(1, 2);
981void QDECL Com_Error( int code, const char *fmt, ... ) Q_NO_RETURN Q_PRINTF_FUNC(2, 3);
982void Com_Quit_f( void ) Q_NO_RETURN;
983void Com_GameRestart(int checksumFeed, qboolean disconnect);
984
985int Com_Milliseconds( void ); // will be journaled properly
986unsigned Com_BlockChecksum( const void *buffer, int length );
987char *Com_MD5File(const char *filename, int length, const char *prefix, int prefix_len);
988int Com_HashKey(char *string, int maxlen);
989int Com_Filter(const char *filter, const char *name, int casesensitive);
990int Com_FilterPath(const char *filter, const char *name, int casesensitive);
991int Com_RealTime(qtime_t *qtime);
992qboolean Com_SafeMode( void );
993void Com_RunAndTimeServerPacket(netadr_t *evFrom, msg_t *buf);
994
995qboolean Com_IsVoipTarget(uint8_t *voipTargets, int voipTargetsSize, int clientNum);
996
997void Com_StartupVariable( const char *match );
998// checks for and removes command line "+set var arg" constructs
999// if match is NULL, all set commands will be executed, otherwise
1000// only a set with the exact name. Only used during startup.
1001qboolean Com_PlayerNameToFieldString( char *str, int length, const char *name );
1002qboolean Com_FieldStringToPlayerName( char *name, int length, const char *rawname );
1003int QDECL Com_strCompare( const void *a, const void *b );
1004
1005
1006extern float currentfps;
1007extern cvar_t *paused;
1008extern cvar_t *config;
1009extern cvar_t *fps;
1010extern cvar_t *developer;
1011extern cvar_t *com_dedicated;
1012extern cvar_t *com_speeds;
1013extern cvar_t *com_timescale;
1014extern cvar_t *com_sv_running;
1015extern cvar_t *com_cl_running;
1016extern cvar_t *com_viewlog; // 0 = hidden, 1 = visible, 2 = minimized
1017extern cvar_t *com_shortversion;
1018extern cvar_t *com_version;
1019extern cvar_t *autopaused;
1020extern cvar_t *deathmatch;
1021extern cvar_t *com_blood;
1022extern cvar_t *com_buildScript; // for building release pak files
1023extern cvar_t *com_radar_range;
1024extern cvar_t *console_spam_filter;
1025extern cvar_t *com_journal;
1026extern cvar_t *com_cameraMode;
1027extern cvar_t *com_ansiColor;
1028extern cvar_t *com_unfocused;
1029extern cvar_t *com_maxfpsUnfocused;
1030extern cvar_t *com_minimized;
1031extern cvar_t *com_maxfpsMinimized;
1032extern cvar_t *com_altivec;
1033extern cvar_t *com_standalone;
1034extern cvar_t *com_gamename;
1035extern cvar_t *com_basegame;
1036extern cvar_t *com_homepath;
1037extern cvar_t *com_altivec;
1038
1039// both client and server must agree to pause
1040extern cvar_t *cl_paused;
1041extern cvar_t *sv_paused;
1042
1043extern cvar_t *cl_packetdelay;
1044extern cvar_t *sv_packetdelay;
1045
1046extern cvar_t* com_protocol;
1047#ifdef LEGACY_PROTOCOL
1048extern cvar_t* com_legacyprotocol;
1049#endif
1050#ifndef DEDICATED
1051extern cvar_t* con_autochat;
1052#endif
1053extern cvar_t* com_target_game;
1054extern cvar_t* com_target_shortversion;
1055extern cvar_t* com_target_version;
1056extern cvar_t* com_target_extension;
1057extern cvar_t* com_target_demo;
1058
1059extern cvar_t* com_updatecheck_enabled;
1060extern cvar_t* com_updatecheck_interval;
1061
1062extern int protocol_version_demo;
1063extern int protocol_version_full;
1064
1065// com_speeds times
1066extern int time_game;
1067extern int time_frontend;
1068extern int time_backend; // renderer backend time
1069
1070extern int com_frameTime;
1071extern int com_frameMsec;
1072
1073extern qboolean com_errorEntered;
1074extern qboolean com_fullyInitialized;
1075extern qboolean com_gotOriginalConfig;
1076
1077extern fileHandle_t com_journalFile;
1078extern fileHandle_t com_journalDataFile;
1079
1080typedef enum {
1081 TAG_FREE,
1082 TAG_CONST,
1083 TAG_GENERAL,
1084 TAG_BOTLIB,
1085 TAG_RENDERER, // memory allocated from renderer
1086 TAG_GAME, // memory allocated from game
1087 TAG_CGAME, // memory allocated from client game
1088 TAG_CLIENT, // memory allocated from client
1089 TAG_TIKI, // su44: memory allocated by qcommon/tiki.c code
1090 TAG_STRINGS_AND_COMMANDS,
1091 TAG_SOUND, // memory allocated from sound
1092 TAG_STATIC,
1093 TAG_STATIC_RENDERER,
1094 TAG_SKEL, // memory allocated from skeletor
1095 TAG_TEMP, // temporary memory
1096 TAG_EXE,
1097 TAG_NUM_TOTAL_TAGS
1098} memtag_t;
1099
1100/*
1101
1102--- low memory ----
1103server vm
1104server clipmap
1105---mark---
1106renderer initialization (shaders, etc)
1107UI vm
1108cgame vm
1109renderer map
1110renderer models
1111
1112---free---
1113
1114temp file loading
1115--- high memory ---
1116
1117*/
1118
1119#if defined(_DEBUG) && !defined(BSPC)
1120 #define ZONE_DEBUG
1121#endif
1122
1123#ifdef ZONE_DEBUG
1124#define Z_TagMalloc(size, tag) Z_TagMallocDebug(size, tag, #size, __FILE__, __LINE__)
1125#define Z_Malloc(size) Z_MallocDebug(size, #size, __FILE__, __LINE__)
1126#define S_Malloc(size) S_MallocDebug(size, #size, __FILE__, __LINE__)
1127void *Z_TagMallocDebug( int size, int tag, const char *label, const char *file, int line ); // NOT 0 filled memory
1128void *Z_MallocDebug( int size, const char *label, const char *file, int line ); // returns 0 filled memory
1129void *S_MallocDebug( int size, const char *label, const char *file, int line ); // returns 0 filled memory
1130#else
1131void *Z_TagMalloc( int size, int tag ); // NOT 0 filled memory
1132void *Z_Malloc( int size ); // returns 0 filled memory
1133void *S_Malloc( int size ); // NOT 0 filled memory only for small allocations
1134#endif
1135void Z_Free( void *ptr );
1136void Z_FreeTags( int tag );
1137int Z_AvailableMemory( void );
1138void Z_LogHeap( void );
1139
1140void Hunk_Clear( void );
1141void Hunk_ClearToMark( void );
1142void Hunk_SetMark( void );
1143qboolean Hunk_CheckMark( void );
1144void Hunk_ClearTempMemory( void );
1145void *Hunk_AllocateTempMemory( int size );
1146void Hunk_FreeTempMemory( void *buf );
1147int Hunk_MemoryRemaining( void );
1148void Hunk_Log( void);
1149
1150void Com_TouchMemory( void );
1151
1152const char* Z_EmptyStringPointer(void);
1153const char* Z_NumberStringPointer(int iNum);
1154
1155// commandLine should not include the executable name (argv[0])
1156void Com_Init( char *commandLine );
1157void Com_Frame( void );
1158void Com_Shutdown( void );
1159
1160qboolean Com_SanitizeName( const char *pszOldName, char *pszNewName, size_t bufferSize );
1161const char *Com_GetArchiveFileName( const char *filename, const char *extension );
1162const char *Com_GetArchiveFolder();
1163void Com_WipeSavegame( const char *savename );
1164qboolean Com_ShiftedStrStr(const char* shifted, const char* name, int offset);
1165qboolean COM_IsMapValid(const char* name);
1166void Com_SwapSaveStruct(savegamestruct_t* save);
1167
1168
1169/*
1170==============================================================
1171
1172CLIENT / SERVER SYSTEMS
1173
1174==============================================================
1175*/
1176
1177//
1178// client interface
1179//
1180void CL_InitKeyCommands( void );
1181// the keyboard binding interface must be setup before execing
1182// config files, but the rest of client startup will happen later
1183
1184void CL_Init( void );
1185void CL_Disconnect();
1186void CL_AbnormalDisconnect();
1187void CL_Shutdown(const char *finalmsg, qboolean disconnect, qboolean quit);
1188qboolean CL_FinishedIntro(void);
1189void CL_FinishedStartStage(void);
1190void CL_SetFrameNumber(int frameNumber);
1191void CL_Frame( int msec );
1192qboolean CL_GameCommand( void );
1193void CL_KeyEvent (int key, qboolean down, unsigned time);
1194
1195void CL_Key_ForceCommand(int key, unsigned int time);
1196
1197void CL_CharEvent( int key );
1198// char events are for field typing, not game control
1199
1200void CL_GetMouseState( int *x, int *y, unsigned int *buttons );
1201
1202void CL_SetMousePos( int x, int y );
1203
1204void CL_MouseEvent( int dx, int dy, int time );
1205
1206void CL_ClearButtons( void );
1207
1208void CL_JoystickEvent( int axis, int value, int time );
1209
1210void CL_PacketEvent( netadr_t from, msg_t *msg );
1211
1212void CL_MapLoading( qboolean flush, const char *pszMapName );
1213// do a screen update before starting to load a map
1214// when the server is going to load a new map, the entire hunk
1215// will be cleared, so the client must shutdown cgame, ui, and
1216// the renderer
1217
1218void CL_ForwardCommandToServer( const char *string );
1219// adds the current command line as a clc_clientCommand to the client message.
1220// things like godmode, noclip, etc, are commands directed to the server,
1221// so when they are typed in at the console, they will need to be forwarded.
1222
1223qboolean CL_UseLargeLightmap(const char* mapName);
1224// returns true if the standard BSP file should be used
1225
1226void CL_CDDialog( void );
1227// bring up the "need a cd to play" dialog
1228
1229void CL_FlushMemory( void );
1230// dump all memory on an error
1231
1232void CL_ShutdownAll(qboolean shutdownRef);
1233// shutdown client
1234
1235void CL_InitRef(void);
1236// initialize renderer interface
1237
1238void CL_StartHunkUsers( qboolean rendererOnly );
1239// start all the client stuff using the hunk
1240
1241void CL_Snd_Shutdown(void);
1242// Restart sound subsystem
1243
1244void Key_KeynameCompletion( void(*callback)(const char *s) );
1245// for keyname autocompletion
1246
1247void Key_WriteBindings( fileHandle_t f );
1248// for writing the config files
1249
1250void S_ClearSoundBuffer( void );
1251// call before filesystem access
1252
1253float *get_camera_offset( qboolean *lookactive, qboolean *resetview );
1254
1255// AVI files have the start of pixel lines 4 byte-aligned
1256#define AVI_LINE_PADDING 4
1257
1258//
1259// server interface
1260//
1261void SV_ServerLoaded( void );
1262void SV_Init( void );
1263void SV_Shutdown( const char *finalmsg );
1264void SV_SetFrameNumber(int frameNumber);
1265void SV_Frame( int msec );
1266void SV_PacketEvent( netadr_t from, msg_t *msg );
1267int SV_FrameMsec(void);
1268void SV_CheckSaveGame(void);
1269qboolean SV_GameCommand(void);
1270int SV_SendQueuedPackets(void);
1271
1272//
1273// input interface
1274//
1275void IN_Init(void *windowData);
1276void IN_Frame(void);
1277void IN_Shutdown(void);
1278void IN_Restart(void);
1279void IN_GetMousePosition(int *x, int *y);
1280
1281typedef void (*pCursorFree)(byte *pic);
1282qboolean IN_SetCursorFromImage(const byte *pic, int width, int height, pCursorFree cursorFreeFn);
1283void IN_FreeCursor();
1284qboolean IN_IsCursorActive();
1285
1286void Com_Pause();
1287void Com_Unpause();
1288void Com_FakePause();
1289void Com_FakeUnpause();
1290void Com_Pause_f();
1291void SV_SoundCallback( int entnum, int channel_number, const char *name );
1292
1293int R_CountTextureMemory();
1294/*
1295==============================================================
1296
1297NON-PORTABLE SYSTEM SERVICES
1298
1299==============================================================
1300*/
1301
1302typedef enum {
1303 AXIS_SIDE,
1304 AXIS_FORWARD,
1305 AXIS_UP,
1306 AXIS_ROLL,
1307 AXIS_YAW,
1308 AXIS_PITCH,
1309 MAX_JOYSTICK_AXIS
1310} joystickAxis_t;
1311
1312typedef enum {
1313 // SE_NONE must be zero
1314 SE_NONE = 0, // evTime is still valid
1315 SE_KEY, // evValue is a key code, evValue2 is the down flag
1316 SE_CHAR, // evValue is an ascii char
1317 SE_MOUSE, // evValue and evValue2 are reletive signed x / y moves
1318 SE_JOYSTICK_AXIS, // evValue is an axis number and evValue2 is the current state (-127 to 127)
1319 SE_CONSOLE, // evPtr is a char*
1320 SE_PACKET // evPtr is a netadr_t followed by data bytes to evPtrLength
1321} sysEventType_t;
1322
1323typedef struct {
1324 int evTime;
1325 sysEventType_t evType;
1326 int evValue, evValue2;
1327 size_t evPtrLength; // bytes of data pointed to by evPtr, for journaling
1328 void *evPtr; // this must be manually freed if not NULL
1329} sysEvent_t;
1330
1331sysEvent_t Sys_GetEvent(void);
1332
1333void Com_QueueEvent( int time, sysEventType_t type, int value, int value2, size_t ptrLength, void *ptr );
1334int Com_EventLoop( void );
1335sysEvent_t Com_GetSystemEvent( void );
1336
1337void Sys_Init (void);
1338
1339// general development dll loading for virtual machine testing
1340void Sys_UnloadDll( void *dllHandle );
1341
1342qboolean Sys_DllExtension(const char* name);
1343
1344void Sys_UnloadGame( void );
1345void *Sys_GetGameAPI( void *parms );
1346
1347void Sys_UnloadCGame( void );
1348void *Sys_GetCGameAPI( void *parms );
1349
1350void Sys_UnloadUI( void );
1351void *Sys_GetUIAPI( void );
1352
1353//bot libraries
1354void Sys_UnloadBotLib( void );
1355void *Sys_GetBotLibAPI( void *parms );
1356
1357char *Sys_GetCurrentUser( void );
1358
1359void QDECL Sys_Error( const char *error, ...) Q_NO_RETURN Q_PRINTF_FUNC(1, 2);
1360void Sys_Quit (void) Q_NO_RETURN;
1361char *Sys_GetClipboardData( void ); // note that this isn't journaled...
1362
1363void Sys_Print( const char *msg );
1364
1365// Sys_Milliseconds should only be used for profiling purposes,
1366// any game related timing information should come from event timestamps
1367int Sys_Milliseconds (void);
1368
1369qboolean Sys_RandomBytes( byte *string, int len );
1370
1371// the system console is shown when a dedicated server is running
1372void Sys_DisplaySystemConsole( qboolean show );
1373
1374cpuFeatures_t Sys_GetProcessorFeatures( void );
1375
1376void Sys_SetErrorText( const char *text );
1377
1378void Sys_SendPacket( int length, const void *data, netadr_t to );
1379
1380qboolean Sys_StringToAdr( const char *s, netadr_t *a, netadrtype_t family );
1381qboolean Sys_GetPacket( netadr_t *net_from, msg_t *net_message );
1382
1383//Does NOT parse port numbers, only base addresses.
1384
1385qboolean Sys_IsLANAddress (netadr_t adr);
1386void Sys_ShowIP(void);
1387
1388FILE *Sys_FOpen( const char *ospath, const char *mode );
1389qboolean Sys_Mkdir( const char *path );
1390FILE *Sys_Mkfifo( const char *ospath );
1391char *Sys_Cwd( void );
1392void Sys_SetDefaultInstallPath(const char *path);
1393char *Sys_DefaultInstallPath(void);
1394char *Sys_SteamPath(void);
1395char *Sys_GogPath(void);
1396char *Sys_MicrosoftStorePath(void);
1397
1398#ifdef __APPLE__
1399char *Sys_DefaultAppPath(void);
1400#endif
1401
1402char *Sys_DefaultHomePath(void);
1403const char *Sys_Dirname( char *path );
1404const char *Sys_Basename( char *path );
1405char *Sys_ConsoleInput( void );
1406
1407void SetProgramPath( const char *path );
1408char *Sys_DefaultBasePath( void );
1409char *Sys_DefaultUserPath( void );
1410char *Sys_DefaultOutputPath( void );
1411
1412char **Sys_ListFiles( const char *directory, const char *extension, const char *filter, int *numfiles, qboolean wantsubs );
1413void Sys_FreeFileList( char **list );
1414void Sys_Sleep(int msec);
1415
1416void Sys_InitStreamThread(void);
1417void Sys_ShutdownStreamThread(void);
1418void Sys_BeginStreamedFile(fileHandle_t f, int readAhead);
1419void Sys_EndStreamedFile(fileHandle_t f);
1420int Sys_StreamedRead(void* buffer, int size, int count, fileHandle_t f);
1421void Sys_StreamSeek(fileHandle_t f, int offset, int origin);
1422
1423qboolean Sys_LowPhysicalMemory(void);
1424
1425void Sys_SetEnv(const char* name, const char* value);
1426
1427void SetNormalThreadPriority( void );
1428void SetBelowNormalThreadPriority( void );
1429
1430void RecoverLostAutodialData( void );
1431
1432void Sys_CloseMutex( void );
1433void Sys_ShowConsole( int visLevel, qboolean quitOnClose );
1434void Sys_DebugPrint(const char* message);
1435void Sys_PumpMessageLoop( void );
1436
1437qboolean SaveRegistryInfo( qboolean user, const char *pszName, void *pvBuf, long lSize );
1438qboolean LoadRegistryInfo( qboolean user, const char *pszName, void *pvBuf, long *plSize );
1439
1440qboolean IsFirstRun( void );
1441qboolean IsNewConfig( void );
1442qboolean IsSafeMode( void );
1443void ClearNewConfigFlag( void );
1444const char *Sys_GetWholeClipboard( void );
1445void Sys_SetClipboard( const char *contents );
1446
1447typedef enum
1448{
1449 DR_YES = 0,
1450 DR_NO = 1,
1451 DR_OK = 0,
1452 DR_CANCEL = 1
1453} dialogResult_t;
1454
1455typedef enum
1456{
1457 DT_INFO,
1458 DT_WARNING,
1459 DT_ERROR,
1460 DT_YES_NO,
1461 DT_OK_CANCEL
1462} dialogType_t;
1463
1464dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *title );
1465
1466void Sys_RemovePIDFile( const char *gamedir );
1467void Sys_InitPIDFile( const char *gamedir );
1468
1469void Sys_ProcessBackgroundTasks();
1470
1471/* This is based on the Adaptive Huffman algorithm described in Sayood's Data
1472 * Compression book. The ranks are not actually stored, but implicitly defined
1473 * by the location of a node within a doubly-linked list */
1474
1475#define NYT HMAX /* NYT = Not Yet Transmitted */
1476#define INTERNAL_NODE (HMAX+1)
1477
1478typedef struct nodetype {
1479 struct nodetype *left, *right, *parent; /* tree structure */
1480 struct nodetype *next, *prev; /* doubly-linked list */
1481 struct nodetype **head; /* highest ranked node in block */
1482 int weight;
1483 int symbol;
1484} node_t;
1485
1486#define HMAX 256 /* Maximum symbol */
1487
1488typedef struct {
1489 int blocNode;
1490 int blocPtrs;
1491
1492 node_t* tree;
1493 node_t* lhead;
1494 node_t* ltail;
1495 node_t* loc[HMAX+1];
1496 node_t** freelist;
1497
1498 node_t nodeList[768];
1499 node_t* nodePtrs[768];
1500} huff_t;
1501
1502typedef struct {
1503 huff_t compressor;
1504 huff_t decompressor;
1505} huffman_t;
1506
1507void Huff_Compress(msg_t *buf, int offset);
1508void Huff_Decompress(msg_t *buf, int offset);
1509void Huff_Init(huffman_t *huff);
1510void Huff_addRef(huff_t* huff, byte ch);
1511int Huff_Receive (node_t *node, int *ch, byte *fin);
1512void Huff_transmit (huff_t *huff, int ch, byte *fout, int maxoffset);
1513void Huff_offsetReceive (node_t *node, int *ch, byte *fin, int *offset, int maxoffset);
1514void Huff_offsetTransmit (huff_t *huff, int ch, byte *fout, int *offset, int maxoffset);
1515void Huff_putBit( int bit, byte *fout, int *offset);
1516int Huff_getBit( byte *fout, int *offset);
1517
1518extern huffman_t clientHuffTables;
1519
1520#define SV_ENCODE_START 4
1521#define SV_DECODE_START 12
1522#define CL_ENCODE_START 12
1523#define CL_DECODE_START 4
1524
1525// flags for sv_allowDownload and cl_allowDownload
1526#define DLF_ENABLE 1
1527#define DLF_NO_REDIRECT 2
1528#define DLF_NO_UDP 4
1529#define DLF_NO_DISCONNECT 8
1530
1531#ifdef __cplusplus
1532}
1533#endif
1534
1535#endif // _QCOMMON_H_
Definition q_shared.h:2011
Definition qcommon.h:897
Definition q_shared.h:1691
Definition qcommon.h:1488
Definition qcommon.h:1502
Definition qcommon.h:40
Definition qcommon.h:218
Definition qcommon.h:265
Definition qcommon.h:335
Definition qcommon.h:308
Definition qcommon.h:314
Definition qcommon.h:1478
Definition q_shared.h:1742
Definition qcommon.h:1323
Definition q_shared.h:1873
Definition q_shared.h:1361
Definition q_shared.h:206