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