OpenMoHAA 0.82.1
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
705cvar_t *Cvar_Unset(cvar_t *cv);
706
707extern int cvar_modifiedFlags;
708extern qboolean cvar_global_force;
709// whenever a cvar is modifed, its flags will be OR'd into this, so
710// a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO,
711// etc, variables have been modified since the last check. The bit
712// can then be cleared to allow another change detection.
713
714/*
715==============================================================
716
717FILESYSTEM
718
719No stdio calls should be used by any part of the game, because
720we need to deal with all sorts of directory and seperator char
721issues.
722==============================================================
723*/
724
725// referenced flags
726// these are in loop specific order so don't change the order
727#define FS_GENERAL_REF 0x01
728#define FS_UI_REF 0x02
729#define FS_CGAME_REF 0x04
730#define FS_QAGAME_REF 0x08
731// number of id paks that will never be autodownloaded from baseq3
732#define NUM_ID_PAKS 5
733
734#define MAX_FILE_HANDLES 64
735
736#ifdef DEDICATED
737# define Q3CONFIG_CFG "q3config_server.cfg"
738#else
739# define Q3CONFIG_CFG "q3config.cfg"
740#endif
741
742qboolean FS_Initialized( void );
743
744void FS_InitFilesystem( void );
745void FS_Shutdown( qboolean closemfp );
746
747qboolean FS_ConditionalRestart( int checksumFeed, qboolean disconnect );
748void FS_Restart( int checksumFeed );
749// shutdown and restart the filesystem so changes to fs_gamedir can take effect
750
751void FS_AddGameDirectory(const char *path, const char *dir);
752void FS_AddGameDirectory2(const char *path, const char *dir, qboolean original_paks_priority);
753
754char **FS_ListFilteredFiles( const char *path, const char *extension, const char *filter, qboolean wantSubs, int *numfiles, qboolean allowNonPureFilesOnDisk );
755char **FS_ListFiles( const char *directory, const char *extension, qboolean wantSubs, int *numfiles );
756// directory should not have either a leading or trailing /
757// if extension is "/", only subdirectories will be returned
758// the returned files will not include any directories or /
759
760void FS_FreeFileList( char **list );
761
762qboolean FS_FileExists( const char *file );
763
764void FS_CorrectCase(char* path);
765
766char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
767
768qboolean FS_CreatePath(char *OSPath);
769
770int FS_LoadStack( void );
771
772int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
773int FS_GetModList( char *listbuf, int bufsize );
774
775void FS_GetModDescription(const char* modDir, char* description, int descriptionLen);
776
777fileHandle_t FS_FOpenFileWrite( const char *qpath );
778fileHandle_t FS_FOpenFileAppend( const char *filename );
779fileHandle_t FS_FCreateOpenPipeFile( const char *filename );
780fileHandle_t FS_FOpenTextFileWrite(const char* qpath);
781// will properly create any needed paths and deal with seperater character issues
782
783void FS_DeleteFile( const char *filename );
784void FS_CanonicalFilename( char *filename );
785fileHandle_t FS_SV_FOpenFileWrite( const char *filename );
786long FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp );
787void FS_SV_Rename( const char *from, const char *to, qboolean safe );
788long FS_FOpenFileRead(const char* filename, fileHandle_t* file, qboolean uniqueFILE, qboolean quiet);
789// if uniqueFILE is true, then a new FILE will be fopened even if the file
790// is found in an already open pak file. If uniqueFILE is false, you must call
791// FS_FCloseFile instead of fclose, otherwise the pak FILE would be improperly closed
792// It is generally safe to always set uniqueFILE to true, because the majority of
793// file IO goes through FS_ReadFile, which Does The Right Thing already.
794
795int FS_FileIsInPAK(const char *filename, int *pChecksum );
796// returns 1 if a file is in the PAK file, otherwise -1
797
798size_t FS_Write( const void *buffer, size_t len, fileHandle_t f );
799
800size_t FS_Read( void *buffer, size_t len, fileHandle_t f );
801// properly handles partial reads and reads from other dlls
802
803void FS_FCloseFile( fileHandle_t f );
804// note: you can't just fclose from another DLL, due to MS libc issues
805
806long FS_ReadFileEx(const char* qpath, void** buffer, qboolean quiet);
807long FS_ReadFile(const char* qpath, void** buffer);
808const char *FS_Gamedir( void );
809// returns the length of the file
810// a null buffer will just return the file length without loading
811// as a quick check for existance. -1 length == not present
812// A 0 byte will always be appended at the end, so string ops are safe.
813// the buffer should be considered read-only, because it may be cached
814// for other uses.
815
816void FS_ForceFlush( fileHandle_t f );
817// forces flush on files we're writing to.
818
819void FS_FreeFile( void *buffer );
820// frees the memory returned by FS_ReadFile
821
822
823const char *FS_PrepFileWrite( const char *filename );
824// prepares the file to be written
825
826int FS_WriteFile( const char *qpath, const void *buffer, int size );
827// writes a complete file, creating any subdirectories needed
828
829void FS_WriteTextFile( const char *qpath, const void *buffer, int size );
830// writes a complete text file, creating any subdirectories needed
831
832long FS_filelength(fileHandle_t f);
833// doesn't work for files that are opened from a pack file
834
835int FS_FTell( fileHandle_t f );
836// where are we?
837
838void FS_Flush( fileHandle_t f );
839
840void QDECL FS_Printf( fileHandle_t f, const char *fmt, ... ) __attribute__ ((format (printf, 2, 3)));
841// like fprintf
842
843int FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode );
844// opens a file for reading, writing, or appending depending on the value of mode
845
846int FS_Seek( fileHandle_t f, long offset, int origin );
847// seek on a file (doesn't work for zip files!!!!!!!!)
848
849qboolean FS_FilenameCompare( const char *s1, const char *s2 );
850qboolean FS_FileNewer( const char *source, const char *destination );
851
852const char *FS_GamePureChecksum( void );
853// Returns the checksum of the pk3 from which the server loaded the qagame.qvm
854
855const char *FS_LoadedPakNames( void );
856const char *FS_LoadedPakChecksums( void );
857const char *FS_LoadedPakPureChecksums( void );
858// Returns a space separated string containing the checksums of all loaded pk3 files.
859// Servers with sv_pure set will get this string and pass it to clients.
860
861const char *FS_ReferencedPakNames( void );
862const char *FS_ReferencedPakChecksums( void );
863const char *FS_ReferencedPakPureChecksums( void );
864// Returns a space separated string containing the checksums of all loaded
865// AND referenced pk3 files. Servers with sv_pure set will get this string
866// back from clients for pure validation
867
868void FS_ClearPakReferences( int flags );
869// clears referenced booleans on loaded pk3s
870
871void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames );
872void FS_PureServerSetLoadedPaks( const char *pakSums, const char *pakNames );
873// If the string is empty, all data sources will be allowed.
874// If not empty, only pk3 files that match one of the space
875// separated checksums will be checked for files, with the
876// sole exception of .cfg files.
877
878qboolean FS_CheckDirTraversal(const char *checkdir);
879qboolean FS_idPak(const char *pak, const char *base);
880qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring );
881
882void FS_Rename( const char *from, const char *to );
883
884void FS_Remove( const char *osPath );
885
886void FS_FilenameCompletion( const char *dir, const char *ext,
887 qboolean stripExt, void(*callback)(const char *s), qboolean allowNonPureFilesOnDisk );
888
889const char* FS_GetCurrentGameDir();
890void FS_GetRelativeFilename( const char *currentDirectory, const char *absoluteFilename, char *out, size_t destlen );
891
892void FS_FileTime(const char* filename, char* date, char* size);
893
894extern cvar_t* fs_debug;
895extern cvar_t* fs_mapdir;
896
897/*
898==============================================================
899
900Edit fields and command line history/completion
901
902==============================================================
903*/
904
905#define MAX_EDIT_LINE 256
906typedef struct {
907 int cursor;
908 int scroll;
909 int widthInChars;
910 char buffer[MAX_EDIT_LINE];
911} field_t;
912
913void Field_Clear( field_t *edit );
914void Field_AutoComplete( field_t *edit );
915void Field_CompleteKeyname( void );
916void Field_CompleteFilename( const char *dir,
917 const char *ext, qboolean stripExt, qboolean allowNonPureFilesOnDisk );
918void Field_CompleteCommand( char *cmd,
919 qboolean doCommands, qboolean doCvars );
920void Field_CompletePlayerName( const char **names, int count );
921/*
922==============================================================
923
924MISC
925
926==============================================================
927*/
928
929// returnbed by Sys_GetProcessorId
930#define CPUID_GENERIC 0 // any unrecognized processor
931
932#define CPUID_AXP 0x10
933
934#define CPUID_INTEL_UNSUPPORTED 0x20 // Intel 386/486
935#define CPUID_INTEL_PENTIUM 0x21 // Intel Pentium or PPro
936#define CPUID_INTEL_MMX 0x22 // Intel Pentium/MMX or P2/MMX
937#define CPUID_INTEL_KATMAI 0x23 // Intel Katmai
938
939#define CPUID_AMD_3DNOW 0x30 // AMD K6 3DNOW!
940
941/*
942==============================================================
943
944MISC
945
946==============================================================
947*/
948
949// vsnprintf is ISO/IEC 9899:1999
950// abstracting this to make it portable
951#ifdef _WIN32
952#define Q_vsnprintf _vsnprintf
953#define Q_snprintf _snprintf
954#else
955#define Q_vsnprintf vsnprintf
956#define Q_snprintf snprintf
957#endif
958
959// centralizing the declarations for cl_cdkey
960// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470
961extern char cl_cdkey[34];
962
963// returned by Sys_GetProcessorFeatures
964typedef enum
965{
966 CF_RDTSC = 1 << 0,
967 CF_MMX = 1 << 1,
968 CF_MMX_EXT = 1 << 2,
969 CF_3DNOW = 1 << 3,
970 CF_3DNOW_EXT = 1 << 4,
971 CF_SSE = 1 << 5,
972 CF_SSE2 = 1 << 6,
973 CF_ALTIVEC = 1 << 7
974} cpuFeatures_t;
975
976// centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
977#define MAXPRINTMSG 4096
978
979
980#define MAX_RENDER_STRINGS 8
981#define MAX_RENDER_STRING_LENGTH 32
982
983char *CopyString( const char *in );
984void Info_Print( const char *s );
985
986void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *));
987void Com_EndRedirect( void );
988void QDECL Com_Printf( const char *fmt, ... ) __attribute__ ((format (printf, 1, 2)));
989void QDECL Com_DPrintf( const char *fmt, ... ) __attribute__ ((format (printf, 1, 2)));
990void QDECL Com_Error( int code, const char *fmt, ... ) __attribute__ ((noreturn, format(printf, 2, 3)));
991void Com_Quit_f( void ) __attribute__ ((noreturn));
992void Com_GameRestart(int checksumFeed, qboolean disconnect);
993
994int Com_Milliseconds( void ); // will be journaled properly
995unsigned Com_BlockChecksum( const void *buffer, int length );
996char *Com_MD5File(const char *filename, int length, const char *prefix, int prefix_len);
997int Com_HashKey(char *string, int maxlen);
998int Com_Filter(const char *filter, const char *name, int casesensitive);
999int Com_FilterPath(const char *filter, const char *name, int casesensitive);
1000int Com_RealTime(qtime_t *qtime);
1001qboolean Com_SafeMode( void );
1002void Com_RunAndTimeServerPacket(netadr_t *evFrom, msg_t *buf);
1003
1004qboolean Com_IsVoipTarget(uint8_t *voipTargets, int voipTargetsSize, int clientNum);
1005
1006void Com_StartupVariable( const char *match );
1007// checks for and removes command line "+set var arg" constructs
1008// if match is NULL, all set commands will be executed, otherwise
1009// only a set with the exact name. Only used during startup.
1010qboolean Com_PlayerNameToFieldString( char *str, int length, const char *name );
1011qboolean Com_FieldStringToPlayerName( char *name, int length, const char *rawname );
1012int QDECL Com_strCompare( const void *a, const void *b );
1013
1014
1015extern float currentfps;
1016extern cvar_t *paused;
1017extern cvar_t *config;
1018extern cvar_t *fps;
1019extern cvar_t *developer;
1020extern cvar_t *com_dedicated;
1021extern cvar_t *com_speeds;
1022extern cvar_t *com_timescale;
1023extern cvar_t *com_sv_running;
1024extern cvar_t *com_cl_running;
1025extern cvar_t *com_viewlog; // 0 = hidden, 1 = visible, 2 = minimized
1026extern cvar_t *com_shortversion;
1027extern cvar_t *com_version;
1028extern cvar_t *autopaused;
1029extern cvar_t *deathmatch;
1030extern cvar_t *com_blood;
1031extern cvar_t *com_buildScript; // for building release pak files
1032extern cvar_t *com_radar_range;
1033extern cvar_t *console_spam_filter;
1034extern cvar_t *com_journal;
1035extern cvar_t *com_cameraMode;
1036extern cvar_t *com_ansiColor;
1037extern cvar_t *com_unfocused;
1038extern cvar_t *com_maxfpsUnfocused;
1039extern cvar_t *com_minimized;
1040extern cvar_t *com_maxfpsMinimized;
1041extern cvar_t *com_altivec;
1042extern cvar_t *com_standalone;
1043extern cvar_t *com_gamename;
1044extern cvar_t *com_basegame;
1045extern cvar_t *com_homepath;
1046extern cvar_t *com_altivec;
1047
1048// both client and server must agree to pause
1049extern cvar_t *cl_paused;
1050extern cvar_t *sv_paused;
1051
1052extern cvar_t *cl_packetdelay;
1053extern cvar_t *sv_packetdelay;
1054
1055extern cvar_t* com_protocol;
1056#ifdef LEGACY_PROTOCOL
1057extern cvar_t* com_legacyprotocol;
1058#endif
1059#ifndef DEDICATED
1060extern cvar_t* con_autochat;
1061#endif
1062extern cvar_t* com_target_game;
1063extern cvar_t* com_target_shortversion;
1064extern cvar_t* com_target_version;
1065extern cvar_t* com_target_extension;
1066extern cvar_t* com_target_demo;
1067
1068extern cvar_t* com_updatecheck_enabled;
1069extern cvar_t* com_updatecheck_interval;
1070
1071extern int protocol_version_demo;
1072extern int protocol_version_full;
1073
1074// com_speeds times
1075extern int time_game;
1076extern int time_frontend;
1077extern int time_backend; // renderer backend time
1078
1079extern int com_frameTime;
1080extern int com_frameMsec;
1081
1082extern qboolean com_errorEntered;
1083extern qboolean com_fullyInitialized;
1084extern qboolean com_gotOriginalConfig;
1085
1086extern fileHandle_t com_journalFile;
1087extern fileHandle_t com_journalDataFile;
1088
1089typedef enum {
1090 TAG_FREE,
1091 TAG_CONST,
1092 TAG_GENERAL,
1093 TAG_BOTLIB,
1094 TAG_RENDERER, // memory allocated from renderer
1095 TAG_GAME, // memory allocated from game
1096 TAG_CGAME, // memory allocated from client game
1097 TAG_CLIENT, // memory allocated from client
1098 TAG_TIKI, // su44: memory allocated by qcommon/tiki.c code
1099 TAG_STRINGS_AND_COMMANDS,
1100 TAG_SOUND, // memory allocated from sound
1101 TAG_STATIC,
1102 TAG_STATIC_RENDERER,
1103 TAG_SKEL, // memory allocated from skeletor
1104 TAG_TEMP, // temporary memory
1105 TAG_EXE,
1106 TAG_NUM_TOTAL_TAGS
1107} memtag_t;
1108
1109/*
1110
1111--- low memory ----
1112server vm
1113server clipmap
1114---mark---
1115renderer initialization (shaders, etc)
1116UI vm
1117cgame vm
1118renderer map
1119renderer models
1120
1121---free---
1122
1123temp file loading
1124--- high memory ---
1125
1126*/
1127
1128#if defined(_DEBUG) && !defined(BSPC)
1129 #define ZONE_DEBUG
1130#endif
1131
1132#ifdef ZONE_DEBUG
1133#define Z_TagMalloc(size, tag) Z_TagMallocDebug(size, tag, #size, __FILE__, __LINE__)
1134#define Z_Malloc(size) Z_MallocDebug(size, #size, __FILE__, __LINE__)
1135#define S_Malloc(size) S_MallocDebug(size, #size, __FILE__, __LINE__)
1136void *Z_TagMallocDebug( int size, int tag, const char *label, const char *file, int line ); // NOT 0 filled memory
1137void *Z_MallocDebug( int size, const char *label, const char *file, int line ); // returns 0 filled memory
1138void *S_MallocDebug( int size, const char *label, const char *file, int line ); // returns 0 filled memory
1139#else
1140void *Z_TagMalloc( int size, int tag ); // NOT 0 filled memory
1141void *Z_Malloc( int size ); // returns 0 filled memory
1142void *S_Malloc( int size ); // NOT 0 filled memory only for small allocations
1143#endif
1144void Z_Free( void *ptr );
1145void Z_FreeTags( int tag );
1146int Z_AvailableMemory( void );
1147void Z_LogHeap( void );
1148
1149void Hunk_Clear( void );
1150void Hunk_ClearToMark( void );
1151void Hunk_SetMark( void );
1152qboolean Hunk_CheckMark( void );
1153void Hunk_ClearTempMemory( void );
1154void *Hunk_AllocateTempMemory( int size );
1155void Hunk_FreeTempMemory( void *buf );
1156int Hunk_MemoryRemaining( void );
1157void Hunk_Log( void);
1158
1159void Com_TouchMemory( void );
1160
1161const char* Z_EmptyStringPointer(void);
1162const char* Z_NumberStringPointer(int iNum);
1163
1164// commandLine should not include the executable name (argv[0])
1165void Com_Init( char *commandLine );
1166void Com_Frame( void );
1167void Com_Shutdown( void );
1168
1169qboolean Com_SanitizeName( const char *pszOldName, char *pszNewName, size_t bufferSize );
1170const char *Com_GetArchiveFileName( const char *filename, const char *extension );
1171const char *Com_GetArchiveFolder();
1172void Com_WipeSavegame( const char *savename );
1173qboolean Com_ShiftedStrStr(const char* shifted, const char* name, int offset);
1174qboolean COM_IsMapValid(const char* name);
1175void Com_SwapSaveStruct(savegamestruct_t* save);
1176
1177
1178/*
1179==============================================================
1180
1181CLIENT / SERVER SYSTEMS
1182
1183==============================================================
1184*/
1185
1186//
1187// client interface
1188//
1189void CL_InitKeyCommands( void );
1190// the keyboard binding interface must be setup before execing
1191// config files, but the rest of client startup will happen later
1192
1193void CL_Init( void );
1194void CL_Disconnect();
1195void CL_AbnormalDisconnect();
1196void CL_Shutdown(const char *finalmsg, qboolean disconnect, qboolean quit);
1197qboolean CL_FinishedIntro(void);
1198void CL_FinishedStartStage(void);
1199void CL_SetFrameNumber(int frameNumber);
1200void CL_Frame( int msec );
1201qboolean CL_GameCommand( void );
1202void CL_KeyEvent (int key, qboolean down, unsigned time);
1203
1204void CL_Key_ForceCommand(int key, unsigned int time);
1205
1206void CL_CharEvent( int key );
1207// char events are for field typing, not game control
1208
1209void CL_GetMouseState( int *x, int *y, unsigned int *buttons );
1210
1211void CL_SetMousePos( int x, int y );
1212
1213void CL_MouseEvent( int dx, int dy, int time );
1214
1215void CL_ClearButtons( void );
1216
1217void CL_JoystickEvent( int axis, int value, int time );
1218
1219void CL_PacketEvent( netadr_t from, msg_t *msg );
1220
1221void CL_MapLoading( qboolean flush, const char *pszMapName );
1222// do a screen update before starting to load a map
1223// when the server is going to load a new map, the entire hunk
1224// will be cleared, so the client must shutdown cgame, ui, and
1225// the renderer
1226
1227void CL_ForwardCommandToServer( const char *string );
1228// adds the current command line as a clc_clientCommand to the client message.
1229// things like godmode, noclip, etc, are commands directed to the server,
1230// so when they are typed in at the console, they will need to be forwarded.
1231
1232qboolean CL_UseLargeLightmap(const char* mapName);
1233// returns true if the standard BSP file should be used
1234
1235void CL_CDDialog( void );
1236// bring up the "need a cd to play" dialog
1237
1238void CL_FlushMemory( void );
1239// dump all memory on an error
1240
1241void CL_ShutdownAll(qboolean shutdownRef);
1242// shutdown client
1243
1244void CL_InitRef(void);
1245// initialize renderer interface
1246
1247void CL_StartHunkUsers( qboolean rendererOnly );
1248// start all the client stuff using the hunk
1249
1250void CL_Snd_Shutdown(void);
1251// Restart sound subsystem
1252
1253void Key_KeynameCompletion( void(*callback)(const char *s) );
1254// for keyname autocompletion
1255
1256void Key_WriteBindings( fileHandle_t f );
1257// for writing the config files
1258
1259void S_ClearSoundBuffer( void );
1260// call before filesystem access
1261
1262float *get_camera_offset( qboolean *lookactive, qboolean *resetview );
1263
1264// AVI files have the start of pixel lines 4 byte-aligned
1265#define AVI_LINE_PADDING 4
1266
1267//
1268// server interface
1269//
1270void SV_ServerLoaded( void );
1271void SV_Init( void );
1272void SV_Shutdown( const char *finalmsg );
1273void SV_SetFrameNumber(int frameNumber);
1274void SV_Frame( int msec );
1275void SV_PacketEvent( netadr_t from, msg_t *msg );
1276int SV_FrameMsec(void);
1277void SV_CheckSaveGame(void);
1278qboolean SV_GameCommand(void);
1279int SV_SendQueuedPackets(void);
1280
1281//
1282// input interface
1283//
1284void IN_Init(void *windowData);
1285void IN_Frame(void);
1286void IN_Shutdown(void);
1287void IN_Restart(void);
1288void IN_GetMousePosition(int *x, int *y);
1289
1290typedef void (*pCursorFree)(byte *pic);
1291qboolean IN_SetCursorFromImage(const byte *pic, int width, int height, pCursorFree cursorFreeFn);
1292void IN_FreeCursor();
1293qboolean IN_IsCursorActive();
1294
1295void Com_Pause();
1296void Com_Unpause();
1297void Com_FakePause();
1298void Com_FakeUnpause();
1299void Com_Pause_f();
1300void SV_SoundCallback( int entnum, int channel_number, const char *name );
1301
1302int R_CountTextureMemory();
1303/*
1304==============================================================
1305
1306NON-PORTABLE SYSTEM SERVICES
1307
1308==============================================================
1309*/
1310
1311typedef enum {
1312 AXIS_SIDE,
1313 AXIS_FORWARD,
1314 AXIS_UP,
1315 AXIS_ROLL,
1316 AXIS_YAW,
1317 AXIS_PITCH,
1318 MAX_JOYSTICK_AXIS
1319} joystickAxis_t;
1320
1321typedef enum {
1322 // SE_NONE must be zero
1323 SE_NONE = 0, // evTime is still valid
1324 SE_KEY, // evValue is a key code, evValue2 is the down flag
1325 SE_CHAR, // evValue is an ascii char
1326 SE_MOUSE, // evValue and evValue2 are reletive signed x / y moves
1327 SE_JOYSTICK_AXIS, // evValue is an axis number and evValue2 is the current state (-127 to 127)
1328 SE_CONSOLE, // evPtr is a char*
1329 SE_PACKET // evPtr is a netadr_t followed by data bytes to evPtrLength
1330} sysEventType_t;
1331
1332typedef struct {
1333 int evTime;
1334 sysEventType_t evType;
1335 int evValue, evValue2;
1336 size_t evPtrLength; // bytes of data pointed to by evPtr, for journaling
1337 void *evPtr; // this must be manually freed if not NULL
1338} sysEvent_t;
1339
1340sysEvent_t Sys_GetEvent(void);
1341
1342void Com_QueueEvent( int time, sysEventType_t type, int value, int value2, size_t ptrLength, void *ptr );
1343int Com_EventLoop( void );
1344sysEvent_t Com_GetSystemEvent( void );
1345
1346void Sys_Init (void);
1347
1348// general development dll loading for virtual machine testing
1349void Sys_UnloadDll( void *dllHandle );
1350
1351qboolean Sys_DllExtension(const char* name);
1352
1353void Sys_UnloadGame( void );
1354void *Sys_GetGameAPI( void *parms );
1355
1356void Sys_UnloadCGame( void );
1357void *Sys_GetCGameAPI( void *parms );
1358
1359void Sys_UnloadUI( void );
1360void *Sys_GetUIAPI( void );
1361
1362//bot libraries
1363void Sys_UnloadBotLib( void );
1364void *Sys_GetBotLibAPI( void *parms );
1365
1366char *Sys_GetCurrentUser( void );
1367
1368void QDECL Sys_Error( const char *error, ...) __attribute__ ((format (printf, 1, 2)));
1369void Sys_Quit (void);
1370char *Sys_GetClipboardData( void ); // note that this isn't journaled...
1371
1372void Sys_Print( const char *msg );
1373
1374// Sys_Milliseconds should only be used for profiling purposes,
1375// any game related timing information should come from event timestamps
1376int Sys_Milliseconds (void);
1377
1378qboolean Sys_RandomBytes( byte *string, int len );
1379
1380// the system console is shown when a dedicated server is running
1381void Sys_DisplaySystemConsole( qboolean show );
1382
1383cpuFeatures_t Sys_GetProcessorFeatures( void );
1384
1385void Sys_SetErrorText( const char *text );
1386
1387void Sys_SendPacket( int length, const void *data, netadr_t to );
1388
1389qboolean Sys_StringToAdr( const char *s, netadr_t *a, netadrtype_t family );
1390qboolean Sys_GetPacket( netadr_t *net_from, msg_t *net_message );
1391
1392//Does NOT parse port numbers, only base addresses.
1393
1394qboolean Sys_IsLANAddress (netadr_t adr);
1395void Sys_ShowIP(void);
1396
1397FILE *Sys_FOpen( const char *ospath, const char *mode );
1398qboolean Sys_Mkdir( const char *path );
1399FILE *Sys_Mkfifo( const char *ospath );
1400char *Sys_Cwd( void );
1401void Sys_SetDefaultInstallPath(const char *path);
1402char *Sys_DefaultInstallPath(void);
1403char *Sys_SteamPath(void);
1404char *Sys_GogPath(void);
1405char *Sys_MicrosoftStorePath(void);
1406
1407#ifdef __APPLE__
1408char *Sys_DefaultAppPath(void);
1409#endif
1410
1411void Sys_SetDefaultHomePath(const char *path);
1412char *Sys_DefaultHomePath(void);
1413const char *Sys_Dirname( char *path );
1414const char *Sys_Basename( char *path );
1415char *Sys_ConsoleInput( void );
1416
1417void SetProgramPath( const char *path );
1418char *Sys_DefaultBasePath( void );
1419char *Sys_DefaultUserPath( void );
1420char *Sys_DefaultOutputPath( void );
1421
1422char **Sys_ListFiles( const char *directory, const char *extension, const char *filter, int *numfiles, qboolean wantsubs );
1423void Sys_FreeFileList( char **list );
1424void Sys_Sleep(int msec);
1425
1426void Sys_InitStreamThread(void);
1427void Sys_ShutdownStreamThread(void);
1428void Sys_BeginStreamedFile(fileHandle_t f, int readAhead);
1429void Sys_EndStreamedFile(fileHandle_t f);
1430int Sys_StreamedRead(void* buffer, int size, int count, fileHandle_t f);
1431void Sys_StreamSeek(fileHandle_t f, int offset, int origin);
1432
1433qboolean Sys_LowPhysicalMemory(void);
1434
1435void Sys_SetEnv(const char* name, const char* value);
1436
1437void SetNormalThreadPriority( void );
1438void SetBelowNormalThreadPriority( void );
1439
1440void RecoverLostAutodialData( void );
1441
1442void Sys_CloseMutex( void );
1443void Sys_ShowConsole( int visLevel, qboolean quitOnClose );
1444void Sys_DebugPrint(const char* message);
1445void Sys_PumpMessageLoop( void );
1446
1447qboolean SaveRegistryInfo( qboolean user, const char *pszName, void *pvBuf, long lSize );
1448qboolean LoadRegistryInfo( qboolean user, const char *pszName, void *pvBuf, long *plSize );
1449
1450qboolean IsFirstRun( void );
1451qboolean IsNewConfig( void );
1452qboolean IsSafeMode( void );
1453void ClearNewConfigFlag( void );
1454const char *Sys_GetWholeClipboard( void );
1455void Sys_SetClipboard( const char *contents );
1456
1457typedef enum
1458{
1459 DR_YES = 0,
1460 DR_NO = 1,
1461 DR_OK = 0,
1462 DR_CANCEL = 1
1463} dialogResult_t;
1464
1465typedef enum
1466{
1467 DT_INFO,
1468 DT_WARNING,
1469 DT_ERROR,
1470 DT_YES_NO,
1471 DT_OK_CANCEL
1472} dialogType_t;
1473
1474dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *title );
1475
1476void Sys_RemovePIDFile( const char *gamedir );
1477void Sys_InitPIDFile( const char *gamedir );
1478
1479void Sys_ProcessBackgroundTasks();
1480
1481/* This is based on the Adaptive Huffman algorithm described in Sayood's Data
1482 * Compression book. The ranks are not actually stored, but implicitly defined
1483 * by the location of a node within a doubly-linked list */
1484
1485#define NYT HMAX /* NYT = Not Yet Transmitted */
1486#define INTERNAL_NODE (HMAX+1)
1487
1488typedef struct nodetype {
1489 struct nodetype *left, *right, *parent; /* tree structure */
1490 struct nodetype *next, *prev; /* doubly-linked list */
1491 struct nodetype **head; /* highest ranked node in block */
1492 int weight;
1493 int symbol;
1494} node_t;
1495
1496#define HMAX 256 /* Maximum symbol */
1497
1498typedef struct {
1499 int blocNode;
1500 int blocPtrs;
1501
1502 node_t* tree;
1503 node_t* lhead;
1504 node_t* ltail;
1505 node_t* loc[HMAX+1];
1506 node_t** freelist;
1507
1508 node_t nodeList[768];
1509 node_t* nodePtrs[768];
1510} huff_t;
1511
1512typedef struct {
1513 huff_t compressor;
1514 huff_t decompressor;
1515} huffman_t;
1516
1517void Huff_Compress(msg_t *buf, int offset);
1518void Huff_Decompress(msg_t *buf, int offset);
1519void Huff_Init(huffman_t *huff);
1520void Huff_addRef(huff_t* huff, byte ch);
1521int Huff_Receive (node_t *node, int *ch, byte *fin);
1522void Huff_transmit (huff_t *huff, int ch, byte *fout, int maxoffset);
1523void Huff_offsetReceive (node_t *node, int *ch, byte *fin, int *offset, int maxoffset);
1524void Huff_offsetTransmit (huff_t *huff, int ch, byte *fout, int *offset, int maxoffset);
1525void Huff_putBit( int bit, byte *fout, int *offset);
1526int Huff_getBit( byte *fout, int *offset);
1527
1528extern huffman_t clientHuffTables;
1529
1530#define SV_ENCODE_START 4
1531#define SV_DECODE_START 12
1532#define CL_ENCODE_START 12
1533#define CL_DECODE_START 4
1534
1535// flags for sv_allowDownload and cl_allowDownload
1536#define DLF_ENABLE 1
1537#define DLF_NO_REDIRECT 2
1538#define DLF_NO_UDP 4
1539#define DLF_NO_DISCONNECT 8
1540
1541#ifdef __cplusplus
1542}
1543#endif
1544
1545#endif // _QCOMMON_H_
Definition str.h:77
Definition q_shared.h:2013
Definition qcommon.h:906
Definition q_shared.h:1693
Definition qcommon.h:1498
Definition qcommon.h:1512
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:1488
Definition q_shared.h:1744
Definition qcommon.h:1332
Definition q_shared.h:1875
Definition q_shared.h:1363
Definition q_shared.h:204