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