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