]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/splines/q_shared.h
more path lengths
[xonotic/netradiant.git] / libs / splines / q_shared.h
1 /*
2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 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 GtkRadiant; 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 typedef enum {qfalse, qtrue}    qboolean;
210
211 typedef unsigned char           byte;
212
213 #define EQUAL_EPSILON   0.001
214
215 typedef int             qhandle_t;
216 typedef int             sfxHandle_t;
217 typedef int             fileHandle_t;
218 typedef int             clipHandle_t;
219
220 typedef enum {
221         INVALID_JOINT = -1
222 } jointHandle_t;
223
224 #ifndef NULL
225 #define NULL ((void *)0)
226 #endif
227
228 #define MAX_QINT                        0x7fffffff
229 #define MIN_QINT                        (-MAX_QINT-1)
230
231 #ifndef max
232 #define max( x, y ) ( ( ( x ) > ( y ) ) ? ( x ) : ( y ) )
233 #define min( x, y ) ( ( ( x ) < ( y ) ) ? ( x ) : ( y ) )
234 #endif
235
236 #ifndef sign
237 #define sign( f )       ( ( f > 0 ) ? 1 : ( ( f < 0 ) ? -1 : 0 ) )
238 #endif
239
240 // angle indexes
241 #define PITCH                           0               // up / down
242 #define YAW                                     1               // left / right
243 #define ROLL                            2               // fall over
244
245 // the game guarantees that no string from the network will ever
246 // exceed MAX_STRING_CHARS
247 #define MAX_STRING_CHARS        1024    // max length of a string passed to Cmd_TokenizeString
248 #define MAX_STRING_TOKENS       256             // max tokens resulting from Cmd_TokenizeString
249 #define MAX_TOKEN_CHARS         1024    // max length of an individual token
250
251 #define MAX_INFO_STRING         1024
252 #define MAX_INFO_KEY            1024
253 #define MAX_INFO_VALUE          1024
254
255
256 #define MAX_QPATH                       64              // max length of a quake game pathname
257 #ifdef PATH_MAX
258 #define MAX_OSPATH                      PATH_MAX                // max length of a filesystem pathname
259 #else
260 #define MAX_OSPATH                      128             // max length of a filesystem pathname
261 #endif
262
263 #define MAX_NAME_LENGTH         32              // max length of a client name
264
265 // paramters for command buffer stuffing
266 typedef enum {
267         EXEC_NOW,                       // don't return until completed, a VM should NEVER use this,
268                                                 // because some commands might cause the VM to be unloaded...
269         EXEC_INSERT,            // insert at current position, but don't run yet
270         EXEC_APPEND                     // add to end of the command buffer (normal case)
271 } cbufExec_t;
272
273
274 //
275 // these aren't needed by any of the VMs.  put in another header?
276 //
277 #define MAX_MAP_AREA_BYTES              32              // bit vector of area visibility
278
279 #undef ERR_FATAL                                                // malloc.h on unix
280
281 // parameters to the main Error routine
282 typedef enum {
283         ERR_NONE,
284         ERR_FATAL,                                      // exit the entire game with a popup window
285         ERR_DROP,                                       // print to console and disconnect from game
286         ERR_DISCONNECT,                         // don't kill server
287         ERR_NEED_CD                                     // pop up the need-cd dialog
288 } errorParm_t;
289
290
291 // font rendering values used by ui and cgame
292
293 #define PROP_GAP_WIDTH                  3
294 #define PROP_SPACE_WIDTH                8
295 #define PROP_HEIGHT                             27
296 #define PROP_SMALL_SIZE_SCALE   0.75
297
298 #define BLINK_DIVISOR                   200
299 #define PULSE_DIVISOR                   75
300
301 #define UI_LEFT                 0x00000000      // default
302 #define UI_CENTER               0x00000001
303 #define UI_RIGHT                0x00000002
304 #define UI_FORMATMASK   0x00000007
305 #define UI_SMALLFONT    0x00000010
306 #define UI_BIGFONT              0x00000020      // default
307 #define UI_GIANTFONT    0x00000040
308 #define UI_DROPSHADOW   0x00000800
309 #define UI_BLINK                0x00001000
310 #define UI_INVERSE              0x00002000
311 #define UI_PULSE                0x00004000
312
313
314 /*
315 ==============================================================
316
317 MATHLIB
318
319 ==============================================================
320 */
321 #ifdef __cplusplus                      // so we can include this in C code
322 #define SIDE_FRONT              0
323 #define SIDE_BACK               1
324 #define SIDE_ON                 2
325 #define SIDE_CROSS              3
326
327 #define Q_PI    3.14159265358979323846
328 #ifndef M_PI
329 #define M_PI            3.14159265358979323846  // matches value in gcc v2 math.h
330 #endif
331
332 #include "math_vector.h"
333 #include "math_angles.h"
334 #include "math_matrix.h"
335 #include "math_quaternion.h"
336
337 class idVec3;                                           // for defining vectors
338 typedef idVec3 &vec3_p;                         // for passing vectors as function arguments
339 typedef const idVec3 &vec3_c;           // for passing vectors as const function arguments
340                                                                         
341 class angles_t;                                         // for defining angle vectors
342 typedef angles_t &angles_p;                     // for passing angles as function arguments
343 typedef const angles_t &angles_c;       // for passing angles as const function arguments
344
345 class mat3_t;                                           // for defining matrices
346 typedef mat3_t &mat3_p;                         // for passing matrices as function arguments
347 typedef const mat3_t &mat3_c;           // for passing matrices as const function arguments
348
349
350
351 #define NUMVERTEXNORMALS        162
352 extern  idVec3  bytedirs[NUMVERTEXNORMALS];
353
354 // all drawing is done to a 640*480 virtual screen size
355 // and will be automatically scaled to the real resolution
356 #define SCREEN_WIDTH            640
357 #define SCREEN_HEIGHT           480
358
359 #define TINYCHAR_WIDTH          (SMALLCHAR_WIDTH)
360 #define TINYCHAR_HEIGHT         (SMALLCHAR_HEIGHT/2)
361
362 #define SMALLCHAR_WIDTH         8
363 #define SMALLCHAR_HEIGHT        16
364
365 #define BIGCHAR_WIDTH           16
366 #define BIGCHAR_HEIGHT          16
367
368 #define GIANTCHAR_WIDTH         32
369 #define GIANTCHAR_HEIGHT        48
370
371 extern  idVec4          colorBlack;
372 extern  idVec4          colorRed;
373 extern  idVec4          colorGreen;
374 extern  idVec4          colorBlue;
375 extern  idVec4          colorYellow;
376 extern  idVec4          colorMagenta;
377 extern  idVec4          colorCyan;
378 extern  idVec4          colorWhite;
379 extern  idVec4          colorLtGrey;
380 extern  idVec4          colorMdGrey;
381 extern  idVec4          colorDkGrey;
382
383 #define Q_COLOR_ESCAPE  '^'
384 #define Q_IsColorString(p)      ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE )
385
386 #define COLOR_BLACK             '0'
387 #define COLOR_RED               '1'
388 #define COLOR_GREEN             '2'
389 #define COLOR_YELLOW    '3'
390 #define COLOR_BLUE              '4'
391 #define COLOR_CYAN              '5'
392 #define COLOR_MAGENTA   '6'
393 #define COLOR_WHITE             '7'
394 #define ColorIndex(c)   ( ( (c) - '0' ) & 7 )
395
396 #define S_COLOR_BLACK   "^0"
397 #define S_COLOR_RED             "^1"
398 #define S_COLOR_GREEN   "^2"
399 #define S_COLOR_YELLOW  "^3"
400 #define S_COLOR_BLUE    "^4"
401 #define S_COLOR_CYAN    "^5"
402 #define S_COLOR_MAGENTA "^6"
403 #define S_COLOR_WHITE   "^7"
404
405 extern idVec4   g_color_table[8];
406
407 #define MAKERGB( v, r, g, b ) v[0]=r;v[1]=g;v[2]=b
408 #define MAKERGBA( v, r, g, b, a ) v[0]=r;v[1]=g;v[2]=b;v[3]=a
409
410 #define DEG2RAD( a ) ( ( (a) * M_PI ) / 180.0F )
411 #define RAD2DEG( a ) ( ( (a) * 180.0f ) / M_PI )
412
413 struct cplane_s;
414
415 extern  idVec3  vec3_origin;
416 extern  idVec4  vec4_origin;
417 extern  mat3_t  axisDefault;
418
419 #define nanmask (255<<23)
420
421 #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
422
423 float Q_fabs( float f );
424 float Q_rsqrt( float f );               // reciprocal square root
425
426 #define SQRTFAST( x ) ( 1.0f / Q_rsqrt( x ) )
427
428 signed char ClampChar( int i );
429 signed short ClampShort( int i );
430
431 // this isn't a real cheap function to call!
432 int DirToByte( const idVec3 &dir );
433 void ByteToDir( int b, vec3_p dir );
434
435 #define DotProduct(a,b)                 ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
436 #define VectorSubtract(a,b,c)   ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
437 #define VectorAdd(a,b,c)                ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
438 #define VectorCopy(a,b)                 ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
439 //#define VectorCopy(a,b)                       ((b).x=(a).x,(b).y=(a).y,(b).z=(a).z])
440
441 #define VectorScale(v, s, o)    ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
442 #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))
443 #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])
444
445 #define DotProduct4(x,y)                ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]+(x)[3]*(y)[3])
446 #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])
447 #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])
448 #define VectorCopy4(a,b)                ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
449 #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))
450 #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))
451
452
453 #define VectorClear(a)                  ((a)[0]=(a)[1]=(a)[2]=0)
454 #define VectorNegate(a,b)               ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
455 #define VectorSet(v, x, y, z)   ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
456 #define Vector4Copy(a,b)                ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
457
458 #define SnapVector(v) {v[0]=(int)v[0];v[1]=(int)v[1];v[2]=(int)v[2];}
459
460 float NormalizeColor( vec3_c in, vec3_p out );
461
462 int VectorCompare( vec3_c v1, vec3_c v2 );
463 float VectorLength( vec3_c v );
464 float Distance( vec3_c p1, vec3_c p2 );
465 float DistanceSquared( vec3_c p1, vec3_c p2 );
466 float VectorNormalize (vec3_p v);               // returns vector length
467 void VectorNormalizeFast(vec3_p v);             // does NOT return vector length, uses rsqrt approximation
468 float VectorNormalize2( vec3_c v, vec3_p out );
469 void VectorInverse (vec3_p v);
470 void VectorRotate( vec3_c in, mat3_c matrix, vec3_p out );
471 void VectorPolar(vec3_p v, float radius, float theta, float phi);
472 void VectorSnap(vec3_p v);
473 void Vector53Copy( const idVec5_t &in, vec3_p out);
474 void Vector5Scale( const idVec5_t &v, float scale, idVec5_t &out);
475 void Vector5Add( const idVec5_t &va, const idVec5_t &vb, idVec5_t &out);
476 void VectorRotate3( vec3_c vIn, vec3_c vRotation, vec3_p out);
477 void VectorRotate3Origin(vec3_c vIn, vec3_c vRotation, vec3_c vOrigin, vec3_p out);
478
479
480 int Q_log2(int val);
481
482 int             Q_rand( int *seed );
483 float   Q_random( int *seed );
484 float   Q_crandom( int *seed );
485
486 #define random()        ((rand () & 0x7fff) / ((float)0x7fff))
487 #define crandom()       (2.0 * (random() - 0.5))
488
489 float Q_rint( float in );
490
491 void vectoangles( vec3_c value1, angles_p angles);
492 void AnglesToAxis( angles_c angles, mat3_p axis );
493
494 void AxisCopy( mat3_c in, mat3_p out );
495 qboolean AxisRotated( mat3_c in );                      // assumes a non-degenerate axis
496
497 int SignbitsForNormal( vec3_c normal );
498 int BoxOnPlaneSide( const Bounds &b, struct cplane_s *p );
499
500 float   AngleMod(float a);
501 float   LerpAngle (float from, float to, float frac);
502 float   AngleSubtract( float a1, float a2 );
503 void    AnglesSubtract( angles_c v1, angles_c v2, angles_p v3 );
504
505 float AngleNormalize360 ( float angle );
506 float AngleNormalize180 ( float angle );
507 float AngleDelta ( float angle1, float angle2 );
508
509 qboolean PlaneFromPoints( idVec4 &plane, vec3_c a, vec3_c b, vec3_c c );
510 void ProjectPointOnPlane( vec3_p dst, vec3_c p, vec3_c normal );
511 void RotatePointAroundVector( vec3_p dst, vec3_c dir, vec3_c point, float degrees );
512 void RotateAroundDirection( mat3_p axis, float yaw );
513 void MakeNormalVectors( vec3_c forward, vec3_p right, vec3_p up );
514 // perpendicular vector could be replaced by this
515
516 int     PlaneTypeForNormal( vec3_c normal );
517
518 void MatrixMultiply( mat3_c in1, mat3_c in2, mat3_p out );
519 void MatrixInverseMultiply( mat3_c in1, mat3_c in2, mat3_p out );       // in2 is transposed during multiply
520 void MatrixTransformVector( vec3_c in, mat3_c matrix, vec3_p out );
521 void MatrixProjectVector( vec3_c in, mat3_c matrix, vec3_p out ); // Places the vector into a new coordinate system.
522 void AngleVectors( angles_c angles, vec3_p forward, vec3_p right, vec3_p up);
523 void PerpendicularVector( vec3_p dst, vec3_c src );
524
525 float TriangleArea( vec3_c a, vec3_c b, vec3_c c );
526 #endif                                                                          // __cplusplus
527
528 //=============================================
529
530 float Com_Clamp( float min, float max, float value );
531
532 #define FILE_HASH_SIZE          1024
533 int Com_HashString( const char *fname );
534
535 char    *Com_SkipPath( char *pathname );
536
537 // it is ok for out == in
538 void    Com_StripExtension( const char *in, char *out );
539
540 // "extension" should include the dot: ".map"
541 void    Com_DefaultExtension( char *path, int maxSize, const char *extension );
542
543 int             Com_ParseInfos( const char *buf, int max, char infos[][MAX_INFO_STRING] );
544
545 /*
546 =====================================================================================
547
548 SCRIPT PARSING
549
550 =====================================================================================
551 */
552
553 // this just controls the comment printing, it doesn't actually load a file
554 void Com_BeginParseSession( const char *filename );
555 void Com_EndParseSession( void );
556
557 int Com_GetCurrentParseLine( void );
558
559 // Will never return NULL, just empty strings.
560 // An empty string will only be returned at end of file.
561 // ParseOnLine will return empty if there isn't another token on this line
562
563 // this funny typedef just means a moving pointer into a const char * buffer
564 const char *Com_Parse( const char *(*data_p) );
565 const char *Com_ParseOnLine( const char *(*data_p) );
566 const char *Com_ParseRestOfLine( const char *(*data_p) );
567
568 void Com_UngetToken( void );
569
570 #ifdef __cplusplus
571 void Com_MatchToken( const char *(*buf_p), const char *match, qboolean warning = qfalse );
572 #else
573 void Com_MatchToken( const char *(*buf_p), const char *match, qboolean warning );
574 #endif
575
576 void Com_ScriptError( const char *msg, ... );
577 void Com_ScriptWarning( const char *msg, ... );
578
579 void Com_SkipBracedSection( const char *(*program) );
580 void Com_SkipRestOfLine( const char *(*data) );
581
582 float Com_ParseFloat( const char *(*buf_p) );
583 int     Com_ParseInt( const char *(*buf_p) );
584
585 void Com_Parse1DMatrix( const char *(*buf_p), int x, float *m );
586 void Com_Parse2DMatrix( const char *(*buf_p), int y, int x, float *m );
587 void Com_Parse3DMatrix( const char *(*buf_p), int z, int y, int x, float *m );
588
589 //=====================================================================================
590 #ifdef __cplusplus
591         extern "C" {
592 #endif
593
594 void    QDECL Com_sprintf (char *dest, int size, const char *fmt, ...);
595
596
597 // mode parm for FS_FOpenFile
598 typedef enum {
599         FS_READ,
600         FS_WRITE,
601         FS_APPEND,
602         FS_APPEND_SYNC
603 } fsMode_t;
604
605 typedef enum {
606         FS_SEEK_CUR,
607         FS_SEEK_END,
608         FS_SEEK_SET
609 } fsOrigin_t;
610
611 //=============================================
612
613 int Q_isprint( int c );
614 int Q_islower( int c );
615 int Q_isupper( int c );
616 int Q_isalpha( int c );
617
618 // portable case insensitive compare
619 int             Q_stricmp (const char *s1, const char *s2);
620 int             Q_strncmp (const char *s1, const char *s2, int n);
621 int             Q_stricmpn (const char *s1, const char *s2, int n);
622 char    *Q_strlwr( char *s1 );
623 char    *Q_strupr( char *s1 );
624 char    *Q_strrchr( const char* string, int c );
625
626 // buffer size safe library replacements
627 void    Q_strncpyz( char *dest, const char *src, int destsize );
628 void    Q_strcat( char *dest, int size, const char *src );
629
630 // strlen that discounts Quake color sequences
631 int Q_PrintStrlen( const char *string );
632 // removes color sequences from string
633 char *Q_CleanStr( char *string );
634
635 int                     Com_Filter( const char *filter, const char *name, int casesensitive );
636 const char *Com_StringContains( const char *str1, const char *str2, int casesensitive );
637
638
639 //=============================================
640
641 short   BigShort(short l);
642 short   LittleShort(short l);
643 int             BigLong (int l);
644 int             LittleLong (int l);
645 float   BigFloat (float l);
646 float   LittleFloat (float l);
647
648 void    Swap_Init (void);
649 char    * QDECL va(char *format, ...);
650
651 #ifdef __cplusplus
652     }
653 #endif
654
655
656 //=============================================
657 #ifdef __cplusplus
658 //
659 // mapfile parsing
660 //
661 typedef struct ePair_s {
662         char    *key;
663         char    *value;
664 } ePair_t;
665
666 typedef struct mapSide_s {
667         char            material[MAX_QPATH];
668         idVec4          plane;
669         idVec4          textureVectors[2];
670 } mapSide_t;
671
672 typedef struct {
673         int                     numSides;
674         mapSide_t       **sides;
675 } mapBrush_t;
676
677 typedef struct {
678         idVec3          xyz;
679         float           st[2];
680 } patchVertex_t;
681
682 typedef struct {
683         char            material[MAX_QPATH];
684         int                     width, height;
685         patchVertex_t   *patchVerts;
686 } mapPatch_t;
687
688 typedef struct {
689         char            modelName[MAX_QPATH];
690         float           matrix[16];
691 } mapModel_t;
692
693 typedef struct mapPrimitive_s {
694         int                             numEpairs;
695         ePair_t                 **ePairs;
696
697         // only one of these will be non-NULL
698         mapBrush_t              *brush;
699         mapPatch_t              *patch;
700         mapModel_t              *model;
701 } mapPrimitive_t;
702
703 typedef struct mapEntity_s {
704         int                             numPrimitives;
705         mapPrimitive_t  **primitives;
706
707         int                             numEpairs;
708         ePair_t                 **ePairs;
709 } mapEntity_t;
710
711 typedef struct {
712         int                             numEntities;
713         mapEntity_t             **entities;
714 } mapFile_t;
715
716
717 // the order of entities, brushes, and sides will be maintained, the
718 // lists won't be swapped on each load or save
719 mapFile_t *ParseMapFile( const char *text );
720 void FreeMapFile( mapFile_t *mapFile );
721 void WriteMapFile( const mapFile_t *mapFile, FILE *f );
722
723 // key names are case-insensitive
724 const char      *ValueForMapEntityKey( const mapEntity_t *ent, const char *key );
725 float   FloatForMapEntityKey( const mapEntity_t *ent, const char *key );
726 qboolean        GetVectorForMapEntityKey( const mapEntity_t *ent, const char *key, idVec3 &vec );
727
728 typedef struct {
729         idVec3          xyz;
730         idVec2          st;
731         idVec3          normal;
732         idVec3          tangents[2];
733         byte            smoothing[4];           // colors for silhouette smoothing
734 } drawVert_t;
735
736 typedef struct {
737         int                     width, height;
738         drawVert_t      *verts;
739 } drawVertMesh_t;
740
741 // Tesselate a map patch into smoothed, drawable vertexes
742 // MaxError of around 4 is reasonable
743 drawVertMesh_t *SubdivideMapPatch( const mapPatch_t *patch, float maxError );
744 #endif                  // __cplusplus
745
746 //=========================================
747
748 #ifdef __cplusplus
749         extern "C" {
750 #endif
751
752 void    QDECL Com_Error( int level, const char *error, ... );
753 void    QDECL Com_Printf( const char *msg, ... );
754 void    QDECL Com_DPrintf( const char *msg, ... );
755
756 #ifdef __cplusplus
757         }
758 #endif
759
760
761 typedef struct {
762         qboolean        frameMemory;
763         int             currentElements;
764         int             maxElements;            // will reallocate and move when exceeded
765         void    **elements;
766 } growList_t;
767
768 // you don't need to init the growlist if you don't mind it growing and moving
769 // the list as it expands
770 void            Com_InitGrowList( growList_t *list, int maxElements );
771 int                     Com_AddToGrowList( growList_t *list, void *data );
772 void            *Com_GrowListElement( const growList_t *list, int index );
773 int                     Com_IndexForGrowListElement( const growList_t *list, const void *element );
774
775
776 //
777 // key / value info strings
778 //
779 char *Info_ValueForKey( const char *s, const char *key );
780 void Info_RemoveKey( char *s, const char *key );
781 void Info_SetValueForKey( char *s, const char *key, const char *value );
782 qboolean Info_Validate( const char *s );
783 void Info_NextPair( const char *(*s), char key[MAX_INFO_KEY], char value[MAX_INFO_VALUE] );
784
785 // get cvar defs, collision defs, etc
786 //#include "../shared/interface.h"
787
788 // get key code numbers for events
789 //#include "../shared/keycodes.h"
790
791 #ifdef __cplusplus
792 // get the polygon winding functions
793 //#include "../shared/windings.h"
794
795 // get the flags class
796 //#include "../shared/idflags.h"
797 #endif  // __cplusplus
798
799 #endif  // __Q_SHARED_H
800