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