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