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