1 /* -------------------------------------------------------------------------------;
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
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.
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.
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
22 -------------------------------------------------------------------------------
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."
27 ------------------------------------------------------------------------------- */
43 returns a pseudorandom number between 0 and 1
48 return (vec_t) rand() / RAND_MAX;
58 static void ExitQ3Map( void )
61 if( mapDrawSurfs != NULL )
69 typedef struct minimap_s
75 float *sample_offsets;
76 float sharpen_boxmult;
77 float sharpen_centermult;
78 float boost, brightness, contrast;
84 static minimap_t minimap;
86 qboolean BrushIntersectionWithLine(bspBrush_t *brush, vec3_t start, vec3_t dir, float *t_in, float *t_out)
89 qboolean in = qfalse, out = qfalse;
90 bspBrushSide_t *sides = &bspBrushSides[brush->firstSide];
92 for(i = 0; i < brush->numSides; ++i)
94 bspPlane_t *p = &bspPlanes[sides[i].planeNum];
95 float sn = DotProduct(start, p->normal);
96 float dn = DotProduct(dir, p->normal);
100 return qfalse; // outside!
104 float t = (p->dist - sn) / dn;
111 // as t_in can only increase, and t_out can only decrease, early out
112 if(out && *t_in >= *t_out)
118 if(!out || t < *t_out)
122 // as t_in can only increase, and t_out can only decrease, early out
123 if(in && *t_in >= *t_out)
132 static float MiniMapSample(float x, float y)
151 for(i = 0; i < minimap.model->numBSPBrushes; ++i)
153 bi = minimap.model->firstBSPBrush + i;
154 if(opaqueBrushes[bi >> 3] & (1 << (bi & 7)))
158 // sort out mins/maxs of the brush
159 s = &bspBrushSides[b->firstSide];
160 if(x < -bspPlanes[s[0].planeNum].dist)
162 if(x > +bspPlanes[s[1].planeNum].dist)
164 if(y < -bspPlanes[s[2].planeNum].dist)
166 if(y > +bspPlanes[s[3].planeNum].dist)
169 if(BrushIntersectionWithLine(b, org, dir, &t0, &t1))
180 void RandomVector2f(float v[2])
184 v[0] = 2 * Random() - 1;
185 v[1] = 2 * Random() - 1;
187 while(v[0] * v[0] + v[1] * v[1] > 1);
190 static void MiniMapRandomlySupersampled(int y)
193 float *p = &minimap.data1f[y * minimap.width];
194 float ymin = minimap.mins[1] + minimap.size[1] * (y / (float) minimap.height);
195 float dx = minimap.size[0] / (float) minimap.width;
196 float dy = minimap.size[1] / (float) minimap.height;
200 for(x = 0; x < minimap.width; ++x)
202 float xmin = minimap.mins[0] + minimap.size[0] * (x / (float) minimap.width);
205 for(i = 0; i < minimap.samples; ++i)
208 thisval = MiniMapSample(
209 xmin + (uv[0] + 0.5) * dx, /* exaggerated random pattern for better results */
210 ymin + (uv[1] + 0.5) * dy /* exaggerated random pattern for better results */
214 val /= minimap.samples * minimap.size[2];
219 static void MiniMapSupersampled(int y)
222 float *p = &minimap.data1f[y * minimap.width];
223 float ymin = minimap.mins[1] + minimap.size[1] * (y / (float) minimap.height);
224 float dx = minimap.size[0] / (float) minimap.width;
225 float dy = minimap.size[1] / (float) minimap.height;
227 for(x = 0; x < minimap.width; ++x)
229 float xmin = minimap.mins[0] + minimap.size[0] * (x / (float) minimap.width);
232 for(i = 0; i < minimap.samples; ++i)
234 float thisval = MiniMapSample(
235 xmin + minimap.sample_offsets[2*i+0] * dx,
236 ymin + minimap.sample_offsets[2*i+1] * dy
240 val /= minimap.samples * minimap.size[2];
245 static void MiniMapNoSupersampling(int y)
248 float *p = &minimap.data1f[y * minimap.width];
249 float ymin = minimap.mins[1] + minimap.size[1] * ((y + 0.5) / (float) minimap.height);
251 for(x = 0; x < minimap.width; ++x)
253 float xmin = minimap.mins[0] + minimap.size[0] * ((x + 0.5) / (float) minimap.width);
254 *p++ = MiniMapSample(xmin, ymin) / minimap.size[2];
258 static void MiniMapSharpen(int y)
261 qboolean up = (y > 0);
262 qboolean down = (y < minimap.height - 1);
263 float *p = &minimap.data1f[y * minimap.width];
264 float *q = &minimap.sharpendata1f[y * minimap.width];
266 for(x = 0; x < minimap.width; ++x)
268 qboolean left = (x > 0);
269 qboolean right = (x < minimap.width - 1);
270 float val = p[0] * minimap.sharpen_centermult;
273 val += p[-1 -minimap.width] * minimap.sharpen_boxmult;
275 val += p[-1 +minimap.width] * minimap.sharpen_boxmult;
277 val += p[+1 -minimap.width] * minimap.sharpen_boxmult;
279 val += p[+1 +minimap.width] * minimap.sharpen_boxmult;
282 val += p[-1] * minimap.sharpen_boxmult;
284 val += p[+1] * minimap.sharpen_boxmult;
286 val += p[-minimap.width] * minimap.sharpen_boxmult;
288 val += p[+minimap.width] * minimap.sharpen_boxmult;
295 static void MiniMapContrastBoost(int y)
298 float *q = &minimap.data1f[y * minimap.width];
299 for(x = 0; x < minimap.width; ++x)
301 *q = *q * minimap.boost / ((minimap.boost - 1) * *q + 1);
306 static void MiniMapBrightnessContrast(int y)
309 float *q = &minimap.data1f[y * minimap.width];
310 for(x = 0; x < minimap.width; ++x)
312 *q = *q * minimap.contrast + minimap.brightness;
317 void MiniMapMakeMinsMaxs(vec3_t mins_in, vec3_t maxs_in, float border, qboolean keepaspect)
319 vec3_t mins, maxs, extend;
320 VectorCopy(mins_in, mins);
321 VectorCopy(maxs_in, maxs);
323 // line compatible to nexuiz mapinfo
324 Sys_Printf("size %f %f %f %f %f %f\n", mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2]);
328 VectorSubtract(maxs, mins, extend);
329 if(extend[1] > extend[0])
331 mins[0] -= (extend[1] - extend[0]) * 0.5;
332 maxs[0] += (extend[1] - extend[0]) * 0.5;
336 mins[1] -= (extend[0] - extend[1]) * 0.5;
337 maxs[1] += (extend[0] - extend[1]) * 0.5;
341 /* border: amount of black area around the image */
342 /* input: border, 1-2*border, border but we need border/(1-2*border) */
344 VectorSubtract(maxs, mins, extend);
345 VectorScale(extend, border / (1 - 2 * border), extend);
347 VectorSubtract(mins, extend, mins);
348 VectorAdd(maxs, extend, maxs);
350 VectorCopy(mins, minimap.mins);
351 VectorSubtract(maxs, mins, minimap.size);
353 // line compatible to nexuiz mapinfo
354 Sys_Printf("size_texcoords %f %f %f %f %f %f\n", mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2]);
358 MiniMapSetupBrushes()
359 determines solid non-sky brushes in the world
362 void MiniMapSetupBrushes( void )
364 SetupBrushesFlags(C_SOLID | C_SKY, C_SOLID, 0, 0);
365 // at least one must be solid
367 // not all may be nodraw
370 qboolean MiniMapEvaluateSampleOffsets(int *bestj, int *bestk, float *bestval)
375 *bestj = *bestk = -1;
376 *bestval = 3; /* max possible val is 2 */
378 for(j = 0; j < minimap.samples; ++j)
379 for(k = j + 1; k < minimap.samples; ++k)
381 dx = minimap.sample_offsets[2*j+0] - minimap.sample_offsets[2*k+0];
382 dy = minimap.sample_offsets[2*j+1] - minimap.sample_offsets[2*k+1];
383 if(dx > +0.5) dx -= 1;
384 if(dx < -0.5) dx += 1;
385 if(dy > +0.5) dy -= 1;
386 if(dy < -0.5) dy += 1;
387 val = dx * dx + dy * dy;
399 void MiniMapMakeSampleOffsets()
402 float val, valj, valk, sx, sy, rx, ry;
404 Sys_Printf( "Generating good sample offsets (this may take a while)...\n" );
406 /* start with entirely random samples */
407 for(i = 0; i < minimap.samples; ++i)
409 minimap.sample_offsets[2*i+0] = Random();
410 minimap.sample_offsets[2*i+1] = Random();
413 for(i = 0; i < 1000; ++i)
415 if(MiniMapEvaluateSampleOffsets(&j, &k, &val))
417 sx = minimap.sample_offsets[2*j+0];
418 sy = minimap.sample_offsets[2*j+1];
419 minimap.sample_offsets[2*j+0] = rx = Random();
420 minimap.sample_offsets[2*j+1] = ry = Random();
421 if(!MiniMapEvaluateSampleOffsets(&jj, &kk, &valj))
423 minimap.sample_offsets[2*j+0] = sx;
424 minimap.sample_offsets[2*j+1] = sy;
426 sx = minimap.sample_offsets[2*k+0];
427 sy = minimap.sample_offsets[2*k+1];
428 minimap.sample_offsets[2*k+0] = rx;
429 minimap.sample_offsets[2*k+1] = ry;
430 if(!MiniMapEvaluateSampleOffsets(&jj, &kk, &valk))
432 minimap.sample_offsets[2*k+0] = sx;
433 minimap.sample_offsets[2*k+1] = sy;
439 /* valj is the greatest */
440 minimap.sample_offsets[2*j+0] = rx;
441 minimap.sample_offsets[2*j+1] = ry;
446 /* valj is the greater and it is useless - forget it */
453 /* valk is the greatest */
454 minimap.sample_offsets[2*k+0] = rx;
455 minimap.sample_offsets[2*k+1] = ry;
460 /* valk is the greater and it is useless - forget it */
469 void MergeRelativePath(char *out, const char *absolute, const char *relative)
471 const char *endpos = absolute + strlen(absolute);
472 while(endpos != absolute && (endpos[-1] == '/' || endpos[-1] == '\\'))
474 while(relative[0] == '.' && relative[1] == '.' && (relative[2] == '/' || relative[2] == '\\'))
477 while(endpos != absolute)
480 if(*endpos == '/' || *endpos == '\\')
483 while(endpos != absolute && (endpos[-1] == '/' || endpos[-1] == '\\'))
486 memcpy(out, absolute, endpos - absolute);
487 out[endpos - absolute] = '/';
488 strcpy(out + (endpos - absolute + 1), relative);
491 int MiniMapBSPMain( int argc, char **argv )
493 char minimapFilename[1024];
496 char relativeMinimapFilename[1024];
498 float minimapSharpen;
511 Sys_Printf( "Usage: q3map [-v] -minimap [-size n] [-sharpen f] [-samples n | -random n] [-o filename.tga] [-minmax Xmin Ymin Zmin Xmax Ymax Zmax] <mapname>\n" );
515 /* load the BSP first */
516 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
517 StripExtension( source );
518 DefaultExtension( source, ".bsp" );
519 Sys_Printf( "Loading %s\n", source );
520 BeginMapShaderFile( source );
522 LoadBSPFile( source );
524 minimap.model = &bspModels[0];
525 VectorCopy(minimap.model->mins, mins);
526 VectorCopy(minimap.model->maxs, maxs);
528 *minimapFilename = 0;
529 minimapSharpen = game->miniMapSharpen;
530 minimap.width = minimap.height = game->miniMapSize;
531 border = game->miniMapBorder;
532 keepaspect = game->miniMapKeepAspect;
533 mode = game->miniMapMode;
537 minimap.sample_offsets = NULL;
539 minimap.brightness = 0.0;
540 minimap.contrast = 1.0;
542 /* process arguments */
543 for( i = 1; i < (argc - 1); i++ )
545 if( !strcmp( argv[ i ], "-size" ) )
547 minimap.width = minimap.height = atoi(argv[i + 1]);
549 Sys_Printf( "Image size set to %i\n", minimap.width );
551 else if( !strcmp( argv[ i ], "-sharpen" ) )
553 minimapSharpen = atof(argv[i + 1]);
555 Sys_Printf( "Sharpening coefficient set to %f\n", minimapSharpen );
557 else if( !strcmp( argv[ i ], "-samples" ) )
559 minimap.samples = atoi(argv[i + 1]);
561 Sys_Printf( "Samples set to %i\n", minimap.samples );
562 if(minimap.sample_offsets)
563 free(minimap.sample_offsets);
564 minimap.sample_offsets = malloc(2 * sizeof(*minimap.sample_offsets) * minimap.samples);
565 MiniMapMakeSampleOffsets();
567 else if( !strcmp( argv[ i ], "-random" ) )
569 minimap.samples = atoi(argv[i + 1]);
571 Sys_Printf( "Random samples set to %i\n", minimap.samples );
572 if(minimap.sample_offsets)
573 free(minimap.sample_offsets);
574 minimap.sample_offsets = NULL;
576 else if( !strcmp( argv[ i ], "-border" ) )
578 border = atof(argv[i + 1]);
580 Sys_Printf( "Border set to %f\n", border );
582 else if( !strcmp( argv[ i ], "-keepaspect" ) )
585 Sys_Printf( "Keeping aspect ratio by letterboxing\n", border );
587 else if( !strcmp( argv[ i ], "-nokeepaspect" ) )
590 Sys_Printf( "Not keeping aspect ratio\n", border );
592 else if( !strcmp( argv[ i ], "-o" ) )
594 strcpy(minimapFilename, argv[i + 1]);
596 Sys_Printf( "Output file name set to %s\n", minimapFilename );
598 else if( !strcmp( argv[ i ], "-minmax" ) && i < (argc - 7) )
600 mins[0] = atof(argv[i + 1]);
601 mins[1] = atof(argv[i + 2]);
602 mins[2] = atof(argv[i + 3]);
603 maxs[0] = atof(argv[i + 4]);
604 maxs[1] = atof(argv[i + 5]);
605 maxs[2] = atof(argv[i + 6]);
607 Sys_Printf( "Map mins/maxs overridden\n" );
609 else if( !strcmp( argv[ i ], "-gray" ) )
611 mode = MINIMAP_MODE_GRAY;
612 Sys_Printf( "Writing as white-on-black image\n" );
614 else if( !strcmp( argv[ i ], "-black" ) )
616 mode = MINIMAP_MODE_BLACK;
617 Sys_Printf( "Writing as black alpha image\n" );
619 else if( !strcmp( argv[ i ], "-white" ) )
621 mode = MINIMAP_MODE_WHITE;
622 Sys_Printf( "Writing as white alpha image\n" );
624 else if( !strcmp( argv[ i ], "-boost" ) && i < (argc - 2) )
626 minimap.boost = atof(argv[i + 1]);
628 Sys_Printf( "Contrast boost set to %f\n", minimap.boost );
630 else if( !strcmp( argv[ i ], "-brightness" ) && i < (argc - 2) )
632 minimap.brightness = atof(argv[i + 1]);
634 Sys_Printf( "Brightness set to %f\n", minimap.brightness );
636 else if( !strcmp( argv[ i ], "-contrast" ) && i < (argc - 2) )
638 minimap.contrast = atof(argv[i + 1]);
640 Sys_Printf( "Contrast set to %f\n", minimap.contrast );
642 else if( !strcmp( argv[ i ], "-autolevel" ) )
645 Sys_Printf( "Auto level enabled\n", border );
647 else if( !strcmp( argv[ i ], "-noautolevel" ) )
650 Sys_Printf( "Auto level disabled\n", border );
654 MiniMapMakeMinsMaxs(mins, maxs, border, keepaspect);
656 if(!*minimapFilename)
658 ExtractFileBase(source, basename);
659 ExtractFilePath(source, path);
660 sprintf(relativeMinimapFilename, game->miniMapNameFormat, basename);
661 MergeRelativePath(minimapFilename, path, relativeMinimapFilename);
662 Sys_Printf("Output file name automatically set to %s\n", minimapFilename);
664 ExtractFilePath(minimapFilename, path);
667 if(minimapSharpen >= 0)
669 minimap.sharpen_centermult = 8 * minimapSharpen + 1;
670 minimap.sharpen_boxmult = -minimapSharpen;
673 minimap.data1f = safe_malloc(minimap.width * minimap.height * sizeof(*minimap.data1f));
674 data4b = safe_malloc(minimap.width * minimap.height * 4);
675 if(minimapSharpen >= 0)
676 minimap.sharpendata1f = safe_malloc(minimap.width * minimap.height * sizeof(*minimap.data1f));
678 MiniMapSetupBrushes();
680 if(minimap.samples <= 1)
682 Sys_Printf( "\n--- MiniMapNoSupersampling (%d) ---\n", minimap.height );
683 RunThreadsOnIndividual(minimap.height, qtrue, MiniMapNoSupersampling);
687 if(minimap.sample_offsets)
689 Sys_Printf( "\n--- MiniMapSupersampled (%d) ---\n", minimap.height );
690 RunThreadsOnIndividual(minimap.height, qtrue, MiniMapSupersampled);
694 Sys_Printf( "\n--- MiniMapRandomlySupersampled (%d) ---\n", minimap.height );
695 RunThreadsOnIndividual(minimap.height, qtrue, MiniMapRandomlySupersampled);
699 if(minimap.boost != 1.0)
701 Sys_Printf( "\n--- MiniMapContrastBoost (%d) ---\n", minimap.height );
702 RunThreadsOnIndividual(minimap.height, qtrue, MiniMapContrastBoost);
707 Sys_Printf( "\n--- MiniMapAutoLevel (%d) ---\n", minimap.height );
708 float mi = 1, ma = 0;
713 for(y = 0; y < minimap.height; ++y)
714 for(x = 0; x < minimap.width; ++x)
728 // brightness + contrast * v
730 // brightness + contrast * (v * s - o)
732 // (brightness - contrast * o) + (contrast * s) * v
733 minimap.brightness = minimap.brightness - minimap.contrast * o;
734 minimap.contrast *= s;
736 Sys_Printf( "Auto level: Brightness changed to %f\n", minimap.brightness );
737 Sys_Printf( "Auto level: Contrast changed to %f\n", minimap.contrast );
740 Sys_Printf( "Auto level: failed because all pixels are the same value\n" );
743 if(minimap.brightness != 0 || minimap.contrast != 1)
745 Sys_Printf( "\n--- MiniMapBrightnessContrast (%d) ---\n", minimap.height );
746 RunThreadsOnIndividual(minimap.height, qtrue, MiniMapBrightnessContrast);
749 if(minimap.sharpendata1f)
751 Sys_Printf( "\n--- MiniMapSharpen (%d) ---\n", minimap.height );
752 RunThreadsOnIndividual(minimap.height, qtrue, MiniMapSharpen);
753 q = minimap.sharpendata1f;
760 Sys_Printf( "\nConverting...");
764 case MINIMAP_MODE_GRAY:
766 for(y = 0; y < minimap.height; ++y)
767 for(x = 0; x < minimap.width; ++x)
772 if(v > 255.0/256.0) v = 255.0/256.0;
776 Sys_Printf( " writing to %s...", minimapFilename );
777 WriteTGAGray(minimapFilename, data4b, minimap.width, minimap.height);
779 case MINIMAP_MODE_BLACK:
781 for(y = 0; y < minimap.height; ++y)
782 for(x = 0; x < minimap.width; ++x)
787 if(v > 255.0/256.0) v = 255.0/256.0;
794 Sys_Printf( " writing to %s...", minimapFilename );
795 WriteTGA(minimapFilename, data4b, minimap.width, minimap.height);
797 case MINIMAP_MODE_WHITE:
799 for(y = 0; y < minimap.height; ++y)
800 for(x = 0; x < minimap.width; ++x)
805 if(v > 255.0/256.0) v = 255.0/256.0;
812 Sys_Printf( " writing to %s...", minimapFilename );
813 WriteTGA(minimapFilename, data4b, minimap.width, minimap.height);
817 Sys_Printf( " done.\n" );
819 /* return to sender */
829 calculates an md4 checksum for a block of data
832 static int MD4BlockChecksum( void *buffer, int length )
834 return Com_BlockChecksum(buffer, length);
839 resets an aas checksum to match the given BSP
842 int FixAAS( int argc, char **argv )
844 int length, checksum;
847 char aas[ 1024 ], **ext;
860 Sys_Printf( "Usage: q3map -fixaas [-v] <mapname>\n" );
864 /* do some path mangling */
865 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
866 StripExtension( source );
867 DefaultExtension( source, ".bsp" );
870 Sys_Printf( "--- FixAAS ---\n" );
873 Sys_Printf( "Loading %s\n", source );
874 length = LoadFile( source, &buffer );
876 /* create bsp checksum */
877 Sys_Printf( "Creating checksum...\n" );
878 checksum = LittleLong( MD4BlockChecksum( buffer, length ) );
880 /* write checksum to aas */
885 strcpy( aas, source );
886 StripExtension( aas );
888 Sys_Printf( "Trying %s\n", aas );
892 file = fopen( aas, "r+b" );
895 if( fwrite( &checksum, 4, 1, file ) != 1 )
896 Error( "Error writing checksum to %s", aas );
900 /* return to sender */
908 analyzes a Quake engine BSP file
911 typedef struct abspHeader_s
916 bspLump_t lumps[ 1 ]; /* unknown size */
920 typedef struct abspLumpTest_s
927 int AnalyzeBSP( int argc, char **argv )
929 abspHeader_t *header;
930 int size, i, version, offset, length, lumpInt, count;
934 char lumpString[ 1024 ], source[ 1024 ];
935 qboolean lumpSwap = qfalse;
936 abspLumpTest_t *lumpTest;
937 static abspLumpTest_t lumpTests[] =
939 { sizeof( bspPlane_t ), 6, "IBSP LUMP_PLANES" },
940 { sizeof( bspBrush_t ), 1, "IBSP LUMP_BRUSHES" },
941 { 8, 6, "IBSP LUMP_BRUSHSIDES" },
942 { sizeof( bspBrushSide_t ), 6, "RBSP LUMP_BRUSHSIDES" },
943 { sizeof( bspModel_t ), 1, "IBSP LUMP_MODELS" },
944 { sizeof( bspNode_t ), 2, "IBSP LUMP_NODES" },
945 { sizeof( bspLeaf_t ), 1, "IBSP LUMP_LEAFS" },
946 { 104, 3, "IBSP LUMP_DRAWSURFS" },
947 { 44, 3, "IBSP LUMP_DRAWVERTS" },
948 { 4, 6, "IBSP LUMP_DRAWINDEXES" },
949 { 128 * 128 * 3, 1, "IBSP LUMP_LIGHTMAPS" },
950 { 256 * 256 * 3, 1, "IBSP LUMP_LIGHTMAPS (256 x 256)" },
951 { 512 * 512 * 3, 1, "IBSP LUMP_LIGHTMAPS (512 x 512)" },
959 Sys_Printf( "Usage: q3map -analyze [-lumpswap] [-v] <mapname>\n" );
963 /* process arguments */
964 for( i = 1; i < (argc - 1); i++ )
966 /* -format map|ase|... */
967 if( !strcmp( argv[ i ], "-lumpswap" ) )
969 Sys_Printf( "Swapped lump structs enabled\n" );
974 /* clean up map name */
975 strcpy( source, ExpandArg( argv[ i ] ) );
976 Sys_Printf( "Loading %s\n", source );
979 size = LoadFile( source, (void**) &header );
980 if( size == 0 || header == NULL )
982 Sys_Printf( "Unable to load %s.\n", source );
986 /* analyze ident/version */
987 memcpy( ident, header->ident, 4 );
989 version = LittleLong( header->version );
991 Sys_Printf( "Identity: %s\n", ident );
992 Sys_Printf( "Version: %d\n", version );
993 Sys_Printf( "---------------------------------------\n" );
995 /* analyze each lump */
996 for( i = 0; i < 100; i++ )
998 /* call of duty swapped lump pairs */
1001 offset = LittleLong( header->lumps[ i ].length );
1002 length = LittleLong( header->lumps[ i ].offset );
1005 /* standard lump pairs */
1008 offset = LittleLong( header->lumps[ i ].offset );
1009 length = LittleLong( header->lumps[ i ].length );
1013 lump = (byte*) header + offset;
1014 lumpInt = LittleLong( (int) *((int*) lump) );
1015 lumpFloat = LittleFloat( (float) *((float*) lump) );
1016 memcpy( lumpString, (char*) lump, ((size_t)length < sizeof(lumpString) ? (size_t)length : sizeof(lumpString)-1) );
1017 lumpString[ sizeof(lumpString)-1 ] = '\0';
1019 /* print basic lump info */
1020 Sys_Printf( "Lump: %d\n", i );
1021 Sys_Printf( "Offset: %d bytes\n", offset );
1022 Sys_Printf( "Length: %d bytes\n", length );
1024 /* only operate on valid lumps */
1027 /* print data in 4 formats */
1028 Sys_Printf( "As hex: %08X\n", lumpInt );
1029 Sys_Printf( "As int: %d\n", lumpInt );
1030 Sys_Printf( "As float: %f\n", lumpFloat );
1031 Sys_Printf( "As string: %s\n", lumpString );
1033 /* guess lump type */
1034 if( lumpString[ 0 ] == '{' && lumpString[ 2 ] == '"' )
1035 Sys_Printf( "Type guess: IBSP LUMP_ENTITIES\n" );
1036 else if( strstr( lumpString, "textures/" ) )
1037 Sys_Printf( "Type guess: IBSP LUMP_SHADERS\n" );
1040 /* guess based on size/count */
1041 for( lumpTest = lumpTests; lumpTest->radix > 0; lumpTest++ )
1043 if( (length % lumpTest->radix) != 0 )
1045 count = length / lumpTest->radix;
1046 if( count < lumpTest->minCount )
1048 Sys_Printf( "Type guess: %s (%d x %d)\n", lumpTest->name, count, lumpTest->radix );
1053 Sys_Printf( "---------------------------------------\n" );
1056 if( offset + length >= size )
1061 Sys_Printf( "Lump count: %d\n", i + 1 );
1062 Sys_Printf( "File size: %d bytes\n", size );
1064 /* return to caller */
1072 emits statistics about the bsp file
1075 int BSPInfo( int count, char **fileNames )
1078 char source[ 1024 ], ext[ 64 ];
1086 Sys_Printf( "No files to dump info for.\n");
1090 /* enable info mode */
1093 /* walk file list */
1094 for( i = 0; i < count; i++ )
1096 Sys_Printf( "---------------------------------\n" );
1098 /* mangle filename and get size */
1099 strcpy( source, fileNames[ i ] );
1100 ExtractFileExtension( source, ext );
1101 if( !Q_stricmp( ext, "map" ) )
1102 StripExtension( source );
1103 DefaultExtension( source, ".bsp" );
1104 f = fopen( source, "rb" );
1107 size = Q_filelength (f);
1113 /* load the bsp file and print lump sizes */
1114 Sys_Printf( "%s\n", source );
1115 LoadBSPFile( source );
1116 PrintBSPFileSizes();
1120 Sys_Printf( " total %9d\n", size );
1121 Sys_Printf( " %9d KB\n", size / 1024 );
1122 Sys_Printf( " %9d MB\n", size / (1024 * 1024) );
1124 Sys_Printf( "---------------------------------\n" );
1132 static void ExtrapolateTexcoords(const float *axyz, const float *ast, const float *bxyz, const float *bst, const float *cxyz, const float *cst, const float *axyz_new, float *ast_out, const float *bxyz_new, float *bst_out, const float *cxyz_new, float *cst_out)
1134 vec4_t scoeffs, tcoeffs;
1140 VectorSubtract(bxyz, axyz, dab);
1141 VectorSubtract(cxyz, axyz, dac);
1142 CrossProduct(dab, dac, norm);
1146 // s(v + norm) = s(v) when n ortho xyz
1148 // s(v) = DotProduct(v, scoeffs) + scoeffs[3]
1151 // scoeffs * (axyz, 1) == ast[0]
1152 // scoeffs * (bxyz, 1) == bst[0]
1153 // scoeffs * (cxyz, 1) == cst[0]
1154 // scoeffs * (norm, 0) == 0
1155 // scoeffs * [axyz, 1 | bxyz, 1 | cxyz, 1 | norm, 0] = [ast[0], bst[0], cst[0], 0]
1156 solvematrix[0] = axyz[0];
1157 solvematrix[4] = axyz[1];
1158 solvematrix[8] = axyz[2];
1159 solvematrix[12] = 1;
1160 solvematrix[1] = bxyz[0];
1161 solvematrix[5] = bxyz[1];
1162 solvematrix[9] = bxyz[2];
1163 solvematrix[13] = 1;
1164 solvematrix[2] = cxyz[0];
1165 solvematrix[6] = cxyz[1];
1166 solvematrix[10] = cxyz[2];
1167 solvematrix[14] = 1;
1168 solvematrix[3] = norm[0];
1169 solvematrix[7] = norm[1];
1170 solvematrix[11] = norm[2];
1171 solvematrix[15] = 0;
1173 md = m4_det(solvematrix);
1176 Sys_Printf("Cannot invert some matrix, some texcoords aren't extrapolated!");
1180 m4x4_invert(solvematrix);
1182 scoeffs[0] = ast[0];
1183 scoeffs[1] = bst[0];
1184 scoeffs[2] = cst[0];
1186 m4x4_transform_vec4(solvematrix, scoeffs);
1187 tcoeffs[0] = ast[1];
1188 tcoeffs[1] = bst[1];
1189 tcoeffs[2] = cst[1];
1191 m4x4_transform_vec4(solvematrix, tcoeffs);
1193 ast_out[0] = scoeffs[0] * axyz_new[0] + scoeffs[1] * axyz_new[1] + scoeffs[2] * axyz_new[2] + scoeffs[3];
1194 ast_out[1] = tcoeffs[0] * axyz_new[0] + tcoeffs[1] * axyz_new[1] + tcoeffs[2] * axyz_new[2] + tcoeffs[3];
1195 bst_out[0] = scoeffs[0] * bxyz_new[0] + scoeffs[1] * bxyz_new[1] + scoeffs[2] * bxyz_new[2] + scoeffs[3];
1196 bst_out[1] = tcoeffs[0] * bxyz_new[0] + tcoeffs[1] * bxyz_new[1] + tcoeffs[2] * bxyz_new[2] + tcoeffs[3];
1197 cst_out[0] = scoeffs[0] * cxyz_new[0] + scoeffs[1] * cxyz_new[1] + scoeffs[2] * cxyz_new[2] + scoeffs[3];
1198 cst_out[1] = tcoeffs[0] * cxyz_new[0] + tcoeffs[1] * cxyz_new[1] + tcoeffs[2] * cxyz_new[2] + tcoeffs[3];
1203 amaze and confuse your enemies with wierd scaled maps!
1206 int ScaleBSPMain( int argc, char **argv )
1215 float *old_xyzst = NULL;
1216 float spawn_ref = 0;
1222 Sys_Printf( "Usage: q3map [-v] -scale [-tex] [-spawn_ref <value>] <value> <mapname>\n" );
1227 for(i = 1; i < argc-2; ++i)
1229 if(!strcmp(argv[i], "-tex"))
1233 else if(!strcmp(argv[i], "-spawn_ref"))
1235 spawn_ref = atof(argv[i+1]);
1243 // if(argc-2 >= i) // always true
1244 scale[2] = scale[1] = scale[0] = atof( argv[ argc - 2 ] );
1246 scale[1] = scale[0] = atof( argv[ argc - 3 ] );
1248 scale[0] = atof( argv[ argc - 4 ] );
1250 uniform = ((scale[0] == scale[1]) && (scale[1] == scale[2]));
1252 if( scale[0] == 0.0f || scale[1] == 0.0f || scale[2] == 0.0f )
1254 Sys_Printf( "Usage: q3map [-v] -scale [-tex] [-spawn_ref <value>] <value> <mapname>\n" );
1255 Sys_Printf( "Non-zero scale value required.\n" );
1259 /* do some path mangling */
1260 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
1261 StripExtension( source );
1262 DefaultExtension( source, ".bsp" );
1265 Sys_Printf( "Loading %s\n", source );
1266 LoadBSPFile( source );
1270 Sys_Printf( "--- ScaleBSP ---\n" );
1271 Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
1273 /* scale entity keys */
1274 for( i = 0; i < numBSPEntities && i < numEntities; i++ )
1277 GetVectorForKey( &entities[ i ], "origin", vec );
1278 if( (vec[ 0 ] || vec[ 1 ] || vec[ 2 ]) )
1280 if(!strncmp(ValueForKey(&entities[i], "classname"), "info_player_", 12))
1281 vec[2] += spawn_ref;
1285 if(!strncmp(ValueForKey(&entities[i], "classname"), "info_player_", 12))
1286 vec[2] -= spawn_ref;
1287 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
1288 SetKeyValue( &entities[ i ], "origin", str );
1291 a = FloatForKey( &entities[ i ], "angle" );
1292 if(a == -1 || a == -2) // z scale
1294 else if(fabs(sin(DEG2RAD(a))) < 0.707)
1299 /* scale door lip */
1300 f = FloatForKey( &entities[ i ], "lip" );
1304 sprintf( str, "%f", f );
1305 SetKeyValue( &entities[ i ], "lip", str );
1308 /* scale plat height */
1309 f = FloatForKey( &entities[ i ], "height" );
1313 sprintf( str, "%f", f );
1314 SetKeyValue( &entities[ i ], "height", str );
1317 // TODO maybe allow a definition file for entities to specify which values are scaled how?
1321 for( i = 0; i < numBSPModels; i++ )
1323 bspModels[ i ].mins[0] *= scale[0];
1324 bspModels[ i ].mins[1] *= scale[1];
1325 bspModels[ i ].mins[2] *= scale[2];
1326 bspModels[ i ].maxs[0] *= scale[0];
1327 bspModels[ i ].maxs[1] *= scale[1];
1328 bspModels[ i ].maxs[2] *= scale[2];
1332 for( i = 0; i < numBSPNodes; i++ )
1334 bspNodes[ i ].mins[0] *= scale[0];
1335 bspNodes[ i ].mins[1] *= scale[1];
1336 bspNodes[ i ].mins[2] *= scale[2];
1337 bspNodes[ i ].maxs[0] *= scale[0];
1338 bspNodes[ i ].maxs[1] *= scale[1];
1339 bspNodes[ i ].maxs[2] *= scale[2];
1343 for( i = 0; i < numBSPLeafs; i++ )
1345 bspLeafs[ i ].mins[0] *= scale[0];
1346 bspLeafs[ i ].mins[1] *= scale[1];
1347 bspLeafs[ i ].mins[2] *= scale[2];
1348 bspLeafs[ i ].maxs[0] *= scale[0];
1349 bspLeafs[ i ].maxs[1] *= scale[1];
1350 bspLeafs[ i ].maxs[2] *= scale[2];
1355 Sys_Printf("Using texture unlocking (and probably breaking texture alignment a lot)\n");
1356 old_xyzst = safe_malloc(sizeof(*old_xyzst) * numBSPDrawVerts * 5);
1357 for(i = 0; i < numBSPDrawVerts; i++)
1359 old_xyzst[5*i+0] = bspDrawVerts[i].xyz[0];
1360 old_xyzst[5*i+1] = bspDrawVerts[i].xyz[1];
1361 old_xyzst[5*i+2] = bspDrawVerts[i].xyz[2];
1362 old_xyzst[5*i+3] = bspDrawVerts[i].st[0];
1363 old_xyzst[5*i+4] = bspDrawVerts[i].st[1];
1367 /* scale drawverts */
1368 for( i = 0; i < numBSPDrawVerts; i++ )
1370 bspDrawVerts[i].xyz[0] *= scale[0];
1371 bspDrawVerts[i].xyz[1] *= scale[1];
1372 bspDrawVerts[i].xyz[2] *= scale[2];
1373 bspDrawVerts[i].normal[0] /= scale[0];
1374 bspDrawVerts[i].normal[1] /= scale[1];
1375 bspDrawVerts[i].normal[2] /= scale[2];
1376 VectorNormalize(bspDrawVerts[i].normal, bspDrawVerts[i].normal);
1381 for(i = 0; i < numBSPDrawSurfaces; i++)
1383 switch(bspDrawSurfaces[i].surfaceType)
1387 if(bspDrawSurfaces[i].numIndexes % 3)
1388 Error("Not a triangulation!");
1389 for(j = bspDrawSurfaces[i].firstIndex; j < bspDrawSurfaces[i].firstIndex + bspDrawSurfaces[i].numIndexes; j += 3)
1391 int ia = bspDrawIndexes[j] + bspDrawSurfaces[i].firstVert, ib = bspDrawIndexes[j+1] + bspDrawSurfaces[i].firstVert, ic = bspDrawIndexes[j+2] + bspDrawSurfaces[i].firstVert;
1392 bspDrawVert_t *a = &bspDrawVerts[ia], *b = &bspDrawVerts[ib], *c = &bspDrawVerts[ic];
1393 float *oa = &old_xyzst[ia*5], *ob = &old_xyzst[ib*5], *oc = &old_xyzst[ic*5];
1398 ExtrapolateTexcoords(
1414 for( i = 0; i < numBSPPlanes; i++ )
1416 bspPlanes[ i ].dist *= scale[0];
1421 for( i = 0; i < numBSPPlanes; i++ )
1423 bspPlanes[ i ].normal[0] /= scale[0];
1424 bspPlanes[ i ].normal[1] /= scale[1];
1425 bspPlanes[ i ].normal[2] /= scale[2];
1426 f = 1/VectorLength(bspPlanes[i].normal);
1427 VectorScale(bspPlanes[i].normal, f, bspPlanes[i].normal);
1428 bspPlanes[ i ].dist *= f;
1432 /* scale gridsize */
1433 GetVectorForKey( &entities[ 0 ], "gridsize", vec );
1434 if( (vec[ 0 ] + vec[ 1 ] + vec[ 2 ]) == 0.0f )
1435 VectorCopy( gridSize, vec );
1439 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
1440 SetKeyValue( &entities[ 0 ], "gridsize", str );
1442 /* inject command line parameters */
1443 InjectCommandLine(argv, 0, argc - 1);
1447 StripExtension( source );
1448 DefaultExtension( source, "_s.bsp" );
1449 Sys_Printf( "Writing %s\n", source );
1450 WriteBSPFile( source );
1452 /* return to sender */
1459 a stripped down ProcessModels
1461 void PseudoCompileBSP(qboolean need_tree)
1464 char modelValue[10];
1473 SetDrawSurfacesBuffer();
1474 mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
1475 memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
1476 numMapDrawSurfs = 0;
1480 for( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
1483 entity = &entities[ mapEntityNum ];
1484 if( entity->brushes == NULL && entity->patches == NULL )
1487 if(mapEntityNum != 0)
1489 sprintf( modelValue, "*%d", models++);
1490 SetKeyValue(entity, "model", modelValue);
1493 /* process the model */
1494 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
1497 entity->firstDrawSurf = numMapDrawSurfs;
1499 ClearMetaTriangles();
1500 PatchMapDrawSurfs(entity);
1502 if(mapEntityNum == 0 && need_tree)
1504 faces = MakeStructuralBSPFaceList(entities[0].brushes);
1505 tree = FaceBSP(faces);
1506 node = tree->headnode;
1511 node->planenum = PLANENUM_LEAF;
1513 tree->headnode = node;
1516 /* a minimized ClipSidesIntoTree */
1517 for( brush = entity->brushes; brush; brush = brush->next )
1519 /* walk the brush sides */
1520 for( i = 0; i < brush->numsides; i++ )
1523 side = &brush->sides[ i ];
1524 if( side->winding == NULL )
1527 if( side->shaderInfo == NULL )
1529 /* save this winding as a visible surface */
1530 DrawSurfaceForSide(entity, brush, side, side->winding);
1536 ClassifyEntitySurfaces(entity);
1537 MakeEntityDecals(entity);
1538 MakeEntityMetaTriangles(entity);
1539 SmoothMetaTriangles();
1540 MergeMetaTriangles();
1542 FilterDrawsurfsIntoTree(entity, tree);
1544 FilterStructuralBrushesIntoTree(entity, tree);
1545 FilterDetailBrushesIntoTree(entity, tree);
1547 EmitBrushes(entity->brushes, &entity->firstBrush, &entity->numBrushes );
1548 EndModel(entity, node);
1555 main argument processing function for bsp conversion
1558 int ConvertBSPMain( int argc, char **argv )
1561 int (*convertFunc)( char * );
1562 game_t *convertGame;
1564 qboolean map_allowed, force_bsp, force_map;
1568 convertFunc = ConvertBSPToASE;
1570 map_allowed = qfalse;
1577 Sys_Printf( "Usage: q3map -convert -format <ase|obj|map_bp|map> [-shadesasbitmap|-lightmapsastexcoord|-deluxemapsastexcoord] [-readbsp|-readmap [-meta|-patchmeta]] <mapname>\n" );
1581 /* process arguments */
1582 for( i = 1; i < (argc - 1); i++ )
1584 /* -format map|ase|... */
1585 if( !strcmp( argv[ i ], "-format" ) )
1588 if( !Q_stricmp( argv[ i ], "ase" ) )
1590 convertFunc = ConvertBSPToASE;
1591 map_allowed = qfalse;
1593 else if( !Q_stricmp( argv[ i ], "obj" ) )
1595 convertFunc = ConvertBSPToOBJ;
1596 map_allowed = qfalse;
1598 else if( !Q_stricmp( argv[ i ], "map_bp" ) )
1600 convertFunc = ConvertBSPToMap_BP;
1601 map_allowed = qtrue;
1603 else if( !Q_stricmp( argv[ i ], "map" ) )
1605 convertFunc = ConvertBSPToMap;
1606 map_allowed = qtrue;
1610 convertGame = GetGame( argv[ i ] );
1611 map_allowed = qfalse;
1612 if( convertGame == NULL )
1613 Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
1616 else if( !strcmp( argv[ i ], "-ne" ) )
1618 normalEpsilon = atof( argv[ i + 1 ] );
1620 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
1622 else if( !strcmp( argv[ i ], "-de" ) )
1624 distanceEpsilon = atof( argv[ i + 1 ] );
1626 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
1628 else if( !strcmp( argv[ i ], "-shaderasbitmap" ) || !strcmp( argv[ i ], "-shadersasbitmap" ) )
1629 shadersAsBitmap = qtrue;
1630 else if( !strcmp( argv[ i ], "-lightmapastexcoord" ) || !strcmp( argv[ i ], "-lightmapsastexcoord" ) )
1631 lightmapsAsTexcoord = qtrue;
1632 else if( !strcmp( argv[ i ], "-deluxemapastexcoord" ) || !strcmp( argv[ i ], "-deluxemapsastexcoord" ) )
1634 lightmapsAsTexcoord = qtrue;
1637 else if( !strcmp( argv[ i ], "-readbsp" ) )
1639 else if( !strcmp( argv[ i ], "-readmap" ) )
1641 else if( !strcmp( argv[ i ], "-meta" ) )
1643 else if( !strcmp( argv[ i ], "-patchmeta" ) )
1652 /* clean up map name */
1653 strcpy(source, ExpandArg(argv[i]));
1654 ExtractFileExtension(source, ext);
1656 if(!map_allowed && !force_map)
1659 if(force_map || (!force_bsp && !Q_stricmp(ext, "map") && map_allowed))
1662 Sys_Printf("WARNING: the requested conversion should not be done from .map files. Compile a .bsp first.\n");
1663 StripExtension(source);
1664 DefaultExtension(source, ".map");
1665 Sys_Printf("Loading %s\n", source);
1666 LoadMapFile(source, qfalse, convertGame == NULL);
1667 PseudoCompileBSP(convertGame != NULL);
1671 StripExtension(source);
1672 DefaultExtension(source, ".bsp");
1673 Sys_Printf("Loading %s\n", source);
1674 LoadBSPFile(source);
1678 /* bsp format convert? */
1679 if( convertGame != NULL )
1681 /* set global game */
1685 StripExtension( source );
1686 DefaultExtension( source, "_c.bsp" );
1687 Sys_Printf( "Writing %s\n", source );
1688 WriteBSPFile( source );
1690 /* return to sender */
1694 /* normal convert */
1695 return convertFunc( source );
1705 int main( int argc, char **argv )
1711 /* we want consistent 'randomness' */
1715 start = I_FloatTime();
1717 /* this was changed to emit version number over the network */
1718 printf( Q3MAP_VERSION "\n" );
1721 atexit( ExitQ3Map );
1723 /* read general options first */
1724 for( i = 1; i < argc; i++ )
1727 if( !strcmp( argv[ i ], "-connect" ) )
1731 Broadcast_Setup( argv[ i ] );
1736 else if( !strcmp( argv[ i ], "-v" ) )
1746 else if( !strcmp( argv[ i ], "-force" ) )
1752 /* patch subdivisions */
1753 else if( !strcmp( argv[ i ], "-subdivisions" ) )
1757 patchSubdivisions = atoi( argv[ i ] );
1759 if( patchSubdivisions <= 0 )
1760 patchSubdivisions = 1;
1764 else if( !strcmp( argv[ i ], "-threads" ) )
1768 numthreads = atoi( argv[ i ] );
1773 /* init model library */
1775 PicoSetMallocFunc( safe_malloc );
1776 PicoSetFreeFunc( free );
1777 PicoSetPrintFunc( PicoPrintFunc );
1778 PicoSetLoadFileFunc( PicoLoadFileFunc );
1779 PicoSetFreeFileFunc( free );
1781 /* set number of threads */
1784 /* generate sinusoid jitter table */
1785 for( i = 0; i < MAX_JITTERS; i++ )
1787 jitters[ i ] = sin( i * 139.54152147 );
1788 //% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
1791 /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
1792 and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
1794 Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
1795 Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
1796 Sys_Printf( "NetRadiant - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
1797 Sys_Printf( "%s\n", Q3MAP_MOTD );
1799 /* ydnar: new path initialization */
1800 InitPaths( &argc, argv );
1802 /* set game options */
1803 if (!patchSubdivisions)
1804 patchSubdivisions = game->patchSubdivisions;
1806 /* check if we have enough options left to attempt something */
1808 Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
1811 if( !strcmp( argv[ 1 ], "-fixaas" ) )
1812 r = FixAAS( argc - 1, argv + 1 );
1815 else if( !strcmp( argv[ 1 ], "-analyze" ) )
1816 r = AnalyzeBSP( argc - 1, argv + 1 );
1819 else if( !strcmp( argv[ 1 ], "-info" ) )
1820 r = BSPInfo( argc - 2, argv + 2 );
1823 else if( !strcmp( argv[ 1 ], "-vis" ) )
1824 r = VisMain( argc - 1, argv + 1 );
1827 else if( !strcmp( argv[ 1 ], "-light" ) )
1828 r = LightMain( argc - 1, argv + 1 );
1831 else if( !strcmp( argv[ 1 ], "-vlight" ) )
1833 Sys_Printf( "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
1834 argv[ 1 ] = "-fast"; /* eek a hack */
1835 r = LightMain( argc, argv );
1838 /* ydnar: lightmap export */
1839 else if( !strcmp( argv[ 1 ], "-export" ) )
1840 r = ExportLightmapsMain( argc - 1, argv + 1 );
1842 /* ydnar: lightmap import */
1843 else if( !strcmp( argv[ 1 ], "-import" ) )
1844 r = ImportLightmapsMain( argc - 1, argv + 1 );
1846 /* ydnar: bsp scaling */
1847 else if( !strcmp( argv[ 1 ], "-scale" ) )
1848 r = ScaleBSPMain( argc - 1, argv + 1 );
1850 /* ydnar: bsp conversion */
1851 else if( !strcmp( argv[ 1 ], "-convert" ) )
1852 r = ConvertBSPMain( argc - 1, argv + 1 );
1855 else if( !strcmp( argv[ 1 ], "-minimap" ) )
1856 r = MiniMapBSPMain(argc - 1, argv + 1);
1858 /* ydnar: otherwise create a bsp */
1860 r = BSPMain( argc, argv );
1863 end = I_FloatTime();
1864 Sys_Printf( "%9.0f seconds elapsed\n", end - start );
1866 /* shut down connection */
1867 Broadcast_Shutdown();
1869 /* return any error code */