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 /* borrowed from light.c */
70 void WriteTGA24( char *filename, byte *data, int width, int height, qboolean flip );
71 typedef struct minimap_s
78 float sharpen_boxmult;
79 float sharpen_centermult;
85 static minimap_t minimap;
87 qboolean BrushIntersectionWithLine(bspBrush_t *brush, vec3_t start, vec3_t dir, float *t_in, float *t_out)
90 qboolean in = qfalse, out = qfalse;
91 bspBrushSide_t *sides = &bspBrushSides[brush->firstSide];
93 for(i = 0; i < brush->numSides; ++i)
95 bspPlane_t *p = &bspPlanes[sides[i].planeNum];
96 float sn = DotProduct(start, p->normal);
97 float dn = DotProduct(dir, p->normal);
101 return qfalse; // outside!
105 float t = (p->dist - sn) / dn;
112 // as t_in can only increase, and t_out can only decrease, early out
113 if(out && *t_in >= *t_out)
119 if(!out || t < *t_out)
123 // as t_in can only increase, and t_out can only decrease, early out
124 if(in && *t_in >= *t_out)
133 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 bspBrushSide_t *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 static void GenerateMiniMapRunner(int y)
183 float *p = &minimap.data1f[y * minimap.width];
184 float ymin = minimap.mins[1] + minimap.size[1] * (y / (float) minimap.height);
185 float dx = minimap.size[0] / (float) minimap.width;
186 float dy = minimap.size[1] / (float) minimap.height;
188 for(x = 0; x < minimap.width; ++x)
190 float xmin = minimap.mins[0] + minimap.size[0] * (x / (float) minimap.width);
193 for(i = 0; i < minimap.samples; ++i)
195 float thisval = MiniMapSample(
196 xmin + Random() * dx,
201 val /= minimap.samples * minimap.size[2];
206 static void GenerateMiniMapRunnerNoSamples(int y)
209 float *p = &minimap.data1f[y * minimap.width];
210 float ymin = minimap.mins[1] + minimap.size[1] * (y / (float) minimap.height);
212 for(x = 0; x < minimap.width; ++x)
214 float xmin = minimap.mins[0] + minimap.size[0] * (x / (float) minimap.width);
215 *p++ = MiniMapSample(xmin, ymin) / minimap.size[2];
219 static void SharpenMiniMapRunner(int y)
222 qboolean up = (y > 0);
223 qboolean down = (y < minimap.height - 1);
224 float *p = &minimap.data1f[y * minimap.width];
225 float *q = &minimap.sharpendata1f[y * minimap.width];
227 for(x = 0; x < minimap.width; ++x)
229 qboolean left = (x > 0);
230 qboolean right = (x < minimap.width - 1);
231 float val = p[0] * minimap.sharpen_centermult;
234 val += p[-1 -minimap.width] * minimap.sharpen_boxmult;
236 val += p[-1 +minimap.width] * minimap.sharpen_boxmult;
238 val += p[+1 -minimap.width] * minimap.sharpen_boxmult;
240 val += p[+1 +minimap.width] * minimap.sharpen_boxmult;
243 val += p[-1] * minimap.sharpen_boxmult;
245 val += p[+1] * minimap.sharpen_boxmult;
247 val += p[-minimap.width] * minimap.sharpen_boxmult;
249 val += p[+minimap.width] * minimap.sharpen_boxmult;
256 int MiniMapBSPMain( int argc, char **argv )
258 char minimapFilename[1024];
266 Sys_Printf( "Usage: q3map [-v] -minimap [-size n] [-sharpen n] [-samples f] [-o filename.tga] <mapname>\n" );
270 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
271 StripExtension( source );
272 DefaultExtension( source, ".bsp" );
274 strcpy( minimapFilename, ExpandArg( argv[ argc - 1 ] ) );
275 StripExtension( minimapFilename );
276 DefaultExtension( minimapFilename, ".tga" );
278 minimap.width = minimap.height = 512;
283 minimap.sharpen_centermult = 8 * minimap.sharpen + 1;
284 minimap.sharpen_boxmult = -minimap.sharpen;
287 minimap.data1f = safe_malloc(minimap.width * minimap.height * sizeof(*minimap.data1f));
288 data3b = safe_malloc(minimap.width * minimap.height * 3);
289 if(minimap.sharpen >= 0)
290 minimap.sharpendata1f = safe_malloc(minimap.width * minimap.height * sizeof(*minimap.data1f));
293 Sys_Printf( "Loading %s\n", source );
294 LoadBSPFile( source );
296 minimap.model = &bspModels[0];
297 VectorCopy(minimap.model->mins, minimap.mins);
298 VectorSubtract(minimap.model->maxs, minimap.model->mins, minimap.size);
302 if(minimap.samples <= 1)
304 Sys_Printf( "\n--- GenerateMiniMap (%d) ---\n", minimap.height );
305 RunThreadsOnIndividual(minimap.height, qtrue, GenerateMiniMapRunnerNoSamples);
309 Sys_Printf( "\n--- GenerateMiniMap (%d) ---\n", minimap.height );
310 RunThreadsOnIndividual(minimap.height, qtrue, GenerateMiniMapRunner);
313 if(minimap.sharpendata1f)
315 Sys_Printf( "\n--- SharpenMiniMap (%d) ---\n", minimap.height );
316 RunThreadsOnIndividual(minimap.height, qtrue, SharpenMiniMapRunner);
317 q = minimap.sharpendata1f;
324 Sys_Printf( "\nConverting...");
326 for(y = 0; y < minimap.height; ++y)
327 for(x = 0; x < minimap.width; ++x)
332 if(v > 255.0/256.0) v = 255.0/256.0;
339 Sys_Printf( " writing to %s...", minimapFilename );
340 WriteTGA24(minimapFilename, data3b, minimap.width, minimap.height, qfalse);
342 Sys_Printf( " done.\n" );
344 /* return to sender */
354 calculates an md4 checksum for a block of data
357 static int MD4BlockChecksum( void *buffer, int length )
359 return Com_BlockChecksum(buffer, length);
364 resets an aas checksum to match the given BSP
367 int FixAAS( int argc, char **argv )
369 int length, checksum;
372 char aas[ 1024 ], **ext;
385 Sys_Printf( "Usage: q3map -fixaas [-v] <mapname>\n" );
389 /* do some path mangling */
390 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
391 StripExtension( source );
392 DefaultExtension( source, ".bsp" );
395 Sys_Printf( "--- FixAAS ---\n" );
398 Sys_Printf( "Loading %s\n", source );
399 length = LoadFile( source, &buffer );
401 /* create bsp checksum */
402 Sys_Printf( "Creating checksum...\n" );
403 checksum = LittleLong( MD4BlockChecksum( buffer, length ) );
405 /* write checksum to aas */
410 strcpy( aas, source );
411 StripExtension( aas );
413 Sys_Printf( "Trying %s\n", aas );
417 file = fopen( aas, "r+b" );
420 if( fwrite( &checksum, 4, 1, file ) != 1 )
421 Error( "Error writing checksum to %s", aas );
425 /* return to sender */
433 analyzes a Quake engine BSP file
436 typedef struct abspHeader_s
441 bspLump_t lumps[ 1 ]; /* unknown size */
445 typedef struct abspLumpTest_s
452 int AnalyzeBSP( int argc, char **argv )
454 abspHeader_t *header;
455 int size, i, version, offset, length, lumpInt, count;
459 char lumpString[ 1024 ], source[ 1024 ];
460 qboolean lumpSwap = qfalse;
461 abspLumpTest_t *lumpTest;
462 static abspLumpTest_t lumpTests[] =
464 { sizeof( bspPlane_t ), 6, "IBSP LUMP_PLANES" },
465 { sizeof( bspBrush_t ), 1, "IBSP LUMP_BRUSHES" },
466 { 8, 6, "IBSP LUMP_BRUSHSIDES" },
467 { sizeof( bspBrushSide_t ), 6, "RBSP LUMP_BRUSHSIDES" },
468 { sizeof( bspModel_t ), 1, "IBSP LUMP_MODELS" },
469 { sizeof( bspNode_t ), 2, "IBSP LUMP_NODES" },
470 { sizeof( bspLeaf_t ), 1, "IBSP LUMP_LEAFS" },
471 { 104, 3, "IBSP LUMP_DRAWSURFS" },
472 { 44, 3, "IBSP LUMP_DRAWVERTS" },
473 { 4, 6, "IBSP LUMP_DRAWINDEXES" },
474 { 128 * 128 * 3, 1, "IBSP LUMP_LIGHTMAPS" },
475 { 256 * 256 * 3, 1, "IBSP LUMP_LIGHTMAPS (256 x 256)" },
476 { 512 * 512 * 3, 1, "IBSP LUMP_LIGHTMAPS (512 x 512)" },
484 Sys_Printf( "Usage: q3map -analyze [-lumpswap] [-v] <mapname>\n" );
488 /* process arguments */
489 for( i = 1; i < (argc - 1); i++ )
491 /* -format map|ase|... */
492 if( !strcmp( argv[ i ], "-lumpswap" ) )
494 Sys_Printf( "Swapped lump structs enabled\n" );
499 /* clean up map name */
500 strcpy( source, ExpandArg( argv[ i ] ) );
501 Sys_Printf( "Loading %s\n", source );
504 size = LoadFile( source, (void**) &header );
505 if( size == 0 || header == NULL )
507 Sys_Printf( "Unable to load %s.\n", source );
511 /* analyze ident/version */
512 memcpy( ident, header->ident, 4 );
514 version = LittleLong( header->version );
516 Sys_Printf( "Identity: %s\n", ident );
517 Sys_Printf( "Version: %d\n", version );
518 Sys_Printf( "---------------------------------------\n" );
520 /* analyze each lump */
521 for( i = 0; i < 100; i++ )
523 /* call of duty swapped lump pairs */
526 offset = LittleLong( header->lumps[ i ].length );
527 length = LittleLong( header->lumps[ i ].offset );
530 /* standard lump pairs */
533 offset = LittleLong( header->lumps[ i ].offset );
534 length = LittleLong( header->lumps[ i ].length );
538 lump = (byte*) header + offset;
539 lumpInt = LittleLong( (int) *((int*) lump) );
540 lumpFloat = LittleFloat( (float) *((float*) lump) );
541 memcpy( lumpString, (char*) lump, (length < 1024 ? length : 1024) );
542 lumpString[ 1024 ] = '\0';
544 /* print basic lump info */
545 Sys_Printf( "Lump: %d\n", i );
546 Sys_Printf( "Offset: %d bytes\n", offset );
547 Sys_Printf( "Length: %d bytes\n", length );
549 /* only operate on valid lumps */
552 /* print data in 4 formats */
553 Sys_Printf( "As hex: %08X\n", lumpInt );
554 Sys_Printf( "As int: %d\n", lumpInt );
555 Sys_Printf( "As float: %f\n", lumpFloat );
556 Sys_Printf( "As string: %s\n", lumpString );
558 /* guess lump type */
559 if( lumpString[ 0 ] == '{' && lumpString[ 2 ] == '"' )
560 Sys_Printf( "Type guess: IBSP LUMP_ENTITIES\n" );
561 else if( strstr( lumpString, "textures/" ) )
562 Sys_Printf( "Type guess: IBSP LUMP_SHADERS\n" );
565 /* guess based on size/count */
566 for( lumpTest = lumpTests; lumpTest->radix > 0; lumpTest++ )
568 if( (length % lumpTest->radix) != 0 )
570 count = length / lumpTest->radix;
571 if( count < lumpTest->minCount )
573 Sys_Printf( "Type guess: %s (%d x %d)\n", lumpTest->name, count, lumpTest->radix );
578 Sys_Printf( "---------------------------------------\n" );
581 if( offset + length >= size )
586 Sys_Printf( "Lump count: %d\n", i + 1 );
587 Sys_Printf( "File size: %d bytes\n", size );
589 /* return to caller */
597 emits statistics about the bsp file
600 int BSPInfo( int count, char **fileNames )
603 char source[ 1024 ], ext[ 64 ];
611 Sys_Printf( "No files to dump info for.\n");
615 /* enable info mode */
619 for( i = 0; i < count; i++ )
621 Sys_Printf( "---------------------------------\n" );
623 /* mangle filename and get size */
624 strcpy( source, fileNames[ i ] );
625 ExtractFileExtension( source, ext );
626 if( !Q_stricmp( ext, "map" ) )
627 StripExtension( source );
628 DefaultExtension( source, ".bsp" );
629 f = fopen( source, "rb" );
632 size = Q_filelength (f);
638 /* load the bsp file and print lump sizes */
639 Sys_Printf( "%s\n", source );
640 LoadBSPFile( source );
645 Sys_Printf( " total %9d\n", size );
646 Sys_Printf( " %9d KB\n", size / 1024 );
647 Sys_Printf( " %9d MB\n", size / (1024 * 1024) );
649 Sys_Printf( "---------------------------------\n" );
657 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)
659 vec4_t scoeffs, tcoeffs;
665 VectorSubtract(bxyz, axyz, dab);
666 VectorSubtract(cxyz, axyz, dac);
667 CrossProduct(dab, dac, norm);
671 // s(v + norm) = s(v) when n ortho xyz
673 // s(v) = DotProduct(v, scoeffs) + scoeffs[3]
676 // scoeffs * (axyz, 1) == ast[0]
677 // scoeffs * (bxyz, 1) == bst[0]
678 // scoeffs * (cxyz, 1) == cst[0]
679 // scoeffs * (norm, 0) == 0
680 // scoeffs * [axyz, 1 | bxyz, 1 | cxyz, 1 | norm, 0] = [ast[0], bst[0], cst[0], 0]
681 solvematrix[0] = axyz[0];
682 solvematrix[4] = axyz[1];
683 solvematrix[8] = axyz[2];
685 solvematrix[1] = bxyz[0];
686 solvematrix[5] = bxyz[1];
687 solvematrix[9] = bxyz[2];
689 solvematrix[2] = cxyz[0];
690 solvematrix[6] = cxyz[1];
691 solvematrix[10] = cxyz[2];
693 solvematrix[3] = norm[0];
694 solvematrix[7] = norm[1];
695 solvematrix[11] = norm[2];
698 md = m4_det(solvematrix);
701 Sys_Printf("Cannot invert some matrix, some texcoords aren't extrapolated!");
705 m4x4_invert(solvematrix);
711 m4x4_transform_vec4(solvematrix, scoeffs);
716 m4x4_transform_vec4(solvematrix, tcoeffs);
718 ast_out[0] = scoeffs[0] * axyz_new[0] + scoeffs[1] * axyz_new[1] + scoeffs[2] * axyz_new[2] + scoeffs[3];
719 ast_out[1] = tcoeffs[0] * axyz_new[0] + tcoeffs[1] * axyz_new[1] + tcoeffs[2] * axyz_new[2] + tcoeffs[3];
720 bst_out[0] = scoeffs[0] * bxyz_new[0] + scoeffs[1] * bxyz_new[1] + scoeffs[2] * bxyz_new[2] + scoeffs[3];
721 bst_out[1] = tcoeffs[0] * bxyz_new[0] + tcoeffs[1] * bxyz_new[1] + tcoeffs[2] * bxyz_new[2] + tcoeffs[3];
722 cst_out[0] = scoeffs[0] * cxyz_new[0] + scoeffs[1] * cxyz_new[1] + scoeffs[2] * cxyz_new[2] + scoeffs[3];
723 cst_out[1] = tcoeffs[0] * cxyz_new[0] + tcoeffs[1] * cxyz_new[1] + tcoeffs[2] * cxyz_new[2] + tcoeffs[3];
728 amaze and confuse your enemies with wierd scaled maps!
731 int ScaleBSPMain( int argc, char **argv )
740 float *old_xyzst = NULL;
746 Sys_Printf( "Usage: q3map [-v] -scale [-tex] <value> <mapname>\n" );
751 scale[2] = scale[1] = scale[0] = atof( argv[ argc - 2 ] );
753 scale[1] = scale[0] = atof( argv[ argc - 3 ] );
755 scale[0] = atof( argv[ argc - 4 ] );
757 texscale = !strcmp(argv[1], "-tex");
759 uniform = ((scale[0] == scale[1]) && (scale[1] == scale[2]));
761 if( scale[0] == 0.0f || scale[1] == 0.0f || scale[2] == 0.0f )
763 Sys_Printf( "Usage: q3map [-v] -scale [-tex] <value> <mapname>\n" );
764 Sys_Printf( "Non-zero scale value required.\n" );
768 /* do some path mangling */
769 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
770 StripExtension( source );
771 DefaultExtension( source, ".bsp" );
774 Sys_Printf( "Loading %s\n", source );
775 LoadBSPFile( source );
779 Sys_Printf( "--- ScaleBSP ---\n" );
780 Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
782 /* scale entity keys */
783 for( i = 0; i < numBSPEntities && i < numEntities; i++ )
786 GetVectorForKey( &entities[ i ], "origin", vec );
787 if( (vec[ 0 ] || vec[ 1 ] || vec[ 2 ]) )
792 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
793 SetKeyValue( &entities[ i ], "origin", str );
796 a = FloatForKey( &entities[ i ], "angle" );
797 if(a == -1 || a == -2) // z scale
799 else if(fabs(sin(DEG2RAD(a))) < 0.707)
805 f = FloatForKey( &entities[ i ], "lip" );
809 sprintf( str, "%f", f );
810 SetKeyValue( &entities[ i ], "lip", str );
813 /* scale plat height */
814 f = FloatForKey( &entities[ i ], "height" );
818 sprintf( str, "%f", f );
819 SetKeyValue( &entities[ i ], "height", str );
822 // TODO maybe allow a definition file for entities to specify which values are scaled how?
826 for( i = 0; i < numBSPModels; i++ )
828 bspModels[ i ].mins[0] *= scale[0];
829 bspModels[ i ].mins[1] *= scale[1];
830 bspModels[ i ].mins[2] *= scale[2];
831 bspModels[ i ].maxs[0] *= scale[0];
832 bspModels[ i ].maxs[1] *= scale[1];
833 bspModels[ i ].maxs[2] *= scale[2];
837 for( i = 0; i < numBSPNodes; i++ )
839 bspNodes[ i ].mins[0] *= scale[0];
840 bspNodes[ i ].mins[1] *= scale[1];
841 bspNodes[ i ].mins[2] *= scale[2];
842 bspNodes[ i ].maxs[0] *= scale[0];
843 bspNodes[ i ].maxs[1] *= scale[1];
844 bspNodes[ i ].maxs[2] *= scale[2];
848 for( i = 0; i < numBSPLeafs; i++ )
850 bspLeafs[ i ].mins[0] *= scale[0];
851 bspLeafs[ i ].mins[1] *= scale[1];
852 bspLeafs[ i ].mins[2] *= scale[2];
853 bspLeafs[ i ].maxs[0] *= scale[0];
854 bspLeafs[ i ].maxs[1] *= scale[1];
855 bspLeafs[ i ].maxs[2] *= scale[2];
860 Sys_Printf("Using texture unlocking (and probably breaking texture alignment a lot)\n");
861 old_xyzst = safe_malloc(sizeof(*old_xyzst) * numBSPDrawVerts * 5);
862 for(i = 0; i < numBSPDrawVerts; i++)
864 old_xyzst[5*i+0] = bspDrawVerts[i].xyz[0];
865 old_xyzst[5*i+1] = bspDrawVerts[i].xyz[1];
866 old_xyzst[5*i+2] = bspDrawVerts[i].xyz[2];
867 old_xyzst[5*i+3] = bspDrawVerts[i].st[0];
868 old_xyzst[5*i+4] = bspDrawVerts[i].st[1];
872 /* scale drawverts */
873 for( i = 0; i < numBSPDrawVerts; i++ )
875 bspDrawVerts[i].xyz[0] *= scale[0];
876 bspDrawVerts[i].xyz[1] *= scale[1];
877 bspDrawVerts[i].xyz[2] *= scale[2];
878 bspDrawVerts[i].normal[0] /= scale[0];
879 bspDrawVerts[i].normal[1] /= scale[1];
880 bspDrawVerts[i].normal[2] /= scale[2];
881 VectorNormalize(bspDrawVerts[i].normal, bspDrawVerts[i].normal);
886 for(i = 0; i < numBSPDrawSurfaces; i++)
888 switch(bspDrawSurfaces[i].surfaceType)
892 if(bspDrawSurfaces[i].numIndexes % 3)
893 Error("Not a triangulation!");
894 for(j = bspDrawSurfaces[i].firstIndex; j < bspDrawSurfaces[i].firstIndex + bspDrawSurfaces[i].numIndexes; j += 3)
896 int ia = bspDrawIndexes[j] + bspDrawSurfaces[i].firstVert, ib = bspDrawIndexes[j+1] + bspDrawSurfaces[i].firstVert, ic = bspDrawIndexes[j+2] + bspDrawSurfaces[i].firstVert;
897 bspDrawVert_t *a = &bspDrawVerts[ia], *b = &bspDrawVerts[ib], *c = &bspDrawVerts[ic];
898 float *oa = &old_xyzst[ia*5], *ob = &old_xyzst[ib*5], *oc = &old_xyzst[ic*5];
903 ExtrapolateTexcoords(
919 for( i = 0; i < numBSPPlanes; i++ )
921 bspPlanes[ i ].dist *= scale[0];
926 for( i = 0; i < numBSPPlanes; i++ )
928 bspPlanes[ i ].normal[0] /= scale[0];
929 bspPlanes[ i ].normal[1] /= scale[1];
930 bspPlanes[ i ].normal[2] /= scale[2];
931 f = 1/VectorLength(bspPlanes[i].normal);
932 VectorScale(bspPlanes[i].normal, f, bspPlanes[i].normal);
933 bspPlanes[ i ].dist *= f;
938 GetVectorForKey( &entities[ 0 ], "gridsize", vec );
939 if( (vec[ 0 ] + vec[ 1 ] + vec[ 2 ]) == 0.0f )
940 VectorCopy( gridSize, vec );
944 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
945 SetKeyValue( &entities[ 0 ], "gridsize", str );
947 /* inject command line parameters */
948 InjectCommandLine(argv, 0, argc - 1);
952 StripExtension( source );
953 DefaultExtension( source, "_s.bsp" );
954 Sys_Printf( "Writing %s\n", source );
955 WriteBSPFile( source );
957 /* return to sender */
965 main argument processing function for bsp conversion
968 int ConvertBSPMain( int argc, char **argv )
971 int (*convertFunc)( char * );
976 convertFunc = ConvertBSPToASE;
982 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
986 /* process arguments */
987 for( i = 1; i < (argc - 1); i++ )
989 /* -format map|ase|... */
990 if( !strcmp( argv[ i ], "-format" ) )
993 if( !Q_stricmp( argv[ i ], "ase" ) )
994 convertFunc = ConvertBSPToASE;
995 else if( !Q_stricmp( argv[ i ], "map" ) )
996 convertFunc = ConvertBSPToMap;
999 convertGame = GetGame( argv[ i ] );
1000 if( convertGame == NULL )
1001 Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
1004 else if( !strcmp( argv[ i ], "-ne" ) )
1006 normalEpsilon = atof( argv[ i + 1 ] );
1008 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
1010 else if( !strcmp( argv[ i ], "-de" ) )
1012 distanceEpsilon = atof( argv[ i + 1 ] );
1014 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
1016 else if( !strcmp( argv[ i ], "-shadersasbitmap" ) )
1017 shadersAsBitmap = qtrue;
1020 /* clean up map name */
1021 strcpy( source, ExpandArg( argv[ i ] ) );
1022 StripExtension( source );
1023 DefaultExtension( source, ".bsp" );
1027 Sys_Printf( "Loading %s\n", source );
1029 /* ydnar: load surface file */
1030 //% LoadSurfaceExtraFile( source );
1032 LoadBSPFile( source );
1034 /* parse bsp entities */
1037 /* bsp format convert? */
1038 if( convertGame != NULL )
1040 /* set global game */
1044 StripExtension( source );
1045 DefaultExtension( source, "_c.bsp" );
1046 Sys_Printf( "Writing %s\n", source );
1047 WriteBSPFile( source );
1049 /* return to sender */
1053 /* normal convert */
1054 return convertFunc( source );
1064 int main( int argc, char **argv )
1070 /* we want consistent 'randomness' */
1074 start = I_FloatTime();
1076 /* this was changed to emit version number over the network */
1077 printf( Q3MAP_VERSION "\n" );
1080 atexit( ExitQ3Map );
1082 /* read general options first */
1083 for( i = 1; i < argc; i++ )
1086 if( !strcmp( argv[ i ], "-connect" ) )
1090 Broadcast_Setup( argv[ i ] );
1095 else if( !strcmp( argv[ i ], "-v" ) )
1105 else if( !strcmp( argv[ i ], "-force" ) )
1111 /* patch subdivisions */
1112 else if( !strcmp( argv[ i ], "-subdivisions" ) )
1116 patchSubdivisions = atoi( argv[ i ] );
1118 if( patchSubdivisions <= 0 )
1119 patchSubdivisions = 1;
1123 else if( !strcmp( argv[ i ], "-threads" ) )
1127 numthreads = atoi( argv[ i ] );
1132 /* init model library */
1134 PicoSetMallocFunc( safe_malloc );
1135 PicoSetFreeFunc( free );
1136 PicoSetPrintFunc( PicoPrintFunc );
1137 PicoSetLoadFileFunc( PicoLoadFileFunc );
1138 PicoSetFreeFileFunc( free );
1140 /* set number of threads */
1143 /* generate sinusoid jitter table */
1144 for( i = 0; i < MAX_JITTERS; i++ )
1146 jitters[ i ] = sin( i * 139.54152147 );
1147 //% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
1150 /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
1151 and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
1153 Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
1154 Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
1155 Sys_Printf( "NetRadiant - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
1156 Sys_Printf( "%s\n", Q3MAP_MOTD );
1158 /* ydnar: new path initialization */
1159 InitPaths( &argc, argv );
1161 /* set game options */
1162 if (!patchSubdivisions)
1163 patchSubdivisions = game->patchSubdivisions;
1165 /* check if we have enough options left to attempt something */
1167 Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
1170 if( !strcmp( argv[ 1 ], "-fixaas" ) )
1171 r = FixAAS( argc - 1, argv + 1 );
1174 else if( !strcmp( argv[ 1 ], "-analyze" ) )
1175 r = AnalyzeBSP( argc - 1, argv + 1 );
1178 else if( !strcmp( argv[ 1 ], "-info" ) )
1179 r = BSPInfo( argc - 2, argv + 2 );
1182 else if( !strcmp( argv[ 1 ], "-vis" ) )
1183 r = VisMain( argc - 1, argv + 1 );
1186 else if( !strcmp( argv[ 1 ], "-light" ) )
1187 r = LightMain( argc - 1, argv + 1 );
1190 else if( !strcmp( argv[ 1 ], "-vlight" ) )
1192 Sys_Printf( "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
1193 argv[ 1 ] = "-fast"; /* eek a hack */
1194 r = LightMain( argc, argv );
1197 /* ydnar: lightmap export */
1198 else if( !strcmp( argv[ 1 ], "-export" ) )
1199 r = ExportLightmapsMain( argc - 1, argv + 1 );
1201 /* ydnar: lightmap import */
1202 else if( !strcmp( argv[ 1 ], "-import" ) )
1203 r = ImportLightmapsMain( argc - 1, argv + 1 );
1205 /* ydnar: bsp scaling */
1206 else if( !strcmp( argv[ 1 ], "-scale" ) )
1207 r = ScaleBSPMain( argc - 1, argv + 1 );
1209 /* ydnar: bsp conversion */
1210 else if( !strcmp( argv[ 1 ], "-convert" ) )
1211 r = ConvertBSPMain( argc - 1, argv + 1 );
1214 else if( !strcmp( argv[ 1 ], "-minimap" ) )
1215 r = MiniMapBSPMain(argc - 1, argv + 1);
1217 /* ydnar: otherwise create a bsp */
1219 r = BSPMain( argc, argv );
1222 end = I_FloatTime();
1223 Sys_Printf( "%9.0f seconds elapsed\n", end - start );
1225 /* shut down connection */
1226 Broadcast_Shutdown();
1228 /* return any error code */