forked from id-Software/Enemy-Territory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq_shared.h
1740 lines (1354 loc) · 56.3 KB
/
q_shared.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
===========================================================================
Wolfenstein: Enemy Territory GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
This file is part of the Wolfenstein: Enemy Territory GPL Source Code (Wolf ET Source Code).
Wolf ET Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Wolf ET Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Wolf ET Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Wolf: ET Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Wolf ET Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __Q_SHARED_H
#define __Q_SHARED_H
// q_shared.h -- included first by ALL program modules.
// A user mod should never modify this file
//#define PRE_RELEASE_DEMO
#ifndef PRE_RELEASE_DEMO
#define Q3_VERSION "ET 2.60d"
#else
#define Q3_VERSION "ET 2.32"
#endif // PRE_RELEASE_DEMO
// 2.60d: Mac OSX universal binaries
// 2.60c: Mac OSX universal binaries
// 2.60b: CVE-2006-2082 fix
// 2.6x: Enemy Territory - ETPro team maintenance release
// 2.5x: Enemy Territory FINAL
// 2.4x: Enemy Territory RC's
// 2.3x: Enemy Territory TEST
// 2.2+: post SP removal
// 2.1+: post Enemy Territory moved standalone
// 2.x: post Enemy Territory
// 1.x: pre Enemy Territory
////
// 1.3-MP : final for release
// 1.1b - TTimo SP linux release (+ MP updates)
// 1.1b5 - Mac update merge in
#define CONFIG_NAME "etconfig.cfg"
//#define LOCALIZATION_SUPPORT
#define NEW_ANIMS
#define MAX_TEAMNAME 32
#if defined _WIN32 && !defined __GNUC__
#pragma warning(disable : 4018) // signed/unsigned mismatch
#pragma warning(disable : 4032)
#pragma warning(disable : 4051)
#pragma warning(disable : 4057) // slightly different base types
#pragma warning(disable : 4100) // unreferenced formal parameter
#pragma warning(disable : 4115)
#pragma warning(disable : 4125) // decimal digit terminates octal escape sequence
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4136)
#pragma warning(disable : 4152) // nonstandard extension, function/data pointer conversion in expression
#pragma warning(disable : 4201)
#pragma warning(disable : 4214)
#pragma warning(disable : 4244)
//#pragma warning(disable : 4142) // benign redefinition
#pragma warning(disable : 4305) // truncation from const double to float
//#pragma warning(disable : 4310) // cast truncates constant value
//#pragma warning(disable : 4505) // unreferenced local function has been removed
#pragma warning(disable : 4514)
#pragma warning(disable : 4702) // unreachable code
#pragma warning(disable : 4711) // selected for automatic inline expansion
#pragma warning(disable : 4220) // varargs matches remaining parameters
#endif
#if defined( ppc ) || defined( __ppc ) || defined( __ppc__ ) || defined( __POWERPC__ )
#define idppc 1
#endif
/**********************************************************************
VM Considerations
The VM can not use the standard system headers because we aren't really
using the compiler they were meant for. We use bg_lib.h which contains
prototypes for the functions we define for our own use in bg_lib.c.
When writing mods, please add needed headers HERE, do not start including
stuff like <stdio.h> in the various .c files that make up each of the VMs
since you will be including system headers files can will have issues.
Remember, if you use a C library function that is not defined in bg_lib.c,
you will have to add your own version for support in the VM.
**********************************************************************/
#ifdef Q3_VM
#include "bg_lib.h"
#else
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <limits.h>
#include <sys/stat.h> // rain
#include <float.h>
#endif
// use MSVC inline asm version of C functions
#if defined _M_IX86
#define id386 1
#else
#define id386 0
#endif
// for windows fastcall option
#define QDECL
//bani
//======================= GNUC DEFINES ==================================
#ifdef __GNUC__
#define _attribute( x ) __attribute__( x )
#else
#define _attribute( x )
#endif
//======================= WIN32 DEFINES =================================
#ifdef WIN32
#define MAC_STATIC
#undef QDECL
#define QDECL __cdecl
// buildstring will be incorporated into the version string
#ifdef NDEBUG
#ifdef _M_IX86
#define CPUSTRING "win-x86"
#elif defined _M_ALPHA
#define CPUSTRING "win-AXP"
#endif
#else
#ifdef _M_IX86
#define CPUSTRING "win-x86-debug"
#elif defined _M_ALPHA
#define CPUSTRING "win-AXP-debug"
#endif
#endif
#define PATH_SEP '\\'
#endif
//======================= MAC OS X SERVER DEFINES =====================
#if defined( MACOS_X )
#error WTF
#define MAC_STATIC
#define CPUSTRING "MacOS_X"
#define PATH_SEP '/'
// Vanilla PPC code, but since PPC has a reciprocal square root estimate instruction,
// runs *much* faster than calling sqrt(). We'll use two Newton-Raphson
// refinement steps to get bunch more precision in the 1/sqrt() value for very little cost.
// We'll then multiply 1/sqrt times the original value to get the sqrt.
// This is about 12.4 times faster than sqrt() and according to my testing (not exhaustive)
// it returns fairly accurate results (error below 1.0e-5 up to 100000.0 in 0.1 increments).
static inline float idSqrt( float x ) {
const float half = 0.5;
const float one = 1.0;
float B, y0, y1;
// This'll NaN if it hits frsqrte. Handle both +0.0 and -0.0
if ( Q_fabs( x ) == 0.0 ) {
return x;
}
B = x;
#ifdef __GNUC__
asm ( "frsqrte %0,%1" : "=f" ( y0 ) : "f" ( B ) );
#else
y0 = __frsqrte( B );
#endif
/* First refinement step */
y1 = y0 + half * y0 * ( one - B * y0 * y0 );
/* Second refinement step -- copy the output of the last step to the input of this step */
y0 = y1;
y1 = y0 + half * y0 * ( one - B * y0 * y0 );
/* Get sqrt(x) from x * 1/sqrt(x) */
return x * y1;
}
#define sqrt idSqrt
#endif
//======================= MAC DEFINES =================================
#ifdef __MACOS__
#define MAC_STATIC
#define CPUSTRING "OSX-universal"
#define PATH_SEP '/'
void Sys_PumpEvents( void );
#endif
//======================= LINUX DEFINES =================================
// the mac compiler can't handle >32k of locals, so we
// just waste space and make big arrays static...
#ifdef __linux__
#define MAC_STATIC
#ifdef __i386__
#define CPUSTRING "linux-i386"
#elif defined __axp__
#define CPUSTRING "linux-alpha"
#else
#define CPUSTRING "linux-other"
#endif
#define PATH_SEP '/'
#endif
//=============================================================
typedef unsigned char byte;
typedef enum {qfalse, qtrue} qboolean;
typedef int qhandle_t;
typedef int sfxHandle_t;
typedef int fileHandle_t;
typedef int clipHandle_t;
//#define SND_NORMAL 0x000 // (default) Allow sound to be cut off only by the same sound on this channel
#define SND_OKTOCUT 0x001 // Allow sound to be cut off by any following sounds on this channel
#define SND_REQUESTCUT 0x002 // Allow sound to be cut off by following sounds on this channel only for sounds who request cutoff
#define SND_CUTOFF 0x004 // Cut off sounds on this channel that are marked 'SND_REQUESTCUT'
#define SND_CUTOFF_ALL 0x008 // Cut off all sounds on this channel
#define SND_NOCUT 0x010 // Don't cut off. Always let finish (overridden by SND_CUTOFF_ALL)
#define SND_NO_ATTENUATION 0x020 // don't attenuate (even though the sound is in voice channel, for example)
#ifndef NULL
#define NULL ( (void *)0 )
#endif
#define MAX_QINT 0x7fffffff
#define MIN_QINT ( -MAX_QINT - 1 )
// TTimo gcc: was missing, added from Q3 source
#ifndef max
#define max( x, y ) ( ( ( x ) > ( y ) ) ? ( x ) : ( y ) )
#define min( x, y ) ( ( ( x ) < ( y ) ) ? ( x ) : ( y ) )
#endif
// angle indexes
#define PITCH 0 // up / down
#define YAW 1 // left / right
#define ROLL 2 // fall over
// RF, this is just here so different elements of the engine can be aware of this setting as it changes
#define MAX_SP_CLIENTS 64 // increasing this will increase memory usage significantly
// the game guarantees that no string from the network will ever
// exceed MAX_STRING_CHARS
#define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString
#define MAX_STRING_TOKENS 256 // max tokens resulting from Cmd_TokenizeString
#define MAX_TOKEN_CHARS 1024 // max length of an individual token
#define MAX_INFO_STRING 1024
#define MAX_INFO_KEY 1024
#define MAX_INFO_VALUE 1024
#define BIG_INFO_STRING 8192 // used for system info key only
#define BIG_INFO_KEY 8192
#define BIG_INFO_VALUE 8192
#define MAX_QPATH 64 // max length of a quake game pathname
#define MAX_OSPATH 256 // max length of a filesystem pathname
// rain - increased to 36 to match MAX_NETNAME, fixes #13 - UI stuff breaks
// with very long names
#define MAX_NAME_LENGTH 36 // max length of a client name
#define MAX_SAY_TEXT 150
#define MAX_BINARY_MESSAGE 32768 // max length of binary message
typedef enum {
MESSAGE_EMPTY = 0,
MESSAGE_WAITING, // rate/packet limited
MESSAGE_WAITING_OVERFLOW, // packet too large with message
} messageStatus_t;
// paramters for command buffer stuffing
typedef enum {
EXEC_NOW, // don't return until completed, a VM should NEVER use this,
// because some commands might cause the VM to be unloaded...
EXEC_INSERT, // insert at current position, but don't run yet
EXEC_APPEND // add to end of the command buffer (normal case)
} cbufExec_t;
//
// these aren't needed by any of the VMs. put in another header?
//
#define MAX_MAP_AREA_BYTES 32 // bit vector of area visibility
// print levels from renderer (FIXME: set up for game / cgame?)
typedef enum {
PRINT_ALL,
PRINT_DEVELOPER, // only print when "developer 1"
PRINT_WARNING,
PRINT_ERROR
} printParm_t;
#ifdef ERR_FATAL
#undef ERR_FATAL // this is be defined in malloc.h
#endif
// parameters to the main Error routine
typedef enum {
ERR_FATAL, // exit the entire game with a popup window
ERR_VID_FATAL, // exit the entire game with a popup window and doesn't delete profile.pid
ERR_DROP, // print to console and disconnect from game
ERR_SERVERDISCONNECT, // don't kill server
ERR_DISCONNECT, // client disconnected from the server
ERR_NEED_CD, // pop up the need-cd dialog
ERR_AUTOUPDATE
} errorParm_t;
// font rendering values used by ui and cgame
#define PROP_GAP_WIDTH 3
#define PROP_SPACE_WIDTH 8
#define PROP_HEIGHT 27
#define PROP_SMALL_SIZE_SCALE 0.75
#define BLINK_DIVISOR 200
#define PULSE_DIVISOR 75
#define UI_LEFT 0x00000000 // default
#define UI_CENTER 0x00000001
#define UI_RIGHT 0x00000002
#define UI_FORMATMASK 0x00000007
#define UI_SMALLFONT 0x00000010
#define UI_BIGFONT 0x00000020 // default
#define UI_GIANTFONT 0x00000040
#define UI_DROPSHADOW 0x00000800
#define UI_BLINK 0x00001000
#define UI_INVERSE 0x00002000
#define UI_PULSE 0x00004000
// JOSEPH 10-24-99
#define UI_MENULEFT 0x00008000
#define UI_MENURIGHT 0x00010000
#define UI_EXSMALLFONT 0x00020000
#define UI_MENUFULL 0x00080000
// END JOSEPH
#define UI_SMALLFONT75 0x00100000
#if defined( _DEBUG ) && !defined( BSPC )
#define HUNK_DEBUG
#endif
typedef enum {
h_high,
h_low,
h_dontcare
} ha_pref;
#ifdef HUNK_DEBUG
#define Hunk_Alloc( size, preference ) Hunk_AllocDebug( size, preference, # size, __FILE__, __LINE__ )
void *Hunk_AllocDebug( int size, ha_pref preference, char *label, char *file, int line );
#else
void *Hunk_Alloc( int size, ha_pref preference );
#endif
#ifdef __linux__
// show_bug.cgi?id=371
// custom Snd_Memset implementation for glibc memset bug workaround
void Snd_Memset( void* dest, const int val, const size_t count );
#else
#define Snd_Memset Com_Memset
#endif
void Com_Memset( void* dest, const int val, const size_t count );
void Com_Memcpy( void* dest, const void* src, const size_t count );
#define CIN_system 1
#define CIN_loop 2
#define CIN_hold 4
#define CIN_silent 8
#define CIN_shader 16
/*
==============================================================
MATHLIB
==============================================================
*/
typedef float vec_t;
typedef vec_t vec2_t[2];
typedef vec_t vec3_t[3];
typedef vec_t vec4_t[4];
typedef vec_t vec5_t[5];
typedef int fixed4_t;
typedef int fixed8_t;
typedef int fixed16_t;
#ifndef M_PI
#define M_PI 3.14159265358979323846f // matches value in gcc v2 math.h
#endif
#define NUMVERTEXNORMALS 162
extern vec3_t bytedirs[NUMVERTEXNORMALS];
// all drawing is done to a 640*480 virtual screen size
// and will be automatically scaled to the real resolution
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define TINYCHAR_WIDTH ( SMALLCHAR_WIDTH )
#define TINYCHAR_HEIGHT ( SMALLCHAR_HEIGHT )
#define MINICHAR_WIDTH 8
#define MINICHAR_HEIGHT 12
#define SMALLCHAR_WIDTH 8
#define SMALLCHAR_HEIGHT 16
#define BIGCHAR_WIDTH 16
#define BIGCHAR_HEIGHT 16
#define GIANTCHAR_WIDTH 32
#define GIANTCHAR_HEIGHT 48
extern vec4_t colorBlack;
extern vec4_t colorRed;
extern vec4_t colorGreen;
extern vec4_t colorBlue;
extern vec4_t colorYellow;
extern vec4_t colorOrange;
extern vec4_t colorMagenta;
extern vec4_t colorCyan;
extern vec4_t colorWhite;
extern vec4_t colorLtGrey;
extern vec4_t colorMdGrey;
extern vec4_t colorDkGrey;
extern vec4_t colorMdRed;
extern vec4_t colorMdGreen;
extern vec4_t colorDkGreen;
extern vec4_t colorMdCyan;
extern vec4_t colorMdYellow;
extern vec4_t colorMdOrange;
extern vec4_t colorMdBlue;
extern vec4_t clrBrown;
extern vec4_t clrBrownDk;
extern vec4_t clrBrownLine;
extern vec4_t clrBrownText;
extern vec4_t clrBrownTextDk;
extern vec4_t clrBrownTextDk2;
extern vec4_t clrBrownTextLt;
extern vec4_t clrBrownTextLt2;
extern vec4_t clrBrownLineFull;
#define GAME_INIT_FRAMES 6
#define FRAMETIME 100 // msec
#define Q_COLOR_ESCAPE '^'
#define Q_IsColorString( p ) ( p && *( p ) == Q_COLOR_ESCAPE && *( ( p ) + 1 ) && *( ( p ) + 1 ) != Q_COLOR_ESCAPE )
#define COLOR_BLACK '0'
#define COLOR_RED '1'
#define COLOR_GREEN '2'
#define COLOR_YELLOW '3'
#define COLOR_BLUE '4'
#define COLOR_CYAN '5'
#define COLOR_MAGENTA '6'
#define COLOR_WHITE '7'
#define COLOR_ORANGE '8'
#define COLOR_MDGREY '9'
#define COLOR_LTGREY ':'
//#define COLOR_LTGREY ';'
#define COLOR_MDGREEN '<'
#define COLOR_MDYELLOW '='
#define COLOR_MDBLUE '>'
#define COLOR_MDRED '?'
#define COLOR_LTORANGE 'A'
#define COLOR_MDCYAN 'B'
#define COLOR_MDPURPLE 'C'
#define COLOR_NULL '*'
#define COLOR_BITS 31
#define ColorIndex( c ) ( ( ( c ) - '0' ) & COLOR_BITS )
#define S_COLOR_BLACK "^0"
#define S_COLOR_RED "^1"
#define S_COLOR_GREEN "^2"
#define S_COLOR_YELLOW "^3"
#define S_COLOR_BLUE "^4"
#define S_COLOR_CYAN "^5"
#define S_COLOR_MAGENTA "^6"
#define S_COLOR_WHITE "^7"
#define S_COLOR_ORANGE "^8"
#define S_COLOR_MDGREY "^9"
#define S_COLOR_LTGREY "^:"
//#define S_COLOR_LTGREY "^;"
#define S_COLOR_MDGREEN "^<"
#define S_COLOR_MDYELLOW "^="
#define S_COLOR_MDBLUE "^>"
#define S_COLOR_MDRED "^?"
#define S_COLOR_LTORANGE "^A"
#define S_COLOR_MDCYAN "^B"
#define S_COLOR_MDPURPLE "^C"
#define S_COLOR_NULL "^*"
extern vec4_t g_color_table[32];
#define MAKERGB( v, r, g, b ) v[0] = r; v[1] = g; v[2] = b
#define MAKERGBA( v, r, g, b, a ) v[0] = r; v[1] = g; v[2] = b; v[3] = a
// Hex Color string support
#define gethex( ch ) ( ( ch ) > '9' ? ( ( ch ) >= 'a' ? ( ( ch ) - 'a' + 10 ) : ( ( ch ) - '7' ) ) : ( ( ch ) - '0' ) )
#define ishex( ch ) ( ( ch ) && ( ( ( ch ) >= '0' && ( ch ) <= '9' ) || ( ( ch ) >= 'A' && ( ch ) <= 'F' ) || ( ( ch ) >= 'a' && ( ch ) <= 'f' ) ) )
// check if it's format rrggbb r,g,b e {0..9} U {A...F}
#define Q_IsHexColorString( p ) ( ishex( *( p ) ) && ishex( *( ( p ) + 1 ) ) && ishex( *( ( p ) + 2 ) ) && ishex( *( ( p ) + 3 ) ) && ishex( *( ( p ) + 4 ) ) && ishex( *( ( p ) + 5 ) ) )
#define Q_HexColorStringHasAlpha( p ) ( ishex( *( ( p ) + 6 ) ) && ishex( *( ( p ) + 7 ) ) )
#define DEG2RAD( a ) ( ( ( a ) * M_PI ) / 180.0F )
#define RAD2DEG( a ) ( ( ( a ) * 180.0f ) / M_PI )
struct cplane_s;
extern vec3_t vec3_origin;
extern vec3_t axisDefault[3];
#define nanmask ( 255 << 23 )
#define IS_NAN( x ) ( ( ( *(int *)&x ) & nanmask ) == nanmask )
float Q_fabs( float f );
float Q_rsqrt( float f ); // reciprocal square root
#define SQRTFAST( x ) ( 1.0f / Q_rsqrt( x ) )
// fast float to int conversion
#if id386 && !( ( defined __linux__ || defined __FreeBSD__ || defined __GNUC__ ) && ( defined __i386__ ) ) // rb010123
long myftol( float f );
#elif defined( __MACOS__ )
#define myftol( x ) (long)( x )
#else
extern long int lrintf( float x );
#define myftol( x ) lrintf( x )
#endif
signed char ClampChar( int i );
signed short ClampShort( int i );
// this isn't a real cheap function to call!
int DirToByte( vec3_t dir );
void ByteToDir( int b, vec3_t dir );
#if 1
#define DotProduct( x,y ) ( ( x )[0] * ( y )[0] + ( x )[1] * ( y )[1] + ( x )[2] * ( y )[2] )
#define VectorSubtract( a,b,c ) ( ( c )[0] = ( a )[0] - ( b )[0],( c )[1] = ( a )[1] - ( b )[1],( c )[2] = ( a )[2] - ( b )[2] )
#define VectorAdd( a,b,c ) ( ( c )[0] = ( a )[0] + ( b )[0],( c )[1] = ( a )[1] + ( b )[1],( c )[2] = ( a )[2] + ( b )[2] )
#define VectorCopy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2] )
#define VectorScale( v, s, o ) ( ( o )[0] = ( v )[0] * ( s ),( o )[1] = ( v )[1] * ( s ),( o )[2] = ( v )[2] * ( s ) )
#define VectorMA( v, s, b, o ) ( ( o )[0] = ( v )[0] + ( b )[0] * ( s ),( o )[1] = ( v )[1] + ( b )[1] * ( s ),( o )[2] = ( v )[2] + ( b )[2] * ( s ) )
#else
#define DotProduct( x,y ) _DotProduct( x,y )
#define VectorSubtract( a,b,c ) _VectorSubtract( a,b,c )
#define VectorAdd( a,b,c ) _VectorAdd( a,b,c )
#define VectorCopy( a,b ) _VectorCopy( a,b )
#define VectorScale( v, s, o ) _VectorScale( v,s,o )
#define VectorMA( v, s, b, o ) _VectorMA( v,s,b,o )
#endif
#ifdef __LCC__
#ifdef VectorCopy
#undef VectorCopy
// this is a little hack to get more efficient copies in our interpreter
typedef struct {
float v[3];
} vec3struct_t;
#define VectorCopy( a,b ) * (vec3struct_t *)b = *(vec3struct_t *)a;
#endif
#endif
#define VectorClear( a ) ( ( a )[0] = ( a )[1] = ( a )[2] = 0 )
#define VectorNegate( a,b ) ( ( b )[0] = -( a )[0],( b )[1] = -( a )[1],( b )[2] = -( a )[2] )
#define VectorSet( v, x, y, z ) ( ( v )[0] = ( x ), ( v )[1] = ( y ), ( v )[2] = ( z ) )
#define Vector2Set( v, x, y ) ( ( v )[0] = ( x ),( v )[1] = ( y ) )
#define Vector2Copy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1] )
#define Vector2Subtract( a,b,c ) ( ( c )[0] = ( a )[0] - ( b )[0],( c )[1] = ( a )[1] - ( b )[1] )
#define Vector4Set( v, x, y, z, n ) ( ( v )[0] = ( x ),( v )[1] = ( y ),( v )[2] = ( z ),( v )[3] = ( n ) )
#define Vector4Copy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2],( b )[3] = ( a )[3] )
#define Vector4MA( v, s, b, o ) ( ( o )[0] = ( v )[0] + ( b )[0] * ( s ),( o )[1] = ( v )[1] + ( b )[1] * ( s ),( o )[2] = ( v )[2] + ( b )[2] * ( s ),( o )[3] = ( v )[3] + ( b )[3] * ( s ) )
#define Vector4Average( v, b, s, o ) ( ( o )[0] = ( ( v )[0] * ( 1 - ( s ) ) ) + ( ( b )[0] * ( s ) ),( o )[1] = ( ( v )[1] * ( 1 - ( s ) ) ) + ( ( b )[1] * ( s ) ),( o )[2] = ( ( v )[2] * ( 1 - ( s ) ) ) + ( ( b )[2] * ( s ) ),( o )[3] = ( ( v )[3] * ( 1 - ( s ) ) ) + ( ( b )[3] * ( s ) ) )
#define SnapVector( v ) {v[0] = ( (int)( v[0] ) ); v[1] = ( (int)( v[1] ) ); v[2] = ( (int)( v[2] ) );}
// just in case you do't want to use the macros
vec_t _DotProduct( const vec3_t v1, const vec3_t v2 );
void _VectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t out );
void _VectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t out );
void _VectorCopy( const vec3_t in, vec3_t out );
void _VectorScale( const vec3_t in, float scale, vec3_t out );
void _VectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc );
unsigned ColorBytes3( float r, float g, float b );
unsigned ColorBytes4( float r, float g, float b, float a );
float NormalizeColor( const vec3_t in, vec3_t out );
float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
void ClearBounds( vec3_t mins, vec3_t maxs );
void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
qboolean PointInBounds( const vec3_t v, const vec3_t mins, const vec3_t maxs );
int VectorCompare( const vec3_t v1, const vec3_t v2 );
vec_t VectorLength( const vec3_t v );
vec_t VectorLengthSquared( const vec3_t v );
vec_t Distance( const vec3_t p1, const vec3_t p2 );
vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 );
void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
vec_t VectorNormalize( vec3_t v ); // returns vector length
void VectorNormalizeFast( vec3_t v ); // does NOT return vector length, uses rsqrt approximation
vec_t VectorNormalize2( const vec3_t v, vec3_t out );
void VectorInverse( vec3_t v );
void Vector4Scale( const vec4_t in, vec_t scale, vec4_t out );
void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out );
int Q_log2( int val );
float Q_acos( float c );
int Q_rand( int *seed );
float Q_random( int *seed );
float Q_crandom( int *seed );
#define random() ( ( rand() & 0x7fff ) / ( (float)0x7fff ) )
#define crandom() ( 2.0 * ( random() - 0.5 ) )
void vectoangles( const vec3_t value1, vec3_t angles );
float vectoyaw( const vec3_t vec );
void AnglesToAxis( const vec3_t angles, vec3_t axis[3] );
// TTimo: const vec_t ** would require explicit casts for ANSI C conformance
// see unix/const-arg.c
void AxisToAngles( /*const*/ vec3_t axis[3], vec3_t angles );
float VectorDistance( vec3_t v1, vec3_t v2 );
float VectorDistanceSquared( vec3_t v1, vec3_t v2 );
void AxisClear( vec3_t axis[3] );
void AxisCopy( vec3_t in[3], vec3_t out[3] );
void SetPlaneSignbits( struct cplane_s *out );
int BoxOnPlaneSide( vec3_t emins, vec3_t emaxs, struct cplane_s *plane );
float AngleMod( float a );
float LerpAngle( float from, float to, float frac );
void LerpPosition( vec3_t start, vec3_t end, float frac, vec3_t out );
float AngleSubtract( float a1, float a2 );
void AnglesSubtract( vec3_t v1, vec3_t v2, vec3_t v3 );
float AngleNormalize2Pi( float angle );
float AngleNormalize360( float angle );
float AngleNormalize180( float angle );
float AngleDelta( float angle1, float angle2 );
qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal );
void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
void RotatePointAroundVertex( vec3_t pnt, float rot_x, float rot_y, float rot_z, const vec3_t origin );
void RotateAroundDirection( vec3_t axis[3], float yaw );
void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up );
// perpendicular vector could be replaced by this
int PlaneTypeForNormal( vec3_t normal );
void MatrixMultiply( float in1[3][3], float in2[3][3], float out[3][3] );
void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up );
void PerpendicularVector( vec3_t dst, const vec3_t src );
// Ridah
void GetPerpendicularViewVector( const vec3_t point, const vec3_t p1, const vec3_t p2, vec3_t up );
void ProjectPointOntoVector( vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t vProj );
void ProjectPointOntoVectorBounded( vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t vProj );
float DistanceFromLineSquared( vec3_t p, vec3_t lp1, vec3_t lp2 );
float DistanceFromVectorSquared( vec3_t p, vec3_t lp1, vec3_t lp2 );
// done.
//=============================================
float Com_Clamp( float min, float max, float value );
char *COM_SkipPath( char *pathname );
void COM_FixPath( char *pathname );
void COM_StripExtension( const char *in, char *out );
void COM_StripExtension2( const char *in, char *out, int destsize );
void COM_StripFilename( char *in, char *out );
void COM_DefaultExtension( char *path, int maxSize, const char *extension );
void COM_BeginParseSession( const char *name );
void COM_RestoreParseSession( char **data_p );
void COM_SetCurrentParseLine( int line );
int COM_GetCurrentParseLine( void );
char *COM_Parse( char **data_p );
char *COM_ParseExt( char **data_p, qboolean allowLineBreak );
int COM_Compress( char *data_p );
void COM_ParseError( char *format, ... ) _attribute( ( format( printf,1,2 ) ) );
void COM_ParseWarning( char *format, ... ) _attribute( ( format( printf,1,2 ) ) );
int Com_ParseInfos( char *buf, int max, char infos[][MAX_INFO_STRING] );
qboolean COM_BitCheck( const int array[], int bitNum );
void COM_BitSet( int array[], int bitNum );
void COM_BitClear( int array[], int bitNum );
#define MAX_TOKENLENGTH 1024
#ifndef TT_STRING
//token types
#define TT_STRING 1 // string
#define TT_LITERAL 2 // literal
#define TT_NUMBER 3 // number
#define TT_NAME 4 // name
#define TT_PUNCTUATION 5 // punctuation
#endif
typedef struct pc_token_s
{
int type;
int subtype;
int intvalue;
float floatvalue;
char string[MAX_TOKENLENGTH];
int line;
int linescrossed;
} pc_token_t;
// data is an in/out parm, returns a parsed out token
void COM_MatchToken( char**buf_p, char *match );
void SkipBracedSection( char **program );
void SkipBracedSection_Depth( char **program, int depth ); // start at given depth if already
void SkipRestOfLine( char **data );
void Parse1DMatrix( char **buf_p, int x, float *m );
void Parse2DMatrix( char **buf_p, int y, int x, float *m );
void Parse3DMatrix( char **buf_p, int z, int y, int x, float *m );
void QDECL Com_sprintf( char *dest, int size, const char *fmt, ... ) _attribute( ( format( printf,3,4 ) ) );
// mode parm for FS_FOpenFile
typedef enum {
FS_READ,
FS_WRITE,
FS_APPEND,
FS_APPEND_SYNC
} fsMode_t;
typedef enum {
FS_SEEK_CUR,
FS_SEEK_END,
FS_SEEK_SET
} fsOrigin_t;
//=============================================
int Q_isprint( int c );
int Q_islower( int c );
int Q_isupper( int c );
int Q_isalpha( int c );
int Q_isnumeric( int c );
int Q_isalphanumeric( int c );
int Q_isforfilename( int c );
// portable case insensitive compare
int Q_stricmp( const char *s1, const char *s2 );
int Q_strncmp( const char *s1, const char *s2, int n );
int Q_stricmpn( const char *s1, const char *s2, int n );
char *Q_strlwr( char *s1 );
char *Q_strupr( char *s1 );
char *Q_strrchr( const char* string, int c );
#ifdef _WIN32
#define Q_putenv _putenv
#else
#define Q_putenv putenv
#endif
// buffer size safe library replacements
void Q_strncpyz( char *dest, const char *src, int destsize );
void Q_strcat( char *dest, int size, const char *src );
// strlen that discounts Quake color sequences
int Q_PrintStrlen( const char *string );
// removes color sequences from string
char *Q_CleanStr( char *string );
// removes whitespaces and other bad directory characters
char *Q_CleanDirName( char *dirname );
#define _vsnprintf use_Q_vsnprintf
#define vsnprintf use_Q_vsnprintf
int Q_vsnprintf( char *dest, int size, const char *fmt, va_list argptr );
//=============================================
// 64-bit integers for global rankings interface
// implemented as a struct for qvm compatibility
typedef struct
{
byte b0;
byte b1;
byte b2;
byte b3;
byte b4;
byte b5;
byte b6;
byte b7;
} qint64;
//=============================================
short LittleShort( short l );
int LittleLong( int l );
qint64 LittleLong64( qint64 l );
float LittleFloat( float l );
short BigShort( short l );
int BigLong( int l );
qint64 BigLong64( qint64 l );
float BigFloat( float l );
void Swap_Init( void );
char * QDECL va( char *format, ... ) _attribute( ( format( printf,1,2 ) ) );
float *tv( float x, float y, float z );
//=============================================
//
// key / value info strings
//
char *Info_ValueForKey( const char *s, const char *key );
void Info_RemoveKey( char *s, const char *key );
void Info_RemoveKey_big( char *s, const char *key );
void Info_SetValueForKey( char *s, const char *key, const char *value );
void Info_SetValueForKey_Big( char *s, const char *key, const char *value );
qboolean Info_Validate( const char *s );
void Info_NextPair( const char **s, char *key, char *value );
// this is only here so the functions in q_shared.c and bg_*.c can link
void QDECL Com_Error( int level, const char *error, ... ) _attribute( ( format( printf,2,3 ) ) );
void QDECL Com_Printf( const char *msg, ... ) _attribute( ( format( printf,1,2 ) ) );
/*
==========================================================
RELOAD STATES
==========================================================
*/
#define RELOAD_SAVEGAME 0x01
#define RELOAD_NEXTMAP 0x02
#define RELOAD_NEXTMAP_WAITING 0x04
#define RELOAD_FAILED 0x08
#define RELOAD_ENDGAME 0x10
/*
==========================================================
CVARS (console variables)
Many variables can be used for cheating purposes, so when
cheats is zero, force all unspecified variables to their
default values.
==========================================================
*/
#define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc
// used for system variables, not for player
// specific configurations
#define CVAR_USERINFO 2 // sent to server on connect or change
#define CVAR_SERVERINFO 4 // sent in response to front end requests
#define CVAR_SYSTEMINFO 8 // these cvars will be duplicated on all clients
#define CVAR_INIT 16 // don't allow change from console at all,
// but can be set from the command line
#define CVAR_LATCH 32 // will only change when C code next does
// a Cvar_Get(), so it can't be changed
// without proper initialization. modified
// will be set, even though the value hasn't
// changed yet
#define CVAR_ROM 64 // display only, cannot be set by user at all
#define CVAR_USER_CREATED 128 // created by a set command
#define CVAR_TEMP 256 // can be set even when cheats are disabled, but is not archived
#define CVAR_CHEAT 512 // can not be changed if cheats are disabled
#define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued
#define CVAR_WOLFINFO 2048 // DHM - NERVE :: Like userinfo, but for wolf multiplayer info
#define CVAR_UNSAFE 4096 // ydnar: unsafe system cvars (renderer, sound settings, anything that might cause a crash)
#define CVAR_SERVERINFO_NOUPDATE 8192 // gordon: WONT automatically send this to clients, but server browsers will see it
// nothing outside the Cvar_*() functions should modify these fields!
typedef struct cvar_s {
char *name;
char *string;
char *resetString; // cvar_restart will reset to this value
char *latchedString; // for CVAR_LATCH vars
int flags;
qboolean modified; // set each time the cvar is changed
int modificationCount; // incremented each time the cvar is changed
float value; // atof( string )
int integer; // atoi( string )
struct cvar_s *next;
struct cvar_s *hashNext;
} cvar_t;
#define MAX_CVAR_VALUE_STRING 256
typedef int cvarHandle_t;
// the modules that run in the virtual machine can't access the cvar_t directly,
// so they must ask for structured updates
typedef struct {
cvarHandle_t handle;
int modificationCount;
float value;
int integer;
char string[MAX_CVAR_VALUE_STRING];
} vmCvar_t;
/*
==============================================================
COLLISION DETECTION
==============================================================
*/