OpenMoHAA 0.83.0
Loading...
Searching...
No Matches
qcommon.h
1/*
2===========================================================================
3Copyright (C) 1999-2005 Id Software, Inc.
4
5This file is part of Quake III Arena source code.
6
7Quake III Arena source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12Quake III Arena source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with Quake III Arena source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22// qcommon.h -- definitions common between client and server, but not game.or ref modules
23#ifndef _QCOMMON_H_
24#define _QCOMMON_H_
25
26#include "cm_public.h"
27#include "alias.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33//#define PRE_RELEASE_DEMO
34
35//============================================================================
36
37//
38// msg.c
39//
40typedef struct msg_s {
41 qboolean allowoverflow; // if false, do a Com_Error
42 qboolean overflowed; // set to true if the buffer size failed (with allowoverflow set)
43 qboolean oob; // set to true if the buffer size failed (with allowoverflow set)
44 byte *data;
45 size_t maxsize;
46 size_t cursize;
47 int readcount;
48 int bit; // for bitwise reads and writes
49} msg_t;
50
51void MSG_Init (msg_t *buf, byte *data, size_t length);
52void MSG_InitOOB( msg_t *buf, byte *data, size_t length );
53void MSG_Clear (msg_t *buf);
54void MSG_WriteData (msg_t *buf, const void *data, size_t length);
55void MSG_Bitstream(msg_t* buf);
56qboolean MSG_IsProtocolVersion15();
57
58// TTimo
59// copy a msg_t in case we need to store it as is for a bit
60// (as I needed this to keep an msg_t from a static var for later use)
61// sets data buffer as MSG_Init does prior to do the copy
62void MSG_Copy(msg_t *buf, byte *data, int length, msg_t *src);
63
64struct usercmd_s;
65struct entityState_s;
66struct playerState_s;
67
68void MSG_WriteBits( msg_t *msg, int value, int bits );
69
70void MSG_WriteChar (msg_t *sb, int c);
71void MSG_WriteByte (msg_t *sb, int c);
72void MSG_WriteShort (msg_t *sb, int c);
73
74void MSG_WriteSVC( msg_t *sb, int c );
75
76void MSG_WriteLong (msg_t *sb, int c);
77void MSG_WriteFloat (msg_t *sb, float f);
78void MSG_WriteString (msg_t *sb, const char *s);
79void MSG_WriteBigString (msg_t *sb, const char *s);
80void MSG_WriteScrambledString(msg_t* sb, const char* s);
81void MSG_WriteScrambledBigString(msg_t* sb, const char* s);
82void MSG_WriteAngle16 (msg_t *sb, float f);
83int MSG_HashKey(const char *string, int maxlen);
84void MSG_WriteEntityNum(msg_t* sb, short number);
85
86void MSG_BeginReading (msg_t *sb);
87void MSG_BeginReadingOOB(msg_t *sb);
88
89int MSG_ReadBits( msg_t *msg, int bits );
90
91int MSG_ReadChar (msg_t *sb);
92int MSG_ReadByte (msg_t *sb);
93int MSG_ReadSVC (msg_t *sb);
94int MSG_ReadShort (msg_t *sb);
95int MSG_ReadLong (msg_t *sb);
96
97void MSG_ReadDir( msg_t *msg, vec3_t dir );
98float MSG_ReadCoord( msg_t *msg );
99void MSG_GetNullEntityState(entityState_t *nullState);
100
101float MSG_ReadFloat (msg_t *sb);
102char *MSG_ReadString (msg_t *sb);
103char *MSG_ReadBigString (msg_t *sb);
104char *MSG_ReadStringLine( msg_t *sb );
105char* MSG_ReadScrambledString(msg_t* msg);
106char* MSG_ReadScrambledBigString(msg_t* msg);
107float MSG_ReadAngle8( msg_t *sb );
108float MSG_ReadAngle16 (msg_t *sb);
109void MSG_ReadData (msg_t *sb, void *buffer, int size);
110unsigned short MSG_ReadEntityNum(msg_t* sb);
111
112
113void MSG_WriteDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
114void MSG_ReadDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
115
116void MSG_WriteDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
117void MSG_ReadDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
118
119void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entityState_s *to
120 , qboolean force, float frameTime);
121
122void MSG_ReadSounds (msg_t *msg, server_sound_t *sounds, int *snapshot_number_of_sounds);
123void MSG_WriteSounds (msg_t *msg, server_sound_t *sounds, int snapshot_number_of_sounds);
124
125void MSG_ReadDeltaEyeInfo(msg_t *msg, usereyes_t *from, usereyes_t *to);
126
127void MSG_ReadDeltaEntity(msg_t* msg, entityState_t* from, entityState_t* to,
128 int number, float frameTime);
129
130void MSG_WriteDeltaEyeInfo (msg_t *msg, usereyes_t *from, usereyes_t *to);
131
132void MSG_WriteDeltaPlayerstate(msg_t* msg, struct playerState_s* from, struct playerState_s* to, float frameTime);
133void MSG_ReadDeltaPlayerstate(msg_t* msg, struct playerState_s* from, struct playerState_s* to, float frameTime);
134
135float MSG_ReadServerFrameTime(msg_t* msg, gameState_t* gameState);
136void MSG_WriteServerFrameTime(msg_t* msg, float value);
137
138void MSG_ReportChangeVectors_f( void );
139
140//====================
141// TA features
142//====================
143
144int MSG_PackAngle(float angle, int bits);
145int MSG_PackAnimTime(float time, int bits);
146int MSG_PackAnimWeight(float weight, int bits);
147int MSG_PackScale(float scale, int bits);
148int MSG_PackAlpha(float alpha, int bits);
149int MSG_PackCoord(float coord);
150int MSG_PackCoordExtra(float coord);
151qboolean MSG_DeltaNeeded(const void* fromField, const void* toField, int fieldType, int bits, int size);
152
153void MSG_WritePackedAngle(msg_t* msg, float value, int bits);
154void MSG_WritePackedAnimTime(msg_t* msg, float fromValue, float toValue, float frameTime, int bits);
155void MSG_WritePackedAnimWeight(msg_t* msg, float value, int bits);
156void MSG_WritePackedScale(msg_t* msg, float value, int bits);
157void MSG_WritePackedAlpha(msg_t* msg, float value, int bits);
158void MSG_WritePackedCoord(msg_t* msg, float fromValue, float toValue, int bits);
159void MSG_WritePackedCoordExtra(msg_t* msg, float fromValue, float toValue, int bits);
160void MSG_WritePackedVelocity(msg_t* msg, float value, int bits);
161void MSG_WritePackedSimple(msg_t* msg, int value, int bits);
162
163float MSG_UnpackAngle(int value, int bits);
164float MSG_UnpackAnimTime(int packed);
165float MSG_UnpackAnimWeight(int result, int bits);
166float MSG_UnpackScale(int packed);
167float MSG_UnpackAlpha(int packed, int bits);
168float MSG_UnpackCoord(int packed, int bits);
169float MSG_UnpackCoordExtra(int packed, int bits);
170
171//============================================================================
172
173/*
174==============================================================
175
176NET
177
178==============================================================
179*/
180
181#define NET_ENABLEV4 0x01
182#define NET_ENABLEV6 0x02
183// if this flag is set, always attempt ipv6 connections instead of ipv4 if a v6 address is found.
184#define NET_PRIOV6 0x04
185// disables ipv6 multicast support if set.
186#define NET_DISABLEMCAST 0x08
187
188#define PACKET_BACKUP 32 // number of old messages that must be kept on client and
189 // server for delta comrpession and ping estimation
190#define PACKET_MASK (PACKET_BACKUP-1)
191
192#define MAX_PACKET_USERCMDS 32 // max number of usercmd_t in a packet
193
194#define PORT_ANY -1
195
196#define MAX_RELIABLE_COMMANDS 512 // max string commands buffered for restransmit
197
198typedef enum {
199 NA_BAD, // an address lookup failed
200 NA_BOT,
201 NA_LOOPBACK,
202 NA_BROADCAST,
203 NA_IP,
204 NA_IPX,
205 NA_BROADCAST_IPX,
206 NA_IP6,
207 NA_MULTICAST6,
208 NA_UNSPEC
209} netadrtype_t;
210
211typedef enum {
212 //NS_MASTER,
213 NS_CLIENT,
214 NS_SERVER
215} netsrc_t;
216
217#define NET_ADDRSTRMAXLEN 48 // maximum length of an IPv6 address string including trailing '\0'
218typedef struct {
219 netadrtype_t type;
220
221 byte ip[4];
222 byte ip6[16];
223 byte ipx[10];
224
225 unsigned short port;
226 unsigned long scope_id; // Needed for IPv6 link-local addresses
227} netadr_t;
228
229void NET_Init( void );
230void NET_Shutdown( void );
231void NET_Restart_f( void );
232void NET_Config( qboolean enableNetworking );
233void NET_FlushPacketQueue(void);
234void NET_SendPacket (netsrc_t sock, size_t length, const void *data, netadr_t to);
235void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...) Q_PRINTF_FUNC(3, 4);
236void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len );
237
238qboolean NET_CompareAdr (netadr_t a, netadr_t b);
239qboolean NET_CompareBaseAdrMask(netadr_t a, netadr_t b, int netmask);
240qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
241qboolean NET_IsLocalAddress (netadr_t adr);
242const char *NET_AdrToString (netadr_t a);
243const char *NET_AdrToStringwPort (netadr_t a);
244int NET_StringToAdr ( const char *s, netadr_t *a, netadrtype_t family);
245qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
246void NET_JoinMulticast6(void);
247void NET_LeaveMulticast6(void);
248void NET_Sleep(int msec);
249
250
251#define MAX_MSGLEN 49152 // max length of a message, which may
252 // be fragmented into multiple packets
253
254#define MAX_DOWNLOAD_WINDOW 48 // ACK window of 48 download chunks. Cannot set this higher, or clients
255 // will overflow the reliable commands buffer
256#define MAX_DOWNLOAD_BLKSIZE 1024 // 896 byte block chunks
257
258#define NETCHAN_GENCHECKSUM(challenge, sequence) ((challenge) ^ ((sequence) * (challenge)))
259
260
261/*
262Netchan handles packet fragmentation and out of order / duplicate suppression
263*/
264
265typedef struct {
266 netsrc_t sock;
267
268 int dropped; // between last packet and previous
269
270 netadr_t remoteAddress;
271 int qport; // qport value to write when transmitting
272
273 // sequencing variables
274 int incomingSequence;
275 int outgoingSequence;
276
277 // incoming fragment assembly buffer
278 int fragmentSequence;
279 int fragmentLength;
280 byte fragmentBuffer[MAX_MSGLEN];
281
282 // outgoing fragment buffer
283 // we need to space out the sending of large fragmented messages
284 qboolean unsentFragments;
285 size_t unsentFragmentStart;
286 size_t unsentLength;
287 byte unsentBuffer[MAX_MSGLEN];
288
289 int challenge;
290 int lastSentTime;
291 int lastSentSize;
292
293#ifdef LEGACY_PROTOCOL
294 qboolean compat;
295#endif
296} netchan_t;
297
298/*
299Packet profiling
300*/
301
302#define NETPROF_PACKET_FRAGMENTED 1
303#define NETPROF_PACKET_DROPPED 2
304#define NETPROF_PACKET_MESSAGE 4
305
306#define NETPROX_MAX_PACKETS 64
307
308typedef struct {
309 int updateTime;
310 int size;
311 int flags;
313
314typedef struct {
315 int updateTime;
316 int index;
317 netprofpacket_t packets[NETPROX_MAX_PACKETS];
318 int lastCalcTime;
319 int lowestUpdateTime;
320 int highestUpdateTime;
321 int totalProcessed;
322 int totalSize;
323 int numFragmented;
324 int numDropped;
325 int numConnectionLess;
326 int totalLengthConnectionLess;
327 int packetsPerSec;
328 int bytesPerSec;
329 int percentFragmented;
330 int percentDropped;
331 int percentConnectionLess;
332 float latency;
334
335typedef struct {
336 qboolean initialized;
337 int rate;
338 netprofpacketlist_t outPackets;
339 netprofpacketlist_t inPackets;
341
342void Netchan_Init( int qport );
343void Netchan_Setup(netsrc_t sock, netchan_t *chan, netadr_t adr, int qport, int challenge, qboolean compat);
344
345void Netchan_Transmit( netchan_t *chan, size_t length, const byte *data, netprofpacketlist_t *packetlist );
346void Netchan_TransmitNextFragment( netchan_t *chan, netprofpacketlist_t *packetlist );
347
348qboolean Netchan_Process( netchan_t *chan, msg_t *msg, netprofpacketlist_t *packetlist );
349
350void NetProfileAddPacket(netprofpacketlist_t* list, size_t size, int flags);
351void NetProfileSetPacketFlags(netprofpacketlist_t* list, int flags);
352void NetProfileCalcStats(netprofpacketlist_t* list, int time);
353
354/*
355==============================================================
356
357PROTOCOL
358
359==============================================================
360*/
361
362#define PROTOCOL_VERSION 17
363#define PROTOCOL_LEGACY_VERSION PROTOCOL_VERSION
364// su44: MoHAA v 1.00 uses protocol version 6
365
366// maintain a list of compatible protocols for demo playing
367// NOTE: that stuff only works with two digits protocols
368extern int demo_protocols[];
369
370// fixme : we need a new master server address
371
372#define UPDATE_SERVER_NAME "updatemoh.2015.com"
373// override on command line, config files etc.
374#ifndef MASTER_SERVER_NAME
375#define MASTER_SERVER_NAME "master.2015.com"
376#endif
377#ifndef AUTHORIZE_SERVER_NAME
378#define AUTHORIZE_SERVER_NAME "authorize.2015.com"
379#endif
380
381#define PORT_MASTER 27950
382#define PORT_UPDATE 27951
383#ifndef PORT_AUTHORIZE
384#define PORT_AUTHORIZE 27952
385#endif
386#define PORT_SERVER 12203
387#define NUM_SERVER_PORTS 4 // broadcast scan this many ports after
388 // PORT_SERVER so a single machine can
389 // run multiple servers
390
391
392// the svc_strings[] array in cl_parse.c should mirror this
393//
394// server to client
395//
396enum svc_ops_e {
397 svc_bad,
398 svc_nop,
399 svc_gamestate,
400 svc_configstring, // [short] [string] only in gamestate messages
401 svc_baseline, // only in gamestate messages
402 svc_serverCommand, // [string] to be executed by client game module
403 svc_download, // [short] size [size bytes]
404 svc_snapshot,
405 svc_centerprint,
406 svc_locprint,
407 svc_cgameMessage,
408 svc_EOF,
409
410// new commands, supported only by ioquake3 protocol but not legacy
411 svc_voipSpeex, // not wrapped in USE_VOIP, so this value is reserved.
412 svc_voipOpus, //
413};
414
415//
416// client to server
417//
418enum clc_ops_e {
419 clc_bad,
420 clc_nop,
421 clc_move, // [[usercmd_t]
422 clc_moveNoDelta, // [[usercmd_t]
423 clc_clientCommand, // [string] message
424 clc_EOF,
425
426// new commands, supported only by ioquake3 protocol but not legacy
427 clc_voipSpeex, // not wrapped in USE_VOIP, so this value is reserved.
428 clc_voipOpus, //
429};
430
431/*
432==============================================================
433
434VIRTUAL MACHINE
435
436==============================================================
437*/
438
439typedef struct vm_s vm_t;
440
441typedef enum {
442 VMI_NATIVE,
443 VMI_BYTECODE,
444 VMI_COMPILED
445} vmInterpret_t;
446
447typedef enum {
448 TRAP_MEMSET = 100,
449 TRAP_MEMCPY,
450 TRAP_STRNCPY,
451 TRAP_SIN,
452 TRAP_COS,
453 TRAP_ATAN2,
454 TRAP_SQRT,
455 TRAP_MATRIXMULTIPLY,
456 TRAP_ANGLEVECTORS,
457 TRAP_PERPENDICULARVECTOR,
458 TRAP_FLOOR,
459 TRAP_CEIL,
460
461 TRAP_TESTPRINTINT,
462 TRAP_TESTPRINTFLOAT
463} sharedTraps_t;
464
465typedef intptr_t (QDECL *vmMainProc)(int callNum, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11);
466
467void VM_Init( void );
468vm_t *VM_Create( const char *module, intptr_t (*systemCalls)(intptr_t *),
469 vmInterpret_t interpret );
470// module should be bare: "cgame", not "cgame.dll" or "vm/cgame.qvm"
471
472void VM_Free( vm_t *vm );
473void VM_Clear(void);
474void VM_Forced_Unload_Start(void);
475void VM_Forced_Unload_Done(void);
476vm_t *VM_Restart(vm_t *vm, qboolean unpure);
477
478intptr_t QDECL VM_Call( vm_t *vm, int callNum, ... );
479
480void VM_Debug( int level );
481
482void *VM_ArgPtr( intptr_t intValue );
483void *VM_ExplicitArgPtr( vm_t *vm, intptr_t intValue );
484
485#define VMA(x) VM_ArgPtr(args[x])
486static ID_INLINE float _vmf(intptr_t x)
487{
488 floatint_t fi;
489 fi.i = (int)x;
490 return fi.f;
491}
492#define VMF(x) _vmf(args[x])
493
494
495/*
496==============================================================
497
498CMD
499
500Command text buffering and command execution
501
502==============================================================
503*/
504
505/*
506
507Any number of commands can be added in a frame, from several different sources.
508Most commands come from either keybindings or console line input, but entire text
509files can be execed.
510
511*/
512
513void Cbuf_Init (void);
514// allocates an initial text buffer that will grow as needed
515
516void Cbuf_AddText( const char *text );
517// Adds command text at the end of the buffer, does NOT add a final \n
518
519void Cbuf_ExecuteText(int exec_when, const char *text );
520// this can be used in place of either Cbuf_AddText or Cbuf_InsertText
521
522void Cbuf_Execute (int msec);
523// Pulls off \n terminated lines of text from the command buffer and sends
524// them through Cmd_ExecuteString. Stops when the buffer is empty.
525// Normally called once per frame, but may be explicitly invoked.
526// Do not call inside a command function, or current args will be destroyed.
527
528void Cmd_WriteAliases( fileHandle_t f );
529
530//===========================================================================
531
532/*
533
534Command execution takes a null terminated string, breaks it into tokens,
535then searches for a command or variable that matches the first token.
536
537*/
538
539typedef void (*xcommand_t) (void);
540
541void Cmd_Init (void);
542
543void Cmd_AddCommand( const char *cmd_name, xcommand_t function );
544// called by the init functions of other parts of the program to
545// register commands and functions to call for them.
546// The cmd_name is referenced later, so it should not be in temp memory
547// if function is NULL, the command will be forwarded to the server
548// as a clc_clientCommand instead of executed locally
549
550void Cmd_RemoveCommand( const char *cmd_name );
551
552typedef void (*completionFunc_t)( const char *args, int argNum );
553
554// don't allow VMs to remove system commands
555void Cmd_RemoveCommandSafe( const char *cmd_name );
556
557void Cmd_CommandCompletion( void(*callback)(const char *s) );
558// callback with each valid string
559void Cmd_SetCommandCompletionFunc( const char *command,
560 completionFunc_t complete );
561void Cmd_CompleteArgument( const char *command, char *args, int argNum );
562void Cmd_CompleteCfgName( const char *args, int argNum );
563void Cmd_CommandCompletion( void(*callback)(const char *s) );
564const char* Cmd_CompleteCommandByNumber(const char* partial, int number);
565// callback with each valid string
566
567int Cmd_Argc (void);
568char *Cmd_Argv (int arg);
569void Cmd_ArgvBuffer( int arg, char *buffer, int bufferLength );
570char *Cmd_Args (void);
571char *Cmd_ArgsFrom( int arg );
572void Cmd_ArgsBuffer( char *buffer, int bufferLength );
573char *Cmd_Cmd (void);
574void Cmd_Args_Sanitize( void );
575// The functions that execute commands get their parameters with these
576// functions. Cmd_Argv () will return an empty string, not a NULL
577// if arg > argc, so string operations are allways safe.
578
579void Cmd_TokenizeString( const char *text );
580void Cmd_TokenizeStringIgnoreQuotes( const char *text_in );
581// Takes a null terminated string. Does not need to be /n terminated.
582// breaks the string up into arg tokens.
583
584void Cmd_ExecuteString( const char *text );
585// Parses a single line of text into arguments and tries to execute it
586// as if it was typed at the console
587
588
589/*
590==============================================================
591
592CVAR
593
594==============================================================
595*/
596
597/*
598
599cvar_t variables are used to hold scalar or string variables that can be changed
600or displayed at the console or prog code as well as accessed directly
601in C code.
602
603The user can access cvars from the console in three ways:
604r_draworder prints the current value
605r_draworder 0 sets the current value to 0
606set r_draworder 0 as above, but creates the cvar if not present
607
608Cvars are restricted from having the same names as commands to keep this
609interface from being ambiguous.
610
611The are also occasionally used to communicated information between different
612modules of the program.
613
614*/
615
616// sets the default value of a variable
617void Cvar_SetDefault( cvar_t *var, const char *var_value );
618
619cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
620// creates the variable if it doesn't exist, or returns the existing one
621// if it exists, the value will not be changed, but flags will be ORed in
622// that allows variables to be unarchived without needing bitflags
623// if value is "", the value will not override a previously set value.
624
625void Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags );
626// basically a slightly modified Cvar_Get for the interpreted modules
627
628void Cvar_Update( vmCvar_t *vmCvar );
629// updates an interpreted modules' version of a cvar
630
631void Cvar_Set( const char *var_name, const char *value );
632// will create the variable with no flags if it doesn't exist
633
634cvar_t *Cvar_Set2( const char *var_name, const char *value, qboolean force );
635// will create the variable with no flags if it doesn't exist
636// can force
637
638cvar_t *Cvar_Next( cvar_t *var );
639// gets the next var
640
641void Cvar_SetLatched( const char *var_name, const char *value);
642// don't set the cvar immediately
643
644void Cvar_SetValue( const char *var_name, float value );
645// expands value to a string and calls Cvar_Set
646
647cvar_t *Cvar_FindVar( const char *var_name );
648float Cvar_VariableValue( const char *var_name );
649int Cvar_VariableIntegerValue(const char* var_name);
650float Cvar_VariableFloatValue(const char* var_name);
651// returns 0 if not defined or non numeric
652
653char *Cvar_VariableString( const char *var_name );
654void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize );
655
656// find a compelte variable
657const char *Cvar_CompleteVariable( const char *partial );
658const char *Cvar_CompleteVariableByNumber( const char *partial, int number );
659// returns an empty string if not defined
660
661int Cvar_Flags(const char *var_name);
662// returns CVAR_NONEXISTENT if cvar doesn't exist or the flags of that particular CVAR.
663
664void Cvar_CommandCompletion( void(*callback)(const char *s) );
665// callback with each valid string
666
667void Cvar_Reset( const char *var_name );
668void Cvar_ForceReset(const char *var_name);
669
670void Cvar_SetCheatState( void );
671// reset all testing vars to a safe value
672
673qboolean Cvar_Command( void );
674// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
675// command. Returns true if the command was a variable reference that
676// was handled. (print or change)
677
678void Cvar_WriteVariables( fileHandle_t f );
679// writes lines containing "set variable value" for all variables
680// with the archive flag set to true.
681
682void Cvar_Init( void );
683
684char *Cvar_InfoString( int bit );
685char *Cvar_InfoString_Big( int bit );
686// returns an info string containing all the cvars that have the given bit set
687// in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
688void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
689void Cvar_CheckRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral );
690void Cvar_SetDescription( cvar_t *var, const char *var_description );
691
692void Cvar_Restart(qboolean unsetVM);
693void Cvar_Restart_f( void );
694void Cvar_SaveGameRestart_f( void );
695
696void Cvar_CompleteCvarName(const char* args, int argNum);
697
698cvar_t *Cvar_Unset(cvar_t *cv);
699
700extern int cvar_modifiedFlags;
701extern qboolean cvar_global_force;
702// whenever a cvar is modifed, its flags will be OR'd into this, so
703// a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO,
704// etc, variables have been modified since the last check. The bit
705// can then be cleared to allow another change detection.
706
707/*
708==============================================================
709
710FILESYSTEM
711
712No stdio calls should be used by any part of the game, because
713we need to deal with all sorts of directory and seperator char
714issues.
715==============================================================
716*/
717
718// referenced flags
719// these are in loop specific order so don't change the order
720#define FS_GENERAL_REF 0x01
721#define FS_UI_REF 0x02
722#define FS_CGAME_REF 0x04
723#define FS_QAGAME_REF 0x08
724// number of id paks that will never be autodownloaded from baseq3
725#define NUM_ID_PAKS 5
726
727#define MAX_FILE_HANDLES 64
728
729#ifdef DEDICATED
730# define Q3CONFIG_CFG CONFIG_PREFIX "_server.cfg"
731#else
732# define Q3CONFIG_CFG CONFIG_PREFIX ".cfg"
733#endif
734
735qboolean FS_Initialized( void );
736
737void FS_InitFilesystem( void );
738void FS_Shutdown( qboolean closemfp );
739
740qboolean FS_ConditionalRestart( int checksumFeed, qboolean disconnect );
741void FS_Restart( int checksumFeed );
742// shutdown and restart the filesystem so changes to fs_gamedir can take effect
743
744char **FS_ListFilteredFiles( const char *path, const char *extension, const char *filter, qboolean wantSubs, int *numfiles, qboolean allowNonPureFilesOnDisk );
745char **FS_ListFiles( const char *directory, const char *extension, qboolean wantSubs, int *numfiles );
746// directory should not have either a leading or trailing /
747// if extension is "/", only subdirectories will be returned
748// the returned files will not include any directories or /
749
750void FS_FreeFileList( char **list );
751
752qboolean FS_FileExists_HomeConfig( const char *file );
753qboolean FS_FileExists_HomeData( const char *file );
754qboolean FS_FileExists_HomeState( const char *file );
755
756void FS_CorrectCase(char* path);
757qboolean FS_CreatePath (const char *OSPath);
758
759char *FS_BaseDir_BuildOSPath( const char *base, const char *qpath );
760char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
761
762int FS_LoadStack( void );
763
764int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
765int FS_GetModList( char *listbuf, int bufsize );
766
767void FS_GetModDescription(const char* modDir, char* description, int descriptionLen);
768
769fileHandle_t FS_FOpenFileWrite_HomeConfig( const char *filename );
770fileHandle_t FS_FOpenFileWrite_HomeData( const char *filename );
771fileHandle_t FS_FOpenFileWrite_HomeState( const char *filename );
772fileHandle_t FS_FOpenFileAppend_HomeData( const char *filename );
773fileHandle_t FS_FCreateOpenPipeFile( const char *filename );
774fileHandle_t FS_FOpenTextFileWrite_HomeConfig(const char* qpath);
775fileHandle_t FS_FOpenTextFileWrite_HomeData(const char* qpath);
776fileHandle_t FS_FOpenTextFileWrite_HomeState(const char* qpath);
777// will properly create any needed paths and deal with seperater character issues
778
779fileHandle_t FS_BaseDir_FOpenFileWrite_HomeConfig( const char *filename );
780fileHandle_t FS_BaseDir_FOpenFileWrite_HomeData( const char *filename );
781fileHandle_t FS_BaseDir_FOpenFileWrite_HomeState( const char *filename );
782long FS_BaseDir_FOpenFileRead( const char *filename, fileHandle_t *fp );
783void FS_BaseDir_Rename_HomeData( const char *from, const char *to, qboolean safe );
784void FS_CanonicalFilename( char *filename );
785
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, ... ) Q_PRINTF_FUNC(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_Remove( const char *osPath );
881void FS_Remove_HomeData( const char *homePath );
882
883void FS_FilenameCompletion( const char *dir, const char *ext,
884 qboolean stripExt, void(*callback)(const char *s), qboolean allowNonPureFilesOnDisk );
885
886const char* FS_GetCurrentGameDir();
887void FS_GetRelativeFilename( const char *currentDirectory, const char *absoluteFilename, char *out, size_t destlen );
888
889void FS_FileTime(const char* filename, char* date, char* size);
890
891void FS_CorrectCase(char* path);
892
893extern cvar_t* fs_debug;
894extern cvar_t* fs_mapdir;
895
896/*
897==============================================================
898
899Edit fields and command line history/completion
900
901==============================================================
902*/
903
904#define MAX_EDIT_LINE 256
905typedef struct {
906 int cursor;
907 int scroll;
908 int widthInChars;
909 char buffer[MAX_EDIT_LINE];
910} field_t;
911
912void Field_Clear( field_t *edit );
913void Field_AutoComplete( field_t *edit );
914void Field_CompleteKeyname( void );
915void Field_CompleteFilename( const char *dir,
916 const char *ext, qboolean stripExt, qboolean allowNonPureFilesOnDisk );
917void Field_CompleteCommand( char *cmd,
918 qboolean doCommands, qboolean doCvars );
919void Field_CompletePlayerName( const char **names, int count );
920/*
921==============================================================
922
923MISC
924
925==============================================================
926*/
927
928// returnbed by Sys_GetProcessorId
929#define CPUID_GENERIC 0 // any unrecognized processor
930
931#define CPUID_AXP 0x10
932
933#define CPUID_INTEL_UNSUPPORTED 0x20 // Intel 386/486
934#define CPUID_INTEL_PENTIUM 0x21 // Intel Pentium or PPro
935#define CPUID_INTEL_MMX 0x22 // Intel Pentium/MMX or P2/MMX
936#define CPUID_INTEL_KATMAI 0x23 // Intel Katmai
937
938#define CPUID_AMD_3DNOW 0x30 // AMD K6 3DNOW!
939
940/*
941==============================================================
942
943MISC
944
945==============================================================
946*/
947
948// vsnprintf is ISO/IEC 9899:1999
949// abstracting this to make it portable
950#ifdef _WIN32
951#define Q_vsnprintf _vsnprintf
952#define Q_snprintf _snprintf
953#else
954#define Q_vsnprintf vsnprintf
955#define Q_snprintf snprintf
956#endif
957
958// centralizing the declarations for cl_cdkey
959// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470
960extern char cl_cdkey[34];
961
962// returned by Sys_GetProcessorFeatures
963typedef enum
964{
965 CF_RDTSC = 1 << 0,
966 CF_MMX = 1 << 1,
967 CF_MMX_EXT = 1 << 2,
968 CF_3DNOW = 1 << 3,
969 CF_3DNOW_EXT = 1 << 4,
970 CF_SSE = 1 << 5,
971 CF_SSE2 = 1 << 6,
972 CF_ALTIVEC = 1 << 7
973} cpuFeatures_t;
974
975// centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
976#define MAXPRINTMSG 4096
977
978
979#define MAX_RENDER_STRINGS 8
980#define MAX_RENDER_STRING_LENGTH 32
981
982char *CopyString( const char *in );
983void Info_Print( const char *s );
984
985void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *));
986void Com_EndRedirect( void );
987void QDECL Com_Printf( const char *fmt, ... ) Q_PRINTF_FUNC(1, 2);
988void QDECL Com_DPrintf( const char *fmt, ... ) Q_PRINTF_FUNC(1, 2);
989void QDECL Com_Error( int code, const char *fmt, ... ) Q_NO_RETURN Q_PRINTF_FUNC(2, 3);
990void Com_Quit_f( void ) Q_NO_RETURN;
991void Com_GameRestart(int checksumFeed, qboolean disconnect);
992
993int Com_Milliseconds( void ); // will be journaled properly
994unsigned Com_BlockChecksum( const void *buffer, int length );
995char *Com_MD5File(const char *filename, int length, const char *prefix, int prefix_len);
996int Com_HashKey(char *string, int maxlen);
997int Com_Filter(const char *filter, const char *name, int casesensitive);
998int Com_FilterPath(const char *filter, const char *name, int casesensitive);
999int Com_RealTime(qtime_t *qtime);
1000qboolean Com_SafeMode( void );
1001void Com_RunAndTimeServerPacket(netadr_t *evFrom, msg_t *buf);
1002
1003qboolean Com_IsVoipTarget(uint8_t *voipTargets, int voipTargetsSize, int clientNum);
1004
1005void Com_StartupVariable( const char *match );
1006// checks for and removes command line "+set var arg" constructs
1007// if match is NULL, all set commands will be executed, otherwise
1008// only a set with the exact name. Only used during startup.
1009qboolean Com_PlayerNameToFieldString( char *str, int length, const char *name );
1010qboolean Com_FieldStringToPlayerName( char *name, int length, const char *rawname );
1011int QDECL Com_strCompare( const void *a, const void *b );
1012
1013
1014extern float currentfps;
1015extern cvar_t *paused;
1016extern cvar_t *config;
1017extern cvar_t *fps;
1018extern cvar_t *developer;
1019extern cvar_t *com_dedicated;
1020extern cvar_t *com_speeds;
1021extern cvar_t *com_timescale;
1022extern cvar_t *com_sv_running;
1023extern cvar_t *com_cl_running;
1024extern cvar_t *com_viewlog; // 0 = hidden, 1 = visible, 2 = minimized
1025extern cvar_t *com_shortversion;
1026extern cvar_t *com_version;
1027extern cvar_t *autopaused;
1028extern cvar_t *deathmatch;
1029extern cvar_t *com_blood;
1030extern cvar_t *com_buildScript; // for building release pak files
1031extern cvar_t *com_radar_range;
1032extern cvar_t *console_spam_filter;
1033extern cvar_t *com_journal;
1034extern cvar_t *com_cameraMode;
1035extern cvar_t *com_ansiColor;
1036extern cvar_t *com_unfocused;
1037extern cvar_t *com_maxfpsUnfocused;
1038extern cvar_t *com_minimized;
1039extern cvar_t *com_maxfpsMinimized;
1040extern cvar_t *com_altivec;
1041extern cvar_t *com_standalone;
1042extern cvar_t *com_gamename;
1043extern cvar_t *com_basegame;
1044extern cvar_t *com_homepath;
1045extern cvar_t *com_altivec;
1046
1047// both client and server must agree to pause
1048extern cvar_t *cl_paused;
1049extern cvar_t *sv_paused;
1050
1051extern cvar_t *cl_packetdelay;
1052extern cvar_t *sv_packetdelay;
1053
1054extern cvar_t* com_protocol;
1055#ifdef LEGACY_PROTOCOL
1056extern cvar_t* com_legacyprotocol;
1057#endif
1058#ifndef DEDICATED
1059extern cvar_t* con_autochat;
1060#endif
1061extern cvar_t* com_target_game;
1062extern cvar_t* com_target_shortversion;
1063extern cvar_t* com_target_version;
1064extern cvar_t* com_target_extension;
1065extern cvar_t* com_target_demo;
1066
1067extern cvar_t* com_updatecheck_enabled;
1068extern cvar_t* com_updatecheck_interval;
1069
1070extern int protocol_version_demo;
1071extern int protocol_version_full;
1072
1073// com_speeds times
1074extern int time_game;
1075extern int time_frontend;
1076extern int time_backend; // renderer backend time
1077
1078extern int com_frameTime;
1079extern int com_frameMsec;
1080
1081extern qboolean com_errorEntered;
1082extern qboolean com_fullyInitialized;
1083extern qboolean com_gotOriginalConfig;
1084extern qboolean com_firstConfig;
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, ...) Q_NO_RETURN Q_PRINTF_FUNC(1, 2);
1369void Sys_Quit (void) Q_NO_RETURN;
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
1411char *Sys_DefaultHomeConfigPath(void);
1412char *Sys_DefaultHomeDataPath(void);
1413char *Sys_DefaultHomeStatePath(void);
1414const char *Sys_Dirname( char *path );
1415const char *Sys_Basename( char *path );
1416char *Sys_ConsoleInput( void );
1417
1418void SetProgramPath( const char *path );
1419char *Sys_DefaultBasePath( void );
1420char *Sys_DefaultUserPath( void );
1421char *Sys_DefaultOutputPath( void );
1422
1423char **Sys_ListFiles( const char *directory, const char *extension, const char *filter, int *numfiles, qboolean wantsubs );
1424void Sys_FreeFileList( char **list );
1425void Sys_Sleep(int msec);
1426
1427void Sys_InitStreamThread(void);
1428void Sys_ShutdownStreamThread(void);
1429void Sys_BeginStreamedFile(fileHandle_t f, int readAhead);
1430void Sys_EndStreamedFile(fileHandle_t f);
1431int Sys_StreamedRead(void* buffer, int size, int count, fileHandle_t f);
1432void Sys_StreamSeek(fileHandle_t f, int offset, int origin);
1433
1434qboolean Sys_LowPhysicalMemory(void);
1435
1436void Sys_SetEnv(const char* name, const char* value);
1437
1438void SetNormalThreadPriority( void );
1439void SetBelowNormalThreadPriority( void );
1440
1441void RecoverLostAutodialData( void );
1442
1443void Sys_CloseMutex( void );
1444void Sys_ShowConsole( int visLevel, qboolean quitOnClose );
1445void Sys_DebugPrint(const char* message);
1446void Sys_PumpMessageLoop( void );
1447
1448qboolean SaveRegistryInfo( qboolean user, const char *pszName, void *pvBuf, long lSize );
1449qboolean LoadRegistryInfo( qboolean user, const char *pszName, void *pvBuf, long *plSize );
1450
1451qboolean IsFirstRun( void );
1452qboolean IsNewConfig( void );
1453qboolean IsSafeMode( void );
1454void ClearNewConfigFlag( void );
1455const char *Sys_GetWholeClipboard( void );
1456void Sys_SetClipboard( const char *contents );
1457
1458typedef enum
1459{
1460 DR_YES = 0,
1461 DR_NO = 1,
1462 DR_OK = 0,
1463 DR_CANCEL = 1
1464} dialogResult_t;
1465
1466typedef enum
1467{
1468 DT_INFO,
1469 DT_WARNING,
1470 DT_ERROR,
1471 DT_YES_NO,
1472 DT_OK_CANCEL
1473} dialogType_t;
1474
1475dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *title );
1476qboolean Sys_OpenFolderInFileManager( const char *path, qboolean create );
1477
1478void Sys_RemovePIDFile( const char *gamedir );
1479void Sys_InitPIDFile( const char *gamedir );
1480
1481void Sys_ProcessBackgroundTasks();
1482
1483/* This is based on the Adaptive Huffman algorithm described in Sayood's Data
1484 * Compression book. The ranks are not actually stored, but implicitly defined
1485 * by the location of a node within a doubly-linked list */
1486
1487#define NYT HMAX /* NYT = Not Yet Transmitted */
1488#define INTERNAL_NODE (HMAX+1)
1489
1490typedef struct nodetype {
1491 struct nodetype *left, *right, *parent; /* tree structure */
1492 struct nodetype *next, *prev; /* doubly-linked list */
1493 struct nodetype **head; /* highest ranked node in block */
1494 int weight;
1495 int symbol;
1496} node_t;
1497
1498#define HMAX 256 /* Maximum symbol */
1499
1500typedef struct {
1501 int blocNode;
1502 int blocPtrs;
1503
1504 node_t* tree;
1505 node_t* lhead;
1506 node_t* ltail;
1507 node_t* loc[HMAX+1];
1508 node_t** freelist;
1509
1510 node_t nodeList[768];
1511 node_t* nodePtrs[768];
1512} huff_t;
1513
1514typedef struct {
1515 huff_t compressor;
1516 huff_t decompressor;
1517} huffman_t;
1518
1519void Huff_Compress(msg_t *buf, int offset);
1520void Huff_Decompress(msg_t *buf, int offset);
1521void Huff_Init(huffman_t *huff);
1522void Huff_addRef(huff_t* huff, byte ch);
1523int Huff_Receive (node_t *node, int *ch, byte *fin);
1524void Huff_transmit (huff_t *huff, int ch, byte *fout, int maxoffset);
1525void Huff_offsetReceive (node_t *node, int *ch, byte *fin, int *offset, int maxoffset);
1526void Huff_offsetTransmit (huff_t *huff, int ch, byte *fout, int *offset, int maxoffset);
1527void Huff_putBit( int bit, byte *fout, int *offset);
1528int Huff_getBit( byte *fout, int *offset);
1529
1530extern huffman_t clientHuffTables;
1531
1532#define SV_ENCODE_START 4
1533#define SV_DECODE_START 12
1534#define CL_ENCODE_START 12
1535#define CL_DECODE_START 4
1536
1537// flags for sv_allowDownload and cl_allowDownload
1538#define DLF_ENABLE 1
1539#define DLF_NO_REDIRECT 2
1540#define DLF_NO_UDP 4
1541#define DLF_NO_DISCONNECT 8
1542
1543#ifdef __cplusplus
1544}
1545#endif
1546
1547#endif // _QCOMMON_H_
Definition q_shared.h:2013
Definition qcommon.h:905
Definition q_shared.h:1693
Definition qcommon.h:1500
Definition qcommon.h:1514
Definition qcommon.h:40
Definition qcommon.h:218
Definition qcommon.h:265
Definition qcommon.h:335
Definition qcommon.h:308
Definition qcommon.h:314
Definition qcommon.h:1490
Definition q_shared.h:1744
Definition qcommon.h:1332
Definition q_shared.h:1875
Definition q_shared.h:1363
Definition q_shared.h:207