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