Debian Codegraph @

tools/quake3/q3map2/q3map2.h

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