q_shared.hpp (22729B)
1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III Arena source code is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the License, 10 or (at your option) any later version. 11 12 Quake III Arena source code is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Foobar; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 #ifndef __Q_SHARED_H 23 #define __Q_SHARED_H 24 25 // q_shared.h -- included first by ALL program modules. 26 // these are the definitions that have no dependance on 27 // central system services, and can be used by any part 28 // of the program without any state issues. 29 30 // A user mod should never modify this file 31 32 // incursion of DOOM code into the Q3A codebase 33 //#define Q3_VERSION "DOOM 0.01" 34 35 // alignment macros for SIMD 36 #define ALIGN_ON 37 #define ALIGN_OFF 38 39 #ifdef _WIN32 40 41 #pragma warning(disable : 4018) // signed/unsigned mismatch 42 #pragma warning(disable : 4032) 43 #pragma warning(disable : 4051) 44 #pragma warning(disable : 4057) // slightly different base types 45 #pragma warning(disable : 4100) // unreferenced formal parameter 46 #pragma warning(disable : 4115) 47 #pragma warning(disable : 4125) // decimal digit terminates octal escape sequence 48 #pragma warning(disable : 4127) // conditional expression is constant 49 #pragma warning(disable : 4136) 50 #pragma warning(disable : 4201) 51 #pragma warning(disable : 4214) 52 #pragma warning(disable : 4244) 53 #pragma warning(disable : 4305) // truncation from const double to float 54 #pragma warning(disable : 4310) // cast truncates constant value 55 #pragma warning(disable : 4514) 56 #pragma warning(disable : 4711) // selected for automatic inline expansion 57 #pragma warning(disable : 4220) // varargs matches remaining parameters 58 59 #endif 60 61 #include <assert.h> 62 #include <math.h> 63 #include <stdio.h> 64 #include <stdarg.h> 65 #include <string.h> 66 #include <stdlib.h> 67 #include <time.h> 68 #include <ctype.h> 69 #ifdef WIN32 // mac doesn't have malloc.h 70 #include <malloc.h> // for _alloca() 71 #endif 72 #ifdef _WIN32 73 74 //#pragma intrinsic( memset, memcpy ) 75 76 #endif 77 78 79 // this is the define for determining if we have an asm version of a C function 80 #if (defined _M_IX86 || defined __i386__) && !defined __sun__ && !defined __LCC__ 81 #define id386 1 82 #else 83 #define id386 0 84 #endif 85 86 // for windows fastcall option 87 88 #define QDECL 89 90 //======================= WIN32 DEFINES ================================= 91 92 #ifdef WIN32 93 94 #define MAC_STATIC 95 96 #undef QDECL 97 #define QDECL __cdecl 98 99 // buildstring will be incorporated into the version string 100 #ifdef NDEBUG 101 #ifdef _M_IX86 102 #define CPUSTRING "win-x86" 103 #elif defined _M_ALPHA 104 #define CPUSTRING "win-AXP" 105 #endif 106 #else 107 #ifdef _M_IX86 108 #define CPUSTRING "win-x86-debug" 109 #elif defined _M_ALPHA 110 #define CPUSTRING "win-AXP-debug" 111 #endif 112 #endif 113 114 115 #define PATH_SEP '\\' 116 117 #endif 118 119 //======================= MAC OS X SERVER DEFINES ===================== 120 121 #if defined(__MACH__) && defined(__APPLE__) 122 123 #define MAC_STATIC 124 125 #ifdef __ppc__ 126 #define CPUSTRING "MacOSXS-ppc" 127 #elif defined __i386__ 128 #define CPUSTRING "MacOSXS-i386" 129 #else 130 #define CPUSTRING "MacOSXS-other" 131 #endif 132 133 #define PATH_SEP '/' 134 135 #define GAME_HARD_LINKED 136 #define CGAME_HARD_LINKED 137 #define UI_HARD_LINKED 138 #define _alloca alloca 139 140 #undef ALIGN_ON 141 #undef ALIGN_OFF 142 #define ALIGN_ON #pragma align(16) 143 #define ALIGN_OFF #pragma align() 144 145 #ifdef __cplusplus 146 extern "C" { 147 #endif 148 149 void *osxAllocateMemory(long size); 150 void osxFreeMemory(void *pointer); 151 152 #ifdef __cplusplus 153 } 154 #endif 155 156 #endif 157 158 //======================= MAC DEFINES ================================= 159 160 #ifdef __MACOS__ 161 162 #define MAC_STATIC static 163 164 #define CPUSTRING "MacOS-PPC" 165 166 #define PATH_SEP ':' 167 168 void Sys_PumpEvents( void ); 169 170 #endif 171 172 #ifdef __MRC__ 173 174 #define MAC_STATIC 175 176 #define CPUSTRING "MacOS-PPC" 177 178 #define PATH_SEP ':' 179 180 void Sys_PumpEvents( void ); 181 182 #undef QDECL 183 #define QDECL __cdecl 184 185 #define _alloca alloca 186 #endif 187 188 //======================= LINUX DEFINES ================================= 189 190 // the mac compiler can't handle >32k of locals, so we 191 // just waste space and make big arrays static... 192 #ifdef __linux__ 193 194 // bk001205 - from Makefile 195 #define stricmp strcasecmp 196 197 #define MAC_STATIC // bk: FIXME 198 199 #ifdef __i386__ 200 #define CPUSTRING "linux-i386" 201 #elif defined __axp__ 202 #define CPUSTRING "linux-alpha" 203 #else 204 #define CPUSTRING "linux-other" 205 #endif 206 207 #define PATH_SEP '/' 208 209 // bk001205 - try 210 #ifdef Q3_STATIC 211 #define GAME_HARD_LINKED 212 #define CGAME_HARD_LINKED 213 #define UI_HARD_LINKED 214 #define BOTLIB_HARD_LINKED 215 #endif 216 217 #endif 218 219 //============================================================= 220 221 222 223 typedef enum {qfalse, qtrue} qboolean; 224 225 typedef unsigned char byte; 226 227 #define EQUAL_EPSILON 0.001 228 229 typedef int qhandle_t; 230 typedef int sfxHandle_t; 231 typedef int fileHandle_t; 232 typedef int clipHandle_t; 233 234 typedef enum { 235 INVALID_JOINT = -1 236 } jointHandle_t; 237 238 #ifndef NULL 239 #define NULL ((void *)0) 240 #endif 241 242 #define MAX_QINT 0x7fffffff 243 #define MIN_QINT (-MAX_QINT-1) 244 245 #ifndef max 246 #define max( x, y ) ( ( ( x ) > ( y ) ) ? ( x ) : ( y ) ) 247 #define min( x, y ) ( ( ( x ) < ( y ) ) ? ( x ) : ( y ) ) 248 #endif 249 250 #ifndef sign 251 #define sign( f ) ( ( f > 0 ) ? 1 : ( ( f < 0 ) ? -1 : 0 ) ) 252 #endif 253 254 // angle indexes 255 #define PITCH 0 // up / down 256 #define YAW 1 // left / right 257 #define ROLL 2 // fall over 258 259 // the game guarantees that no string from the network will ever 260 // exceed MAX_STRING_CHARS 261 #define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString 262 #define MAX_STRING_TOKENS 256 // max tokens resulting from Cmd_TokenizeString 263 #define MAX_TOKEN_CHARS 1024 // max length of an individual token 264 265 #define MAX_INFO_STRING 1024 266 #define MAX_INFO_KEY 1024 267 #define MAX_INFO_VALUE 1024 268 269 270 #define MAX_QPATH 64 // max length of a quake game pathname 271 #define MAX_OSPATH 128 // max length of a filesystem pathname 272 273 #define MAX_NAME_LENGTH 32 // max length of a client name 274 275 // paramters for command buffer stuffing 276 typedef enum { 277 EXEC_NOW, // don't return until completed, a VM should NEVER use this, 278 // because some commands might cause the VM to be unloaded... 279 EXEC_INSERT, // insert at current position, but don't run yet 280 EXEC_APPEND // add to end of the command buffer (normal case) 281 } cbufExec_t; 282 283 284 // 285 // these aren't needed by any of the VMs. put in another header? 286 // 287 #define MAX_MAP_AREA_BYTES 32 // bit vector of area visibility 288 289 #undef ERR_FATAL // malloc.h on unix 290 291 // parameters to the main Error routine 292 typedef enum { 293 ERR_NONE, 294 ERR_FATAL, // exit the entire game with a popup window 295 ERR_DROP, // print to console and disconnect from game 296 ERR_DISCONNECT, // don't kill server 297 ERR_NEED_CD // pop up the need-cd dialog 298 } errorParm_t; 299 300 301 // font rendering values used by ui and cgame 302 303 #define PROP_GAP_WIDTH 3 304 #define PROP_SPACE_WIDTH 8 305 #define PROP_HEIGHT 27 306 #define PROP_SMALL_SIZE_SCALE 0.75 307 308 #define BLINK_DIVISOR 200 309 #define PULSE_DIVISOR 75 310 311 #define UI_LEFT 0x00000000 // default 312 #define UI_CENTER 0x00000001 313 #define UI_RIGHT 0x00000002 314 #define UI_FORMATMASK 0x00000007 315 #define UI_SMALLFONT 0x00000010 316 #define UI_BIGFONT 0x00000020 // default 317 #define UI_GIANTFONT 0x00000040 318 #define UI_DROPSHADOW 0x00000800 319 #define UI_BLINK 0x00001000 320 #define UI_INVERSE 0x00002000 321 #define UI_PULSE 0x00004000 322 323 324 /* 325 ============================================================== 326 327 MATHLIB 328 329 ============================================================== 330 */ 331 #ifdef __cplusplus // so we can include this in C code 332 #define SIDE_FRONT 0 333 #define SIDE_BACK 1 334 #define SIDE_ON 2 335 #define SIDE_CROSS 3 336 337 #define Q_PI 3.14159265358979323846 338 #ifndef M_PI 339 #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h 340 #endif 341 342 #include "math_vector.h" 343 #include "math_angles.h" 344 #include "math_matrix.h" 345 #include "math_quaternion.h" 346 347 class idVec3_t; // for defining vectors 348 typedef idVec3_t &vec3_p; // for passing vectors as function arguments 349 typedef const idVec3_t &vec3_c; // for passing vectors as const function arguments 350 351 class angles_t; // for defining angle vectors 352 typedef angles_t &angles_p; // for passing angles as function arguments 353 typedef const angles_t &angles_c; // for passing angles as const function arguments 354 355 class mat3_t; // for defining matrices 356 typedef mat3_t &mat3_p; // for passing matrices as function arguments 357 typedef const mat3_t &mat3_c; // for passing matrices as const function arguments 358 359 360 361 #define NUMVERTEXNORMALS 162 362 extern idVec3_t bytedirs[NUMVERTEXNORMALS]; 363 364 // all drawing is done to a 640*480 virtual screen size 365 // and will be automatically scaled to the real resolution 366 #define SCREEN_WIDTH 640 367 #define SCREEN_HEIGHT 480 368 369 #define TINYCHAR_WIDTH (SMALLCHAR_WIDTH) 370 #define TINYCHAR_HEIGHT (SMALLCHAR_HEIGHT/2) 371 372 #define SMALLCHAR_WIDTH 8 373 #define SMALLCHAR_HEIGHT 16 374 375 #define BIGCHAR_WIDTH 16 376 #define BIGCHAR_HEIGHT 16 377 378 #define GIANTCHAR_WIDTH 32 379 #define GIANTCHAR_HEIGHT 48 380 381 extern vec4_t colorBlack; 382 extern vec4_t colorRed; 383 extern vec4_t colorGreen; 384 extern vec4_t colorBlue; 385 extern vec4_t colorYellow; 386 extern vec4_t colorMagenta; 387 extern vec4_t colorCyan; 388 extern vec4_t colorWhite; 389 extern vec4_t colorLtGrey; 390 extern vec4_t colorMdGrey; 391 extern vec4_t colorDkGrey; 392 393 #define Q_COLOR_ESCAPE '^' 394 #define Q_IsColorString(p) ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE ) 395 396 #define COLOR_BLACK '0' 397 #define COLOR_RED '1' 398 #define COLOR_GREEN '2' 399 #define COLOR_YELLOW '3' 400 #define COLOR_BLUE '4' 401 #define COLOR_CYAN '5' 402 #define COLOR_MAGENTA '6' 403 #define COLOR_WHITE '7' 404 #define ColorIndex(c) ( ( (c) - '0' ) & 7 ) 405 406 #define S_COLOR_BLACK "^0" 407 #define S_COLOR_RED "^1" 408 #define S_COLOR_GREEN "^2" 409 #define S_COLOR_YELLOW "^3" 410 #define S_COLOR_BLUE "^4" 411 #define S_COLOR_CYAN "^5" 412 #define S_COLOR_MAGENTA "^6" 413 #define S_COLOR_WHITE "^7" 414 415 extern vec4_t g_color_table[8]; 416 417 #define MAKERGB( v, r, g, b ) v[0]=r;v[1]=g;v[2]=b 418 #define MAKERGBA( v, r, g, b, a ) v[0]=r;v[1]=g;v[2]=b;v[3]=a 419 420 #define DEG2RAD( a ) ( ( (a) * M_PI ) / 180.0F ) 421 #define RAD2DEG( a ) ( ( (a) * 180.0f ) / M_PI ) 422 423 struct cplane_s; 424 425 extern idVec3_t vec3_origin; 426 extern vec4_t vec4_origin; 427 extern mat3_t axisDefault; 428 429 #define nanmask (255<<23) 430 431 #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) 432 433 float Q_fabs( float f ); 434 float Q_rsqrt( float f ); // reciprocal square root 435 436 #define SQRTFAST( x ) ( 1.0f / Q_rsqrt( x ) ) 437 438 signed char ClampChar( int i ); 439 signed short ClampShort( int i ); 440 441 // this isn't a real cheap function to call! 442 int DirToByte( const idVec3_t &dir ); 443 void ByteToDir( int b, vec3_p dir ); 444 445 #define DotProduct(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2]) 446 #define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2]) 447 #define VectorAdd(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2]) 448 #define VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2]) 449 //#define VectorCopy(a,b) ((b).x=(a).x,(b).y=(a).y,(b).z=(a).z]) 450 451 #define VectorScale(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s)) 452 #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)) 453 #define CrossProduct(a,b,c) ((c)[0]=(a)[1]*(b)[2]-(a)[2]*(b)[1],(c)[1]=(a)[2]*(b)[0]-(a)[0]*(b)[2],(c)[2]=(a)[0]*(b)[1]-(a)[1]*(b)[0]) 454 455 #define DotProduct4(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]+(x)[3]*(y)[3]) 456 #define VectorSubtract4(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2],(c)[3]=(a)[3]-(b)[3]) 457 #define VectorAdd4(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2],(c)[3]=(a)[3]+(b)[3]) 458 #define VectorCopy4(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3]) 459 #define VectorScale4(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s),(o)[3]=(v)[3]*(s)) 460 #define VectorMA4(v, s, b, o) ((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s),(o)[3]=(v)[3]+(b)[3]*(s)) 461 462 463 #define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0) 464 #define VectorNegate(a,b) ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2]) 465 #define VectorSet(v, x, y, z) ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z)) 466 #define Vector4Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3]) 467 468 #define SnapVector(v) {v[0]=(int)v[0];v[1]=(int)v[1];v[2]=(int)v[2];} 469 470 float NormalizeColor( vec3_c in, vec3_p out ); 471 472 int VectorCompare( vec3_c v1, vec3_c v2 ); 473 float VectorLength( vec3_c v ); 474 float Distance( vec3_c p1, vec3_c p2 ); 475 float DistanceSquared( vec3_c p1, vec3_c p2 ); 476 float VectorNormalize (vec3_p v); // returns vector length 477 void VectorNormalizeFast(vec3_p v); // does NOT return vector length, uses rsqrt approximation 478 float VectorNormalize2( vec3_c v, vec3_p out ); 479 void VectorInverse (vec3_p v); 480 void VectorRotate( vec3_c in, mat3_c matrix, vec3_p out ); 481 void VectorPolar(vec3_p v, float radius, float theta, float phi); 482 void VectorSnap(vec3_p v); 483 void Vector53Copy( const idVec5_t &in, vec3_p out); 484 void Vector5Scale( const idVec5_t &v, float scale, idVec5_t &out); 485 void Vector5Add( const idVec5_t &va, const idVec5_t &vb, idVec5_t &out); 486 void VectorRotate3( vec3_c vIn, vec3_c vRotation, vec3_p out); 487 void VectorRotate3Origin(vec3_c vIn, vec3_c vRotation, vec3_c vOrigin, vec3_p out); 488 489 490 int Q_log2(int val); 491 492 int Q_rand( int *seed ); 493 float Q_random( int *seed ); 494 float Q_crandom( int *seed ); 495 496 #define random() ((rand () & 0x7fff) / ((float)0x7fff)) 497 #define crandom() (2.0 * (random() - 0.5)) 498 499 float Q_rint( float in ); 500 501 void vectoangles( vec3_c value1, angles_p angles); 502 void AnglesToAxis( angles_c angles, mat3_p axis ); 503 504 void AxisCopy( mat3_c in, mat3_p out ); 505 qboolean AxisRotated( mat3_c in ); // assumes a non-degenerate axis 506 507 int SignbitsForNormal( vec3_c normal ); 508 int BoxOnPlaneSide( const Bounds &b, struct cplane_s *p ); 509 510 float AngleMod(float a); 511 float LerpAngle (float from, float to, float frac); 512 float AngleSubtract( float a1, float a2 ); 513 void AnglesSubtract( angles_c v1, angles_c v2, angles_p v3 ); 514 515 float AngleNormalize360 ( float angle ); 516 float AngleNormalize180 ( float angle ); 517 float AngleDelta ( float angle1, float angle2 ); 518 519 qboolean PlaneFromPoints( vec4_t &plane, vec3_c a, vec3_c b, vec3_c c ); 520 void ProjectPointOnPlane( vec3_p dst, vec3_c p, vec3_c normal ); 521 void RotatePointAroundVector( vec3_p dst, vec3_c dir, vec3_c point, float degrees ); 522 void RotateAroundDirection( mat3_p axis, float yaw ); 523 void MakeNormalVectors( vec3_c forward, vec3_p right, vec3_p up ); 524 // perpendicular vector could be replaced by this 525 526 int PlaneTypeForNormal( vec3_c normal ); 527 528 void MatrixMultiply( mat3_c in1, mat3_c in2, mat3_p out ); 529 void MatrixInverseMultiply( mat3_c in1, mat3_c in2, mat3_p out ); // in2 is transposed during multiply 530 void MatrixTransformVector( vec3_c in, mat3_c matrix, vec3_p out ); 531 void MatrixProjectVector( vec3_c in, mat3_c matrix, vec3_p out ); // Places the vector into a new coordinate system. 532 void AngleVectors( angles_c angles, vec3_p forward, vec3_p right, vec3_p up); 533 void PerpendicularVector( vec3_p dst, vec3_c src ); 534 535 float TriangleArea( vec3_c a, vec3_c b, vec3_c c ); 536 #endif // __cplusplus 537 538 //============================================= 539 540 float Com_Clamp( float min, float max, float value ); 541 542 #define FILE_HASH_SIZE 1024 543 int Com_HashString( const char *fname ); 544 545 char *Com_SkipPath( char *pathname ); 546 547 // it is ok for out == in 548 void Com_StripExtension( const char *in, char *out ); 549 550 // "extension" should include the dot: ".map" 551 void Com_DefaultExtension( char *path, int maxSize, const char *extension ); 552 553 int Com_ParseInfos( const char *buf, int max, char infos[][MAX_INFO_STRING] ); 554 555 /* 556 ===================================================================================== 557 558 SCRIPT PARSING 559 560 ===================================================================================== 561 */ 562 563 // this just controls the comment printing, it doesn't actually load a file 564 void Com_BeginParseSession( const char *filename ); 565 void Com_EndParseSession( void ); 566 567 int Com_GetCurrentParseLine( void ); 568 569 // Will never return NULL, just empty strings. 570 // An empty string will only be returned at end of file. 571 // ParseOnLine will return empty if there isn't another token on this line 572 573 // this funny typedef just means a moving pointer into a const char * buffer 574 const char *Com_Parse( const char *(*data_p) ); 575 const char *Com_ParseOnLine( const char *(*data_p) ); 576 const char *Com_ParseRestOfLine( const char *(*data_p) ); 577 578 void Com_UngetToken( void ); 579 580 #ifdef __cplusplus 581 void Com_MatchToken( const char *(*buf_p), const char *match, qboolean warning = qfalse ); 582 #else 583 void Com_MatchToken( const char *(*buf_p), const char *match, qboolean warning ); 584 #endif 585 586 void Com_ScriptError( const char *msg, ... ); 587 void Com_ScriptWarning( const char *msg, ... ); 588 589 void Com_SkipBracedSection( const char *(*program) ); 590 void Com_SkipRestOfLine( const char *(*data) ); 591 592 float Com_ParseFloat( const char *(*buf_p) ); 593 int Com_ParseInt( const char *(*buf_p) ); 594 595 void Com_Parse1DMatrix( const char *(*buf_p), int x, float *m ); 596 void Com_Parse2DMatrix( const char *(*buf_p), int y, int x, float *m ); 597 void Com_Parse3DMatrix( const char *(*buf_p), int z, int y, int x, float *m ); 598 599 //===================================================================================== 600 #ifdef __cplusplus 601 extern "C" { 602 #endif 603 604 void QDECL Com_sprintf (char *dest, int size, const char *fmt, ...); 605 606 607 // mode parm for FS_FOpenFile 608 typedef enum { 609 FS_READ, 610 FS_WRITE, 611 FS_APPEND, 612 FS_APPEND_SYNC 613 } fsMode_t; 614 615 typedef enum { 616 FS_SEEK_CUR, 617 FS_SEEK_END, 618 FS_SEEK_SET 619 } fsOrigin_t; 620 621 //============================================= 622 623 int Q_isprint( int c ); 624 int Q_islower( int c ); 625 int Q_isupper( int c ); 626 int Q_isalpha( int c ); 627 628 // portable case insensitive compare 629 int Q_stricmp (const char *s1, const char *s2); 630 int Q_strncmp (const char *s1, const char *s2, int n); 631 int Q_stricmpn (const char *s1, const char *s2, int n); 632 char *Q_strlwr( char *s1 ); 633 char *Q_strupr( char *s1 ); 634 char *Q_strrchr( const char* string, int c ); 635 636 // buffer size safe library replacements 637 void Q_strncpyz( char *dest, const char *src, int destsize ); 638 void Q_strcat( char *dest, int size, const char *src ); 639 640 // strlen that discounts Quake color sequences 641 int Q_PrintStrlen( const char *string ); 642 // removes color sequences from string 643 char *Q_CleanStr( char *string ); 644 645 int Com_Filter( const char *filter, const char *name, int casesensitive ); 646 const char *Com_StringContains( const char *str1, const char *str2, int casesensitive ); 647 648 649 //============================================= 650 651 short BigShort(short l); 652 short LittleShort(short l); 653 int BigLong (int l); 654 int LittleLong (int l); 655 float BigFloat (float l); 656 float LittleFloat (float l); 657 658 void Swap_Init (void); 659 char * QDECL va(char *format, ...); 660 661 #ifdef __cplusplus 662 } 663 #endif 664 665 666 //============================================= 667 #ifdef __cplusplus 668 // 669 // mapfile parsing 670 // 671 typedef struct ePair_s { 672 char *key; 673 char *value; 674 } ePair_t; 675 676 typedef struct mapSide_s { 677 char material[MAX_QPATH]; 678 vec4_t plane; 679 vec4_t textureVectors[2]; 680 } mapSide_t; 681 682 typedef struct { 683 int numSides; 684 mapSide_t **sides; 685 } mapBrush_t; 686 687 typedef struct { 688 idVec3_t xyz; 689 float st[2]; 690 } patchVertex_t; 691 692 typedef struct { 693 char material[MAX_QPATH]; 694 int width, height; 695 patchVertex_t *patchVerts; 696 } mapPatch_t; 697 698 typedef struct { 699 char modelName[MAX_QPATH]; 700 float matrix[16]; 701 } mapModel_t; 702 703 typedef struct mapPrimitive_s { 704 int numEpairs; 705 ePair_t **ePairs; 706 707 // only one of these will be non-NULL 708 mapBrush_t *brush; 709 mapPatch_t *patch; 710 mapModel_t *model; 711 } mapPrimitive_t; 712 713 typedef struct mapEntity_s { 714 int numPrimitives; 715 mapPrimitive_t **primitives; 716 717 int numEpairs; 718 ePair_t **ePairs; 719 } mapEntity_t; 720 721 typedef struct { 722 int numEntities; 723 mapEntity_t **entities; 724 } mapFile_t; 725 726 727 // the order of entities, brushes, and sides will be maintained, the 728 // lists won't be swapped on each load or save 729 mapFile_t *ParseMapFile( const char *text ); 730 void FreeMapFile( mapFile_t *mapFile ); 731 void WriteMapFile( const mapFile_t *mapFile, FILE *f ); 732 733 // key names are case-insensitive 734 const char *ValueForMapEntityKey( const mapEntity_t *ent, const char *key ); 735 float FloatForMapEntityKey( const mapEntity_t *ent, const char *key ); 736 qboolean GetVectorForMapEntityKey( const mapEntity_t *ent, const char *key, idVec3_t &vec ); 737 738 typedef struct { 739 idVec3_t xyz; 740 idVec2_t st; 741 idVec3_t normal; 742 idVec3_t tangents[2]; 743 byte smoothing[4]; // colors for silhouette smoothing 744 } drawVert_t; 745 746 typedef struct { 747 int width, height; 748 drawVert_t *verts; 749 } drawVertMesh_t; 750 751 // Tesselate a map patch into smoothed, drawable vertexes 752 // MaxError of around 4 is reasonable 753 drawVertMesh_t *SubdivideMapPatch( const mapPatch_t *patch, float maxError ); 754 #endif // __cplusplus 755 756 //========================================= 757 758 #ifdef __cplusplus 759 extern "C" { 760 #endif 761 762 void QDECL Com_Error( int level, const char *error, ... ); 763 void QDECL Com_Printf( const char *msg, ... ); 764 void QDECL Com_DPrintf( const char *msg, ... ); 765 766 #ifdef __cplusplus 767 } 768 #endif 769 770 771 typedef struct { 772 qboolean frameMemory; 773 int currentElements; 774 int maxElements; // will reallocate and move when exceeded 775 void **elements; 776 } growList_t; 777 778 // you don't need to init the growlist if you don't mind it growing and moving 779 // the list as it expands 780 void Com_InitGrowList( growList_t *list, int maxElements ); 781 int Com_AddToGrowList( growList_t *list, void *data ); 782 void *Com_GrowListElement( const growList_t *list, int index ); 783 int Com_IndexForGrowListElement( const growList_t *list, const void *element ); 784 785 786 // 787 // key / value info strings 788 // 789 char *Info_ValueForKey( const char *s, const char *key ); 790 void Info_RemoveKey( char *s, const char *key ); 791 void Info_SetValueForKey( char *s, const char *key, const char *value ); 792 qboolean Info_Validate( const char *s ); 793 void Info_NextPair( const char *(*s), char key[MAX_INFO_KEY], char value[MAX_INFO_VALUE] ); 794 795 // get cvar defs, collision defs, etc 796 //#include "../shared/interface.h" 797 798 // get key code numbers for events 799 //#include "../shared/keycodes.h" 800 801 #ifdef __cplusplus 802 // get the polygon winding functions 803 //#include "../shared/windings.h" 804 805 // get the flags class 806 //#include "../shared/idflags.h" 807 #endif // __cplusplus 808 809 #endif // __Q_SHARED_H 810