Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

q_shared.h (40436B)


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