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