1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4 
5 This file is part of Quake III Arena source code.
6 
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11 
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Foobar; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 ===========================================================================
21 */
22 #ifndef __Q_SHARED_H
23 #define __Q_SHARED_H
24 
25 // q_shared.h -- included first by ALL program modules.
26 // A user mod should never modify this file
27 
28 #ifdef STANDALONE
29   #define PRODUCT_NAME				"fooq3"
30   #define BASEGAME					"foobar"
31   #define CLIENT_WINDOW_TITLE     	"changeme"
32   #define CLIENT_WINDOW_MIN_TITLE 	"changeme2"
33 #else
34   #define PRODUCT_NAME				"evq3"
35   #define BASEGAME					"baseq3"
36   #define CLIENT_WINDOW_TITLE     	"evolutionQ3"
37   #define CLIENT_WINDOW_MIN_TITLE 	"evq3"
38 #endif
39 
40 #ifdef _MSC_VER
41   #define PRODUCT_VERSION "1.3"
42 #endif
43 
44 #define Q3_VERSION PRODUCT_NAME " " PRODUCT_VERSION
45 
46 #define MAX_TEAMNAME 32
47 
48 #ifdef _MSC_VER
49 
50 #pragma warning(disable : 4018)     // signed/unsigned mismatch
51 #pragma warning(disable : 4032)
52 #pragma warning(disable : 4051)
53 #pragma warning(disable : 4057)		// slightly different base types
54 #pragma warning(disable : 4100)		// unreferenced formal parameter
55 #pragma warning(disable : 4115)
56 #pragma warning(disable : 4125)		// decimal digit terminates octal escape sequence
57 #pragma warning(disable : 4127)		// conditional expression is constant
58 #pragma warning(disable : 4136)
59 #pragma warning(disable : 4152)		// nonstandard extension, function/data pointer conversion in expression
60 //#pragma warning(disable : 4201)
61 //#pragma warning(disable : 4214)
62 #pragma warning(disable : 4244)
63 #pragma warning(disable : 4142)		// benign redefinition
64 //#pragma warning(disable : 4305)		// truncation from const double to float
65 //#pragma warning(disable : 4310)		// cast truncates constant value
66 //#pragma warning(disable:  4505) 	// unreferenced local function has been removed
67 #pragma warning(disable : 4514)
68 #pragma warning(disable : 4702)		// unreachable code
69 #pragma warning(disable : 4711)		// selected for automatic inline expansion
70 #pragma warning(disable : 4220)		// varargs matches remaining parameters
71 #pragma warning(disable : 4996)		// deprecated functions
72 //#pragma intrinsic( memset, memcpy )
73 #endif
74 
75 //Ignore __attribute__ on non-gcc platforms
76 #ifndef __GNUC__
77 #ifndef __attribute__
78 #define __attribute__(x)
79 #endif
80 #endif
81 
82 /**********************************************************************
83   VM Considerations
84 
85   The VM can not use the standard system headers because we aren't really
86   using the compiler they were meant for.  We use bg_lib.h which contains
87   prototypes for the functions we define for our own use in bg_lib.c.
88 
89   When writing mods, please add needed headers HERE, do not start including
90   stuff like <stdio.h> in the various .c files that make up each of the VMs
91   since you will be including system headers files can will have issues.
92 
93   Remember, if you use a C library function that is not defined in bg_lib.c,
94   you will have to add your own version for support in the VM.
95 
96  **********************************************************************/
97 
98 #ifdef Q3_VM
99 
100 #include "../game/bg_lib.h"
101 
102 typedef int intptr_t;
103 
104 #else
105 
106 #include <assert.h>
107 #include <math.h>
108 #include <float.h>
109 #include <stdio.h>
110 #include <stdarg.h>
111 #include <string.h>
112 #include <stdlib.h>
113 #include <time.h>
114 #include <ctype.h>
115 #include <limits.h>
116 
117 // vsnprintf is ISO/IEC 9899:1999
118 // abstracting this to make it portable
119 #ifdef _WIN32
120   #define Q_vsnprintf _vsnprintf
121   #define Q_snprintf _snprintf
122 #else
123   #define Q_vsnprintf vsnprintf
124   #define Q_snprintf snprintf
125 #endif
126 
127 #ifdef _MSC_VER
128   #include <io.h>
129 
130   typedef __int64 int64_t;
131   typedef __int32 int32_t;
132   typedef __int16 int16_t;
133   typedef __int8 int8_t;
134   typedef unsigned __int64 uint64_t;
135   typedef unsigned __int32 uint32_t;
136   typedef unsigned __int16 uint16_t;
137   typedef unsigned __int8 uint8_t;
138 #else
139   #include <stdint.h>
140 #endif
141 
142 #endif
143 
144 #include "q_platform.h"
145 
146 //=============================================================
147 
148 typedef unsigned char byte;
149 
150 typedef enum {qfalse, qtrue}	qboolean;
151 
152 #define	EQUAL_EPSILON	0.001
153 
154 typedef int     qhandle_t;
155 typedef int     sfxHandle_t;
156 typedef int     fileHandle_t;
157 typedef int     clipHandle_t;
158 
159 #define PAD(x,y) (((x)+(y)-1) & ~((y)-1))
160 
161 // ignore __attribute__ on non-gcc platforms
162 #ifndef __GNUC__
163 #ifndef __attribute__
164 #define __attribute__(x)
165 #endif
166 #endif
167 
168 #if defined(_MSC_VER)
169 #define ALIGN(x) __declspec(align(x));
170 #elif defined(__GNUC__)
171 #define ALIGN(x) __attribute__((aligned(x)))
172 #else
173 #define ALIGN(x)
174 #endif
175 
176 #ifndef NULL
177 #define NULL				((void *)0)
178 #endif
179 
180 #ifndef BIT
181 #define BIT(x)				(1 << x)
182 #endif
183 
184 #define	MAX_QINT			0x7fffffff
185 #define	MIN_QINT			(-MAX_QINT-1)
186 
187 #ifndef max
188 #define max( x, y ) ( ( ( x ) > ( y ) ) ? ( x ) : ( y ) )
189 #define min( x, y ) ( ( ( x ) < ( y ) ) ? ( x ) : ( y ) )
190 #endif
191 
192 #ifndef sign
193 #define sign( f )	( ( f > 0 ) ? 1 : ( ( f < 0 ) ? -1 : 0 ) )
194 #endif
195 
196 // the game guarantees that no string from the network will ever
197 // exceed MAX_STRING_CHARS
198 #define	MAX_STRING_CHARS	1024	// max length of a string passed to Cmd_TokenizeString
199 #define	MAX_STRING_TOKENS	1024	// max tokens resulting from Cmd_TokenizeString
200 #define	MAX_TOKEN_CHARS		1024	// max length of an individual token
201 
202 #define	MAX_INFO_STRING		1024
203 #define	MAX_INFO_KEY		1024
204 #define	MAX_INFO_VALUE		1024
205 
206 #define	BIG_INFO_STRING		8192	// used for system info key only
207 #define	BIG_INFO_KEY		8192
208 #define	BIG_INFO_VALUE		8192
209 
210 
211 #define	MAX_QPATH			256	// max length of a quake game pathname, formerly 64
212 #ifdef PATH_MAX
213 #define MAX_OSPATH			PATH_MAX
214 #else
215 #define	MAX_OSPATH			256	// max length of a filesystem pathname
216 #endif
217 
218 #define	MAX_NAME_LENGTH		32	// max length of a client name
219 
220 #define	MAX_SAY_TEXT		150
221 
222 // paramters for command buffer stuffing
223 typedef enum
224 {
225 	EXEC_NOW,					// don't return until completed, a VM should NEVER use this,
226 	// because some commands might cause the VM to be unloaded...
227 	EXEC_INSERT,				// insert at current position, but don't run yet
228 	EXEC_APPEND					// add to end of the command buffer (normal case)
229 } cbufExec_t;
230 
231 
232 //
233 // these aren't needed by any of the VMs.  put in another header?
234 //
235 #define	MAX_MAP_AREA_BYTES	32	// bit vector of area visibility
236 
237 
238 // print levels from renderer (FIXME: set up for game / cgame?)
239 typedef enum
240 {
241 	PRINT_ALL,
242 	PRINT_DEVELOPER,			// only print when "developer 1"
243 	PRINT_WARNING,
244 	PRINT_ERROR
245 } printParm_t;
246 
247 #ifdef ERR_FATAL
248 #undef ERR_FATAL				// this is defined in malloc.h
249 #endif
250 
251 // parameters to the main Error routine
252 typedef enum
253 {
254 	ERR_FATAL,					// exit the entire game with a popup window
255 	ERR_DROP,					// print to console and disconnect from game
256 	ERR_SERVERDISCONNECT,		// don't kill server
257 	ERR_DISCONNECT,				// client disconnected from the server
258 	ERR_NEED_CD					// pop up the need-cd dialog
259 } errorParm_t;
260 
261 // font rendering values used by ui and cgame
262 
263 #define PROP_GAP_WIDTH			3
264 #define PROP_SPACE_WIDTH		8
265 #define PROP_HEIGHT				27
266 #define PROP_SMALL_SIZE_SCALE	0.75
267 
268 #define BLINK_DIVISOR			200
269 #define PULSE_DIVISOR			75
270 
271 #define UI_LEFT			0x00000000	// default
272 #define UI_CENTER		0x00000001
273 #define UI_RIGHT		0x00000002
274 #define UI_FORMATMASK	0x00000007
275 #define UI_SMALLFONT	0x00000010
276 #define UI_BIGFONT		0x00000020	// default
277 #define UI_GIANTFONT	0x00000040
278 #define UI_DROPSHADOW	0x00000800
279 #define UI_BLINK		0x00001000
280 #define UI_INVERSE		0x00002000
281 #define UI_PULSE		0x00004000
282 
283 #if defined(_DEBUG)
284 #define HUNK_DEBUG
285 #endif
286 
287 typedef enum
288 {
289 	h_high,
290 	h_low,
291 	h_dontcare
292 } ha_pref;
293 
294 #ifdef HUNK_DEBUG
295 #define Hunk_Alloc( size, preference )				Hunk_AllocDebug(size, preference, #size, __FILE__, __LINE__)
296 void           *Hunk_AllocDebug(int size, ha_pref preference, char *label, char *file, int line);
297 #else
298 void           *Hunk_Alloc(int size, ha_pref preference);
299 #endif
300 
301 #define Com_Memset memset
302 #define Com_Memcpy memcpy
303 
304 #define CIN_system	1
305 #define CIN_loop	2
306 #define	CIN_hold	4
307 #define CIN_silent	8
308 #define CIN_shader	16
309 
310 /*
311 ==============================================================
312 
313 MATHLIB
314 
315 ==============================================================
316 */
317 
318 
319 typedef float   vec_t;
320 typedef vec_t   vec2_t[2];
321 typedef vec_t   vec3_t[3];
322 typedef vec_t   vec4_t[4];
323 typedef vec_t   vec5_t[5];
324 
325 typedef vec_t   axis_t[3][3];
326 typedef vec_t   matrix_t[16];
327 typedef vec_t   quat_t[4];		// | x y z w |
328 
329 typedef int     fixed4_t;
330 typedef int     fixed8_t;
331 typedef int     fixed16_t;
332 
333 #ifndef M_PI
334 #define M_PI		3.14159265358979323846f	// matches value in gcc v2 math.h
335 #endif
336 
337 // angle indexes
338 #define	PITCH				0	// up / down
339 #define	YAW					1	// left / right
340 #define	ROLL				2	// fall over
341 
342 // plane sides
343 typedef enum
344 {
345 	SIDE_FRONT = 0,
346 	SIDE_BACK = 1,
347 	SIDE_ON = 2,
348 	SIDE_CROSS = 3
349 } planeSide_t;
350 
351 #define NUMVERTEXNORMALS	162
352 extern vec3_t   bytedirs[NUMVERTEXNORMALS];
353 
354 // all drawing is done to a 640*480 virtual screen size
355 // and will be automatically scaled to the real resolution
356 #define	SCREEN_WIDTH		640
357 #define	SCREEN_HEIGHT		480
358 
359 #define TINYCHAR_WIDTH		(SMALLCHAR_WIDTH)
360 #define TINYCHAR_HEIGHT		(SMALLCHAR_HEIGHT/2)
361 
362 #define SMALLCHAR_WIDTH		8
363 #define SMALLCHAR_HEIGHT	16
364 
365 #define BIGCHAR_WIDTH		16
366 #define BIGCHAR_HEIGHT		16
367 
368 #define	GIANTCHAR_WIDTH		32
369 #define	GIANTCHAR_HEIGHT	48
370 
371 extern vec4_t   colorBlack;
372 extern vec4_t   colorRed;
373 extern vec4_t   colorGreen;
374 extern vec4_t   colorBlue;
375 extern vec4_t   colorYellow;
376 extern vec4_t   colorMagenta;
377 extern vec4_t   colorCyan;
378 extern vec4_t   colorWhite;
379 extern vec4_t   colorLtGrey;
380 extern vec4_t   colorMdGrey;
381 extern vec4_t   colorDkGrey;
382 
383 #define Q_COLOR_ESCAPE	'^'
384 #define Q_IsColorString(p)	( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && isalnum(*((p)+1)) )	// ^[0-9a-zA-Z]
385 
386 #define COLOR_BLACK		'0'
387 #define COLOR_RED		'1'
388 #define COLOR_GREEN		'2'
389 #define COLOR_YELLOW	'3'
390 #define COLOR_BLUE		'4'
391 #define COLOR_CYAN		'5'
392 #define COLOR_MAGENTA	'6'
393 #define COLOR_WHITE		'7'
394 #define ColorIndex(c)	( ( (c) - '0' ) & 7 )
395 
396 #define S_COLOR_BLACK	"^0"
397 #define S_COLOR_RED		"^1"
398 #define S_COLOR_GREEN	"^2"
399 #define S_COLOR_YELLOW	"^3"
400 #define S_COLOR_BLUE	"^4"
401 #define S_COLOR_CYAN	"^5"
402 #define S_COLOR_MAGENTA	"^6"
403 #define S_COLOR_WHITE	"^7"
404 
405 extern vec4_t   g_color_table[8];
406 
407 #define	MAKERGB( v, r, g, b ) v[0]=r;v[1]=g;v[2]=b
408 #define	MAKERGBA( v, r, g, b, a ) v[0]=r;v[1]=g;v[2]=b;v[3]=a
409 
410 #define DEG2RAD( a ) ( ( (a) * M_PI ) / 180.0F )
411 #define RAD2DEG( a ) ( ( (a) * 180.0f ) / M_PI )
412 
413 #define Q_max(a, b)      ((a) > (b) ? (a) : (b))
414 #define Q_min(a, b)      ((a) < (b) ? (a) : (b))
415 #define Q_bound(a, b, c) (Q_max(a, Q_min(b, c)))
416 #define Q_clamp(a, b, c) ((b) >= (c) ? (a)=(b) : (a) < (b) ? (a)=(b) : (a) > (c) ? (a)=(c) : (a))
417 
418 struct cplane_s;
419 
420 extern vec3_t   vec3_origin;
421 extern vec3_t   axisDefault[3];
422 extern matrix_t matrixIdentity;
423 extern quat_t   quatIdentity;
424 
425 #define	nanmask (255<<23)
426 
427 #define	IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
428 
429 #if idppc
430 
Q_rsqrt(float number)431 static ID_INLINE float Q_rsqrt(float number)
432 {
433 	float           x = 0.5f * number;
434 	float           y;
435 
436 #ifdef __GNUC__
437   asm("frsqrte %0,%1": "=f"(y):"f"(number));
438 #else
439 	y = __frsqrte(number);
440 #endif
441 	return y * (1.5f - (x * y * y));
442 }
443 
444 #ifdef __GNUC__
Q_fabs(float x)445 static ID_INLINE float Q_fabs(float x)
446 {
447 	float           abs_x;
448 
449   asm("fabs %0,%1": "=f"(abs_x):"f"(x));
450 	return abs_x;
451 }
452 #else
453 #define Q_fabs __fabsf
454 #endif
455 
456 #else
457 float           Q_fabs(float f);
458 float           Q_rsqrt(float f);	// reciprocal square root
459 #endif
460 
461 float           Q_recip(float f);
462 
463 signed char     ClampChar(int i);
464 signed short    ClampShort(int i);
465 
466 // this isn't a real cheap function to call!
467 int             DirToByte(vec3_t dir);
468 void            ByteToDir(int b, vec3_t dir);
469 
470 #define DotProduct(a,b)			((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
471 #define VectorSubtract(a,b,c)	((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
472 #define VectorAdd(a,b,c)		((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
473 #define VectorCopy(a,b)			((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
474 #define	VectorScale(v, s, o)	((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
475 #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))
476 #define VectorClear(a)			((a)[0]=(a)[1]=(a)[2]=0)
477 #define VectorNegate(a,b)		((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
478 #define VectorSet(v, x, y, z)	((v)[0]=(x),(v)[1]=(y),(v)[2]=(z))
479 
480 #define DotProduct4(x,y)		((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]+(x)[3]*(y)[3])
481 #define VectorSubtract4(a,b,c)	((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2],(c)[3]=(a)[3]-(b)[3])
482 #define VectorAdd4(a,b,c)		((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2],(c)[3]=(a)[3]+(b)[3])
483 #define VectorCopy4(a,b)		((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
484 #define	VectorScale4(v, s, o)	((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s),(o)[3]=(v)[3]*(s))
485 #define	VectorMA4(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))
486 #define VectorClear4(a)			((a)[0]=(a)[1]=(a)[2]=(a)[3]=0)
487 #define VectorNegate4(a,b)		((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2],(b)[3]=-(a)[3])
488 #define VectorSet4(v,x,y,z,w)	((v)[0]=(x),(v)[1]=(y),(v)[2]=(z),(v)[3]=(w))
489 
490 #define	SnapVector(v) {v[0]=((int)(v[0]));v[1]=((int)(v[1]));v[2]=((int)(v[2]));}
491 
492 // just in case you do't want to use the macros
493 vec_t           _DotProduct(const vec3_t a, const vec3_t b);
494 void            _VectorSubtract(const vec3_t a, const vec3_t b, vec3_t out);
495 void            _VectorAdd(const vec3_t a, const vec3_t b, vec3_t out);
496 void            _VectorCopy(const vec3_t in, vec3_t out);
497 void            _VectorScale(const vec3_t in, float scale, vec3_t out);
498 void            _VectorMA(const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc);
499 
500 unsigned        ColorBytes3(float r, float g, float b);
501 unsigned        ColorBytes4(float r, float g, float b, float a);
502 
503 float           NormalizeColor(const vec3_t in, vec3_t out);
504 void            ClampColor(vec4_t color);
505 
506 float           RadiusFromBounds(const vec3_t mins, const vec3_t maxs);
507 void            ClearBounds(vec3_t mins, vec3_t maxs);
508 void            AddPointToBounds(const vec3_t v, vec3_t mins, vec3_t maxs);
509 qboolean        BoundsIntersect(const vec3_t mins, const vec3_t maxs, const vec3_t mins2, const vec3_t maxs2);
510 qboolean        BoundsIntersectSphere(const vec3_t mins, const vec3_t maxs, const vec3_t origin, vec_t radius);
511 qboolean        BoundsIntersectPoint(const vec3_t mins, const vec3_t maxs, const vec3_t origin);
512 
VectorCompare(const vec3_t v1,const vec3_t v2)513 static ID_INLINE int VectorCompare(const vec3_t v1, const vec3_t v2)
514 {
515 	if(v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2])
516 	{
517 		return 0;
518 	}
519 	return 1;
520 }
521 
VectorLength(const vec3_t v)522 static ID_INLINE vec_t VectorLength(const vec3_t v)
523 {
524 	return (vec_t) sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
525 }
526 
VectorLengthSquared(const vec3_t v)527 static ID_INLINE vec_t VectorLengthSquared(const vec3_t v)
528 {
529 	return (v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
530 }
531 
Distance(const vec3_t p1,const vec3_t p2)532 static ID_INLINE vec_t Distance(const vec3_t p1, const vec3_t p2)
533 {
534 	vec3_t          v;
535 
536 	VectorSubtract(p2, p1, v);
537 	return VectorLength(v);
538 }
539 
DistanceSquared(const vec3_t p1,const vec3_t p2)540 static ID_INLINE vec_t DistanceSquared(const vec3_t p1, const vec3_t p2)
541 {
542 	vec3_t          v;
543 
544 	VectorSubtract(p2, p1, v);
545 	return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
546 }
547 
548 // fast vector normalize routine that uses rsqrt approximation, nor does it return length
VectorNormalizeFast(vec3_t v)549 static ID_INLINE void VectorNormalizeFast(vec3_t v)
550 {
551 	float           lengthSquared, lengthInversed;
552 
553 	lengthSquared = DotProduct(v, v);
554 
555 	if(lengthSquared)
556 	{
557 		lengthInversed = Q_rsqrt(lengthSquared);
558 		v[0] *= lengthInversed;
559 		v[1] *= lengthInversed;
560 		v[2] *= lengthInversed;
561 	}
562 }
563 
VectorInverse(vec3_t v)564 static ID_INLINE void VectorInverse(vec3_t v)
565 {
566 	v[0] = -v[0];
567 	v[1] = -v[1];
568 	v[2] = -v[2];
569 }
570 
CrossProduct(const vec3_t v1,const vec3_t v2,vec3_t cross)571 static ID_INLINE void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross)
572 {
573 	cross[0] = v1[1] * v2[2] - v1[2] * v2[1];
574 	cross[1] = v1[2] * v2[0] - v1[0] * v2[2];
575 	cross[2] = v1[0] * v2[1] - v1[1] * v2[0];
576 }
577 
VectorLerp(const vec3_t from,const vec3_t to,float frac,vec3_t out)578 static ID_INLINE void VectorLerp(const vec3_t from, const vec3_t to, float frac, vec3_t out)
579 {
580 	//*this = to + ((from - to) * f);
581 
582 	out[0] = to[0] + ((from[0] - to[0]) * frac);
583 	out[1] = to[1] + ((from[1] - to[1]) * frac);
584 	out[2] = to[2] + ((from[2] - to[2]) * frac);
585 }
586 
587 vec_t           VectorNormalize(vec3_t v);	// returns vector length
588 vec_t           VectorNormalize2(const vec3_t v, vec3_t out);
589 
590 void            VectorRotate(vec3_t in, vec3_t matrix[3], vec3_t out);
591 
592 int             NearestPowerOfTwo(int val);
593 int             Q_log2(int val);
594 
595 float           Q_acos(float c);
596 
597 int             Q_isnan(float x);
598 
599 int             Q_rand(int *seed);
600 float           Q_random(int *seed);
601 float           Q_crandom(int *seed);
602 
603 #define random()	((rand () & 0x7fff) / ((float)0x7fff))
604 #define crandom()	(2.0 * (random() - 0.5))
605 
606 void            vectoangles(const vec3_t value1, vec3_t angles);
607 void            AnglesToAxis(const vec3_t angles, vec3_t axis[3]);
608 
609 void            AxisClear(vec3_t axis[3]);
610 void            AxisCopy(vec3_t in[3], vec3_t out[3]);
611 
612 void            SetPlaneSignbits(struct cplane_s *out);
613 int             BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, struct cplane_s *plane);
614 int             BoxOnPlaneSide2(vec3_t mins, vec3_t maxs, vec4_t plane);
615 
616 float           AngleMod(float a);
617 float           LerpAngle(float from, float to, float frac);
618 float           AngleSubtract(float a1, float a2);
619 void            AnglesSubtract(vec3_t v1, vec3_t v2, vec3_t v3);
620 
621 float           AngleNormalize360(float angle);
622 float           AngleNormalize180(float angle);
623 float           AngleDelta(float angle1, float angle2);
624 float           AngleBetweenVectors(const vec3_t a, const vec3_t b);
625 
626 vec_t           PlaneNormalize(vec4_t plane);	// returns normal length
627 qboolean        PlaneFromPoints(vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c, qboolean cw);
628 void            ProjectPointOnPlane(vec3_t dst, const vec3_t p, const vec3_t normal);
629 void            RotatePointAroundVector(vec3_t dst, const vec3_t dir, const vec3_t point, float degrees);
630 void            RotateAroundDirection(vec3_t axis[3], float yaw);
631 void            MakeNormalVectors(const vec3_t forward, vec3_t right, vec3_t up);
632 
633 // perpendicular vector could be replaced by this
634 
635 //int   PlaneTypeForNormal (vec3_t normal);
636 
637 void            AxisMultiply(float in1[3][3], float in2[3][3], float out[3][3]);
638 void            AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
639 void            PerpendicularVector(vec3_t dst, const vec3_t src);
640 
641 void            MatrixIdentity(matrix_t m);
642 void            MatrixClear(matrix_t m);
643 void            MatrixCopy(const matrix_t in, matrix_t out);
644 void            MatrixTransposeIntoXMM(const matrix_t m);
645 void            MatrixTranspose(const matrix_t in, matrix_t out);
646 void            MatrixSetupXRotation(matrix_t m, vec_t degrees);
647 void            MatrixSetupYRotation(matrix_t m, vec_t degrees);
648 void            MatrixSetupZRotation(matrix_t m, vec_t degrees);
649 void            MatrixSetupTranslation(matrix_t m, vec_t x, vec_t y, vec_t z);
650 void            MatrixSetupScale(matrix_t m, vec_t x, vec_t y, vec_t z);
651 void            MatrixSetupShear(matrix_t m, vec_t x, vec_t y);
652 void            MatrixMultiply(const matrix_t a, const matrix_t b, matrix_t out);
653 void            MatrixMultiply2(matrix_t m, matrix_t m2);
654 void            MatrixMultiplyRotation(matrix_t m, vec_t pitch, vec_t yaw, vec_t roll);
655 void            MatrixMultiplyZRotation(matrix_t m, vec_t degrees);
656 void            MatrixMultiplyTranslation(matrix_t m, vec_t x, vec_t y, vec_t z);
657 void            MatrixMultiplyScale(matrix_t m, vec_t x, vec_t y, vec_t z);
658 void            MatrixMultiplyShear(matrix_t m, vec_t x, vec_t y);
659 void            MatrixToAngles(const matrix_t m, vec3_t angles);
660 void            MatrixFromAngles(matrix_t m, vec_t pitch, vec_t yaw, vec_t roll);
661 void            MatrixFromVectorsFLU(matrix_t m, const vec3_t forward, const vec3_t left, const vec3_t up);
662 void            MatrixFromVectorsFRU(matrix_t m, const vec3_t forward, const vec3_t right, const vec3_t up);
663 void            MatrixFromQuat(matrix_t m, const quat_t q);
664 void            MatrixFromPlanes(matrix_t m, const vec4_t left, const vec4_t right, const vec4_t bottom, const vec4_t top,
665 								 const vec4_t front, const vec4_t back);
666 void            MatrixToVectorsFLU(const matrix_t m, vec3_t forward, vec3_t left, vec3_t up);
667 void            MatrixToVectorsFRU(const matrix_t m, vec3_t forward, vec3_t right, vec3_t up);
668 void            MatrixSetupTransform(matrix_t m, const vec3_t forward, const vec3_t left, const vec3_t up, const vec3_t origin);
669 void            MatrixSetupTransformFromRotation(matrix_t m, const matrix_t rot, const vec3_t origin);
670 void            MatrixSetupTransformFromQuat(matrix_t m, const quat_t quat, const vec3_t origin);
671 void            MatrixAffineInverse(const matrix_t in, matrix_t out);
672 void            MatrixTransformNormal(const matrix_t m, const vec3_t in, vec3_t out);
673 void            MatrixTransformPoint(const matrix_t m, const vec3_t in, vec3_t out);
674 void            MatrixTransform4(const matrix_t m, const vec4_t in, vec4_t out);
675 
AnglesToMatrix(const vec3_t angles,matrix_t m)676 static ID_INLINE void AnglesToMatrix(const vec3_t angles, matrix_t m)
677 {
678 	MatrixFromAngles(m, angles[PITCH], angles[YAW], angles[ROLL]);
679 }
680 
681 
682 #define QuatSet(q,x,y,z,w)	((q)[0]=(x),(q)[1]=(y),(q)[2]=(z),(q)[3]=(w))
683 #define QuatCopy(a, b)          ((b)[0]=(a)[0], (b)[1]=(a)[1], (b)[2]=(a)[2], (b)[3]=(a)[3])
684 
685 #define QuatCompare(a,b)	((a)[0]==(b)[0] && (a)[1]==(b)[1] && (a)[2]==(b)[2] && (a)[3]==(b)[3])
686 
QuatClear(quat_t q)687 static ID_INLINE void QuatClear(quat_t q)
688 {
689 	q[0] = 0;
690 	q[1] = 0;
691 	q[2] = 0;
692 	q[3] = 1;
693 }
694 
695 /*
696 static ID_INLINE int QuatCompare(const quat_t a, const quat_t b)
697 {
698 	if(a[0] != b[0] || a[1] != b[1] || a[2] != b[2] || a[3] != b[3])
699 	{
700 		return 0;
701 	}
702 	return 1;
703 }
704 */
705 
QuatCalcW(quat_t q)706 static ID_INLINE void QuatCalcW(quat_t q)
707 {
708 #if 1
709 	vec_t           term = 1.0f - (q[0] * q[0] + q[1] * q[1] + q[2] * q[2]);
710 
711 	if(term < 0.0)
712 		q[3] = 0.0;
713 	else
714 		q[3] = -sqrt(term);
715 #else
716 	q[3] = sqrt(fabs(1.0f - (q[0] * q[0] + q[1] * q[1] + q[2] * q[2])));
717 #endif
718 }
719 
QuatInverse(quat_t q)720 static ID_INLINE void QuatInverse(quat_t q)
721 {
722 	q[0] = -q[0];
723 	q[1] = -q[1];
724 	q[2] = -q[2];
725 }
726 
QuatAntipodal(quat_t q)727 static ID_INLINE void QuatAntipodal(quat_t q)
728 {
729 	q[0] = -q[0];
730 	q[1] = -q[1];
731 	q[2] = -q[2];
732 	q[3] = -q[3];
733 }
734 
QuatLength(const quat_t q)735 static ID_INLINE vec_t QuatLength(const quat_t q)
736 {
737 	return (vec_t) sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);
738 }
739 
740 vec_t           QuatNormalize(quat_t q);
741 
742 void            QuatFromAngles(quat_t q, vec_t pitch, vec_t yaw, vec_t roll);
743 
AnglesToQuat(const vec3_t angles,quat_t q)744 static ID_INLINE void AnglesToQuat(const vec3_t angles, quat_t q)
745 {
746 	QuatFromAngles(q, angles[PITCH], angles[YAW], angles[ROLL]);
747 }
748 
749 void            QuatFromMatrix(quat_t q, const matrix_t m);
750 void            QuatToVectors(const quat_t quat, vec3_t forward, vec3_t right, vec3_t up);
751 void            QuatToAxis(const quat_t q, vec3_t axis[3]);
752 void            QuatToAngles(const quat_t q, vec3_t angles);
753 
754 // Quaternion multiplication, analogous to the matrix multiplication routines.
755 
756 // qa = rotate by qa, then qb
757 void            QuatMultiply0(quat_t qa, const quat_t qb);
758 
759 // qc = rotate by qa, then qb
760 void            QuatMultiply1(const quat_t qa, const quat_t qb, quat_t qc);
761 
762 // qc = rotate by qa, then by inverse of qb
763 void            QuatMultiply2(const quat_t qa, const quat_t qb, quat_t qc);
764 
765 // qc = rotate by inverse of qa, then by qb
766 void            QuatMultiply3(const quat_t qa, const quat_t qb, quat_t qc);
767 
768 // qc = rotate by inverse of qa, then by inverse of qb
769 void            QuatMultiply4(const quat_t qa, const quat_t qb, quat_t qc);
770 
771 
772 void            QuatSlerp(const quat_t from, const quat_t to, float frac, quat_t out);
773 void            QuatTransformVector(const quat_t q, const vec3_t in, vec3_t out);
774 
775 //=============================================
776 
777 typedef struct
778 {
779 	qboolean        frameMemory;
780 	int             currentElements;
781 	int             maxElements;	// will reallocate and move when exceeded
782 	void          **elements;
783 } growList_t;
784 
785 // you don't need to init the growlist if you don't mind it growing and moving
786 // the list as it expands
787 void            Com_InitGrowList(growList_t * list, int maxElements);
788 void            Com_DestroyGrowList(growList_t * list);
789 int             Com_AddToGrowList(growList_t * list, void *data);
790 void           *Com_GrowListElement(const growList_t * list, int index);
791 int             Com_IndexForGrowListElement(const growList_t * list, const void *element);
792 
793 //=============================================
794 
795 float           Com_Clamp(float min, float max, float value);
796 
797 char           *Com_SkipPath(char *pathname);
798 const char     *Com_GetExtension(const char *name);
799 void            Com_StripExtension(const char *src, char *dest, int destsize);
800 void            Com_DefaultExtension(char *path, int maxSize, const char *extension);
801 
802 void            Com_BeginParseSession(const char *name);
803 int             Com_GetCurrentParseLine(void);
804 char           *Com_Parse(char **data_p);
805 char           *Com_ParseExt(char **data_p, qboolean allowLineBreak);
806 int             Com_Compress(char *data_p);
807 void            Com_ParseError(char *format, ...) __attribute__ ((format(printf, 1, 2)));
808 void            Com_ParseWarning(char *format, ...) __attribute__ ((format(printf, 1, 2)));
809 
810 #define MAX_TOKENLENGTH		1024
811 
812 #ifndef TT_STRING
813 //token types
814 #define TT_STRING					1	// string
815 #define TT_LITERAL					2	// literal
816 #define TT_NUMBER					3	// number
817 #define TT_NAME						4	// name
818 #define TT_PUNCTUATION				5	// punctuation
819 #endif
820 
821 typedef struct pc_token_s
822 {
823 	int             type;
824 	int             subtype;
825 	int             intvalue;
826 	float           floatvalue;
827 	char            string[MAX_TOKENLENGTH];
828 } pc_token_t;
829 
830 // data is an in/out parm, returns a parsed out token
831 
832 void            COM_MatchToken(char **buf_p, char *match);
833 
834 void            Com_SkipBracedSection(char **program);
835 void            Com_SkipRestOfLine(char **data);
836 
837 void            Parse1DMatrix(char **buf_p, int x, float *m);
838 void            Parse2DMatrix(char **buf_p, int y, int x, float *m);
839 void            Parse3DMatrix(char **buf_p, int z, int y, int x, float *m);
840 
841 void QDECL      Com_sprintf(char *dest, int size, const char *fmt, ...) __attribute__ ((format(printf, 3, 4)));
842 
843 char 		   *Com_SkipTokens( char *s, int numTokens, char *sep );
844 char 		   *Com_SkipCharset( char *s, char *sep );
845 
846 void 			Com_RandomBytes( byte *string, int len );
847 
848 // mode parm for FS_FOpenFile
849 typedef enum
850 {
851 	FS_READ,
852 	FS_WRITE,
853 	FS_APPEND,
854 	FS_APPEND_SYNC
855 } fsMode_t;
856 
857 typedef enum
858 {
859 	FS_SEEK_CUR,
860 	FS_SEEK_END,
861 	FS_SEEK_SET
862 } fsOrigin_t;
863 
864 //=============================================
865 
866 int             Q_isprint(int c);
867 int             Q_islower(int c);
868 int             Q_isupper(int c);
869 int             Q_isalpha(int c);
870 
871 // portable case insensitive compare
872 int             Q_stricmp(const char *s1, const char *s2);
873 int             Q_strncmp(const char *s1, const char *s2, int n);
874 int             Q_stricmpn(const char *s1, const char *s2, int n);
875 char           *Q_strlwr(char *s1);
876 char           *Q_strupr(char *s1);
877 char           *Q_strrchr(const char *string, int c);
878 const char     *Q_stristr(const char *s, const char *find);
879 
880 // buffer size safe library replacements
881 void            Q_strncpyz(char *dest, const char *src, int destsize);
882 void            Q_strcat(char *dest, int size, const char *src);
883 qboolean        Q_strreplace(char *dest, int destsize, const char *find, const char *replace);
884 
885 // strlen that discounts Quake color sequences
886 int             Q_PrintStrlen(const char *string);
887 
888 // removes color sequences from string
889 char           *Q_CleanStr(char *string);
890 
891 // count the number of char tocount encountered in string
892 int Q_CountChar(const char *string, char tocount);
893 
894 //=============================================
895 
896 // 64-bit integers for global rankings interface
897 // implemented as a struct for qvm compatibility
898 typedef struct
899 {
900 	byte            b0;
901 	byte            b1;
902 	byte            b2;
903 	byte            b3;
904 	byte            b4;
905 	byte            b5;
906 	byte            b6;
907 	byte            b7;
908 } qint64;
909 
910 //=============================================
911 /*
912 short	BigShort(short l);
913 short	LittleShort(short l);
914 int		BigLong (int l);
915 int		LittleLong (int l);
916 qint64  BigLong64 (qint64 l);
917 qint64  LittleLong64 (qint64 l);
918 float	BigFloat (const float *l);
919 float	LittleFloat (const float *l);
920 
921 void	Swap_Init (void);
922 */
923 char           *QDECL va(char *format, ...) __attribute__ ((format(printf, 1, 2)));
924 
925 #define TRUNCATE_LENGTH	64
926 void            Com_TruncateLongString(char *buffer, const char *s);
927 
928 //=============================================
929 
930 //
931 // key / value info strings
932 //
933 char           *Info_ValueForKey(const char *s, const char *key);
934 void            Info_RemoveKey(char *s, const char *key);
935 void            Info_RemoveKey_big(char *s, const char *key);
936 void            Info_SetValueForKey(char *s, const char *key, const char *value);
937 void            Info_SetValueForKey_Big(char *s, const char *key, const char *value);
938 qboolean        Info_Validate(const char *s);
939 void            Info_NextPair(const char **s, char *key, char *value);
940 
941 // this is only here so the functions in q_shared.c and bg_*.c can link
942 void QDECL      Com_Error(int level, const char *error, ...) __attribute__ ((format(printf, 2, 3)));
943 void QDECL      Com_Printf(const char *msg, ...) __attribute__ ((format(printf, 1, 2)));
944 
945 
946 /*
947 ==========================================================
948 
949 CVARS (console variables)
950 
951 Many variables can be used for cheating purposes, so when
952 cheats is zero, force all unspecified variables to their
953 default values.
954 ==========================================================
955 */
956 
957 #define	CVAR_ARCHIVE		1	// set to cause it to be saved to vars.rc
958 								// used for system variables, not for player
959 								// specific configurations
960 #define	CVAR_USERINFO		2	// sent to server on connect or change
961 #define	CVAR_SERVERINFO		4	// sent in response to front end requests
962 #define	CVAR_SYSTEMINFO		8	// these cvars will be duplicated on all clients
963 #define	CVAR_INIT			16	// don't allow change from console at all,
964 								// but can be set from the command line
965 #define	CVAR_LATCH			32	// will only change when C code next does
966 								// a Cvar_Get(), so it can't be changed
967 								// without proper initialization.  modified
968 								// will be set, even though the value hasn't
969 								// changed yet
970 #define	CVAR_ROM			64	// display only, cannot be set by user at all
971 #define	CVAR_USER_CREATED	128	// created by a set command
972 #define	CVAR_TEMP			256	// can be set even when cheats are disabled, but is not archived
973 #define CVAR_CHEAT			512	// can not be changed if cheats are disabled
974 #define CVAR_NORESTART		1024	// do not clear when a cvar_restart is issued
975 
976 #define CVAR_SERVER_CREATED	2048	// cvar was created by a server the client connected to.
977 #define CVAR_NONEXISTENT	0xFFFFFFFF	// Cvar doesn't exist.
978 
979 // nothing outside the Cvar_*() functions should modify these fields!
980 typedef struct cvar_s
981 {
982 	char           *name;
983 	char           *string;
984 	char           *resetString;	// cvar_restart will reset to this value
985 	char           *latchedString;	// for CVAR_LATCH vars
986 	int             flags;
987 	qboolean        modified;	// set each time the cvar is changed
988 	int             modificationCount;	// incremented each time the cvar is changed
989 	float           value;		// atof( string )
990 	int             integer;	// atoi( string )
991 	struct cvar_s  *next;
992 	struct cvar_s  *hashNext;
993 } cvar_t;
994 
995 #define	MAX_CVAR_VALUE_STRING	256
996 
997 typedef int     cvarHandle_t;
998 
999 // the modules that run in the virtual machine can't access the cvar_t directly,
1000 // so they must ask for structured updates
1001 typedef struct
1002 {
1003 	cvarHandle_t    handle;
1004 	int             modificationCount;
1005 	float           value;
1006 	int             integer;
1007 	char            string[MAX_CVAR_VALUE_STRING];
1008 } vmCvar_t;
1009 
1010 /*
1011 ==============================================================
1012 
1013 COLLISION DETECTION
1014 
1015 ==============================================================
1016 */
1017 
1018 #include "surfaceflags.h"		// shared with the q3map utility
1019 
1020 // plane types are used to speed some tests
1021 // 0-2 are axial planes
1022 typedef enum
1023 {
1024 	PLANE_X			 = 0,
1025 	PLANE_Y			 = 1,
1026 	PLANE_Z			 = 2,
1027 	PLANE_NON_AXIAL	 = 3
1028 } planeType_t;
1029 
1030 //#define PlaneTypeForNormal(x) (x[0] == 1.0 ? PLANE_X : (x[1] == 1.0 ? PLANE_Y : (x[2] == 1.0 ? PLANE_Z : PLANE_NON_AXIAL) ) )
PlaneTypeForNormal(vec3_t normal)1031 static ID_INLINE int	PlaneTypeForNormal(vec3_t normal)
1032 {
1033 	if(normal[0] == 1.0)
1034 		return PLANE_X;
1035 
1036 	if(normal[1] == 1.0)
1037 		return PLANE_Y;
1038 
1039 	if(normal[2] == 1.0)
1040 		return PLANE_Z;
1041 
1042 	return PLANE_NON_AXIAL;
1043 }
1044 
1045 // plane_t structure
1046 // !!! if this is changed, it must be changed in asm code too !!!
1047 typedef struct cplane_s
1048 {
1049 	vec3_t          normal;
1050 	float           dist;
1051 	byte            type;		// for fast side tests: 0,1,2 = axial, 3 = nonaxial
1052 	byte            signbits;	// signx + (signy<<1) + (signz<<2), used as lookup during collision
1053 	byte            pad[2];
1054 } cplane_t;
1055 
1056 
1057 // a trace is returned when a box is swept through the world
1058 typedef struct
1059 {
1060 	qboolean        allsolid;	// if true, plane is not valid
1061 	qboolean        startsolid;	// if true, the initial point was in a solid area
1062 	float           fraction;	// time completed, 1.0 = didn't hit anything
1063 	vec3_t          endpos;		// final position
1064 	cplane_t        plane;		// surface normal at impact, transformed to world space
1065 	int             surfaceFlags;	// surface hit
1066 	int             contents;	// contents on other side of surface hit
1067 	int             entityNum;	// entity the contacted sirface is a part of
1068 } trace_t;
1069 
1070 // trace->entityNum can also be 0 to (MAX_GENTITIES-1)
1071 // or ENTITYNUM_NONE, ENTITYNUM_WORLD
1072 
1073 
1074 // markfragments are returned by CM_MarkFragments()
1075 typedef struct
1076 {
1077 	int             firstPoint;
1078 	int             numPoints;
1079 } markFragment_t;
1080 
1081 
1082 
1083 typedef struct
1084 {
1085 	vec3_t          origin;
1086 	vec3_t          axis[3];
1087 } orientation_t;
1088 
1089 //=====================================================================
1090 
1091 
1092 // in order from highest priority to lowest
1093 // if none of the catchers are active, bound key strings will be executed
1094 #define KEYCATCH_CONSOLE		0x0001
1095 #define	KEYCATCH_UI					0x0002
1096 #define	KEYCATCH_MESSAGE		0x0004
1097 #define	KEYCATCH_CGAME			0x0008
1098 
1099 
1100 // sound channels
1101 // channel 0 never willingly overrides
1102 // other channels will allways override a playing sound on that channel
1103 typedef enum
1104 {
1105 	CHAN_AUTO,
1106 	CHAN_LOCAL,					// menu sounds, etc
1107 	CHAN_WEAPON,
1108 	CHAN_VOICE,
1109 	CHAN_ITEM,
1110 	CHAN_BODY,
1111 	CHAN_LOCAL_SOUND,			// chat messages, etc
1112 	CHAN_ANNOUNCER				// announcer voices, etc
1113 } soundChannel_t;
1114 
1115 
1116 /*
1117 ========================================================================
1118 
1119   ELEMENTS COMMUNICATED ACROSS THE NET
1120 
1121 ========================================================================
1122 */
1123 
1124 #define	ANGLE2SHORT(x)	((int)((x)*65536/360) & 65535)
1125 #define	SHORT2ANGLE(x)	((x)*(360.0/65536))
1126 
1127 #define	SNAPFLAG_RATE_DELAYED	1
1128 #define	SNAPFLAG_NOT_ACTIVE		2	// snapshot used during connection and for zombies
1129 #define SNAPFLAG_SERVERCOUNT	4	// toggled every map_restart so transitions can be detected
1130 
1131 //
1132 // per-level limits
1133 //
1134 #define	MAX_CLIENTS			64	// absolute limit
1135 #define MAX_LOCATIONS		64
1136 
1137 #define	GENTITYNUM_BITS		10	// don't need to send any more
1138 #define	MAX_GENTITIES		(1<<GENTITYNUM_BITS)
1139 
1140 // entitynums are communicated with GENTITY_BITS, so any reserved
1141 // values that are going to be communcated over the net need to
1142 // also be in this range
1143 #define	ENTITYNUM_NONE		(MAX_GENTITIES-1)
1144 #define	ENTITYNUM_WORLD		(MAX_GENTITIES-2)
1145 #define	ENTITYNUM_MAX_NORMAL	(MAX_GENTITIES-2)
1146 
1147 
1148 #define	MAX_MODELS			256	// these are sent over the net as 8 bits
1149 #define	MAX_SOUNDS			256	// so they cannot be blindly increased
1150 
1151 
1152 #define	MAX_CONFIGSTRINGS	1024
1153 
1154 // these are the only configstrings that the system reserves, all the
1155 // other ones are strictly for servergame to clientgame communication
1156 #define	CS_SERVERINFO		0	// an info string with all the serverinfo cvars
1157 #define	CS_SYSTEMINFO		1	// an info string for server system to client system configuration (timescale, etc)
1158 
1159 #define	RESERVED_CONFIGSTRINGS	2	// game can't modify below this, only the system can
1160 
1161 #define	MAX_GAMESTATE_CHARS	16000
1162 typedef struct
1163 {
1164 	int             stringOffsets[MAX_CONFIGSTRINGS];
1165 	char            stringData[MAX_GAMESTATE_CHARS];
1166 	int             dataCount;
1167 } gameState_t;
1168 
1169 //=========================================================
1170 
1171 // bit field limits
1172 #define	MAX_STATS				16
1173 #define	MAX_PERSISTANT			16
1174 #define	MAX_POWERUPS			16
1175 #define	MAX_WEAPONS				16
1176 
1177 #define	MAX_PS_EVENTS			2
1178 
1179 #define PS_PMOVEFRAMECOUNTBITS	6
1180 
1181 // playerState_t is the information needed by both the client and server
1182 // to predict player motion and actions
1183 // nothing outside of pmove should modify these, or some degree of prediction error
1184 // will occur
1185 
1186 // you can't add anything to this without modifying the code in msg.c
1187 
1188 // playerState_t is a full superset of entityState_t as it is used by players,
1189 // so if a playerState_t is transmitted, the entityState_t can be fully derived
1190 // from it.
1191 typedef struct playerState_s
1192 {
1193 	int             commandTime;	// cmd->serverTime of last executed command
1194 	int             pm_type;
1195 	int             bobCycle;	// for view bobbing and footstep generation
1196 	int             pm_flags;	// ducked, jump_held, etc
1197 	int             pm_time;
1198 
1199 	vec3_t          origin;
1200 	vec3_t          velocity;
1201 	int             weaponTime;
1202 	int             gravity;
1203 	int             speed;
1204 	int             delta_angles[3];	// add to command angles to get view direction
1205 	// changed by spawns, rotating objects, and teleporters
1206 
1207 	int             groundEntityNum;	// ENTITYNUM_NONE = in air
1208 
1209 	int             legsTimer;	// don't change low priority animations until this runs out
1210 	int             legsAnim;	// mask off ANIM_TOGGLEBIT
1211 
1212 	int             torsoTimer;	// don't change low priority animations until this runs out
1213 	int             torsoAnim;	// mask off ANIM_TOGGLEBIT
1214 
1215 	int             movementDir;	// a number 0 to 7 that represents the reletive angle
1216 	// of movement to the view angle (axial and diagonals)
1217 	// when at rest, the value will remain unchanged
1218 	// used to twist the legs during strafing
1219 
1220 	vec3_t          grapplePoint;	// location of grapple to pull towards if PMF_GRAPPLE_PULL
1221 
1222 	int             eFlags;		// copied to entityState_t->eFlags
1223 
1224 	int             eventSequence;	// pmove generated events
1225 	int             events[MAX_PS_EVENTS];
1226 	int             eventParms[MAX_PS_EVENTS];
1227 
1228 	int             externalEvent;	// events set on player from another source
1229 	int             externalEventParm;
1230 	int             externalEventTime;
1231 
1232 	int             clientNum;	// ranges from 0 to MAX_CLIENTS-1
1233 	int             weapon;		// copied to entityState_t->weapon
1234 	int             weaponstate;
1235 
1236 	vec3_t          viewangles;	// for fixed views
1237 	int             viewheight;
1238 
1239 	// damage feedback
1240 	int             damageEvent;	// when it changes, latch the other parms
1241 	int             damageYaw;
1242 	int             damagePitch;
1243 	int             damageCount;
1244 
1245 	int             stats[MAX_STATS];
1246 	int             persistant[MAX_PERSISTANT];	// stats that aren't cleared on death
1247 	int             powerups[MAX_POWERUPS];	// level.time that the powerup runs out
1248 	int             ammo[MAX_WEAPONS];
1249 
1250 	int             generic1;
1251 	int             loopSound;
1252 	int             jumppad_ent;	// jumppad entity hit this frame
1253 
1254 	// not communicated over the net at all
1255 	int             ping;		// server to game info for scoreboard
1256 	int             pmove_framecount;	// FIXME: don't transmit over the network
1257 	int             jumppad_frame;
1258 	int             entityEventSequence;
1259 } playerState_t;
1260 
1261 
1262 //====================================================================
1263 
1264 
1265 //
1266 // usercmd_t->button bits, many of which are generated by the client system,
1267 // so they aren't game/cgame only definitions
1268 //
1269 #define	BUTTON_ATTACK		1
1270 #define	BUTTON_TALK			2	// displays talk balloon and disables actions
1271 #define	BUTTON_USE_HOLDABLE	4
1272 #define	BUTTON_GESTURE		8
1273 #define	BUTTON_WALKING		16	// walking can't just be infered from MOVE_RUN
1274 										// because a key pressed late in the frame will
1275 										// only generate a small move value for that frame
1276 										// walking will use different animations and
1277 										// won't generate footsteps
1278 #define BUTTON_AFFIRMATIVE	32
1279 #define	BUTTON_NEGATIVE		64
1280 
1281 #define BUTTON_GETFLAG		128
1282 #define BUTTON_GUARDBASE	256
1283 #define BUTTON_PATROL		512
1284 #define BUTTON_FOLLOWME		1024
1285 
1286 #define	BUTTON_ANY			2048	// any key whatsoever
1287 
1288 #define	MOVE_RUN			120	// if forwardmove or rightmove are >= MOVE_RUN,
1289 										// then BUTTON_WALKING should be set
1290 
1291 // usercmd_t is sent to the server each client frame
1292 typedef struct usercmd_s
1293 {
1294 	int             serverTime;
1295 	int             angles[3];
1296 	int             buttons;
1297 	byte            weapon;		// weapon
1298 	signed char     forwardmove, rightmove, upmove;
1299 } usercmd_t;
1300 
1301 //===================================================================
1302 
1303 // if entityState->solid == SOLID_BMODEL, modelindex is an inline model number
1304 #define	SOLID_BMODEL	0xffffff
1305 
1306 typedef enum
1307 {
1308 	TR_STATIONARY,
1309 	TR_INTERPOLATE,				// non-parametric, but interpolate between snapshots
1310 	TR_LINEAR,
1311 	TR_LINEAR_STOP,
1312 	TR_SINE,					// value = base + sin( time / duration ) * delta
1313 	TR_GRAVITY
1314 } trType_t;
1315 
1316 typedef struct
1317 {
1318 	trType_t        trType;
1319 	int             trTime;
1320 	int             trDuration;	// if non 0, trTime + trDuration = stop time
1321 	vec3_t          trBase;
1322 	vec3_t          trDelta;	// velocity, etc
1323 } trajectory_t;
1324 
1325 // entityState_t is the information conveyed from the server
1326 // in an update message about entities that the client will
1327 // need to render in some way
1328 // Different eTypes may use the information in different ways
1329 // The messages are delta compressed, so it doesn't really matter if
1330 // the structure size is fairly large
1331 
1332 typedef struct entityState_s
1333 {
1334 	int             number;		// entity index
1335 	int             eType;		// entityType_t
1336 	int             eFlags;
1337 
1338 	trajectory_t    pos;		// for calculating position
1339 	trajectory_t    apos;		// for calculating angles
1340 
1341 	int             time;
1342 	int             time2;
1343 
1344 	vec3_t          origin;
1345 	vec3_t          origin2;
1346 
1347 	vec3_t          angles;
1348 	vec3_t          angles2;
1349 
1350 	int             otherEntityNum;	// shotgun sources, etc
1351 	int             otherEntityNum2;
1352 
1353 	int             groundEntityNum;	// -1 = in air
1354 
1355 	int             constantLight;	// r + (g<<8) + (b<<16) + (intensity<<24)
1356 	int             loopSound;	// constantly loop this sound
1357 
1358 	int             modelindex;
1359 	int             modelindex2;
1360 	int             clientNum;	// 0 to (MAX_CLIENTS - 1), for players and corpses
1361 	int             frame;
1362 
1363 	int             solid;		// for client side prediction, trap_linkentity sets this properly
1364 
1365 	int             event;		// impulse events -- muzzle flashes, footsteps, etc
1366 	int             eventParm;
1367 
1368 	// for players
1369 	int             powerups;	// bit flags
1370 	int             weapon;		// determines weapon and flash model, etc
1371 	int             legsAnim;	// mask off ANIM_TOGGLEBIT
1372 	int             torsoAnim;	// mask off ANIM_TOGGLEBIT
1373 
1374 	int             generic1;
1375 } entityState_t;
1376 
1377 typedef enum
1378 {
1379 	CA_UNINITIALIZED,
1380 	CA_DISCONNECTED,			// not talking to a server
1381 	CA_AUTHORIZING,				// not used any more, was checking cd key
1382 	CA_CONNECTING,				// sending request packets to the server
1383 	CA_CHALLENGING,				// sending challenge packets to the server
1384 	CA_CONNECTED,				// netchan_t established, getting gamestate
1385 	CA_LOADING,					// only during cgame initialization, never during main loop
1386 	CA_PRIMED,					// got gamestate, waiting for first frame
1387 	CA_ACTIVE,					// game views should be displayed
1388 	CA_CINEMATIC				// playing a cinematic or a static pic, not connected to a server
1389 } connstate_t;
1390 
1391 // font support
1392 
1393 #define GLYPH_START 0
1394 #define GLYPH_END 255
1395 #define GLYPH_CHARSTART 32
1396 #define GLYPH_CHAREND 127
1397 #define GLYPHS_PER_FONT GLYPH_END - GLYPH_START + 1
1398 typedef struct
1399 {
1400 	int             height;		// number of scan lines
1401 	int             top;		// top of glyph in buffer
1402 	int             bottom;		// bottom of glyph in buffer
1403 	int             pitch;		// width for copying
1404 	int             xSkip;		// x adjustment
1405 	int             imageWidth;	// width of actual image
1406 	int             imageHeight;	// height of actual image
1407 	float           s;			// x offset in image where glyph starts
1408 	float           t;			// y offset in image where glyph starts
1409 	float           s2;
1410 	float           t2;
1411 	qhandle_t       glyph;		// handle to the shader with the glyph
1412 	char            shaderName[32];
1413 } glyphInfo_t;
1414 
1415 typedef struct
1416 {
1417 	glyphInfo_t     glyphs[GLYPHS_PER_FONT];
1418 	float           glyphScale;
1419 	char            name[MAX_QPATH];
1420 } fontInfo_t;
1421 
1422 #define Square(x) ((x)*(x))
1423 
1424 // real time
1425 //=============================================
1426 
1427 
1428 typedef struct qtime_s
1429 {
1430 	int             tm_sec;		/* seconds after the minute - [0,59] */
1431 	int             tm_min;		/* minutes after the hour - [0,59] */
1432 	int             tm_hour;	/* hours since midnight - [0,23] */
1433 	int             tm_mday;	/* day of the month - [1,31] */
1434 	int             tm_mon;		/* months since January - [0,11] */
1435 	int             tm_year;	/* years since 1900 */
1436 	int             tm_wday;	/* days since Sunday - [0,6] */
1437 	int             tm_yday;	/* days since January 1 - [0,365] */
1438 	int             tm_isdst;	/* daylight savings time flag */
1439 } qtime_t;
1440 
1441 
1442 // server browser sources
1443 // TTimo: AS_MPLAYER is no longer used
1444 #define AS_LOCAL			0
1445 #define AS_MPLAYER		1
1446 #define AS_GLOBAL			2
1447 #define AS_FAVORITES	3
1448 
1449 
1450 // cinematic states
1451 typedef enum
1452 {
1453 	FMV_IDLE,
1454 	FMV_PLAY,					// play
1455 	FMV_EOF,					// all other conditions, i.e. stop/EOF/abort
1456 	FMV_ID_BLT,
1457 	FMV_ID_IDLE,
1458 	FMV_LOOPED,
1459 	FMV_ID_WAIT
1460 } e_status;
1461 
1462 typedef enum _flag_status
1463 {
1464 	FLAG_ATBASE = 0,
1465 	FLAG_TAKEN,					// CTF
1466 	FLAG_TAKEN_RED,				// One Flag CTF
1467 	FLAG_TAKEN_BLUE,			// One Flag CTF
1468 	FLAG_DROPPED
1469 } flagStatus_t;
1470 
1471 #define	MAX_GLOBAL_SERVERS				4096
1472 #define	MAX_OTHER_SERVERS			128
1473 #define MAX_PINGREQUESTS			32
1474 #define MAX_SERVERSTATUSREQUESTS	16
1475 
1476 #define SAY_ALL						0
1477 #define SAY_TEAM					1
1478 #define SAY_TELL					2
1479 
1480 #define CDKEY_LEN					16
1481 #define CDCHKSUM_LEN				2
1482 
1483 #endif							// __Q_SHARED_H
1484