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