]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake3/q3map2/q3map2.h
Merge branch 'NateEag-master-patch-12920' into 'master'
[xonotic/netradiant.git] / tools / quake3 / q3map2 / q3map2.h
1 /* -------------------------------------------------------------------------------
2
3    Copyright (C) 1999-2007 id Software, Inc. and contributors.
4    For a list of contributors, see the accompanying CONTRIBUTORS file.
5
6    This file is part of GtkRadiant.
7
8    GtkRadiant is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    GtkRadiant is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GtkRadiant; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
22    ----------------------------------------------------------------------------------
23
24    This code has been altered significantly from its original form, to support
25    several games based on the Quake III Arena engine, in the form of "Q3Map2."
26
27    ------------------------------------------------------------------------------- */
28
29
30
31 /* marker */
32 #ifndef Q3MAP2_H
33 #define Q3MAP2_H
34
35 #include "globaldefs.h"
36
37 /* version */
38 #ifndef Q3MAP_VERSION
39 #error no Q3MAP_VERSION defined
40 #endif
41 #define Q3MAP_MOTD      "Your map saw the pretty lights from q3map2's BFG"
42
43
44
45
46 /* -------------------------------------------------------------------------------
47
48    dependencies
49
50    ------------------------------------------------------------------------------- */
51
52 /* platform-specific */
53 #if GDEF_OS_POSIX
54         #include <unistd.h>
55         #include <pwd.h>
56         #include <limits.h>
57 #endif
58
59 #if GDEF_OS_WINDOWS
60         #include <windows.h>
61 #endif
62
63
64 /* general */
65 #include "cmdlib.h"
66 #include "mathlib.h"
67 #include "md5lib.h"
68 #include "ddslib.h"
69 #ifdef BUILD_CRUNCH
70 #include "crn_rgba.h"
71 #endif // BUILD_CRUNCH
72
73 #include "picomodel.h"
74
75 #include "scriplib.h"
76 #include "polylib.h"
77 #include "imagelib.h"
78 #include "qthreads.h"
79 #include "inout.h"
80 #include "vfs.h"
81 #include "png.h"
82 #include "md4.h"
83 #include <stdlib.h>
84
85
86 /* -------------------------------------------------------------------------------
87
88    port-related hacks
89
90    ------------------------------------------------------------------------------- */
91
92         #if GDEF_OS_WINDOWS
93                 #define Q_stricmp           stricmp
94                 #define Q_strncasecmp       strnicmp
95         #else
96                 #define Q_stricmp           strcasecmp
97                 #define Q_strncasecmp       strncasecmp
98         #endif
99
100 // hack to declare and define in the same file
101 #ifdef MAIN_C
102         #define Q_EXTERN
103         #define Q_ASSIGN( a )   = a
104 #else
105         #define Q_EXTERN extern
106         #define Q_ASSIGN( a )
107 #endif
108
109 /* macro version */
110 #define VectorMA( a, s, b, c )  ( ( c )[ 0 ] = ( a )[ 0 ] + ( s ) * ( b )[ 0 ], ( c )[ 1 ] = ( a )[ 1 ] + ( s ) * ( b )[ 1 ], ( c )[ 2 ] = ( a )[ 2 ] + ( s ) * ( b )[ 2 ] )
111
112
113
114 /* -------------------------------------------------------------------------------
115
116    constants
117
118    ------------------------------------------------------------------------------- */
119
120 /* temporary hacks and tests (please keep off in SVN to prevent anyone's legacy map from screwing up) */
121 /* 2011-01-10 TTimo says we should turn these on in SVN, so turning on now */
122 #define Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES   1
123 #define Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX     1
124 #define Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX      1
125
126 /* general */
127 #define MAX_QPATH               64
128
129 #define MAX_IMAGES              2048
130 #define DEFAULT_IMAGE           "*default"
131
132 #define MAX_MODELS              2048
133
134 #define DEF_BACKSPLASH_FRACTION 0.05f   /* 5% backsplash by default */
135 #define DEF_BACKSPLASH_DISTANCE 23
136
137 #define DEF_RADIOSITY_BOUNCE    1.0f    /* ydnar: default to 100% re-emitted light */
138
139 #define MAX_SHADER_INFO         8192
140 #define MAX_CUST_SURFACEPARMS   256
141
142 #define SHADER_MAX_VERTEXES     1000
143 #define SHADER_MAX_INDEXES      ( 6 * SHADER_MAX_VERTEXES )
144
145 #define MAX_JITTERS             256
146
147
148 /* epair parsing (note case-sensitivity directive) */
149 #define CASE_INSENSITIVE_EPAIRS 1
150
151 #if CASE_INSENSITIVE_EPAIRS
152         #define EPAIR_STRCMP        Q_stricmp
153 #else
154         #define EPAIR_STRCMP        strcmp
155 #endif
156
157
158 /* ydnar: compiler flags, because games have widely varying content/surface flags */
159 #define C_SOLID                 0x00000001
160 #define C_TRANSLUCENT           0x00000002
161 #define C_STRUCTURAL            0x00000004
162 #define C_HINT                  0x00000008
163 #define C_NODRAW                0x00000010
164 #define C_LIGHTGRID             0x00000020
165 #define C_ALPHASHADOW           0x00000040
166 #define C_LIGHTFILTER           0x00000080
167 #define C_VERTEXLIT             0x00000100
168 #define C_LIQUID                0x00000200
169 #define C_FOG                   0x00000400
170 #define C_SKY                   0x00000800
171 #define C_ORIGIN                0x00001000
172 #define C_AREAPORTAL            0x00002000
173 #define C_ANTIPORTAL            0x00004000  /* like hint, but doesn't generate portals */
174 #define C_SKIP                  0x00008000  /* like hint, but skips this face (doesn't split bsp) */
175 #define C_NOMARKS               0x00010000  /* no decals */
176 #define C_OB                    0x00020000  /* skip -noob for this */
177 #define C_DETAIL                0x08000000  /* THIS MUST BE THE SAME AS IN RADIANT! */
178
179
180 /* new tex surface flags, like Smokin'Guns */
181 #define TEX_SURF_METAL             0x00001000
182 #define TEX_SURF_WOOD              0x00080000
183 #define TEX_SURF_CLOTH             0x00100000
184 #define TEX_SURF_DIRT              0x00200000
185 #define TEX_SURF_GLASS             0x00400000
186 #define TEX_SURF_PLANT             0x00800000
187 #define TEX_SURF_SAND              0x01000000
188 #define TEX_SURF_SNOW              0x02000000
189 #define TEX_SURF_STONE             0x04000000
190 #define TEX_SURF_WATER             0x08000000
191 #define TEX_SURF_GRASS             0x10000000
192 #define TEX_SURF_BREAKABLE         0x20000000
193
194
195 /* shadow flags */
196 #define WORLDSPAWN_CAST_SHADOWS 1
197 #define WORLDSPAWN_RECV_SHADOWS 1
198 #define ENTITY_CAST_SHADOWS     0
199 #define ENTITY_RECV_SHADOWS     1
200
201
202 /* bsp */
203 #define MAX_PATCH_SIZE          32
204 #define MAX_BRUSH_SIDES         1024
205 #define MAX_BUILD_SIDES         1024
206
207 #define MAX_EXPANDED_AXIS       128
208
209 #define CLIP_EPSILON            0.1f
210 #define PLANESIDE_EPSILON       0.001f
211 #define PLANENUM_LEAF           -1
212
213 #define HINT_PRIORITY           1000        /* ydnar: force hint splits first and antiportal/areaportal splits last */
214 #define ANTIPORTAL_PRIORITY     -1000
215 #define AREAPORTAL_PRIORITY     -1000
216 #define DETAIL_PRIORITY     -3000
217
218 #define PSIDE_FRONT             1
219 #define PSIDE_BACK              2
220 #define PSIDE_BOTH              ( PSIDE_FRONT | PSIDE_BACK )
221 #define PSIDE_FACING            4
222
223 #define BPRIMIT_UNDEFINED       0
224 #define BPRIMIT_OLDBRUSHES      1
225 #define BPRIMIT_NEWBRUSHES      2
226
227
228 /* vis */
229 #define VIS_HEADER_SIZE         8
230
231 #define SEPERATORCACHE          /* seperator caching helps a bit */
232
233 #define PORTALFILE              "PRT1"
234
235 #define MAX_PORTALS             0x20000 /* same as MAX_MAP_PORTALS */
236 #define MAX_SEPERATORS          MAX_POINTS_ON_WINDING
237 #define MAX_POINTS_ON_FIXED_WINDING 24  /* ydnar: increased this from 12 at the expense of more memory */
238 #define MAX_PORTALS_ON_LEAF     1024
239
240
241 /* light */
242 #define EMIT_POINT              0
243 #define EMIT_AREA               1
244 #define EMIT_SPOT               2
245 #define EMIT_SUN                3
246
247 #define LIGHT_ATTEN_LINEAR      1
248 #define LIGHT_ATTEN_ANGLE       2
249 #define LIGHT_ATTEN_DISTANCE    4
250 #define LIGHT_TWOSIDED          8
251 #define LIGHT_GRID              16
252 #define LIGHT_SURFACES          32
253 #define LIGHT_DARK              64      /* probably never use this */
254 #define LIGHT_FAST              256
255 #define LIGHT_FAST_TEMP         512
256 #define LIGHT_FAST_ACTUAL       ( LIGHT_FAST | LIGHT_FAST_TEMP )
257 #define LIGHT_NEGATIVE          1024
258 #define LIGHT_UNNORMALIZED      2048    /* vortex: do not normalize _color */
259
260 #define LIGHT_SUN_DEFAULT       ( LIGHT_ATTEN_ANGLE | LIGHT_GRID | LIGHT_SURFACES )
261 #define LIGHT_AREA_DEFAULT      ( LIGHT_ATTEN_ANGLE | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES )    /* q3a and wolf are the same */
262 #define LIGHT_Q3A_DEFAULT       ( LIGHT_ATTEN_ANGLE | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES | LIGHT_FAST )
263 #define LIGHT_WOLF_DEFAULT      ( LIGHT_ATTEN_LINEAR | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES | LIGHT_FAST )
264
265 #define MAX_TRACE_TEST_NODES    256
266 #define DEFAULT_INHIBIT_RADIUS  1.5f
267
268 #define LUXEL_EPSILON           0.125f
269 #define VERTEX_EPSILON          -0.125f
270 #define GRID_EPSILON            0.0f
271
272 #define DEFAULT_LIGHTMAP_SAMPLE_SIZE    16
273 #define DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE    0
274 #define DEFAULT_LIGHTMAP_SAMPLE_OFFSET  1.0f
275 #define DEFAULT_SUBDIVIDE_THRESHOLD     1.0f
276
277 #define EXTRA_SCALE             2   /* -extrawide = -super 2 */
278 #define EXTRAWIDE_SCALE         2   /* -extrawide = -super 2 -filter */
279
280 #define CLUSTER_UNMAPPED        -1
281 #define CLUSTER_OCCLUDED        -2
282 #define CLUSTER_FLOODED         -3
283
284 #define VERTEX_LUXEL_SIZE       3
285 #define BSP_LUXEL_SIZE          3
286 #define RAD_LUXEL_SIZE          3
287 #define SUPER_LUXEL_SIZE        4
288 #define SUPER_FLAG_SIZE         4
289 #define FLAG_FORCE_SUBSAMPLING 1
290 #define FLAG_ALREADY_SUBSAMPLED 2
291 #define SUPER_ORIGIN_SIZE       3
292 #define SUPER_NORMAL_SIZE       4
293 #define SUPER_DELUXEL_SIZE      3
294 #define BSP_DELUXEL_SIZE        3
295 #define SUPER_FLOODLIGHT_SIZE   4
296
297 #define VERTEX_LUXEL( s, v )    ( vertexLuxels[ s ] + ( ( v ) * VERTEX_LUXEL_SIZE ) )
298 #define RAD_VERTEX_LUXEL( s, v )( radVertexLuxels[ s ] + ( ( v ) * VERTEX_LUXEL_SIZE ) )
299 #define BSP_LUXEL( s, x, y )    ( lm->bspLuxels[ s ] + ( ( ( ( y ) * lm->w ) + ( x ) ) * BSP_LUXEL_SIZE ) )
300 #define RAD_LUXEL( s, x, y )    ( lm->radLuxels[ s ] + ( ( ( ( y ) * lm->w ) + ( x ) ) * RAD_LUXEL_SIZE ) )
301 #define SUPER_LUXEL( s, x, y )  ( lm->superLuxels[ s ] + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_LUXEL_SIZE ) )
302 #define SUPER_FLAG( x, y )  ( lm->superFlags + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_FLAG_SIZE ) )
303 #define SUPER_DELUXEL( x, y )   ( lm->superDeluxels + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_DELUXEL_SIZE ) )
304 #define BSP_DELUXEL( x, y )     ( lm->bspDeluxels + ( ( ( ( y ) * lm->w ) + ( x ) ) * BSP_DELUXEL_SIZE ) )
305 #define SUPER_CLUSTER( x, y )   ( lm->superClusters + ( ( ( y ) * lm->sw ) + ( x ) ) )
306 #define SUPER_ORIGIN( x, y )    ( lm->superOrigins + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_ORIGIN_SIZE ) )
307 #define SUPER_NORMAL( x, y )    ( lm->superNormals + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_NORMAL_SIZE ) )
308 #define SUPER_DIRT( x, y )      ( lm->superNormals + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_NORMAL_SIZE ) + 3 )   /* stash dirtyness in normal[ 3 ] */
309 #define SUPER_FLOODLIGHT( x, y )    ( lm->superFloodLight + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_FLOODLIGHT_SIZE ) )
310
311
312
313 /* -------------------------------------------------------------------------------
314
315    abstracted bsp file
316
317    ------------------------------------------------------------------------------- */
318
319 #define EXTERNAL_LIGHTMAP       "lm_%04d.tga"
320
321 #define MAX_LIGHTMAPS           4           /* RBSP */
322 #define MAX_LIGHT_STYLES        64
323 #define MAX_SWITCHED_LIGHTS     32
324 #define LS_NORMAL               0x00
325 #define LS_UNUSED               0xFE
326 #define LS_NONE                 0xFF
327
328 #define MAX_LIGHTMAP_SHADERS    256
329
330 /* ok to increase these at the expense of more memory */
331 #define MAX_MAP_AREAS           0x100       /* MAX_MAP_AREA_BYTES in q_shared must match! */
332 #define MAX_MAP_FOGS            30          //& 0x100   /* RBSP (32 - world fog - goggles) */
333 #define MAX_MAP_LEAFS           0x20000
334 #define MAX_MAP_PORTALS         0x20000
335 #define MAX_MAP_LIGHTING        0x800000
336 #define MAX_MAP_LIGHTGRID       0x100000    //% 0x800000 /* ydnar: set to points, not bytes */
337 #define MAX_MAP_VISCLUSTERS     0x4000 // <= MAX_MAP_LEAFS
338 #define MAX_MAP_VISIBILITY      ( VIS_HEADER_SIZE + MAX_MAP_VISCLUSTERS * ( ( ( MAX_MAP_VISCLUSTERS + 63 ) & ~63 ) >> 3 ) )
339
340 #define MAX_MAP_DRAW_SURFS      0x20000
341
342 #define MAX_MAP_ADVERTISEMENTS  30
343
344 /* key / value pair sizes in the entities lump */
345 #define MAX_KEY                 32
346 #define MAX_VALUE               1024
347
348 /* the editor uses these predefined yaw angles to orient entities up or down */
349 #define ANGLE_UP                -1
350 #define ANGLE_DOWN              -2
351
352 #define LIGHTMAP_WIDTH          128
353 #define LIGHTMAP_HEIGHT         128
354
355 #define MIN_WORLD_COORD         ( -65536 )
356 #define MAX_WORLD_COORD         ( 65536 )
357 #define WORLD_SIZE              ( MAX_WORLD_COORD - MIN_WORLD_COORD )
358
359
360 typedef void ( *bspFunc )( const char * );
361
362
363 typedef struct
364 {
365         int offset, length;
366 }
367 bspLump_t;
368
369
370 typedef struct
371 {
372         char ident[ 4 ];
373         int version;
374
375         bspLump_t lumps[ 100 ];     /* theoretical maximum # of bsp lumps */
376 }
377 bspHeader_t;
378
379
380 typedef struct
381 {
382         float mins[ 3 ], maxs[ 3 ];
383         int firstBSPSurface, numBSPSurfaces;
384         int firstBSPBrush, numBSPBrushes;
385 }
386 bspModel_t;
387
388
389 typedef struct
390 {
391         char shader[ MAX_QPATH ];
392         int surfaceFlags;
393         int contentFlags;
394 }
395 bspShader_t;
396
397
398 /* planes x^1 is always the opposite of plane x */
399
400 typedef struct
401 {
402         float normal[ 3 ];
403         float dist;
404 }
405 bspPlane_t;
406
407
408 typedef struct
409 {
410         int planeNum;
411         int children[ 2 ];              /* negative numbers are -(leafs+1), not nodes */
412         int mins[ 3 ];                  /* for frustum culling */
413         int maxs[ 3 ];
414 }
415 bspNode_t;
416
417
418 typedef struct
419 {
420         int cluster;                    /* -1 = opaque cluster (do I still store these?) */
421         int area;
422
423         int mins[ 3 ];                  /* for frustum culling */
424         int maxs[ 3 ];
425
426         int firstBSPLeafSurface;
427         int numBSPLeafSurfaces;
428
429         int firstBSPLeafBrush;
430         int numBSPLeafBrushes;
431 }
432 bspLeaf_t;
433
434
435 typedef struct
436 {
437         int planeNum;                   /* positive plane side faces out of the leaf */
438         int shaderNum;
439         int surfaceNum;                 /* RBSP */
440 }
441 bspBrushSide_t;
442
443
444 typedef struct
445 {
446         int firstSide;
447         int numSides;
448         int shaderNum;                  /* the shader that determines the content flags */
449 }
450 bspBrush_t;
451
452
453 typedef struct
454 {
455         char shader[ MAX_QPATH ];
456         int brushNum;
457         int visibleSide;                /* the brush side that ray tests need to clip against (-1 == none) */
458 }
459 bspFog_t;
460
461
462 typedef struct
463 {
464         vec3_t xyz;
465         float st[ 2 ];
466         float lightmap[ MAX_LIGHTMAPS ][ 2 ];       /* RBSP */
467         vec3_t normal;
468         byte color[ MAX_LIGHTMAPS ][ 4 ];           /* RBSP */
469 }
470 bspDrawVert_t;
471
472
473 typedef enum
474 {
475         MST_BAD,
476         MST_PLANAR,
477         MST_PATCH,
478         MST_TRIANGLE_SOUP,
479         MST_FLARE,
480         MST_FOLIAGE
481 }
482 bspSurfaceType_t;
483
484
485 typedef struct bspGridPoint_s
486 {
487         byte ambient[ MAX_LIGHTMAPS ][ 3 ];
488         byte directed[ MAX_LIGHTMAPS ][ 3 ];
489         byte styles[ MAX_LIGHTMAPS ];
490         byte latLong[ 2 ];
491 }
492 bspGridPoint_t;
493
494
495 typedef struct
496 {
497         int shaderNum;
498         int fogNum;
499         int surfaceType;
500
501         int firstVert;
502         int numVerts;
503
504         int firstIndex;
505         int numIndexes;
506
507         byte lightmapStyles[ MAX_LIGHTMAPS ];                               /* RBSP */
508         byte vertexStyles[ MAX_LIGHTMAPS ];                                 /* RBSP */
509         int lightmapNum[ MAX_LIGHTMAPS ];                                   /* RBSP */
510         int lightmapX[ MAX_LIGHTMAPS ], lightmapY[ MAX_LIGHTMAPS ];         /* RBSP */
511         int lightmapWidth, lightmapHeight;
512
513         vec3_t lightmapOrigin;
514         vec3_t lightmapVecs[ 3 ];       /* on patches, [ 0 ] and [ 1 ] are lodbounds */
515
516         int patchWidth;
517         int patchHeight;
518 }
519 bspDrawSurface_t;
520
521
522 /* advertisements */
523 typedef struct {
524         int cellId;
525         vec3_t normal;
526         vec3_t rect[4];
527         char model[ MAX_QPATH ];
528 } bspAdvertisement_t;
529
530
531 /* -------------------------------------------------------------------------------
532
533    general types
534
535    ------------------------------------------------------------------------------- */
536
537 /* ydnar: for smaller structs */
538 typedef unsigned char qb_t;
539
540
541 /* ydnar: for q3map_tcMod */
542 typedef float tcMod_t[ 3 ][ 3 ];
543
544
545 /* ydnar: for multiple game support */
546 typedef struct surfaceParm_s
547 {
548         char        *name;
549         int contentFlags, contentFlagsClear;
550         int surfaceFlags, surfaceFlagsClear;
551         int compileFlags, compileFlagsClear;
552 }
553 surfaceParm_t;
554
555 typedef enum
556 {
557         MINIMAP_MODE_GRAY,
558         MINIMAP_MODE_BLACK,
559         MINIMAP_MODE_WHITE
560 }
561 miniMapMode_t;
562
563 typedef enum
564 {
565         MINIMAP_SIDECAR_NONE,
566         MINIMAP_SIDECAR_UNVANQUISHED
567 }
568 miniMapSidecarFormat_t;
569
570 typedef struct game_s
571 {
572         char                *arg;                           /* -game matches this */
573         char                *gamePath;                      /* main game data dir */
574         char                *homeBasePath;                  /* home sub-dir on unix */
575         char                *magic;                         /* magic word for figuring out base path */
576         char                *shaderPath;                    /* shader directory */
577         int maxLMSurfaceVerts;                              /* default maximum meta surface verts */
578         int maxSurfaceVerts;                                /* default maximum surface verts */
579         int maxSurfaceIndexes;                              /* default maximum surface indexes (tris * 3) */
580         qboolean texFile;                                   /* enable per shader prefix surface flags and .tex file */
581         qboolean emitFlares;                                /* when true, emit flare surfaces */
582         char                *flareShader;                   /* default flare shader (MUST BE SET) */
583         qboolean wolfLight;                                 /* when true, lights work like wolf q3map  */
584         int lightmapSize;                                   /* bsp lightmap width/height */
585         float lightmapGamma;                                /* default lightmap gamma */
586         qboolean lightmapsRGB;                              /* default lightmap sRGB mode */
587         qboolean texturesRGB;                               /* default texture sRGB mode */
588         qboolean colorsRGB;                             /* default color sRGB mode */
589         float lightmapExposure;                             /* default lightmap exposure */
590         float lightmapCompensate;                           /* default lightmap compensate value */
591         float gridScale;                                    /* vortex: default lightgrid scale (affects both directional and ambient spectres) */
592         float gridAmbientScale;                             /* vortex: default lightgrid ambient spectre scale */
593         qboolean lightAngleHL;                              /* jal: use half-lambert curve for light angle attenuation */
594         qboolean noStyles;                                  /* use lightstyles hack or not */
595         qboolean keepLights;                                /* keep light entities on bsp */
596         int patchSubdivisions;                              /* default patch subdivisions tolerance */
597         qboolean patchShadows;                              /* patch casting enabled */
598         qboolean deluxeMap;                                 /* compile deluxemaps */
599         int deluxeMode;                                     /* deluxemap mode (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
600         int miniMapSize;                                    /* minimap size */
601         float miniMapSharpen;                               /* minimap sharpening coefficient */
602         float miniMapBorder;                                /* minimap border amount */
603         qboolean miniMapKeepAspect;                         /* minimap keep aspect ratio by letterboxing */
604         miniMapMode_t miniMapMode;                          /* minimap mode */
605         char                *miniMapNameFormat;             /* minimap name format */
606         miniMapSidecarFormat_t miniMapSidecarFormat;        /* minimap sidecar format */
607         char                *bspIdent;                      /* 4-letter bsp file prefix */
608         int bspVersion;                                     /* bsp version to use */
609         qboolean lumpSwap;                                  /* cod-style len/ofs order */
610         bspFunc load, write;                                /* load/write function pointers */
611         surfaceParm_t surfaceParms[ 128 ];                  /* surfaceparm array */
612 }
613 game_t;
614
615
616 typedef struct image_s
617 {
618         char                *name, *filename;
619         int refCount;
620         int width, height;
621         byte                *pixels;
622 }
623 image_t;
624
625
626 typedef struct sun_s
627 {
628         struct sun_s        *next;
629         vec3_t direction, color;
630         float photons, deviance, filterRadius;
631         int numSamples, style;
632 }
633 sun_t;
634
635
636 typedef struct surfaceModel_s
637 {
638         struct surfaceModel_s   *next;
639         char model[ MAX_QPATH ];
640         float density, odds;
641         float minScale, maxScale;
642         float minAngle, maxAngle;
643         qboolean oriented;
644 }
645 surfaceModel_t;
646
647
648 /* ydnar/sd: foliage stuff for wolf et (engine-supported optimization of the above) */
649 typedef struct foliage_s
650 {
651         struct foliage_s    *next;
652         char model[ MAX_QPATH ];
653         float scale, density, odds;
654         qboolean inverseAlpha;
655 }
656 foliage_t;
657
658 typedef struct foliageInstance_s
659 {
660         vec3_t xyz, normal;
661 }
662 foliageInstance_t;
663
664
665 typedef struct remap_s
666 {
667         struct remap_s      *next;
668         char from[ 1024 ];
669         char to[ MAX_QPATH ];
670 }
671 remap_t;
672
673 typedef struct skinfile_s
674 {
675         struct skinfile_s   *next;
676         char name[ 1024 ];
677         char to[ MAX_QPATH ];
678 }
679 skinfile_t;
680
681
682 /* wingdi.h hack, it's the same: 0 */
683 #undef CM_NONE
684
685 typedef enum
686 {
687         CM_NONE,
688         CM_VOLUME,
689         CM_COLOR_SET,
690         CM_ALPHA_SET,
691         CM_COLOR_SCALE,
692         CM_ALPHA_SCALE,
693         CM_COLOR_DOT_PRODUCT,
694         CM_ALPHA_DOT_PRODUCT,
695         CM_COLOR_DOT_PRODUCT_SCALE,
696         CM_ALPHA_DOT_PRODUCT_SCALE,
697         CM_COLOR_DOT_PRODUCT_2,
698         CM_ALPHA_DOT_PRODUCT_2,
699         CM_COLOR_DOT_PRODUCT_2_SCALE,
700         CM_ALPHA_DOT_PRODUCT_2_SCALE
701 }
702 colorModType_t;
703
704
705 typedef struct colorMod_s
706 {
707         struct colorMod_s   *next;
708         colorModType_t type;
709         vec_t data[ 16 ];
710 }
711 colorMod_t;
712
713
714 typedef enum
715 {
716         IM_NONE,
717         IM_OPAQUE,
718         IM_MASKED,
719         IM_BLEND
720 }
721 implicitMap_t;
722
723
724 typedef struct shaderInfo_s
725 {
726         char shader[ MAX_QPATH ];
727         int surfaceFlags;
728         int contentFlags;
729         int compileFlags;
730         float value;                                        /* light value */
731
732         char                *flareShader;                   /* for light flares */
733         char                *damageShader;                  /* ydnar: sof2 damage shader name */
734         char                *backShader;                    /* for surfaces that generate different front and back passes */
735         char                *cloneShader;                   /* ydnar: for cloning of a surface */
736         char                *remapShader;                   /* ydnar: remap a shader in final stage */
737         char                *deprecateShader;               /* vortex: shader is deprecated and replaced by this on use */
738
739         surfaceModel_t      *surfaceModel;                  /* ydnar: for distribution of models */
740         foliage_t           *foliage;                       /* ydnar/splash damage: wolf et foliage */
741
742         float subdivisions;                                 /* from a "tesssize xxx" */
743         float backsplashFraction;                           /* floating point value, usually 0.05 */
744         float backsplashDistance;                           /* default 16 */
745         float lightSubdivide;                               /* default 999 */
746         float lightFilterRadius;                            /* ydnar: lightmap filtering/blurring radius for lights created by this shader (default: 0) */
747
748         int lightmapSampleSize;                             /* lightmap sample size */
749         float lightmapSampleOffset;                         /* ydnar: lightmap sample offset (default: 1.0) */
750
751         float bounceScale;                                  /* ydnar: radiosity re-emission [0,1.0+] */
752         float offset;                                       /* ydnar: offset in units */
753         float shadeAngleDegrees;                            /* ydnar: breaking angle for smooth shading (degrees) */
754
755         vec3_t mins, maxs;                                  /* ydnar: for particle studio vertexDeform move support */
756
757         qb_t legacyTerrain;                                 /* ydnar: enable legacy terrain crutches */
758         qb_t indexed;                                       /* ydnar: attempt to use indexmap (terrain alphamap style) */
759         qb_t forceMeta;                                     /* ydnar: force metasurface path */
760         qb_t noClip;                                        /* ydnar: don't clip into bsp, preserve original face winding */
761         qb_t noFast;                                        /* ydnar: supress fast lighting for surfaces with this shader */
762         qb_t invert;                                        /* ydnar: reverse facing */
763         qb_t nonplanar;                                     /* ydnar: for nonplanar meta surface merging */
764         qb_t tcGen;                                         /* ydnar: has explicit texcoord generation */
765         vec3_t vecs[ 2 ];                                   /* ydnar: explicit texture vectors for [0,1] texture space */
766         tcMod_t mod;                                        /* ydnar: q3map_tcMod matrix for djbob :) */
767         vec3_t lightmapAxis;                                /* ydnar: explicit lightmap axis projection */
768         colorMod_t          *colorMod;                      /* ydnar: q3map_rgb/color/alpha/Set/Mod support */
769
770         int furNumLayers;                                   /* ydnar: number of fur layers */
771         float furOffset;                                    /* ydnar: offset of each layer */
772         float furFade;                                      /* ydnar: alpha fade amount per layer */
773
774         qb_t splotchFix;                                    /* ydnar: filter splotches on lightmaps */
775
776         qb_t hasPasses;                                     /* false if the shader doesn't define any rendering passes */
777         qb_t globalTexture;                                 /* don't normalize texture repeats */
778         qb_t twoSided;                                      /* cull none */
779         qb_t autosprite;                                    /* autosprite shaders will become point lights instead of area lights */
780         qb_t polygonOffset;                                 /* ydnar: don't face cull this or against this */
781         qb_t patchShadows;                                  /* have patches casting shadows when using -light for this surface */
782         qb_t vertexShadows;                                 /* shadows will be casted at this surface even when vertex lit */
783         qb_t forceSunlight;                                 /* force sun light at this surface even tho we might not calculate shadows in vertex lighting */
784         qb_t notjunc;                                       /* don't use this surface for tjunction fixing */
785         qb_t fogParms;                                      /* ydnar: has fogparms */
786         qb_t noFog;                                         /* ydnar: supress fogging */
787         qb_t clipModel;                                     /* ydnar: solid model hack */
788         qb_t noVertexLight;                                 /* ydnar: leave vertex color alone */
789         qb_t noDirty;                                       /* jal: do not apply the dirty pass to this surface */
790
791         byte styleMarker;                                   /* ydnar: light styles hack */
792
793         float vertexScale;                                  /* vertex light scale */
794
795         char skyParmsImageBase[ MAX_QPATH ];                /* ydnar: for skies */
796
797         char editorImagePath[ MAX_QPATH ];                  /* use this image to generate texture coordinates */
798         char lightImagePath[ MAX_QPATH ];                   /* use this image to generate color / averageColor */
799         char normalImagePath[ MAX_QPATH ];                  /* ydnar: normalmap image for bumpmapping */
800
801         implicitMap_t implicitMap;                          /* ydnar: enemy territory implicit shaders */
802         char implicitImagePath[ MAX_QPATH ];
803
804         image_t             *shaderImage;
805         image_t             *lightImage;
806         image_t             *normalImage;
807
808         float skyLightValue;                                /* ydnar */
809         int skyLightIterations;                             /* ydnar */
810         sun_t               *sun;                           /* ydnar */
811
812         vec3_t color;                                       /* normalized color */
813         vec4_t averageColor;
814         byte lightStyle;
815
816         /* vortex: per-surface floodlight */
817         float floodlightDirectionScale;
818         vec3_t floodlightRGB;
819         float floodlightIntensity;
820         float floodlightDistance;
821
822         qb_t lmMergable;                                    /* ydnar */
823         int lmCustomWidth, lmCustomHeight;                  /* ydnar */
824         float lmBrightness;                                 /* ydnar */
825         float lmFilterRadius;                               /* ydnar: lightmap filtering/blurring radius for this shader (default: 0) */
826
827         int shaderWidth, shaderHeight;                      /* ydnar */
828         float stFlat[ 2 ];
829
830         vec3_t fogDir;                                      /* ydnar */
831
832         char                *shaderText;                    /* ydnar */
833         qb_t custom;
834         qb_t finished;
835 }
836 shaderInfo_t;
837
838
839
840 /* -------------------------------------------------------------------------------
841
842    bsp structures
843
844    ------------------------------------------------------------------------------- */
845
846 typedef struct face_s
847 {
848         struct face_s       *next;
849         int planenum;
850         int priority;
851         //qboolean                      checked;
852         int compileFlags;
853         winding_t           *w;
854 }
855 face_t;
856
857
858 typedef struct plane_s
859 {
860         vec3_t normal;
861         vec_t dist;
862         int type;
863         int counter;
864         int hash_chain;
865 }
866 plane_t;
867
868
869 typedef struct side_s
870 {
871         int planenum;
872
873         int outputNum;                          /* set when the side is written to the file list */
874
875         float texMat[ 2 ][ 3 ];                 /* brush primitive texture matrix */
876         float vecs[ 2 ][ 4 ];                   /* old-style texture coordinate mapping */
877
878         winding_t           *winding;
879         winding_t           *visibleHull;       /* convex hull of all visible fragments */
880
881         shaderInfo_t        *shaderInfo;
882
883         int contentFlags;                       /* from shaderInfo */
884         int surfaceFlags;                       /* from shaderInfo */
885         int compileFlags;                       /* from shaderInfo */
886         int value;                              /* from shaderInfo */
887
888         qboolean visible;                       /* choose visble planes first */
889         qboolean bevel;                         /* don't ever use for bsp splitting, and don't bother making windings for it */
890         qboolean culled;                        /* ydnar: face culling */
891 }
892 side_t;
893
894
895 typedef struct sideRef_s
896 {
897         struct sideRef_s    *next;
898         side_t              *side;
899 }
900 sideRef_t;
901
902
903 /* ydnar: generic index mapping for entities (natural extension of terrain texturing) */
904 typedef struct indexMap_s
905 {
906         int w, h, numLayers;
907         char name[ MAX_QPATH ], shader[ MAX_QPATH ];
908         float offsets[ 256 ];
909         byte                *pixels;
910 }
911 indexMap_t;
912
913
914 typedef struct brush_s
915 {
916         struct brush_s      *next;
917         struct brush_s      *nextColorModBrush; /* ydnar: colorMod volume brushes go here */
918         struct brush_s      *original;          /* chopped up brushes will reference the originals */
919
920         int entityNum, brushNum;                /* editor numbering */
921         int outputNum;                          /* set when the brush is written to the file list */
922
923         /* ydnar: for shadowcasting entities */
924         int castShadows;
925         int recvShadows;
926
927         shaderInfo_t        *contentShader;
928         shaderInfo_t        *celShader;         /* :) */
929
930         /* ydnar: gs mods */
931         int lightmapSampleSize;                 /* jal : entity based _lightmapsamplesize */
932         float lightmapScale;
933         float shadeAngleDegrees;               /* jal : entity based _shadeangle */
934         vec3_t eMins, eMaxs;
935         indexMap_t          *im;
936
937         int contentFlags;
938         int compileFlags;                       /* ydnar */
939         qboolean detail;
940         qboolean opaque;
941
942         int portalareas[ 2 ];
943
944         vec3_t mins, maxs;
945         int numsides;
946
947         side_t sides[ 6 ];                      /* variably sized */
948 }
949 brush_t;
950
951
952 typedef struct fog_s
953 {
954         shaderInfo_t        *si;
955         brush_t             *brush;
956         int visibleSide;                        /* the brush side that ray tests need to clip against (-1 == none) */
957 }
958 fog_t;
959
960
961 typedef struct
962 {
963         int width, height;
964         bspDrawVert_t       *verts;
965 }
966 mesh_t;
967
968
969 typedef struct parseMesh_s
970 {
971         struct parseMesh_s  *next;
972
973         int entityNum, brushNum;                    /* ydnar: editor numbering */
974
975         /* ydnar: for shadowcasting entities */
976         int castShadows;
977         int recvShadows;
978
979         mesh_t mesh;
980         shaderInfo_t        *shaderInfo;
981         shaderInfo_t        *celShader;             /* :) */
982
983         /* jal : entity based _lightmapsamplesize */
984         int lightmapSampleSize;
985         /* ydnar: gs mods */
986         float lightmapScale;
987         vec3_t eMins, eMaxs;
988         indexMap_t          *im;
989
990         /* grouping */
991         qboolean grouped;
992         float longestCurve;
993         int maxIterations;
994 }
995 parseMesh_t;
996
997
998 /*
999     ydnar: the drawsurf struct was extended to allow for:
1000     - non-convex planar surfaces
1001     - non-planar brushface surfaces
1002     - lightmapped terrain
1003     - planar patches
1004  */
1005
1006 typedef enum
1007 {
1008         /* ydnar: these match up exactly with bspSurfaceType_t */
1009         SURFACE_BAD,
1010         SURFACE_FACE,
1011         SURFACE_PATCH,
1012         SURFACE_TRIANGLES,
1013         SURFACE_FLARE,
1014         SURFACE_FOLIAGE,    /* wolf et */
1015
1016         /* ydnar: compiler-relevant surface types */
1017         SURFACE_FORCED_META,
1018         SURFACE_META,
1019         SURFACE_FOGHULL,
1020         SURFACE_DECAL,
1021         SURFACE_SHADER,
1022
1023         NUM_SURFACE_TYPES
1024 }
1025 surfaceType_t;
1026
1027 Q_EXTERN char *surfaceTypes[ NUM_SURFACE_TYPES ]
1028 #ifndef MAIN_C
1029 ;
1030 #else
1031         =
1032         {
1033         "SURFACE_BAD",
1034         "SURFACE_FACE",
1035         "SURFACE_PATCH",
1036         "SURFACE_TRIANGLES",
1037         "SURFACE_FLARE",
1038         "SURFACE_FOLIAGE",
1039         "SURFACE_FORCED_META",
1040         "SURFACE_META",
1041         "SURFACE_FOGHULL",
1042         "SURFACE_DECAL",
1043         "SURFACE_SHADER"
1044         };
1045 #endif
1046
1047
1048 /* ydnar: this struct needs an overhaul (again, heh) */
1049 typedef struct mapDrawSurface_s
1050 {
1051         surfaceType_t type;
1052         qboolean planar;
1053         int outputNum;                          /* ydnar: to match this sort of thing up */
1054
1055         qboolean fur;                           /* ydnar: this is kind of a hack, but hey... */
1056         qboolean skybox;                        /* ydnar: yet another fun hack */
1057         qboolean backSide;                      /* ydnar: q3map_backShader support */
1058
1059         struct mapDrawSurface_s *parent;        /* ydnar: for cloned (skybox) surfaces to share lighting data */
1060         struct mapDrawSurface_s *clone;         /* ydnar: for cloned surfaces */
1061         struct mapDrawSurface_s *cel;           /* ydnar: for cloned cel surfaces */
1062
1063         shaderInfo_t        *shaderInfo;
1064         shaderInfo_t        *celShader;
1065         brush_t             *mapBrush;
1066         parseMesh_t         *mapMesh;
1067         sideRef_t           *sideRef;
1068
1069         int fogNum;
1070
1071         int numVerts;                           /* vertexes and triangles */
1072         bspDrawVert_t       *verts;
1073         int numIndexes;
1074         int                 *indexes;
1075
1076         int planeNum;
1077         vec3_t lightmapOrigin;                  /* also used for flares */
1078         vec3_t lightmapVecs[ 3 ];               /* also used for flares */
1079         int lightStyle;                         /* used for flares */
1080
1081         /* ydnar: per-surface (per-entity, actually) lightmap sample size scaling */
1082         float lightmapScale;
1083
1084         /* jal: per-surface (per-entity, actually) shadeangle */
1085         float shadeAngleDegrees;
1086
1087         /* ydnar: surface classification */
1088         vec3_t mins, maxs;
1089         vec3_t lightmapAxis;
1090         int sampleSize;
1091
1092         /* ydnar: shadow group support */
1093         int castShadows, recvShadows;
1094
1095         /* ydnar: texture coordinate range monitoring for hardware with limited texcoord precision (in texel space) */
1096         float bias[ 2 ];
1097         int texMins[ 2 ], texMaxs[ 2 ], texRange[ 2 ];
1098
1099         /* ydnar: for patches */
1100         float longestCurve;
1101         int maxIterations;
1102         int patchWidth, patchHeight;
1103         vec3_t bounds[ 2 ];
1104
1105         /* ydnar/sd: for foliage */
1106         int numFoliageInstances;
1107
1108         /* ydnar: editor/useful numbering */
1109         int entityNum;
1110         int surfaceNum;
1111 }
1112 mapDrawSurface_t;
1113
1114
1115 typedef struct drawSurfRef_s
1116 {
1117         struct drawSurfRef_s    *nextRef;
1118         int outputNum;
1119 }
1120 drawSurfRef_t;
1121
1122
1123 /* ydnar: metasurfaces are constructed from lists of metatriangles so they can be merged in the best way */
1124 typedef struct metaTriangle_s
1125 {
1126         shaderInfo_t        *si;
1127         side_t              *side;
1128         int entityNum, surfaceNum, planeNum, fogNum, sampleSize, castShadows, recvShadows;
1129         float shadeAngleDegrees;
1130         vec4_t plane;
1131         vec3_t lightmapAxis;
1132         int indexes[ 3 ];
1133 }
1134 metaTriangle_t;
1135
1136
1137 typedef struct epair_s
1138 {
1139         struct epair_s      *next;
1140         char                *key, *value;
1141 }
1142 epair_t;
1143
1144
1145 typedef struct
1146 {
1147         vec3_t origin;
1148         brush_t             *brushes, *lastBrush, *colorModBrushes;
1149         parseMesh_t         *patches;
1150         int mapEntityNum, firstDrawSurf;
1151         int firstBrush, numBrushes;                     /* only valid during BSP compile */
1152         epair_t             *epairs;
1153         vec3_t originbrush_origin;
1154 }
1155 entity_t;
1156
1157
1158 typedef struct node_s
1159 {
1160         /* both leafs and nodes */
1161         int planenum;                       /* -1 = leaf node */
1162         struct node_s       *parent;
1163         vec3_t mins, maxs;                  /* valid after portalization */
1164         brush_t             *volume;        /* one for each leaf/node */
1165
1166         /* nodes only */
1167         side_t              *side;          /* the side that created the node */
1168         struct node_s       *children[ 2 ];
1169         int compileFlags;                   /* ydnar: hint, antiportal */
1170         int tinyportals;
1171         vec3_t referencepoint;
1172
1173         /* leafs only */
1174         qboolean opaque;                    /* view can never be inside */
1175         qboolean areaportal;
1176         qboolean skybox;                    /* ydnar: a skybox leaf */
1177         qboolean sky;                       /* ydnar: a sky leaf */
1178         int cluster;                        /* for portalfile writing */
1179         int area;                           /* for areaportals */
1180         brush_t             *brushlist;     /* fragments of all brushes in this leaf */
1181         drawSurfRef_t       *drawSurfReferences;
1182
1183         int occupied;                       /* 1 or greater can reach entity */
1184         entity_t            *occupant;      /* for leak file testing */
1185
1186         struct portal_s     *portals;       /* also on nodes during construction */
1187
1188         qboolean has_structural_children;
1189 }
1190 node_t;
1191
1192
1193 typedef struct portal_s
1194 {
1195         plane_t plane;
1196         node_t              *onnode;        /* NULL = outside box */
1197         node_t              *nodes[ 2 ];    /* [ 0 ] = front side of plane */
1198         struct portal_s     *next[ 2 ];
1199         winding_t           *winding;
1200
1201         qboolean sidefound;                 /* false if ->side hasn't been checked */
1202         int compileFlags;                   /* from original face that caused the split */
1203         side_t              *side;          /* NULL = non-visible */
1204 }
1205 portal_t;
1206
1207
1208 typedef struct
1209 {
1210         node_t              *headnode;
1211         node_t outside_node;
1212         vec3_t mins, maxs;
1213 }
1214 tree_t;
1215
1216
1217
1218 /* -------------------------------------------------------------------------------
1219
1220    vis structures
1221
1222    ------------------------------------------------------------------------------- */
1223
1224 typedef struct
1225 {
1226         vec3_t normal;
1227         float dist;
1228 }
1229 visPlane_t;
1230
1231
1232 typedef struct
1233 {
1234         int numpoints;
1235         vec3_t points[ MAX_POINTS_ON_FIXED_WINDING ];                   /* variable sized */
1236 }
1237 fixedWinding_t;
1238
1239
1240 typedef struct passage_s
1241 {
1242         struct passage_s    *next;
1243         byte cansee[ 1 ];                   /* all portals that can be seen through this passage */
1244 } passage_t;
1245
1246
1247 typedef enum
1248 {
1249         stat_none,
1250         stat_working,
1251         stat_done
1252 }
1253 vstatus_t;
1254
1255
1256 typedef struct
1257 {
1258         int num;
1259         qboolean hint;                      /* true if this portal was created from a hint splitter */
1260         qboolean sky;                       /* true if this portal belongs to a sky leaf */
1261         qboolean removed;
1262         visPlane_t plane;                   /* normal pointing into neighbor */
1263         int leaf;                           /* neighbor */
1264
1265         vec3_t origin;                      /* for fast clip testing */
1266         float radius;
1267
1268         fixedWinding_t      *winding;
1269         vstatus_t status;
1270         byte                *portalfront;   /* [portals], preliminary */
1271         byte                *portalflood;   /* [portals], intermediate */
1272         byte                *portalvis;     /* [portals], final */
1273
1274         int nummightsee;                    /* bit count on portalflood for sort */
1275         passage_t           *passages;      /* there are just as many passages as there */
1276                                             /* are portals in the leaf this portal leads */
1277 }
1278 vportal_t;
1279
1280
1281 typedef struct leaf_s
1282 {
1283         int numportals;
1284         int merged;
1285         vportal_t           *portals[MAX_PORTALS_ON_LEAF];
1286 }
1287 leaf_t;
1288
1289
1290 typedef struct pstack_s
1291 {
1292         byte mightsee[ MAX_PORTALS / 8 ];
1293         struct pstack_s     *next;
1294         leaf_t              *leaf;
1295         vportal_t           *portal;        /* portal exiting */
1296         fixedWinding_t      *source;
1297         fixedWinding_t      *pass;
1298
1299         fixedWinding_t windings[ 3 ];       /* source, pass, temp in any order */
1300         int freewindings[ 3 ];
1301
1302         visPlane_t portalplane;
1303         int depth;
1304 #ifdef SEPERATORCACHE
1305         visPlane_t seperators[ 2 ][ MAX_SEPERATORS ];
1306         int numseperators[ 2 ];
1307 #endif
1308 }
1309 pstack_t;
1310
1311
1312 typedef struct
1313 {
1314         vportal_t           *base;
1315         int c_chains;
1316         pstack_t pstack_head;
1317 }
1318 threaddata_t;
1319
1320
1321
1322 /* -------------------------------------------------------------------------------
1323
1324    light structures
1325
1326    ------------------------------------------------------------------------------- */
1327
1328 /* ydnar: new light struct with flags */
1329 typedef struct light_s
1330 {
1331         struct light_s      *next;
1332
1333         int type;
1334         int flags;                          /* ydnar: condensed all the booleans into one flags int */
1335         shaderInfo_t        *si;
1336
1337         vec3_t origin;
1338         vec3_t normal;                      /* for surfaces, spotlights, and suns */
1339         float dist;                         /* plane location along normal */
1340
1341         float photons;
1342         int style;
1343         vec3_t color;
1344         float radiusByDist;                 /* for spotlights */
1345         float fade;                         /* ydnar: from wolf, for linear lights */
1346         float angleScale;                   /* ydnar: stolen from vlight for K */
1347         float extraDist;                    /* "extra dimension" distance of the light, to kill hot spots */
1348
1349         float add;                          /* ydnar: used for area lights */
1350         float envelope;                     /* ydnar: units until falloff < tolerance */
1351         float envelope2;                    /* ydnar: envelope squared (tiny optimization) */
1352         vec3_t mins, maxs;                  /* ydnar: pvs envelope */
1353         int cluster;                        /* ydnar: cluster light falls into */
1354
1355         winding_t           *w;
1356         vec3_t emitColor;                   /* full out-of-gamut value */
1357
1358         float falloffTolerance;                 /* ydnar: minimum attenuation threshold */
1359         float filterRadius;                 /* ydnar: lightmap filter radius in world units, 0 == default */
1360 }
1361 light_t;
1362
1363
1364 typedef struct
1365 {
1366         /* constant input */
1367         qboolean testOcclusion, forceSunlight, testAll;
1368         int recvShadows;
1369
1370         int numSurfaces;
1371         int                 *surfaces;
1372
1373         int numLights;
1374         light_t             **lights;
1375
1376         qboolean twoSided;
1377
1378         /* per-sample input */
1379         int cluster;
1380         vec3_t origin, normal;
1381         vec_t inhibitRadius;                /* sphere in which occluding geometry is ignored */
1382
1383         /* per-light input */
1384         light_t             *light;
1385         vec3_t end;
1386
1387         /* calculated input */
1388         vec3_t displacement, direction;
1389         vec_t distance;
1390
1391         /* input and output */
1392         vec3_t color;                       /* starts out at full color, may be reduced if transparent surfaces are crossed */
1393         vec3_t colorNoShadow;               /* result color with no shadow casting */
1394         vec3_t directionContribution;              /* result contribution to the deluxe map */
1395
1396         /* output */
1397         vec3_t hit;
1398         int compileFlags;                   /* for determining surface compile flags traced through */
1399         qboolean passSolid;
1400         qboolean opaque;
1401         vec_t forceSubsampling;           /* needs subsampling (alphashadow), value = max color contribution possible from it */
1402
1403         /* working data */
1404         int numTestNodes;
1405         int testNodes[ MAX_TRACE_TEST_NODES ];
1406 }
1407 trace_t;
1408
1409
1410
1411 /* must be identical to bspDrawVert_t except for float color! */
1412 typedef struct
1413 {
1414         vec3_t xyz;
1415         float st[ 2 ];
1416         float lightmap[ MAX_LIGHTMAPS ][ 2 ];
1417         vec3_t normal;
1418         float color[ MAX_LIGHTMAPS ][ 4 ];
1419 }
1420 radVert_t;
1421
1422
1423 typedef struct
1424 {
1425         int numVerts;
1426         radVert_t verts[ MAX_POINTS_ON_WINDING ];
1427 }
1428 radWinding_t;
1429
1430
1431 /* crutch for poor local allocations in win32 smp */
1432 typedef struct
1433 {
1434         vec_t dists[ MAX_POINTS_ON_WINDING + 4 ];
1435         int sides[ MAX_POINTS_ON_WINDING + 4 ];
1436 }
1437 clipWork_t;
1438
1439
1440 /* ydnar: new lightmap handling code */
1441 typedef struct outLightmap_s
1442 {
1443         int lightmapNum, extLightmapNum;
1444         int customWidth, customHeight;
1445         int numLightmaps;
1446         int freeLuxels;
1447         int numShaders;
1448         shaderInfo_t        *shaders[ MAX_LIGHTMAP_SHADERS ];
1449         byte                *lightBits;
1450         byte                *bspLightBytes;
1451         byte                *bspDirBytes;
1452 }
1453 outLightmap_t;
1454
1455
1456 typedef struct rawLightmap_s
1457 {
1458         qboolean finished, splotchFix, wrap[ 2 ];
1459         int customWidth, customHeight;
1460         float brightness;
1461         float filterRadius;
1462
1463         int firstLightSurface, numLightSurfaces;                        /* index into lightSurfaces */
1464         int numLightClusters, *lightClusters;
1465
1466         int sampleSize, actualSampleSize, axisNum;
1467
1468         /* vortex: per-surface floodlight */
1469         float floodlightDirectionScale;
1470         vec3_t floodlightRGB;
1471         float floodlightIntensity;
1472         float floodlightDistance;
1473
1474         int entityNum;
1475         int recvShadows;
1476         vec3_t mins, maxs, axis, origin, *vecs;
1477         float                   *plane;
1478         int w, h, sw, sh, used;
1479
1480         qboolean solid[ MAX_LIGHTMAPS ];
1481         vec3_t solidColor[ MAX_LIGHTMAPS ];
1482
1483         int numStyledTwins;
1484         struct rawLightmap_s    *twins[ MAX_LIGHTMAPS ];
1485
1486         int outLightmapNums[ MAX_LIGHTMAPS ];
1487         int twinNums[ MAX_LIGHTMAPS ];
1488         int lightmapX[ MAX_LIGHTMAPS ], lightmapY[ MAX_LIGHTMAPS ];
1489         byte styles[ MAX_LIGHTMAPS ];
1490         float                   *bspLuxels[ MAX_LIGHTMAPS ];
1491         float                   *radLuxels[ MAX_LIGHTMAPS ];
1492         float                   *superLuxels[ MAX_LIGHTMAPS ];
1493         unsigned char               *superFlags;
1494         float                   *superOrigins;
1495         float                   *superNormals;
1496         int                     *superClusters;
1497
1498         float                   *superDeluxels; /* average light direction */
1499         float                   *bspDeluxels;
1500         float                   *superFloodLight;
1501 }
1502 rawLightmap_t;
1503
1504
1505 typedef struct rawGridPoint_s
1506 {
1507         vec3_t ambient[ MAX_LIGHTMAPS ];
1508         vec3_t directed[ MAX_LIGHTMAPS ];
1509         vec3_t dir;
1510         byte styles[ MAX_LIGHTMAPS ];
1511 }
1512 rawGridPoint_t;
1513
1514
1515 typedef struct surfaceInfo_s
1516 {
1517         int modelindex;
1518         shaderInfo_t        *si;
1519         rawLightmap_t       *lm;
1520         int parentSurfaceNum, childSurfaceNum;
1521         int entityNum, castShadows, recvShadows, sampleSize, patchIterations;
1522         float longestCurve;
1523         float               *plane;
1524         vec3_t axis, mins, maxs;
1525         qboolean hasLightmap, approximated;
1526         int firstSurfaceCluster, numSurfaceClusters;
1527 }
1528 surfaceInfo_t;
1529
1530 /* -------------------------------------------------------------------------------
1531
1532    prototypes
1533
1534    ------------------------------------------------------------------------------- */
1535
1536 /* main.c */
1537 vec_t                       Random( void );
1538 char                        *Q_strncpyz( char *dst, const char *src, size_t len );
1539 char                        *Q_strcat( char *dst, size_t dlen, const char *src );
1540 char                        *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen );
1541 int                         ShiftBSPMain( int argc, char **argv );
1542
1543 /* help.c */
1544 void                        HelpMain(const char* arg);
1545
1546 /* path_init.c */
1547 game_t                      *GetGame( char *arg );
1548 void                        InitPaths( int *argc, char **argv );
1549
1550
1551 /* fixaas.c */
1552 int                         FixAASMain( int argc, char **argv );
1553
1554
1555 /* bsp.c */
1556 int                         BSPMain( int argc, char **argv );
1557
1558
1559 /* bsp_analyze.c */
1560 int                         AnalyzeBSPMain( int argc, char **argv );
1561
1562
1563 /* bsp_info.c */
1564 int                         BSPInfoMain( int count, char **fileNames );
1565
1566 /* bsp_scale.c */
1567 int                         ScaleBSPMain( int argc, char **argv );
1568
1569 /* minimap.c */
1570 int                         MiniMapBSPMain( int argc, char **argv );
1571
1572 /* convert_bsp.c */
1573 int                         ConvertBSPMain( int argc, char **argv );
1574
1575
1576 /* convert_map.c */
1577 int                         ConvertBSPToMap( char *bspName );
1578 int                         ConvertBSPToMap_BP( char *bspName );
1579
1580 /* convert_ase.c */
1581 int                         ConvertBSPToASE( char *bspName );
1582
1583 /* convert_obj.c */
1584 int                         ConvertBSPToOBJ( char *bspName );
1585
1586 /* brush.c */
1587 sideRef_t                   *AllocSideRef( side_t *side, sideRef_t *next );
1588 int                         CountBrushList( brush_t *brushes );
1589 brush_t                     *AllocBrush( int numsides );
1590 void                        FreeBrush( brush_t *brushes );
1591 void                        FreeBrushList( brush_t *brushes );
1592 brush_t                     *CopyBrush( brush_t *brush );
1593 qboolean                    BoundBrush( brush_t *brush );
1594 qboolean                    CreateBrushWindings( brush_t *brush );
1595 brush_t                     *BrushFromBounds( vec3_t mins, vec3_t maxs );
1596 vec_t                       BrushVolume( brush_t *brush );
1597 void                        WriteBSPBrushMap( char *name, brush_t *list );
1598
1599 void                        FilterDetailBrushesIntoTree( entity_t *e, tree_t *tree );
1600 void                        FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree );
1601
1602 int                         BoxOnPlaneSide( vec3_t mins, vec3_t maxs, plane_t *plane );
1603 qboolean                    WindingIsTiny( winding_t *w );
1604
1605 void                        SplitBrush( brush_t *brush, int planenum, brush_t **front, brush_t **back );
1606
1607 tree_t                      *AllocTree( void );
1608 node_t                      *AllocNode( void );
1609
1610
1611 /* mesh.c */
1612 void                        LerpDrawVert( bspDrawVert_t *a, bspDrawVert_t *b, bspDrawVert_t *out );
1613 void                        LerpDrawVertAmount( bspDrawVert_t *a, bspDrawVert_t *b, float amount, bspDrawVert_t *out );
1614 void                        FreeMesh( mesh_t *m );
1615 mesh_t                      *CopyMesh( mesh_t *mesh );
1616 void                        PrintMesh( mesh_t *m );
1617 mesh_t                      *TransposeMesh( mesh_t *in );
1618 void                        InvertMesh( mesh_t *m );
1619 mesh_t                      *SubdivideMesh( mesh_t in, float maxError, float minLength );
1620 int                         IterationsForCurve( float len, int subdivisions );
1621 mesh_t                      *SubdivideMesh2( mesh_t in, int iterations );
1622 mesh_t                      *SubdivideMeshQuads( mesh_t *in, float minLength, int maxsize, int *widthtable, int *heighttable );
1623 mesh_t                      *RemoveLinearMeshColumnsRows( mesh_t *in );
1624 void                        MakeMeshNormals( mesh_t in );
1625 void                        PutMeshOnCurve( mesh_t in );
1626
1627 void                        MakeNormalVectors( vec3_t forward, vec3_t right, vec3_t up );
1628
1629
1630 /* map.c */
1631 void                        LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups );
1632 int                         FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points );
1633 qboolean                                        PlaneEqual( plane_t *p, vec3_t normal, vec_t dist );
1634 int                         PlaneTypeForNormal( vec3_t normal );
1635 void                        AddBrushBevels( void );
1636 brush_t                     *FinishBrush( qboolean noCollapseGroups );
1637
1638
1639 /* portals.c */
1640 void                        MakeHeadnodePortals( tree_t *tree );
1641 void                        MakeNodePortal( node_t *node );
1642 void                        SplitNodePortals( node_t *node );
1643
1644 qboolean                    PortalPassable( portal_t *p );
1645
1646 #define FLOODENTITIES_LEAKED 1
1647 #define FLOODENTITIES_GOOD 0
1648 #define FLOODENTITIES_EMPTY -1
1649 int                     FloodEntities( tree_t *tree );
1650 void                        FillOutside( node_t *headnode );
1651 void                        FloodAreas( tree_t *tree );
1652 face_t                      *VisibleFaces( entity_t *e, tree_t *tree );
1653 void                        FreePortal( portal_t *p );
1654
1655 void                        MakeTreePortals( tree_t *tree );
1656
1657
1658 /* leakfile.c */
1659 xmlNodePtr                  LeakFile( tree_t *tree, const char *lineFilePath );
1660
1661
1662 /* prtfile.c */
1663 void                        NumberClusters( tree_t *tree );
1664 void                        WritePortalFile( tree_t *tree, const char *portalFilePath );
1665
1666
1667 /* writebsp.c */
1668 void                        SetModelNumbers( void );
1669 void                        SetLightStyles( void );
1670
1671 int                         EmitShader( const char *shader, int *contentFlags, int *surfaceFlags );
1672
1673 void                        BeginBSPFile( void );
1674 void                        EndBSPFile( qboolean do_write, const char *BSPFilePath, const char *surfaceFilePath );
1675 void                        EmitBrushes( brush_t *brushes, int *firstBrush, int *numBrushes );
1676 void                        EmitFogs( void );
1677
1678 void                        BeginModel( void );
1679 void                        EndModel( entity_t *e, node_t *headnode );
1680
1681
1682 /* tree.c */
1683 void                        FreeTree( tree_t *tree );
1684 void                        FreeTree_r( node_t *node );
1685 void                        PrintTree_r( node_t *node, int depth );
1686 void                        FreeTreePortals_r( node_t *node );
1687
1688
1689 /* patch.c */
1690 void                        ParsePatch( qboolean onlyLights );
1691 mesh_t                      *SubdivideMesh( mesh_t in, float maxError, float minLength );
1692 void                        PatchMapDrawSurfs( entity_t *e );
1693 void                        TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds );
1694
1695
1696 /* tjunction.c */
1697 void                        FixTJunctions( entity_t *e );
1698
1699
1700 /* fog.c */
1701 winding_t                   *WindingFromDrawSurf( mapDrawSurface_t *ds );
1702 void                        FogDrawSurfaces( entity_t *e );
1703 int                         FogForPoint( vec3_t point, float epsilon );
1704 int                         FogForBounds( vec3_t mins, vec3_t maxs, float epsilon );
1705 void                        CreateMapFogs( void );
1706
1707
1708 /* facebsp.c */
1709 face_t                      *MakeStructuralBSPFaceList( brush_t *list );
1710 face_t                      *MakeVisibleBSPFaceList( brush_t *list );
1711 tree_t                      *FaceBSP( face_t *list );
1712
1713
1714 /* model.c */
1715 void                        PicoPrintFunc( int level, const char *str );
1716 void                        PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize );
1717 picoModel_t                 *FindModel( const char *name, int frame );
1718 picoModel_t                 *LoadModel( const char *name, int frame );
1719 void                        InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, float clipDepth );
1720 void                        AddTriangleModels( entity_t *e );
1721
1722
1723 /* surface.c */
1724 mapDrawSurface_t            *AllocDrawSurface( surfaceType_t type );
1725 void                        FinishSurface( mapDrawSurface_t *ds );
1726 void                        StripFaceSurface( mapDrawSurface_t *ds );
1727 void                        MaxAreaFaceSurface( mapDrawSurface_t *ds );
1728 qboolean                    CalcSurfaceTextureRange( mapDrawSurface_t *ds );
1729 qboolean                    CalcLightmapAxis( vec3_t normal, vec3_t axis );
1730 void                        ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds );
1731 void                        ClassifyEntitySurfaces( entity_t *e );
1732 void                        TidyEntitySurfaces( entity_t *e );
1733 mapDrawSurface_t            *CloneSurface( mapDrawSurface_t *src, shaderInfo_t *si );
1734 mapDrawSurface_t            *MakeCelSurface( mapDrawSurface_t *src, shaderInfo_t *si );
1735 qboolean                    IsTriangleDegenerate( bspDrawVert_t *points, int a, int b, int c );
1736 void                        ClearSurface( mapDrawSurface_t *ds );
1737 void                        AddEntitySurfaceModels( entity_t *e );
1738 mapDrawSurface_t            *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, winding_t *w );
1739 mapDrawSurface_t            *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh );
1740 mapDrawSurface_t            *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal, vec3_t color, const char *flareShader, int lightStyle );
1741 mapDrawSurface_t            *DrawSurfaceForShader( char *shader );
1742 void                        ClipSidesIntoTree( entity_t *e, tree_t *tree );
1743 void                        MakeDebugPortalSurfs( tree_t *tree );
1744 void                        MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader );
1745 void                        SubdivideFaceSurfaces( entity_t *e, tree_t *tree );
1746 void                        AddEntitySurfaceModels( entity_t *e );
1747 int                         AddSurfaceModels( mapDrawSurface_t *ds );
1748 void                        FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree );
1749 void                        EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds );
1750 void                        EmitTriangleSurface( mapDrawSurface_t *ds );
1751
1752
1753 /* surface_fur.c */
1754 void                        Fur( mapDrawSurface_t *src );
1755
1756
1757 /* surface_foliage.c */
1758 void                        Foliage( mapDrawSurface_t *src );
1759
1760
1761 /* ydnar: surface_meta.c */
1762 void                        ClearMetaTriangles( void );
1763 int                         FindMetaTriangle( metaTriangle_t *src, bspDrawVert_t *a, bspDrawVert_t *b, bspDrawVert_t *c, int planeNum );
1764 void                        MakeEntityMetaTriangles( entity_t *e );
1765 void                        FixMetaTJunctions( void );
1766 void                        SmoothMetaTriangles( void );
1767 void                        MergeMetaTriangles( void );
1768 void                        EmitMetaStats(); // vortex: print meta statistics even in no-verbose mode
1769
1770
1771 /* surface_extra.c */
1772 void                        SetDefaultSampleSize( int sampleSize );
1773
1774 void                        SetSurfaceExtra( mapDrawSurface_t *ds, int num );
1775
1776 shaderInfo_t                *GetSurfaceExtraShaderInfo( int num );
1777 int                         GetSurfaceExtraParentSurfaceNum( int num );
1778 int                         GetSurfaceExtraEntityNum( int num );
1779 int                         GetSurfaceExtraCastShadows( int num );
1780 int                         GetSurfaceExtraRecvShadows( int num );
1781 int                         GetSurfaceExtraSampleSize( int num );
1782 int                         GetSurfaceExtraMinSampleSize( int num );
1783 float                       GetSurfaceExtraLongestCurve( int num );
1784 void                        GetSurfaceExtraLightmapAxis( int num, vec3_t lightmapAxis );
1785
1786 void                        WriteSurfaceExtraFile( const char *surfaceFilePath );
1787 void                        LoadSurfaceExtraFile( const char *surfaceFilePath );
1788
1789
1790 /* decals.c */
1791 void                        ProcessDecals( void );
1792 void                        MakeEntityDecals( entity_t *e );
1793
1794 /* map.c */
1795 void                        TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv );
1796
1797 /* brush_primit.c */
1798 void                        ComputeAxisBase( vec3_t normal, vec3_t texX, vec3_t texY );
1799
1800
1801 /* vis.c */
1802 fixedWinding_t              *NewFixedWinding( int points );
1803 int                         VisMain( int argc, char **argv );
1804
1805 /* visflow.c */
1806 int                         CountBits( byte *bits, int numbits );
1807 void                        PassageFlow( int portalnum );
1808 void                        CreatePassages( int portalnum );
1809 void                        PassageMemory( void );
1810 void                        BasePortalVis( int portalnum );
1811 void                        BetterPortalVis( int portalnum );
1812 void                        PortalFlow( int portalnum );
1813 void                        PassagePortalFlow( int portalnum );
1814
1815
1816
1817 /* light.c  */
1818 float                       PointToPolygonFormFactor( const vec3_t point, const vec3_t normal, const winding_t *w );
1819 int                         LightContributionToSample( trace_t *trace );
1820 void LightingAtSample( trace_t * trace, byte styles[ MAX_LIGHTMAPS ], vec3_t colors[ MAX_LIGHTMAPS ] );
1821 int                         LightContributionToPoint( trace_t *trace );
1822 int                         LightMain( int argc, char **argv );
1823
1824
1825 /* light_trace.c */
1826 void                        SetupTraceNodes( void );
1827 void                        TraceLine( trace_t *trace );
1828 float                       SetupTrace( trace_t *trace );
1829
1830
1831 /* light_bounce.c */
1832 qboolean RadSampleImage( byte * pixels, int width, int height, float st[ 2 ], float color[ 4 ] );
1833 void                        RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
1834 void                        RadLightForPatch( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
1835 void                        RadCreateDiffuseLights( void );
1836 void                        RadFreeLights();
1837
1838
1839 /* light_ydnar.c */
1840 void                        ColorToBytes( const float *color, byte *colorBytes, float scale );
1841 void                        ColorToBytesNonZero( const float *color, byte *colorBytes, float scale );
1842 void                        SmoothNormals( void );
1843
1844 void                        MapRawLightmap( int num );
1845
1846 void                        SetupDirt();
1847 float                       DirtForSample( trace_t *trace );
1848 void                        DirtyRawLightmap( int num );
1849
1850 void                        SetupFloodLight();
1851 void                        FloodlightRawLightmaps();
1852 void                        FloodlightIlluminateLightmap( rawLightmap_t *lm );
1853 float                       FloodLightForSample( trace_t *trace, float floodLightDistance, qboolean floodLightLowQuality );
1854 void                        FloodLightRawLightmap( int num );
1855
1856 void                        IlluminateRawLightmap( int num );
1857 void                        IlluminateVertexes( int num );
1858
1859 void                        SetupBrushesFlags( unsigned int mask_any, unsigned int test_any, unsigned int mask_all, unsigned int test_all );
1860 void                        SetupBrushes( void );
1861 void                        SetupClusters( void );
1862 qboolean                    ClusterVisible( int a, int b );
1863 qboolean                    ClusterVisibleToPoint( vec3_t point, int cluster );
1864 int                         ClusterForPoint( vec3_t point );
1865 int                         ClusterForPointExt( vec3_t point, float epsilon );
1866 int                         ClusterForPointExtFilter( vec3_t point, float epsilon, int numClusters, int *clusters );
1867 int                         ShaderForPointInLeaf( vec3_t point, int leafNum, float epsilon, int wantContentFlags, int wantSurfaceFlags, int *contentFlags, int *surfaceFlags );
1868 void                        SetupEnvelopes( qboolean forGrid, qboolean fastFlag );
1869 void                        FreeTraceLights( trace_t *trace );
1870 void                        CreateTraceLightsForBounds( vec3_t mins, vec3_t maxs, vec3_t normal, int numClusters, int *clusters, int flags, trace_t *trace );
1871 void                        CreateTraceLightsForSurface( int num, trace_t *trace );
1872
1873
1874 /* lightmaps_ydnar.c */
1875 void                        ExportLightmaps( void );
1876
1877 int                         ExportLightmapsMain( int argc, char **argv );
1878 int                         ImportLightmapsMain( int argc, char **argv );
1879
1880 void                        SetupSurfaceLightmaps( void );
1881 void                        StitchSurfaceLightmaps( void );
1882 void                        StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal );
1883
1884
1885 /* exportents.c */
1886 void                        ExportEntities( void );
1887 int                         ExportEntitiesMain( int argc, char **argv );
1888
1889
1890 /* image.c */
1891 void                        ImageFree( image_t *image );
1892 image_t                     *ImageFind( const char *filename );
1893 image_t                     *ImageLoad( const char *filename );
1894
1895
1896 /* shaders.c */
1897 void                        ColorMod( colorMod_t *am, int numVerts, bspDrawVert_t *drawVerts );
1898
1899 void TCMod( tcMod_t mod, float st[ 2 ] );
1900 void                        TCModIdentity( tcMod_t mod );
1901 void                        TCModMultiply( tcMod_t a, tcMod_t b, tcMod_t out );
1902 void                        TCModTranslate( tcMod_t mod, float s, float t );
1903 void                        TCModScale( tcMod_t mod, float s, float t );
1904 void                        TCModRotate( tcMod_t mod, float euler );
1905
1906 qboolean                    ApplySurfaceParm( char *name, int *contentFlags, int *surfaceFlags, int *compileFlags );
1907
1908 void                        BeginMapShaderFile( const char *mapFile );
1909 void                        WriteMapShaderFile( void );
1910 shaderInfo_t                *CustomShader( shaderInfo_t *si, char *find, char *replace );
1911 void                        EmitVertexRemapShader( char *from, char *to );
1912
1913 void                        LoadShaderInfo( void );
1914 shaderInfo_t                *ShaderInfoForShader( const char *shader );
1915 shaderInfo_t                *ShaderInfoForShaderNull( const char *shader );
1916
1917
1918 /* bspfile_abstract.c */
1919 void                        SetGridPoints( int n );
1920 void                        SetDrawVerts( int n );
1921 void                        IncDrawVerts();
1922 void                        SetDrawSurfaces( int n );
1923 void                        SetDrawSurfacesBuffer();
1924 void                        BSPFilesCleanup();
1925
1926 void                        SwapBlock( int *block, int size );
1927
1928 int                         GetLumpElements( bspHeader_t *header, int lump, int size );
1929 void                        *GetLump( bspHeader_t *header, int lump );
1930 int                         CopyLump( bspHeader_t *header, int lump, void *dest, int size );
1931 int                         CopyLump_Allocate( bspHeader_t *header, int lump, void **dest, int size, int *allocationVariable );
1932 void                        AddLump( FILE *file, bspHeader_t *header, int lumpNum, const void *data, int length );
1933
1934 void                        LoadBSPFile( const char *filename );
1935 void                        PartialLoadBSPFile( const char *filename );
1936 void                        WriteBSPFile( const char *filename );
1937 void                        PrintBSPFileSizes( void );
1938
1939 void                        WriteTexFile( char *name );
1940 void                        LoadSurfaceFlags( char *filename );
1941 int                         GetSurfaceParm( const char *tex );
1942 void                        RestoreSurfaceFlags( char *filename );
1943
1944 epair_t                     *ParseEPair( void );
1945 void                        ParseEntities( void );
1946 void                        UnparseEntities( void );
1947 void                        PrintEntity( const entity_t *ent );
1948 void                        SetKeyValue( entity_t *ent, const char *key, const char *value );
1949 qboolean                    KeyExists( const entity_t *ent, const char *key ); /* VorteX: check if key exists */
1950 const char                  *ValueForKey( const entity_t *ent, const char *key );
1951 int                         IntForKey( const entity_t *ent, const char *key );
1952 vec_t                       FloatForKey( const entity_t *ent, const char *key );
1953 qboolean                    GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec );
1954 entity_t                    *FindTargetEntity( const char *target );
1955 void                        GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows );
1956 void InjectCommandLine( char **argv, int beginArgs, int endArgs );
1957
1958
1959
1960 /* bspfile_ibsp.c */
1961 void                        LoadIBSPFile( const char *filename );
1962 void                        WriteIBSPFile( const char *filename );
1963 void                                            PartialLoadIBSPFile( const char *filename );
1964
1965
1966
1967 /* bspfile_rbsp.c */
1968 void                        LoadRBSPFile( const char *filename );
1969 void                        WriteRBSPFile( const char *filename );
1970
1971
1972
1973 /* -------------------------------------------------------------------------------
1974
1975    bsp/general global variables
1976
1977    ------------------------------------------------------------------------------- */
1978
1979 /* game support */
1980 Q_EXTERN game_t games[]
1981 #ifndef MAIN_C
1982 ;
1983 #else
1984         =
1985         {
1986                                                                 #include "game_quake3.h"
1987         ,
1988                                                                 #include "game_nexuiz.h" /* must be after game_quake3.h as they share defines! */
1989         ,
1990                                                                 #include "game_oa.h" /* must be after game_quake3.h as they share defines! */
1991         ,
1992                                                                 #include "game_q3rally.h" /* must be after game_quake3.h as they share defines! */
1993         ,
1994                                                                 #include "game_quakelive.h" /* must be after game_quake3.h as they share defines! */
1995         ,
1996                                                                 #include "game_reaction.h" /* must be after game_quake3.h */
1997         ,
1998                                                                 #include "game_smokinguns.h" /* must be after game_quake3.h */
1999         ,
2000                                                                 #include "game_tremulous.h" /*LinuxManMikeC: must be after game_quake3.h, depends on #define's set in it */
2001         ,
2002                                                                 #include "game_unvanquished.h" /* must be after game_tremulous.h as they share defines! */
2003         ,
2004                                                                 #include "game_wop.h" /* must be after game_quake3.h as they share defines! */
2005         ,
2006                                                                 #include "game_xonotic.h" /* must be after game_quake3.h as they share defines! */
2007         ,
2008                                                                 #include "game_tenebrae.h"
2009         ,
2010                                                                 #include "game_wolf.h"
2011         ,
2012                                                                 #include "game_wolfet.h" /* must be after game_wolf.h as they share defines! */
2013         ,
2014                                                                 #include "game_etut.h"
2015         ,
2016                                                                 #include "game_ef.h"
2017         ,
2018                                                                 #include "game_sof2.h"
2019         ,
2020                                                                 #include "game_jk2.h"   /* must be after game_sof2.h as they share defines! */
2021         ,
2022                                                                 #include "game_ja.h"    /* must be after game_jk2.h as they share defines! */
2023         ,
2024                                                                 #include "game_qfusion.h"   /* qfusion game */
2025         ,
2026                                                                 #include "game_warsow.h" /* must be after game_qfusion.h as they share defines! */
2027         ,
2028                                                                 #include "game_warfork.h" /* must be after game_qfusion.h as they share defines! */
2029         ,
2030                                                                 #include "game_darkplaces.h" /* darkplaces q1 engine */
2031         ,
2032                                                                 #include "game_dq.h" /* deluxe quake game ( darkplaces q1 engine) */
2033         ,
2034                                                                 #include "game_prophecy.h"  /* vortex: prophecy game ( darkplaces q1 engine) */
2035         ,
2036                                                                 #include "game__null.h" /* null game (must be last item) */
2037         };
2038 #endif
2039 Q_EXTERN game_t             *game Q_ASSIGN( &games[ 0 ] );
2040
2041
2042 /* general */
2043 Q_EXTERN int numImages Q_ASSIGN( 0 );
2044 Q_EXTERN image_t images[ MAX_IMAGES ];
2045
2046 Q_EXTERN int numPicoModels Q_ASSIGN( 0 );
2047 Q_EXTERN picoModel_t        *picoModels[ MAX_MODELS ];
2048
2049 Q_EXTERN shaderInfo_t       *shaderInfo Q_ASSIGN( NULL );
2050 Q_EXTERN int numShaderInfo Q_ASSIGN( 0 );
2051 Q_EXTERN int numVertexRemaps Q_ASSIGN( 0 );
2052
2053 Q_EXTERN surfaceParm_t custSurfaceParms[ MAX_CUST_SURFACEPARMS ];
2054 Q_EXTERN int numCustSurfaceParms Q_ASSIGN( 0 );
2055
2056 Q_EXTERN char mapName[ MAX_QPATH ];                 /* ydnar: per-map custom shaders for larger lightmaps */
2057 Q_EXTERN char mapShaderFile[ 1024 ];
2058 Q_EXTERN qboolean warnImage Q_ASSIGN( qtrue );
2059
2060 /* ydnar: sinusoid samples */
2061 Q_EXTERN float jitters[ MAX_JITTERS ];
2062
2063 /*can't code*/
2064 Q_EXTERN qboolean doingBSP Q_ASSIGN( qfalse );
2065
2066 /* commandline arguments */
2067 Q_EXTERN qboolean verboseEntities Q_ASSIGN( qfalse );
2068 Q_EXTERN qboolean force Q_ASSIGN( qfalse );
2069 Q_EXTERN qboolean infoMode Q_ASSIGN( qfalse );
2070 Q_EXTERN qboolean useCustomInfoParms Q_ASSIGN( qfalse );
2071 Q_EXTERN qboolean noprune Q_ASSIGN( qfalse );
2072 Q_EXTERN qboolean leaktest Q_ASSIGN( qfalse );
2073 Q_EXTERN qboolean nodetail Q_ASSIGN( qfalse );
2074 Q_EXTERN qboolean nosubdivide Q_ASSIGN( qfalse );
2075 Q_EXTERN qboolean notjunc Q_ASSIGN( qfalse );
2076 Q_EXTERN qboolean fulldetail Q_ASSIGN( qfalse );
2077 Q_EXTERN qboolean nowater Q_ASSIGN( qfalse );
2078 Q_EXTERN qboolean noCurveBrushes Q_ASSIGN( qfalse );
2079 Q_EXTERN qboolean fakemap Q_ASSIGN( qfalse );
2080 Q_EXTERN qboolean coplanar Q_ASSIGN( qfalse );
2081 Q_EXTERN qboolean nofog Q_ASSIGN( qfalse );
2082 Q_EXTERN qboolean noHint Q_ASSIGN( qfalse );                        /* ydnar */
2083 Q_EXTERN qboolean renameModelShaders Q_ASSIGN( qfalse );            /* ydnar */
2084 Q_EXTERN qboolean skyFixHack Q_ASSIGN( qfalse );                    /* ydnar */
2085 Q_EXTERN qboolean bspAlternateSplitWeights Q_ASSIGN( qfalse );                      /* 27 */
2086 Q_EXTERN qboolean deepBSP Q_ASSIGN( qfalse );                   /* div0 */
2087 Q_EXTERN qboolean maxAreaFaceSurface Q_ASSIGN( qfalse );                    /* divVerent */
2088 Q_EXTERN qboolean nocmdline Q_ASSIGN( qfalse );
2089
2090 Q_EXTERN int patchSubdivisions Q_ASSIGN( 8 );                       /* ydnar: -patchmeta subdivisions */
2091
2092 Q_EXTERN int maxLMSurfaceVerts Q_ASSIGN( 64 );                      /* ydnar */
2093 Q_EXTERN int maxSurfaceVerts Q_ASSIGN( 999 );                       /* ydnar */
2094 Q_EXTERN int maxSurfaceIndexes Q_ASSIGN( 6000 );                    /* ydnar */
2095 Q_EXTERN float npDegrees Q_ASSIGN( 0.0f );                          /* ydnar: nonplanar degrees */
2096 Q_EXTERN int bevelSnap Q_ASSIGN( 0 );                               /* ydnar: bevel plane snap */
2097 Q_EXTERN int texRange Q_ASSIGN( 0 );
2098 Q_EXTERN qboolean flat Q_ASSIGN( qfalse );
2099 Q_EXTERN qboolean meta Q_ASSIGN( qfalse );
2100 Q_EXTERN qboolean patchMeta Q_ASSIGN( qfalse );
2101 Q_EXTERN qboolean emitFlares Q_ASSIGN( qfalse );
2102 Q_EXTERN qboolean debugSurfaces Q_ASSIGN( qfalse );
2103 Q_EXTERN qboolean debugInset Q_ASSIGN( qfalse );
2104 Q_EXTERN qboolean debugPortals Q_ASSIGN( qfalse );
2105 Q_EXTERN qboolean debugClip Q_ASSIGN( qfalse );                 /* debug model autoclipping */
2106 Q_EXTERN float clipDepthGlobal Q_ASSIGN( 2.0f );
2107 Q_EXTERN qboolean lightmapTriangleCheck Q_ASSIGN( qfalse );
2108 Q_EXTERN qboolean lightmapExtraVisClusterNudge Q_ASSIGN( qfalse );
2109 Q_EXTERN qboolean lightmapFill Q_ASSIGN( qfalse );
2110 Q_EXTERN int metaAdequateScore Q_ASSIGN( -1 );
2111 Q_EXTERN int metaGoodScore Q_ASSIGN( -1 );
2112 Q_EXTERN float metaMaxBBoxDistance Q_ASSIGN( -1 );
2113 Q_EXTERN qboolean noob Q_ASSIGN( qfalse );
2114
2115 #if Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX
2116 // Increasing the normalEpsilon to compensate for new logic in SnapNormal(), where
2117 // this epsilon is now used to compare against 0 components instead of the 1 or -1
2118 // components.  Unfortunately, normalEpsilon is also used in PlaneEqual().  So changing
2119 // this will affect anything that calls PlaneEqual() as well (which are, at the time
2120 // of this writing, FindFloatPlane() and AddBrushBevels()).
2121 Q_EXTERN double normalEpsilon Q_ASSIGN( 0.00005 );
2122 #else
2123 Q_EXTERN double normalEpsilon Q_ASSIGN( 0.00001 );
2124 #endif
2125
2126 #if Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES
2127 // NOTE: This distanceEpsilon is too small if parts of the map are at maximum world
2128 // extents (in the range of plus or minus 2^16).  The smallest epsilon at values
2129 // close to 2^16 is about 0.007, which is greater than distanceEpsilon.  Therefore,
2130 // maps should be constrained to about 2^15, otherwise slightly undesirable effects
2131 // may result.  The 0.01 distanceEpsilon used previously is just too coarse in my
2132 // opinion.  The real fix for this problem is to have 64 bit distances and then make
2133 // this epsilon even smaller, or to constrain world coordinates to plus minus 2^15
2134 // (or even 2^14).
2135 Q_EXTERN double distanceEpsilon Q_ASSIGN( 0.005 );
2136 #else
2137 Q_EXTERN double distanceEpsilon Q_ASSIGN( 0.01 );
2138 #endif
2139
2140
2141 /* bsp */
2142 Q_EXTERN int numMapEntities Q_ASSIGN( 0 );
2143
2144 Q_EXTERN int blockSize[ 3 ]                                 /* should be the same as in radiant */
2145 #ifndef MAIN_C
2146 ;
2147 #else
2148         = { 1024, 1024, 1024 };
2149 #endif
2150
2151 Q_EXTERN char EnginePath[ 1024 ];
2152
2153 Q_EXTERN char name[ 1024 ];
2154 Q_EXTERN char source[ 1024 ];
2155 Q_EXTERN char outbase[ 32 ];
2156
2157 Q_EXTERN int sampleSize;                                    /* lightmap sample size in units */
2158 Q_EXTERN int minSampleSize;                                 /* minimum sample size to use at all */
2159 Q_EXTERN int sampleScale;                                   /* vortex: lightmap sample scale (ie quality)*/
2160
2161 Q_EXTERN int mapEntityNum Q_ASSIGN( 0 );
2162
2163 Q_EXTERN int entitySourceBrushes;
2164
2165 Q_EXTERN plane_t            *mapplanes Q_ASSIGN( NULL );  /* mapplanes[ num ^ 1 ] will always be the mirror or mapplanes[ num ] */
2166 Q_EXTERN int nummapplanes Q_ASSIGN( 0 );                    /* nummapplanes will always be even */
2167 Q_EXTERN int allocatedmapplanes Q_ASSIGN( 0 );
2168 Q_EXTERN int numMapPatches;
2169 Q_EXTERN vec3_t mapMins, mapMaxs;
2170
2171 Q_EXTERN int defaultFogNum Q_ASSIGN( -1 );                  /* ydnar: cleaner fog handling */
2172 Q_EXTERN int numMapFogs Q_ASSIGN( 0 );
2173 Q_EXTERN fog_t mapFogs[ MAX_MAP_FOGS ];
2174
2175 Q_EXTERN entity_t           *mapEnt;
2176 Q_EXTERN brush_t            *buildBrush;
2177 Q_EXTERN int numActiveBrushes;
2178 Q_EXTERN int g_bBrushPrimit;
2179
2180 Q_EXTERN int numStrippedLights Q_ASSIGN( 0 );
2181
2182
2183 /* surface stuff */
2184 Q_EXTERN mapDrawSurface_t   *mapDrawSurfs Q_ASSIGN( NULL );
2185 Q_EXTERN int numMapDrawSurfs;
2186
2187 Q_EXTERN int numSurfacesByType[ NUM_SURFACE_TYPES ];
2188 Q_EXTERN int numClearedSurfaces;
2189 Q_EXTERN int numStripSurfaces;
2190 Q_EXTERN int numMaxAreaSurfaces;
2191 Q_EXTERN int numFanSurfaces;
2192 Q_EXTERN int numMergedSurfaces;
2193 Q_EXTERN int numMergedVerts;
2194
2195 Q_EXTERN int numRedundantIndexes;
2196
2197 Q_EXTERN int numSurfaceModels Q_ASSIGN( 0 );
2198
2199 Q_EXTERN byte debugColors[ 12 ][ 3 ]
2200 #ifndef MAIN_C
2201 ;
2202 #else
2203         =
2204         {
2205         { 255, 0, 0 },
2206         { 192, 128, 128 },
2207         { 255, 255, 0 },
2208         { 192, 192, 128 },
2209         { 0, 255, 255 },
2210         { 128, 192, 192 },
2211         { 0, 0, 255 },
2212         { 128, 128, 192 },
2213         { 255, 0, 255 },
2214         { 192, 128, 192 },
2215         { 0, 255, 0 },
2216         { 128, 192, 128 }
2217         };
2218 #endif
2219
2220 Q_EXTERN qboolean skyboxPresent Q_ASSIGN( qfalse );
2221 Q_EXTERN int skyboxArea Q_ASSIGN( -1 );
2222 Q_EXTERN m4x4_t skyboxTransform;
2223
2224
2225
2226 /* -------------------------------------------------------------------------------
2227
2228    vis global variables
2229
2230    ------------------------------------------------------------------------------- */
2231
2232 /* commandline arguments */
2233 Q_EXTERN qboolean fastvis;
2234 Q_EXTERN qboolean noPassageVis;
2235 Q_EXTERN qboolean passageVisOnly;
2236 Q_EXTERN qboolean mergevis;
2237 Q_EXTERN qboolean mergevisportals;
2238 Q_EXTERN qboolean nosort;
2239 Q_EXTERN qboolean saveprt;
2240 Q_EXTERN qboolean hint;             /* ydnar */
2241 Q_EXTERN char inbase[ MAX_QPATH ];
2242 Q_EXTERN char globalCelShader[ MAX_QPATH ];
2243
2244 Q_EXTERN float farPlaneDist;                /* rr2do2, rf, mre, ydnar all contributed to this one... */
2245 Q_EXTERN int farPlaneDistMode;
2246
2247 Q_EXTERN int numportals;
2248 Q_EXTERN int portalclusters;
2249
2250 Q_EXTERN vportal_t          *portals;
2251 Q_EXTERN leaf_t             *leafs;
2252
2253 Q_EXTERN vportal_t          *faces;
2254 Q_EXTERN leaf_t             *faceleafs;
2255
2256 Q_EXTERN int numfaces;
2257
2258 Q_EXTERN int c_portaltest, c_portalpass, c_portalcheck;
2259 Q_EXTERN int c_portalskip, c_leafskip;
2260 Q_EXTERN int c_vistest, c_mighttest;
2261 Q_EXTERN int c_chains;
2262
2263 Q_EXTERN byte               *vismap, *vismap_p, *vismap_end;
2264
2265 Q_EXTERN int testlevel;
2266
2267 Q_EXTERN byte               *uncompressed;
2268
2269 Q_EXTERN int leafbytes, leaflongs;
2270 Q_EXTERN int portalbytes, portallongs;
2271
2272 Q_EXTERN vportal_t          *sorted_portals[ MAX_MAP_PORTALS * 2 ];
2273
2274
2275
2276 /* -------------------------------------------------------------------------------
2277
2278    light global variables
2279
2280    ------------------------------------------------------------------------------- */
2281
2282 /* commandline arguments */
2283 Q_EXTERN qboolean wolfLight Q_ASSIGN( qfalse );
2284 Q_EXTERN float extraDist Q_ASSIGN( 0.0f );
2285 Q_EXTERN qboolean loMem Q_ASSIGN( qfalse );
2286 Q_EXTERN qboolean noStyles Q_ASSIGN( qfalse );
2287 Q_EXTERN qboolean keepLights Q_ASSIGN( qfalse );
2288
2289 Q_EXTERN int sampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_SAMPLE_SIZE );
2290 Q_EXTERN int minSampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE );
2291 Q_EXTERN qboolean noVertexLighting Q_ASSIGN( qfalse );
2292 Q_EXTERN qboolean nolm Q_ASSIGN( qfalse );
2293 Q_EXTERN qboolean noGridLighting Q_ASSIGN( qfalse );
2294
2295 Q_EXTERN qboolean noTrace Q_ASSIGN( qfalse );
2296 Q_EXTERN qboolean noSurfaces Q_ASSIGN( qfalse );
2297 Q_EXTERN qboolean patchShadows Q_ASSIGN( qfalse );
2298 Q_EXTERN qboolean cpmaHack Q_ASSIGN( qfalse );
2299
2300 Q_EXTERN qboolean deluxemap Q_ASSIGN( qfalse );
2301 Q_EXTERN qboolean debugDeluxemap Q_ASSIGN( qfalse );
2302 Q_EXTERN int deluxemode Q_ASSIGN( 0 );                  /* deluxemap format (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
2303
2304 Q_EXTERN qboolean fast Q_ASSIGN( qfalse );
2305 Q_EXTERN qboolean fastpoint Q_ASSIGN( qtrue );
2306 Q_EXTERN qboolean faster Q_ASSIGN( qfalse );
2307 Q_EXTERN qboolean fastgrid Q_ASSIGN( qfalse );
2308 Q_EXTERN qboolean fastbounce Q_ASSIGN( qfalse );
2309 Q_EXTERN qboolean cheap Q_ASSIGN( qfalse );
2310 Q_EXTERN qboolean cheapgrid Q_ASSIGN( qfalse );
2311 Q_EXTERN int bounce Q_ASSIGN( 0 );
2312 Q_EXTERN qboolean bounceOnly Q_ASSIGN( qfalse );
2313 Q_EXTERN qboolean bouncing Q_ASSIGN( qfalse );
2314 Q_EXTERN qboolean bouncegrid Q_ASSIGN( qfalse );
2315 Q_EXTERN qboolean normalmap Q_ASSIGN( qfalse );
2316 Q_EXTERN qboolean trisoup Q_ASSIGN( qfalse );
2317 Q_EXTERN qboolean shade Q_ASSIGN( qfalse );
2318 Q_EXTERN float shadeAngleDegrees Q_ASSIGN( 0.0f );
2319 Q_EXTERN int superSample Q_ASSIGN( 0 );
2320 Q_EXTERN int lightSamples Q_ASSIGN( 1 );
2321 Q_EXTERN qboolean lightRandomSamples Q_ASSIGN( qfalse );
2322 Q_EXTERN int lightSamplesSearchBoxSize Q_ASSIGN( 1 );
2323 Q_EXTERN qboolean filter Q_ASSIGN( qfalse );
2324 Q_EXTERN qboolean dark Q_ASSIGN( qfalse );
2325 Q_EXTERN qboolean sunOnly Q_ASSIGN( qfalse );
2326 Q_EXTERN int approximateTolerance Q_ASSIGN( 0 );
2327 Q_EXTERN qboolean noCollapse Q_ASSIGN( qfalse );
2328 Q_EXTERN int lightmapSearchBlockSize Q_ASSIGN( 0 );
2329 Q_EXTERN qboolean exportLightmaps Q_ASSIGN( qfalse );
2330 Q_EXTERN qboolean externalLightmaps Q_ASSIGN( qfalse );
2331 Q_EXTERN qboolean externalLightmapNames Q_ASSIGN( qfalse );
2332 Q_EXTERN int lmCustomSize Q_ASSIGN( LIGHTMAP_WIDTH );
2333 Q_EXTERN char *             lmCustomDir Q_ASSIGN( NULL );
2334 Q_EXTERN int lmLimitSize Q_ASSIGN( 0 );
2335
2336 Q_EXTERN qboolean dirty Q_ASSIGN( qfalse );
2337 Q_EXTERN qboolean dirtDebug Q_ASSIGN( qfalse );
2338 Q_EXTERN int dirtMode Q_ASSIGN( 0 );
2339 Q_EXTERN float dirtDepth Q_ASSIGN( 128.0f );
2340 Q_EXTERN float dirtScale Q_ASSIGN( 1.0f );
2341 Q_EXTERN float dirtGain Q_ASSIGN( 1.0f );
2342
2343 /* 27: floodlighting */
2344 Q_EXTERN qboolean debugnormals Q_ASSIGN( qfalse );
2345 Q_EXTERN qboolean floodlighty Q_ASSIGN( qfalse );
2346 Q_EXTERN qboolean floodlight_lowquality Q_ASSIGN( qfalse );
2347 Q_EXTERN vec3_t floodlightRGB;
2348 Q_EXTERN float floodlightIntensity Q_ASSIGN( 512.0f );
2349 Q_EXTERN float floodlightDistance Q_ASSIGN( 1024.0f );
2350 Q_EXTERN float floodlightDirectionScale Q_ASSIGN( 1.0f );
2351
2352 Q_EXTERN qboolean dump Q_ASSIGN( qfalse );
2353 Q_EXTERN qboolean debug Q_ASSIGN( qfalse );
2354 Q_EXTERN qboolean debugUnused Q_ASSIGN( qfalse );
2355 Q_EXTERN qboolean debugAxis Q_ASSIGN( qfalse );
2356 Q_EXTERN qboolean debugCluster Q_ASSIGN( qfalse );
2357 Q_EXTERN qboolean debugOrigin Q_ASSIGN( qfalse );
2358 Q_EXTERN qboolean lightmapBorder Q_ASSIGN( qfalse );
2359 //1=warn; 0=warn if lmsize>128
2360 Q_EXTERN int debugSampleSize Q_ASSIGN( 0 );
2361
2362 /* longest distance across the map */
2363 Q_EXTERN float maxMapDistance Q_ASSIGN( 0 );
2364
2365 /* for run time tweaking of light sources */
2366 Q_EXTERN float pointScale Q_ASSIGN( 7500.0f );
2367 Q_EXTERN float spotScale Q_ASSIGN( 7500.0f );
2368 Q_EXTERN float areaScale Q_ASSIGN( 0.25f );
2369 Q_EXTERN float skyScale Q_ASSIGN( 1.0f );
2370 Q_EXTERN float bounceScale Q_ASSIGN( 0.25f );
2371 Q_EXTERN float bounceColorRatio Q_ASSIGN( 1.0f );
2372 Q_EXTERN float vertexglobalscale Q_ASSIGN( 1.0f );
2373 Q_EXTERN float g_backsplashFractionScale Q_ASSIGN( 1.0f );
2374 Q_EXTERN float g_backsplashDistance Q_ASSIGN( -999.0f );
2375
2376 /* jal: alternative angle attenuation curve */
2377 Q_EXTERN qboolean lightAngleHL Q_ASSIGN( qfalse );
2378
2379 /* vortex: gridscale and gridambientscale */
2380 Q_EXTERN float gridScale Q_ASSIGN( 1.0f );
2381 Q_EXTERN float gridAmbientScale Q_ASSIGN( 1.0f );
2382 Q_EXTERN float gridDirectionality Q_ASSIGN( 1.0f );
2383 Q_EXTERN float gridAmbientDirectionality Q_ASSIGN( 0.0f );
2384 Q_EXTERN qboolean inGrid Q_ASSIGN( 0 );
2385
2386 /* ydnar: lightmap gamma/compensation */
2387 Q_EXTERN float lightmapGamma Q_ASSIGN( 1.0f );
2388 Q_EXTERN float lightmapsRGB Q_ASSIGN( qfalse );
2389 Q_EXTERN float texturesRGB Q_ASSIGN( qfalse );
2390 Q_EXTERN float colorsRGB Q_ASSIGN( qfalse );
2391 Q_EXTERN float lightmapExposure Q_ASSIGN( 0.0f );
2392 Q_EXTERN float lightmapCompensate Q_ASSIGN( 1.0f );
2393 Q_EXTERN float lightmapBrightness Q_ASSIGN( 1.0f );
2394 Q_EXTERN float lightmapContrast Q_ASSIGN( 1.0f );
2395
2396 /* ydnar: for runtime tweaking of falloff tolerance */
2397 Q_EXTERN float falloffTolerance Q_ASSIGN( 1.0f );
2398 Q_EXTERN qboolean exactPointToPolygon Q_ASSIGN( qtrue );
2399 Q_EXTERN float formFactorValueScale Q_ASSIGN( 3.0f );
2400 Q_EXTERN float linearScale Q_ASSIGN( 1.0f / 8000.0f );
2401
2402 // for .ase conversion
2403 Q_EXTERN qboolean shadersAsBitmap Q_ASSIGN( qfalse );
2404 Q_EXTERN qboolean lightmapsAsTexcoord Q_ASSIGN( qfalse );
2405
2406 Q_EXTERN light_t            *lights;
2407 Q_EXTERN int numPointLights;
2408 Q_EXTERN int numSpotLights;
2409 Q_EXTERN int numSunLights;
2410 Q_EXTERN int numAreaLights;
2411
2412 /* ydnar: for luxel placement */
2413 Q_EXTERN int numSurfaceClusters, maxSurfaceClusters;
2414 Q_EXTERN int                *surfaceClusters;
2415
2416 /* ydnar: for radiosity */
2417 Q_EXTERN int numDiffuseLights;
2418 Q_EXTERN int numBrushDiffuseLights;
2419 Q_EXTERN int numTriangleDiffuseLights;
2420 Q_EXTERN int numPatchDiffuseLights;
2421
2422 /* ydnar: general purpose extra copy of drawvert list */
2423 Q_EXTERN bspDrawVert_t      *yDrawVerts;
2424
2425 /* ydnar: for tracing statistics */
2426 Q_EXTERN int minSurfacesTested;
2427 Q_EXTERN int maxSurfacesTested;
2428 Q_EXTERN int totalSurfacesTested;
2429 Q_EXTERN int totalTraces;
2430
2431 Q_EXTERN FILE               *dumpFile;
2432
2433 Q_EXTERN int c_visible, c_occluded;
2434 Q_EXTERN int c_subsampled;                  /* ydnar */
2435
2436 Q_EXTERN int defaultLightSubdivide Q_ASSIGN( 999 );
2437
2438 Q_EXTERN vec3_t ambientColor;
2439 Q_EXTERN vec3_t minLight, minVertexLight, minGridLight;
2440
2441 Q_EXTERN int                *entitySurface;
2442 Q_EXTERN vec3_t             *surfaceOrigin;
2443
2444 Q_EXTERN vec3_t sunDirection;
2445 Q_EXTERN vec3_t sunLight;
2446
2447 /* tracing */
2448 Q_EXTERN int c_totalTrace;
2449 Q_EXTERN int c_cullTrace, c_testTrace;
2450 Q_EXTERN int c_testFacets;
2451
2452 /* ydnar: light optimization */
2453 Q_EXTERN float subdivideThreshold Q_ASSIGN( DEFAULT_SUBDIVIDE_THRESHOLD );
2454
2455 Q_EXTERN int numOpaqueBrushes, maxOpaqueBrush;
2456 Q_EXTERN byte               *opaqueBrushes;
2457
2458 Q_EXTERN int numLights;
2459 Q_EXTERN int numCulledLights;
2460
2461 Q_EXTERN int gridBoundsCulled;
2462 Q_EXTERN int gridEnvelopeCulled;
2463
2464 Q_EXTERN int lightsBoundsCulled;
2465 Q_EXTERN int lightsEnvelopeCulled;
2466 Q_EXTERN int lightsPlaneCulled;
2467 Q_EXTERN int lightsClusterCulled;
2468
2469 /* ydnar: radiosity */
2470 Q_EXTERN float diffuseSubdivide Q_ASSIGN( 256.0f );
2471 Q_EXTERN float minDiffuseSubdivide Q_ASSIGN( 64.0f );
2472 Q_EXTERN int numDiffuseSurfaces Q_ASSIGN( 0 );
2473
2474 /* ydnar: list of surface information necessary for lightmap calculation */
2475 Q_EXTERN surfaceInfo_t      *surfaceInfos Q_ASSIGN( NULL );
2476
2477 /* ydnar: sorted list of surfaces */
2478 Q_EXTERN int                *sortSurfaces Q_ASSIGN( NULL );
2479
2480 /* clumps of surfaces that share a raw lightmap */
2481 Q_EXTERN int numLightSurfaces Q_ASSIGN( 0 );
2482 Q_EXTERN int                *lightSurfaces Q_ASSIGN( NULL );
2483
2484 /* raw lightmaps */
2485 Q_EXTERN int numRawSuperLuxels Q_ASSIGN( 0 );
2486 Q_EXTERN int numRawLightmaps Q_ASSIGN( 0 );
2487 Q_EXTERN rawLightmap_t      *rawLightmaps Q_ASSIGN( NULL );
2488 Q_EXTERN int                *sortLightmaps Q_ASSIGN( NULL );
2489
2490 /* vertex luxels */
2491 Q_EXTERN float              *vertexLuxels[ MAX_LIGHTMAPS ];
2492 Q_EXTERN float              *radVertexLuxels[ MAX_LIGHTMAPS ];
2493
2494 /* bsp lightmaps */
2495 Q_EXTERN int numLightmapShaders Q_ASSIGN( 0 );
2496 Q_EXTERN int numSolidLightmaps Q_ASSIGN( 0 );
2497 Q_EXTERN int numOutLightmaps Q_ASSIGN( 0 );
2498 Q_EXTERN int numBSPLightmaps Q_ASSIGN( 0 );
2499 Q_EXTERN int numExtLightmaps Q_ASSIGN( 0 );
2500 Q_EXTERN outLightmap_t      *outLightmaps Q_ASSIGN( NULL );
2501
2502 /* vortex: per surface floodlight statictics */
2503 Q_EXTERN int numSurfacesFloodlighten Q_ASSIGN( 0 );
2504
2505 /* grid points */
2506 Q_EXTERN int numRawGridPoints Q_ASSIGN( 0 );
2507 Q_EXTERN rawGridPoint_t     *rawGridPoints Q_ASSIGN( NULL );
2508
2509 Q_EXTERN int numSurfsVertexLit Q_ASSIGN( 0 );
2510 Q_EXTERN int numSurfsVertexForced Q_ASSIGN( 0 );
2511 Q_EXTERN int numSurfsVertexApproximated Q_ASSIGN( 0 );
2512 Q_EXTERN int numSurfsLightmapped Q_ASSIGN( 0 );
2513 Q_EXTERN int numPlanarsLightmapped Q_ASSIGN( 0 );
2514 Q_EXTERN int numNonPlanarsLightmapped Q_ASSIGN( 0 );
2515 Q_EXTERN int numPatchesLightmapped Q_ASSIGN( 0 );
2516 Q_EXTERN int numPlanarPatchesLightmapped Q_ASSIGN( 0 );
2517
2518 Q_EXTERN int numLuxels Q_ASSIGN( 0 );
2519 Q_EXTERN int numLuxelsMapped Q_ASSIGN( 0 );
2520 Q_EXTERN int numLuxelsOccluded Q_ASSIGN( 0 );
2521 Q_EXTERN int numLuxelsIlluminated Q_ASSIGN( 0 );
2522 Q_EXTERN int numVertsIlluminated Q_ASSIGN( 0 );
2523
2524 /* lightgrid */
2525 Q_EXTERN vec3_t gridMins;
2526 Q_EXTERN int gridBounds[ 3 ];
2527 Q_EXTERN vec3_t gridSize
2528 #ifndef MAIN_C
2529 ;
2530 #else
2531         = { 64, 64, 128 };
2532 #endif
2533
2534
2535
2536 /* -------------------------------------------------------------------------------
2537
2538    abstracted bsp globals
2539
2540    ------------------------------------------------------------------------------- */
2541
2542 Q_EXTERN int numEntities Q_ASSIGN( 0 );
2543 Q_EXTERN int numBSPEntities Q_ASSIGN( 0 );
2544 Q_EXTERN int allocatedEntities Q_ASSIGN( 0 );
2545 Q_EXTERN entity_t*          entities Q_ASSIGN( NULL );
2546
2547 Q_EXTERN int numBSPModels Q_ASSIGN( 0 );
2548 Q_EXTERN int allocatedBSPModels Q_ASSIGN( 0 );
2549 Q_EXTERN bspModel_t*        bspModels Q_ASSIGN( NULL );
2550
2551 Q_EXTERN int numBSPShaders Q_ASSIGN( 0 );
2552 Q_EXTERN int allocatedBSPShaders Q_ASSIGN( 0 );
2553 Q_EXTERN bspShader_t*       bspShaders Q_ASSIGN( 0 );
2554
2555 Q_EXTERN int bspEntDataSize Q_ASSIGN( 0 );
2556 Q_EXTERN int allocatedBSPEntData Q_ASSIGN( 0 );
2557 Q_EXTERN char               *bspEntData Q_ASSIGN( 0 );
2558
2559 Q_EXTERN int numBSPLeafs Q_ASSIGN( 0 );
2560 Q_EXTERN bspLeaf_t bspLeafs[ MAX_MAP_LEAFS ];
2561
2562 Q_EXTERN int numBSPPlanes Q_ASSIGN( 0 );
2563 Q_EXTERN int allocatedBSPPlanes Q_ASSIGN( 0 );
2564 Q_EXTERN bspPlane_t         *bspPlanes;
2565
2566 Q_EXTERN int numBSPNodes Q_ASSIGN( 0 );
2567 Q_EXTERN int allocatedBSPNodes Q_ASSIGN( 0 );
2568 Q_EXTERN bspNode_t*         bspNodes Q_ASSIGN( NULL );
2569
2570 Q_EXTERN int numBSPLeafSurfaces Q_ASSIGN( 0 );
2571 Q_EXTERN int allocatedBSPLeafSurfaces Q_ASSIGN( 0 );
2572 Q_EXTERN int*               bspLeafSurfaces Q_ASSIGN( NULL );
2573
2574 Q_EXTERN int numBSPLeafBrushes Q_ASSIGN( 0 );
2575 Q_EXTERN int allocatedBSPLeafBrushes Q_ASSIGN( 0 );
2576 Q_EXTERN int*               bspLeafBrushes Q_ASSIGN( NULL );
2577
2578 Q_EXTERN int numBSPBrushes Q_ASSIGN( 0 );
2579 Q_EXTERN int allocatedBSPBrushes Q_ASSIGN( 0 );
2580 Q_EXTERN bspBrush_t*        bspBrushes Q_ASSIGN( NULL );
2581
2582 Q_EXTERN int numBSPBrushSides Q_ASSIGN( 0 );
2583 Q_EXTERN int allocatedBSPBrushSides Q_ASSIGN( 0 );
2584 Q_EXTERN bspBrushSide_t*    bspBrushSides Q_ASSIGN( NULL );
2585
2586 Q_EXTERN int numBSPLightBytes Q_ASSIGN( 0 );
2587 Q_EXTERN byte               *bspLightBytes Q_ASSIGN( NULL );
2588
2589 //%     Q_EXTERN int                            numBSPGridPoints Q_ASSIGN( 0 );
2590 //%     Q_EXTERN byte                           *bspGridPoints Q_ASSIGN( NULL );
2591
2592 Q_EXTERN int numBSPGridPoints Q_ASSIGN( 0 );
2593 Q_EXTERN bspGridPoint_t     *bspGridPoints Q_ASSIGN( NULL );
2594
2595 Q_EXTERN int numBSPVisBytes Q_ASSIGN( 0 );
2596 Q_EXTERN byte bspVisBytes[ MAX_MAP_VISIBILITY ];
2597
2598 Q_EXTERN int numBSPDrawVerts Q_ASSIGN( 0 );
2599 Q_EXTERN bspDrawVert_t          *bspDrawVerts Q_ASSIGN( NULL );
2600
2601 Q_EXTERN int numBSPDrawIndexes Q_ASSIGN( 0 );
2602 Q_EXTERN int allocatedBSPDrawIndexes Q_ASSIGN( 0 );
2603 Q_EXTERN int                *bspDrawIndexes Q_ASSIGN( NULL );
2604
2605 Q_EXTERN int numBSPDrawSurfaces Q_ASSIGN( 0 );
2606 Q_EXTERN bspDrawSurface_t   *bspDrawSurfaces Q_ASSIGN( NULL );
2607
2608 Q_EXTERN int numBSPFogs Q_ASSIGN( 0 );
2609 Q_EXTERN bspFog_t bspFogs[ MAX_MAP_FOGS ];
2610
2611 Q_EXTERN int numBSPAds Q_ASSIGN( 0 );
2612 Q_EXTERN bspAdvertisement_t bspAds[ MAX_MAP_ADVERTISEMENTS ];
2613
2614 // Used for tex file support, Smokin'Guns globals
2615 Q_EXTERN qboolean compile_map;
2616
2617 #define _AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def, fillWithZeros ) \
2618         do \
2619         { \
2620                 int prevAllocated = allocated; \
2621                 if ( reqitem >= allocated )     \
2622                 { \
2623                         if ( allocated == 0 ) { \
2624                                 allocated = def; \
2625                         } \
2626                         while ( reqitem >= allocated && allocated )     \
2627                         { \
2628                                 allocated *= 2; \
2629                         } \
2630                         if ( !allocated || allocated > 2147483647 / (int)sizeof( *ptr ) ) \
2631                         { \
2632                                 Error( # ptr " over 2 GB" ); \
2633                         } \
2634                         ptr = realloc( ptr, sizeof( *ptr ) * allocated ); \
2635                         if ( !ptr ) { \
2636                                 Error( #ptr " out of memory" ); \
2637                         } \
2638                         if ( fillWithZeros ) \
2639                         { \
2640                                 memset( ptr + ( sizeof( *ptr ) * prevAllocated ), 0 , sizeof( *ptr ) * ( allocated - prevAllocated ) ); \
2641                         } \
2642                 } \
2643         } \
2644         while ( 0 )
2645
2646 #define AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def ) _AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def, qfalse )
2647
2648 #define AUTOEXPAND_BY_REALLOC0( ptr, reqitem, allocated, def ) _AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def, qtrue )
2649
2650 #define AUTOEXPAND_BY_REALLOC_BSP( suffix, def ) AUTOEXPAND_BY_REALLOC( bsp ## suffix, numBSP ## suffix, allocatedBSP ## suffix, def )
2651
2652 #define AUTOEXPAND_BY_REALLOC0_BSP( suffix, def ) AUTOEXPAND_BY_REALLOC0( bsp##suffix, numBSP##suffix, allocatedBSP##suffix, def )
2653
2654 #define Image_LinearFloatFromsRGBFloat( c ) ( ( ( c ) <= 0.04045f ) ? ( c ) * ( 1.0f / 12.92f ) : (float)pow( ( ( c ) + 0.055f ) * ( 1.0f / 1.055f ), 2.4f ) )
2655 #define Image_sRGBFloatFromLinearFloat( c ) ( ( ( c ) < 0.0031308f ) ? ( c ) * 12.92f : 1.055f * (float)pow( ( c ), 1.0f / 2.4f ) - 0.055f )
2656
2657 /* end marker */
2658 #endif