Debian Codegraph @

code/qcommon/q_shared.h

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