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