Debian Codegraph @

code/qcommon/q_shared.h

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