00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __Q_SHARED_H
00024 #define __Q_SHARED_H
00025
00026
00027
00028
00029 #define Q3_VERSION "Q3 1.32b"
00030
00031
00032 #define MAX_TEAMNAME 32
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifdef Q3_VM
00076
00077 #include "bg_lib.h"
00078
00079 #else
00080
00081 #include <assert.h>
00082 #include <math.h>
00083 #include <stdio.h>
00084 #include <stdarg.h>
00085 #include <string.h>
00086 #include <stdlib.h>
00087 #include <time.h>
00088 #include <ctype.h>
00089 #include <limits.h>
00090
00091 #endif
00092
00093 #ifdef _WIN32
00094
00095
00096
00097 #endif
00098
00099
00100
00101 #if (defined _M_IX86 || defined __i386__) && !defined __sun__ && !defined __LCC__
00102 #define id386 1
00103 #else
00104 #define id386 0
00105 #endif
00106
00107 #if (defined(powerc) || defined(powerpc) || defined(ppc) || defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY)
00108 #define idppc 1
00109 #if defined(__VEC__)
00110 #define idppc_altivec 1
00111 #else
00112 #define idppc_altivec 0
00113 #endif
00114 #else
00115 #define idppc 0
00116 #define idppc_altivec 0
00117 #endif
00118
00119
00120
00121 #define QDECL
00122
00123 short ShortSwap (short l);
00124 int LongSwap (int l);
00125 float FloatSwap (const float *f);
00126
00127
00128
00129 #ifdef WIN32
00130
00131 #define MAC_STATIC
00132
00133 #undef QDECL
00134 #define QDECL __cdecl
00135
00136
00137 #ifdef NDEBUG
00138 #ifdef _M_IX86
00139 #define CPUSTRING "win-x86"
00140 #elif defined _M_ALPHA
00141 #define CPUSTRING "win-AXP"
00142 #endif
00143 #else
00144 #ifdef _M_IX86
00145 #define CPUSTRING "win-x86-debug"
00146 #elif defined _M_ALPHA
00147 #define CPUSTRING "win-AXP-debug"
00148 #endif
00149 #endif
00150
00151 #define ID_INLINE __inline
00152
00153 static ID_INLINE short BigShort( short l) { return ShortSwap(l); }
00154 #define LittleShort
00155 static ID_INLINE int BigLong(int l) { LongSwap(l); }
00156 #define LittleLong
00157 static ID_INLINE float BigFloat(const float *l) { FloatSwap(l); }
00158 #define LittleFloat
00159
00160 #define PATH_SEP '\\'
00161
00162 #endif
00163
00164
00165
00166 #if defined(MACOS_X)
00167
00168 #define MAC_STATIC
00169 #define __cdecl
00170 #define __declspec(x)
00171 #define stricmp strcasecmp
00172 #define ID_INLINE inline
00173
00174 #ifdef __ppc__
00175 #define CPUSTRING "MacOSX-ppc"
00176 #elif defined __i386__
00177 #define CPUSTRING "MacOSX-i386"
00178 #else
00179 #define CPUSTRING "MacOSX-other"
00180 #endif
00181
00182 #define PATH_SEP '/'
00183
00184 #define __rlwimi(out, in, shift, maskBegin, maskEnd) asm("rlwimi %0,%1,%2,%3,%4" : "=r" (out) : "r" (in), "i" (shift), "i" (maskBegin), "i" (maskEnd))
00185 #define __dcbt(addr, offset) asm("dcbt %0,%1" : : "b" (addr), "r" (offset))
00186
00187 static inline unsigned int __lwbrx(register void *addr, register int offset) {
00188 register unsigned int word;
00189
00190 asm("lwbrx %0,%2,%1" : "=r" (word) : "r" (addr), "b" (offset));
00191 return word;
00192 }
00193
00194 static inline unsigned short __lhbrx(register void *addr, register int offset) {
00195 register unsigned short halfword;
00196
00197 asm("lhbrx %0,%2,%1" : "=r" (halfword) : "r" (addr), "b" (offset));
00198 return halfword;
00199 }
00200
00201 static inline float __fctiw(register float f) {
00202 register float fi;
00203
00204 asm("fctiw %0,%1" : "=f" (fi) : "f" (f));
00205
00206 return fi;
00207 }
00208
00209 #define BigShort
00210 static inline short LittleShort(short l) { return ShortSwap(l); }
00211 #define BigLong
00212 static inline int LittleLong (int l) { return LongSwap(l); }
00213 #define BigFloat
00214 static inline float LittleFloat (const float l) { return FloatSwap(&l); }
00215
00216 #endif
00217
00218
00219
00220 #ifdef __MACOS__
00221
00222 #include <MacTypes.h>
00223 #define MAC_STATIC
00224 #define ID_INLINE inline
00225
00226 #define CPUSTRING "MacOS-PPC"
00227
00228 #define PATH_SEP ':'
00229
00230 void Sys_PumpEvents( void );
00231
00232 #define BigShort
00233 static inline short LittleShort(short l) { return ShortSwap(l); }
00234 #define BigLong
00235 static inline int LittleLong (int l) { return LongSwap(l); }
00236 #define BigFloat
00237 static inline float LittleFloat (const float l) { return FloatSwap(&l); }
00238
00239 #endif
00240
00241
00242
00243
00244
00245 #ifdef __linux__
00246
00247
00248 #define stricmp strcasecmp
00249
00250 #define MAC_STATIC // bk: FIXME
00251 #define ID_INLINE inline
00252
00253 #ifdef __i386__
00254 #define CPUSTRING "linux-i386"
00255 #elif defined __axp__
00256 #define CPUSTRING "linux-alpha"
00257 #else
00258 #define CPUSTRING "linux-other"
00259 #endif
00260
00261 #define PATH_SEP '/'
00262
00263
00264 #ifdef Q3_STATIC
00265 #define GAME_HARD_LINKED
00266 #define CGAME_HARD_LINKED
00267 #define UI_HARD_LINKED
00268 #define BOTLIB_HARD_LINKED
00269 #endif
00270
00271 #if !idppc
00272 inline static short BigShort( short l) { return ShortSwap(l); }
00273 #define LittleShort
00274 inline static int BigLong(int l) { return LongSwap(l); }
00275 #define LittleLong
00276 inline static float BigFloat(const float *l) { return FloatSwap(l); }
00277 #define LittleFloat
00278 #else
00279 #define BigShort
00280 inline static short LittleShort(short l) { return ShortSwap(l); }
00281 #define BigLong
00282 inline static int LittleLong (int l) { return LongSwap(l); }
00283 #define BigFloat
00284 inline static float LittleFloat (const float *l) { return FloatSwap(l); }
00285 #endif
00286
00287 #endif
00288
00289
00290 #ifdef __FreeBSD__ // rb010123
00291
00292 #define stricmp strcasecmp
00293
00294 #define MAC_STATIC
00295 #define ID_INLINE inline
00296
00297 #ifdef __i386__
00298 #define CPUSTRING "freebsd-i386"
00299 #elif defined __axp__
00300 #define CPUSTRING "freebsd-alpha"
00301 #else
00302 #define CPUSTRING "freebsd-other"
00303 #endif
00304
00305 #define PATH_SEP '/'
00306
00307
00308
00309 #if !idppc
00310 static short BigShort( short l) { return ShortSwap(l); }
00311 #define LittleShort
00312 static int BigLong(int l) { LongSwap(l); }
00313 #define LittleLong
00314 static float BigFloat(const float *l) { FloatSwap(l); }
00315 #define LittleFloat
00316 #else
00317 #define BigShort
00318 static short LittleShort(short l) { return ShortSwap(l); }
00319 #define BigLong
00320 static int LittleLong (int l) { return LongSwap(l); }
00321 #define BigFloat
00322 static float LittleFloat (const float *l) { return FloatSwap(l); }
00323 #endif
00324
00325 #endif
00326
00327
00328
00329 typedef unsigned char byte;
00330
00331 typedef enum {qfalse, qtrue} qboolean;
00332
00333 typedef int qhandle_t;
00334 typedef int sfxHandle_t;
00335 typedef int fileHandle_t;
00336 typedef int clipHandle_t;
00337
00338
00339 #ifndef NULL
00340 #define NULL ((void *)0)
00341 #endif
00342
00343 #define MAX_QINT 0x7fffffff
00344 #define MIN_QINT (-MAX_QINT-1)
00345
00346
00347
00348 #define PITCH 0 // up / down
00349 #define YAW 1 // left / right
00350 #define ROLL 2 // fall over
00351
00352
00353
00354 #define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString
00355 #define MAX_STRING_TOKENS 1024 // max tokens resulting from Cmd_TokenizeString
00356 #define MAX_TOKEN_CHARS 1024 // max length of an individual token
00357
00358 #define MAX_INFO_STRING 1024
00359 #define MAX_INFO_KEY 1024
00360 #define MAX_INFO_VALUE 1024
00361
00362 #define BIG_INFO_STRING 8192 // used for system info key only
00363 #define BIG_INFO_KEY 8192
00364 #define BIG_INFO_VALUE 8192
00365
00366
00367 #define MAX_QPATH 64 // max length of a quake game pathname
00368 #ifdef PATH_MAX
00369 #define MAX_OSPATH PATH_MAX
00370 #else
00371 #define MAX_OSPATH 256 // max length of a filesystem pathname
00372 #endif
00373
00374 #define MAX_NAME_LENGTH 32 // max length of a client name
00375
00376 #define MAX_SAY_TEXT 150
00377
00378
00379 typedef enum {
00380 EXEC_NOW,
00381
00382 EXEC_INSERT,
00383 EXEC_APPEND
00384 } cbufExec_t;
00385
00386
00387
00388
00389
00390 #define MAX_MAP_AREA_BYTES 32 // bit vector of area visibility
00391
00392
00393
00394 typedef enum {
00395 PRINT_ALL,
00396 PRINT_DEVELOPER,
00397 PRINT_WARNING,
00398 PRINT_ERROR
00399 } printParm_t;
00400
00401
00402 #ifdef ERR_FATAL
00403 #undef ERR_FATAL // this is be defined in malloc.h
00404 #endif
00405
00406
00407 typedef enum {
00408 ERR_FATAL,
00409 ERR_DROP,
00410 ERR_SERVERDISCONNECT,
00411 ERR_DISCONNECT,
00412 ERR_NEED_CD
00413 } errorParm_t;
00414
00415
00416
00417
00418 #define PROP_GAP_WIDTH 3
00419 #define PROP_SPACE_WIDTH 8
00420 #define PROP_HEIGHT 27
00421 #define PROP_SMALL_SIZE_SCALE 0.75
00422
00423 #define BLINK_DIVISOR 200
00424 #define PULSE_DIVISOR 75
00425
00426 #define UI_LEFT 0x00000000 // default
00427 #define UI_CENTER 0x00000001
00428 #define UI_RIGHT 0x00000002
00429 #define UI_FORMATMASK 0x00000007
00430 #define UI_SMALLFONT 0x00000010
00431 #define UI_BIGFONT 0x00000020 // default
00432 #define UI_GIANTFONT 0x00000040
00433 #define UI_DROPSHADOW 0x00000800
00434 #define UI_BLINK 0x00001000
00435 #define UI_INVERSE 0x00002000
00436 #define UI_PULSE 0x00004000
00437
00438 #if defined(_DEBUG) && !defined(BSPC)
00439 #define HUNK_DEBUG
00440 #endif
00441
00442 typedef enum {
00443 h_high,
00444 h_low,
00445 h_dontcare
00446 } ha_pref;
00447
00448 #ifdef HUNK_DEBUG
00449 #define Hunk_Alloc( size, preference ) Hunk_AllocDebug(size, preference, #size, __FILE__, __LINE__)
00450 void *Hunk_AllocDebug( int size, ha_pref preference, char *label, char *file, int line );
00451 #else
00452 void *Hunk_Alloc( int size, ha_pref preference );
00453 #endif
00454
00455 #ifdef __linux__
00456
00457
00458 void Snd_Memset (void* dest, const int val, const size_t count);
00459 #else
00460 #define Snd_Memset Com_Memset
00461 #endif
00462
00463 #if !( defined __VECTORC )
00464 void Com_Memset (void* dest, const int val, const size_t count);
00465 void Com_Memcpy (void* dest, const void* src, const size_t count);
00466 #else
00467 #define Com_Memset memset
00468 #define Com_Memcpy memcpy
00469 #endif
00470
00471 #define CIN_system 1
00472 #define CIN_loop 2
00473 #define CIN_hold 4
00474 #define CIN_silent 8
00475 #define CIN_shader 16
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486 typedef float vec_t;
00487 typedef vec_t vec2_t[2];
00488 typedef vec_t vec3_t[3];
00489 typedef vec_t vec4_t[4];
00490 typedef vec_t vec5_t[5];
00491
00492 typedef int fixed4_t;
00493 typedef int fixed8_t;
00494 typedef int fixed16_t;
00495
00496 #ifndef M_PI
00497 #define M_PI 3.14159265358979323846f // matches value in gcc v2 math.h
00498 #endif
00499
00500 #define NUMVERTEXNORMALS 162
00501 extern vec3_t bytedirs[NUMVERTEXNORMALS];
00502
00503
00504
00505 #define SCREEN_WIDTH 640
00506 #define SCREEN_HEIGHT 480
00507
00508 #define TINYCHAR_WIDTH (SMALLCHAR_WIDTH)
00509 #define TINYCHAR_HEIGHT (SMALLCHAR_HEIGHT/2)
00510
00511 #define SMALLCHAR_WIDTH 8
00512 #define SMALLCHAR_HEIGHT 16
00513
00514 #define BIGCHAR_WIDTH 16
00515 #define BIGCHAR_HEIGHT 16
00516
00517 #define GIANTCHAR_WIDTH 32
00518 #define GIANTCHAR_HEIGHT 48
00519
00520 extern vec4_t colorBlack;
00521 extern vec4_t colorRed;
00522 extern vec4_t colorGreen;
00523 extern vec4_t colorBlue;
00524 extern vec4_t colorYellow;
00525 extern vec4_t colorMagenta;
00526 extern vec4_t colorCyan;
00527 extern vec4_t colorWhite;
00528 extern vec4_t colorLtGrey;
00529 extern vec4_t colorMdGrey;
00530 extern vec4_t colorDkGrey;
00531
00532 #define Q_COLOR_ESCAPE '^'
00533 #define Q_IsColorString(p) ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE )
00534
00535 #define COLOR_BLACK '0'
00536 #define COLOR_RED '1'
00537 #define COLOR_GREEN '2'
00538 #define COLOR_YELLOW '3'
00539 #define COLOR_BLUE '4'
00540 #define COLOR_CYAN '5'
00541 #define COLOR_MAGENTA '6'
00542 #define COLOR_WHITE '7'
00543 #define ColorIndex(c) ( ( (c) - '0' ) & 7 )
00544
00545 #define S_COLOR_BLACK "^0"
00546 #define S_COLOR_RED "^1"
00547 #define S_COLOR_GREEN "^2"
00548 #define S_COLOR_YELLOW "^3"
00549 #define S_COLOR_BLUE "^4"
00550 #define S_COLOR_CYAN "^5"
00551 #define S_COLOR_MAGENTA "^6"
00552 #define S_COLOR_WHITE "^7"
00553
00554 extern vec4_t g_color_table[8];
00555
00556 #define MAKERGB( v, r, g, b ) v[0]=r;v[1]=g;v[2]=b
00557 #define MAKERGBA( v, r, g, b, a ) v[0]=r;v[1]=g;v[2]=b;v[3]=a
00558
00559 #define DEG2RAD( a ) ( ( (a) * M_PI ) / 180.0F )
00560 #define RAD2DEG( a ) ( ( (a) * 180.0f ) / M_PI )
00561
00562 struct cplane_s;
00563
00564 extern vec3_t vec3_origin;
00565 extern vec3_t axisDefault[3];
00566
00567 #define nanmask (255<<23)
00568
00569 #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
00570
00571 #if idppc
00572
00573 static inline float Q_rsqrt( float number ) {
00574 float x = 0.5f * number;
00575 float y;
00576 #ifdef __GNUC__
00577 asm("frsqrte %0,%1" : "=f" (y) : "f" (number));
00578 #else
00579 y = __frsqrte( number );
00580 #endif
00581 return y * (1.5f - (x * y * y));
00582 }
00583
00584 #ifdef __GNUC__
00585 static inline float Q_fabs(float x) {
00586 float abs_x;
00587
00588 asm("fabs %0,%1" : "=f" (abs_x) : "f" (x));
00589 return abs_x;
00590 }
00591 #else
00592 #define Q_fabs __fabsf
00593 #endif
00594
00595 #else
00596 float Q_fabs( float f );
00597 float Q_rsqrt( float f );
00598 #endif
00599
00600 #define SQRTFAST( x ) ( (x) * Q_rsqrt( x ) )
00601
00602 signed char ClampChar( int i );
00603 signed short ClampShort( int i );
00604
00605
00606 int DirToByte( vec3_t dir );
00607 void ByteToDir( int b, vec3_t dir );
00608
00609 #if 1
00610
00611 #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
00612 #define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
00613 #define VectorAdd(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
00614 #define VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
00615 #define VectorScale(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
00616 #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))
00617
00618 #else
00619
00620 #define DotProduct(x,y) _DotProduct(x,y)
00621 #define VectorSubtract(a,b,c) _VectorSubtract(a,b,c)
00622 #define VectorAdd(a,b,c) _VectorAdd(a,b,c)
00623 #define VectorCopy(a,b) _VectorCopy(a,b)
00624 #define VectorScale(v, s, o) _VectorScale(v,s,o)
00625 #define VectorMA(v, s, b, o) _VectorMA(v,s,b,o)
00626
00627 #endif
00628
00629 #ifdef __LCC__
00630 #ifdef VectorCopy
00631 #undef VectorCopy
00632
00633 typedef struct {
00634 float v[3];
00635 } vec3struct_t;
00636 #define VectorCopy(a,b) (*(vec3struct_t *)b=*(vec3struct_t *)a)
00637 #define ID_INLINE static
00638 #endif
00639 #endif
00640
00641 #define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0)
00642 #define VectorNegate(a,b) ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
00643 #define VectorSet(v, x, y, z) ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
00644 #define Vector4Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
00645
00646 #define SnapVector(v) {v[0]=((int)(v[0]));v[1]=((int)(v[1]));v[2]=((int)(v[2]));}
00647
00648 vec_t _DotProduct( const vec3_t v1, const vec3_t v2 );
00649 void _VectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t out );
00650 void _VectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t out );
00651 void _VectorCopy( const vec3_t in, vec3_t out );
00652 void _VectorScale( const vec3_t in, float scale, vec3_t out );
00653 void _VectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc );
00654
00655 unsigned ColorBytes3 (float r, float g, float b);
00656 unsigned ColorBytes4 (float r, float g, float b, float a);
00657
00658 float NormalizeColor( const vec3_t in, vec3_t out );
00659
00660 float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
00661 void ClearBounds( vec3_t mins, vec3_t maxs );
00662 void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
00663
00664 #ifndef __LCC__
00665 static ID_INLINE int VectorCompare( const vec3_t v1, const vec3_t v2 ) {
00666 if (v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2]) {
00667 return 0;
00668 }
00669 return 1;
00670 }
00671
00672 static ID_INLINE vec_t VectorLength( const vec3_t v ) {
00673 return (vec_t)sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00674 }
00675
00676 static ID_INLINE vec_t VectorLengthSquared( const vec3_t v ) {
00677 return (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00678 }
00679
00680 static ID_INLINE vec_t Distance( const vec3_t p1, const vec3_t p2 ) {
00681 vec3_t v;
00682
00683 VectorSubtract (p2, p1, v);
00684 return VectorLength( v );
00685 }
00686
00687 static ID_INLINE vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 ) {
00688 vec3_t v;
00689
00690 VectorSubtract (p2, p1, v);
00691 return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
00692 }
00693
00694
00695
00696 static ID_INLINE void VectorNormalizeFast( vec3_t v )
00697 {
00698 float ilength;
00699
00700 ilength = Q_rsqrt( DotProduct( v, v ) );
00701
00702 v[0] *= ilength;
00703 v[1] *= ilength;
00704 v[2] *= ilength;
00705 }
00706
00707 static ID_INLINE void VectorInverse( vec3_t v ){
00708 v[0] = -v[0];
00709 v[1] = -v[1];
00710 v[2] = -v[2];
00711 }
00712
00713 static ID_INLINE void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ) {
00714 cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
00715 cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
00716 cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
00717 }
00718
00719 #else
00720 int VectorCompare( const vec3_t v1, const vec3_t v2 );
00721
00722 vec_t VectorLength( const vec3_t v );
00723
00724 vec_t VectorLengthSquared( const vec3_t v );
00725
00726 vec_t Distance( const vec3_t p1, const vec3_t p2 );
00727
00728 vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 );
00729
00730 void VectorNormalizeFast( vec3_t v );
00731
00732 void VectorInverse( vec3_t v );
00733
00734 void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
00735
00736 #endif
00737
00738 vec_t VectorNormalize (vec3_t v);
00739 vec_t VectorNormalize2( const vec3_t v, vec3_t out );
00740 void Vector4Scale( const vec4_t in, vec_t scale, vec4_t out );
00741 void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out );
00742 int Q_log2(int val);
00743
00744 float Q_acos(float c);
00745
00746 int Q_rand( int *seed );
00747 float Q_random( int *seed );
00748 float Q_crandom( int *seed );
00749
00750 #define random() ((rand () & 0x7fff) / ((float)0x7fff))
00751 #define crandom() (2.0 * (random() - 0.5))
00752
00753 void vectoangles( const vec3_t value1, vec3_t angles);
00754 void AnglesToAxis( const vec3_t angles, vec3_t axis[3] );
00755
00756 void AxisClear( vec3_t axis[3] );
00757 void AxisCopy( vec3_t in[3], vec3_t out[3] );
00758
00759 void SetPlaneSignbits( struct cplane_s *out );
00760 int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct cplane_s *plane);
00761
00762 float AngleMod(float a);
00763 float LerpAngle (float from, float to, float frac);
00764 float AngleSubtract( float a1, float a2 );
00765 void AnglesSubtract( vec3_t v1, vec3_t v2, vec3_t v3 );
00766
00767 float AngleNormalize360 ( float angle );
00768 float AngleNormalize180 ( float angle );
00769 float AngleDelta ( float angle1, float angle2 );
00770
00771 qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
00772 void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal );
00773 void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
00774 void RotateAroundDirection( vec3_t axis[3], float yaw );
00775 void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up );
00776
00777
00778
00779
00780 void MatrixMultiply(float in1[3][3], float in2[3][3], float out[3][3]);
00781 void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
00782 void PerpendicularVector( vec3_t dst, const vec3_t src );
00783
00784
00785
00786
00787 float Com_Clamp( float min, float max, float value );
00788
00789 char *COM_SkipPath( char *pathname );
00790 void COM_StripExtension( const char *in, char *out );
00791 void COM_DefaultExtension( char *path, int maxSize, const char *extension );
00792
00793 void COM_BeginParseSession( const char *name );
00794 int COM_GetCurrentParseLine( void );
00795 char *COM_Parse( char **data_p );
00796 char *COM_ParseExt( char **data_p, qboolean allowLineBreak );
00797 int COM_Compress( char *data_p );
00798 void COM_ParseError( char *format, ... );
00799 void COM_ParseWarning( char *format, ... );
00800
00801
00802 #define MAX_TOKENLENGTH 1024
00803
00804 #ifndef TT_STRING
00805
00806 #define TT_STRING 1 // string
00807 #define TT_LITERAL 2 // literal
00808 #define TT_NUMBER 3 // number
00809 #define TT_NAME 4 // name
00810 #define TT_PUNCTUATION 5 // punctuation
00811 #endif
00812
00813 typedef struct pc_token_s
00814 {
00815 int type;
00816 int subtype;
00817 int intvalue;
00818 float floatvalue;
00819 char string[MAX_TOKENLENGTH];
00820 } pc_token_t;
00821
00822
00823
00824 void COM_MatchToken( char**buf_p, char *match );
00825
00826 void SkipBracedSection (char **program);
00827 void SkipRestOfLine ( char **data );
00828
00829 void Parse1DMatrix (char **buf_p, int x, float *m);
00830 void Parse2DMatrix (char **buf_p, int y, int x, float *m);
00831 void Parse3DMatrix (char **buf_p, int z, int y, int x, float *m);
00832
00833 void QDECL Com_sprintf (char *dest, int size, const char *fmt, ...);
00834
00835
00836
00837 typedef enum {
00838 FS_READ,
00839 FS_WRITE,
00840 FS_APPEND,
00841 FS_APPEND_SYNC
00842 } fsMode_t;
00843
00844 typedef enum {
00845 FS_SEEK_CUR,
00846 FS_SEEK_END,
00847 FS_SEEK_SET
00848 } fsOrigin_t;
00849
00850
00851
00852 int Q_isprint( int c );
00853 int Q_islower( int c );
00854 int Q_isupper( int c );
00855 int Q_isalpha( int c );
00856
00857
00858 int Q_stricmp (const char *s1, const char *s2);
00859 int Q_strncmp (const char *s1, const char *s2, int n);
00860 int Q_stricmpn (const char *s1, const char *s2, int n);
00861 char *Q_strlwr( char *s1 );
00862 char *Q_strupr( char *s1 );
00863 char *Q_strrchr( const char* string, int c );
00864
00865
00866 void Q_strncpyz( char *dest, const char *src, int destsize );
00867 void Q_strcat( char *dest, int size, const char *src );
00868
00869
00870 int Q_PrintStrlen( const char *string );
00871
00872 char *Q_CleanStr( char *string );
00873
00874
00875
00876
00877
00878 typedef struct
00879 {
00880 byte b0;
00881 byte b1;
00882 byte b2;
00883 byte b3;
00884 byte b4;
00885 byte b5;
00886 byte b6;
00887 byte b7;
00888 } qint64;
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903 char * QDECL va(char *format, ...);
00904
00905
00906
00907
00908
00909
00910 char *Info_ValueForKey( const char *s, const char *key );
00911 void Info_RemoveKey( char *s, const char *key );
00912 void Info_RemoveKey_big( char *s, const char *key );
00913 void Info_SetValueForKey( char *s, const char *key, const char *value );
00914 void Info_SetValueForKey_Big( char *s, const char *key, const char *value );
00915 qboolean Info_Validate( const char *s );
00916 void Info_NextPair( const char **s, char *key, char *value );
00917
00918
00919 void QDECL Com_Error( int level, const char *error, ... );
00920 void QDECL Com_Printf( const char *msg, ... );
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934 #define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc
00935
00936
00937 #define CVAR_USERINFO 2 // sent to server on connect or change
00938 #define CVAR_SERVERINFO 4 // sent in response to front end requests
00939 #define CVAR_SYSTEMINFO 8 // these cvars will be duplicated on all clients
00940 #define CVAR_INIT 16 // don't allow change from console at all,
00941
00942 #define CVAR_LATCH 32 // will only change when C code next does
00943
00944
00945
00946
00947 #define CVAR_ROM 64 // display only, cannot be set by user at all
00948 #define CVAR_USER_CREATED 128 // created by a set command
00949 #define CVAR_TEMP 256 // can be set even when cheats are disabled, but is not archived
00950 #define CVAR_CHEAT 512 // can not be changed if cheats are disabled
00951 #define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued
00952
00953
00954 typedef struct cvar_s {
00955 char *name;
00956 char *string;
00957 char *resetString;
00958 char *latchedString;
00959 int flags;
00960 qboolean modified;
00961 int modificationCount;
00962 float value;
00963 int integer;
00964 struct cvar_s *next;
00965 struct cvar_s *hashNext;
00966 } cvar_t;
00967
00968 #define MAX_CVAR_VALUE_STRING 256
00969
00970 typedef int cvarHandle_t;
00971
00972
00973
00974 typedef struct {
00975 cvarHandle_t handle;
00976 int modificationCount;
00977 float value;
00978 int integer;
00979 char string[MAX_CVAR_VALUE_STRING];
00980 } vmCvar_t;
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990 #include "surfaceflags.h"
00991
00992
00993
00994 #define PLANE_X 0
00995 #define PLANE_Y 1
00996 #define PLANE_Z 2
00997 #define PLANE_NON_AXIAL 3
00998
00999
01000
01001
01002
01003
01004
01005
01006 #define PlaneTypeForNormal(x) (x[0] == 1.0 ? PLANE_X : (x[1] == 1.0 ? PLANE_Y : (x[2] == 1.0 ? PLANE_Z : PLANE_NON_AXIAL) ) )
01007
01008
01009
01010 typedef struct cplane_s {
01011 vec3_t normal;
01012 float dist;
01013 byte type;
01014 byte signbits;
01015 byte pad[2];
01016 } cplane_t;
01017
01018
01019
01020 typedef struct {
01021 qboolean allsolid;
01022 qboolean startsolid;
01023 float fraction;
01024 vec3_t endpos;
01025 cplane_t plane;
01026 int surfaceFlags;
01027 int contents;
01028 int entityNum;
01029 } trace_t;
01030
01031
01032
01033
01034
01035
01036 typedef struct {
01037 int firstPoint;
01038 int numPoints;
01039 } markFragment_t;
01040
01041
01042
01043 typedef struct {
01044 vec3_t origin;
01045 vec3_t axis[3];
01046 } orientation_t;
01047
01048
01049
01050
01051
01052
01053 #define KEYCATCH_CONSOLE 0x0001
01054 #define KEYCATCH_UI 0x0002
01055 #define KEYCATCH_MESSAGE 0x0004
01056 #define KEYCATCH_CGAME 0x0008
01057
01058
01059
01060
01061
01062 typedef enum {
01063 CHAN_AUTO,
01064 CHAN_LOCAL,
01065 CHAN_WEAPON,
01066 CHAN_VOICE,
01067 CHAN_ITEM,
01068 CHAN_BODY,
01069 CHAN_LOCAL_SOUND,
01070 CHAN_ANNOUNCER
01071 } soundChannel_t;
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082 #define ANGLE2SHORT(x) ((int)((x)*65536/360) & 65535)
01083 #define SHORT2ANGLE(x) ((x)*(360.0/65536))
01084
01085 #define SNAPFLAG_RATE_DELAYED 1
01086 #define SNAPFLAG_NOT_ACTIVE 2 // snapshot used during connection and for zombies
01087 #define SNAPFLAG_SERVERCOUNT 4 // toggled every map_restart so transitions can be detected
01088
01089
01090
01091
01092 #define MAX_CLIENTS 64 // absolute limit
01093 #define MAX_LOCATIONS 64
01094
01095 #define GENTITYNUM_BITS 10 // don't need to send any more
01096 #define MAX_GENTITIES (1<<GENTITYNUM_BITS)
01097
01098
01099
01100
01101 #define ENTITYNUM_NONE (MAX_GENTITIES-1)
01102 #define ENTITYNUM_WORLD (MAX_GENTITIES-2)
01103 #define ENTITYNUM_MAX_NORMAL (MAX_GENTITIES-2)
01104
01105
01106 #define MAX_MODELS 256 // these are sent over the net as 8 bits
01107 #define MAX_SOUNDS 256 // so they cannot be blindly increased
01108
01109
01110 #define MAX_CONFIGSTRINGS 1024
01111
01112
01113
01114 #define CS_SERVERINFO 0 // an info string with all the serverinfo cvars
01115 #define CS_SYSTEMINFO 1 // an info string for server system to client system configuration (timescale, etc)
01116
01117 #define RESERVED_CONFIGSTRINGS 2 // game can't modify below this, only the system can
01118
01119 #define MAX_GAMESTATE_CHARS 16000
01120 typedef struct {
01121 int stringOffsets[MAX_CONFIGSTRINGS];
01122 char stringData[MAX_GAMESTATE_CHARS];
01123 int dataCount;
01124 } gameState_t;
01125
01126
01127
01128
01129 #define MAX_STATS 16
01130 #define MAX_PERSISTANT 16
01131 #define MAX_POWERUPS 16
01132 #define MAX_WEAPONS 16
01133
01134 #define MAX_PS_EVENTS 2
01135
01136 #define PS_PMOVEFRAMECOUNTBITS 6
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148 typedef struct playerState_s {
01149 int commandTime;
01150 int pm_type;
01151 int bobCycle;
01152 int pm_flags;
01153 int pm_time;
01154
01155 vec3_t origin;
01156 vec3_t velocity;
01157 int weaponTime;
01158 int gravity;
01159 int speed;
01160 int delta_angles[3];
01161
01162
01163 int groundEntityNum;
01164
01165 int legsTimer;
01166 int legsAnim;
01167
01168 int torsoTimer;
01169 int torsoAnim;
01170
01171 int movementDir;
01172
01173
01174
01175
01176 vec3_t grapplePoint;
01177
01178 int eFlags;
01179
01180 int eventSequence;
01181 int events[MAX_PS_EVENTS];
01182 int eventParms[MAX_PS_EVENTS];
01183
01184 int externalEvent;
01185 int externalEventParm;
01186 int externalEventTime;
01187
01188 int clientNum;
01189 int weapon;
01190 int weaponstate;
01191
01192 vec3_t viewangles;
01193 int viewheight;
01194
01195
01196 int damageEvent;
01197 int damageYaw;
01198 int damagePitch;
01199 int damageCount;
01200
01201 int stats[MAX_STATS];
01202 int persistant[MAX_PERSISTANT];
01203 int powerups[MAX_POWERUPS];
01204 int ammo[MAX_WEAPONS];
01205
01206 int generic1;
01207 int loopSound;
01208 int jumppad_ent;
01209
01210
01211 int ping;
01212 int pmove_framecount;
01213 int jumppad_frame;
01214 int entityEventSequence;
01215 } playerState_t;
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225 #define BUTTON_ATTACK 1
01226 #define BUTTON_TALK 2 // displays talk balloon and disables actions
01227 #define BUTTON_USE_HOLDABLE 4
01228 #define BUTTON_GESTURE 8
01229 #define BUTTON_WALKING 16 // walking can't just be infered from MOVE_RUN
01230
01231
01232
01233
01234 #define BUTTON_AFFIRMATIVE 32
01235 #define BUTTON_NEGATIVE 64
01236
01237 #define BUTTON_GETFLAG 128
01238 #define BUTTON_GUARDBASE 256
01239 #define BUTTON_PATROL 512
01240 #define BUTTON_FOLLOWME 1024
01241
01242 #define BUTTON_ANY 2048 // any key whatsoever
01243
01244 #define MOVE_RUN 120 // if forwardmove or rightmove are >= MOVE_RUN,
01245
01246
01247
01248 typedef struct usercmd_s {
01249 int serverTime;
01250 int angles[3];
01251 int buttons;
01252 byte weapon;
01253 signed char forwardmove, rightmove, upmove;
01254 } usercmd_t;
01255
01256
01257
01258
01259 #define SOLID_BMODEL 0xffffff
01260
01261 typedef enum {
01262 TR_STATIONARY,
01263 TR_INTERPOLATE,
01264 TR_LINEAR,
01265 TR_LINEAR_STOP,
01266 TR_SINE,
01267 TR_GRAVITY
01268 } trType_t;
01269
01270 typedef struct {
01271 trType_t trType;
01272 int trTime;
01273 int trDuration;
01274 vec3_t trBase;
01275 vec3_t trDelta;
01276 } trajectory_t;
01277
01278
01279
01280
01281
01282
01283
01284
01285 typedef struct entityState_s {
01286 int number;
01287 int eType;
01288 int eFlags;
01289
01290 trajectory_t pos;
01291 trajectory_t apos;
01292
01293 int time;
01294 int time2;
01295
01296 vec3_t origin;
01297 vec3_t origin2;
01298
01299 vec3_t angles;
01300 vec3_t angles2;
01301
01302 int otherEntityNum;
01303 int otherEntityNum2;
01304
01305 int groundEntityNum;
01306
01307 int constantLight;
01308 int loopSound;
01309
01310 int modelindex;
01311 int modelindex2;
01312 int clientNum;
01313 int frame;
01314
01315 int solid;
01316
01317 int event;
01318 int eventParm;
01319
01320
01321 int powerups;
01322 int weapon;
01323 int legsAnim;
01324 int torsoAnim;
01325
01326 int generic1;
01327 } entityState_t;
01328
01329 typedef enum {
01330 CA_UNINITIALIZED,
01331 CA_DISCONNECTED,
01332 CA_AUTHORIZING,
01333 CA_CONNECTING,
01334 CA_CHALLENGING,
01335 CA_CONNECTED,
01336 CA_LOADING,
01337 CA_PRIMED,
01338 CA_ACTIVE,
01339 CA_CINEMATIC
01340 } connstate_t;
01341
01342
01343
01344 #define GLYPH_START 0
01345 #define GLYPH_END 255
01346 #define GLYPH_CHARSTART 32
01347 #define GLYPH_CHAREND 127
01348 #define GLYPHS_PER_FONT GLYPH_END - GLYPH_START + 1
01349 typedef struct {
01350 int height;
01351 int top;
01352 int bottom;
01353 int pitch;
01354 int xSkip;
01355 int imageWidth;
01356 int imageHeight;
01357 float s;
01358 float t;
01359 float s2;
01360 float t2;
01361 qhandle_t glyph;
01362 char shaderName[32];
01363 } glyphInfo_t;
01364
01365 typedef struct {
01366 glyphInfo_t glyphs [GLYPHS_PER_FONT];
01367 float glyphScale;
01368 char name[MAX_QPATH];
01369 } fontInfo_t;
01370
01371 #define Square(x) ((x)*(x))
01372
01373
01374
01375
01376
01377 typedef struct qtime_s {
01378 int tm_sec;
01379 int tm_min;
01380 int tm_hour;
01381 int tm_mday;
01382 int tm_mon;
01383 int tm_year;
01384 int tm_wday;
01385 int tm_yday;
01386 int tm_isdst;
01387 } qtime_t;
01388
01389
01390
01391
01392 #define AS_LOCAL 0
01393 #define AS_MPLAYER 1
01394 #define AS_GLOBAL 2
01395 #define AS_FAVORITES 3
01396
01397
01398
01399 typedef enum {
01400 FMV_IDLE,
01401 FMV_PLAY,
01402 FMV_EOF,
01403 FMV_ID_BLT,
01404 FMV_ID_IDLE,
01405 FMV_LOOPED,
01406 FMV_ID_WAIT
01407 } e_status;
01408
01409 typedef enum _flag_status {
01410 FLAG_ATBASE = 0,
01411 FLAG_TAKEN,
01412 FLAG_TAKEN_RED,
01413 FLAG_TAKEN_BLUE,
01414 FLAG_DROPPED
01415 } flagStatus_t;
01416
01417
01418
01419 #define MAX_GLOBAL_SERVERS 4096
01420 #define MAX_OTHER_SERVERS 128
01421 #define MAX_PINGREQUESTS 32
01422 #define MAX_SERVERSTATUSREQUESTS 16
01423
01424 #define SAY_ALL 0
01425 #define SAY_TEAM 1
01426 #define SAY_TELL 2
01427
01428 #define CDKEY_LEN 16
01429 #define CDCHKSUM_LEN 2
01430
01431
01432 #endif // __Q_SHARED_H