2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 extern qboolean verbose;
39 extern qboolean drawflag;
40 extern qboolean noprune;
41 extern qboolean glview;
42 extern qboolean nodetail;
43 extern qboolean fulldetail;
44 extern qboolean onlyents;
45 extern qboolean nomerge;
46 extern qboolean nowater;
47 extern qboolean nofill;
48 extern qboolean nocsg;
49 extern qboolean noweld;
50 extern qboolean noshare;
51 extern qboolean nosubdiv;
52 extern qboolean notjunc;
53 extern qboolean noopt;
54 extern qboolean leaktest;
55 extern qboolean verboseentities;
56 extern char outbase[32];
57 extern int block_xl, block_xh, block_yl, block_yh;
58 extern vec_t microvolume;
59 extern float subdivide_size;
62 extern char inbase[32];
63 extern char outbase[32];
64 extern qboolean fastvis;
65 extern qboolean nosort;
69 extern qboolean dumppatches;
71 extern qboolean extrasamples;
73 extern float lightscale;
74 extern float direct_scale;
75 extern float entity_scale;
76 extern qboolean nopvs;
78 extern float maxlight;
81 void InitPaths( int *argc, char **argv );
85 returns a pseudorandom number between 0 and 1
90 return (vec_t) rand() / RAND_MAX;
100 static void ExitQ2Map( void )
103 if( mapDrawSurfs != NULL )
104 free( mapDrawSurfs );
111 emits statistics about the bsp file
115 char source[ 1024 ], ext[ 64 ];
119 Sys_Printf( "\n----- INFO ----\n\n" );
122 if ( mapname == NULL ) {
123 Sys_Printf( "No files to dump info for.\n" );
127 /* enable info mode */
131 /* mangle filename and get size */
132 strcpy( source, mapname );
133 ExtractFileExtension( source, ext );
134 if ( !Q_stricmp( ext, "map" ) ) {
135 StripExtension( source );
137 DefaultExtension( source, ".bsp" );
138 f = fopen( source, "rb" );
140 size = Q_filelength( f );
147 /* load the bsp file and print lump sizes */
148 Sys_Printf( "Map: %s\n\n", source );
150 Sys_Printf( "-----------------------------------------------------\n" );
152 LoadBSPFile( source );
155 Sys_Printf( "-----------------------------------------------------\n" );
158 Sys_Printf( "Total: %d B = %.3f kB = %.3f MB\n", size, size / 1024.0, size / ( 1024.0 * 1024.0 ) );
160 Sys_Printf( "-----------------------------------------------------\n" );
170 amaze and confuse your enemies with wierd scaled maps!
173 int ScaleBSPMain( int argc, char **argv )
184 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
189 scale = atof( argv[ argc - 2 ] );
192 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
193 Sys_Printf( "Non-zero scale value required.\n" );
197 // do some path mangling
198 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
199 StripExtension( source );
200 DefaultExtension( source, ".bsp" );
203 Sys_Printf( "Loading %s\n", source );
204 LoadBSPFile( source );
208 Sys_Printf( "--- ScaleBSP ---\n" );
209 Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
212 for( i = 0; i < numBSPEntities && i < numEntities; i++ )
215 GetVectorForKey( &entities[ i ], "origin", vec );
216 if( (vec[ 0 ] + vec[ 1 ] + vec[ 2 ]) )
218 VectorScale( vec, scale, vec );
219 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
220 SetKeyValue( &entities[ i ], "origin", str );
224 f = FloatForKey( &entities[ i ], "lip" );
228 sprintf( str, "%f", f );
229 SetKeyValue( &entities[ i ], "lip", str );
234 for( i = 0; i < numBSPModels; i++ )
236 VectorScale( bspModels[ i ].mins, scale, bspModels[ i ].mins );
237 VectorScale( bspModels[ i ].maxs, scale, bspModels[ i ].maxs );
241 for( i = 0; i < numBSPNodes; i++ )
243 VectorScale( bspNodes[ i ].mins, scale, bspNodes[ i ].mins );
244 VectorScale( bspNodes[ i ].maxs, scale, bspNodes[ i ].maxs );
248 for( i = 0; i < numBSPLeafs; i++ )
250 VectorScale( bspLeafs[ i ].mins, scale, bspLeafs[ i ].mins );
251 VectorScale( bspLeafs[ i ].maxs, scale, bspLeafs[ i ].maxs );
255 for( i = 0; i < numBSPDrawVerts; i++ )
256 VectorScale( bspDrawVerts[ i ].xyz, scale, bspDrawVerts[ i ].xyz );
259 for( i = 0; i < numBSPPlanes; i++ )
260 bspPlanes[ i ].dist *= scale;
263 GetVectorForKey( &entities[ 0 ], "gridsize", vec );
264 if( (vec[ 0 ] + vec[ 1 ] + vec[ 2 ]) == 0.0f )
265 VectorCopy( gridSize, vec );
266 VectorScale( vec, scale, vec );
267 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
268 SetKeyValue( &entities[ 0 ], "gridsize", str );
272 StripExtension( source );
273 DefaultExtension( source, "_s.bsp" );
274 Sys_Printf( "Writing %s\n", source );
275 WriteBSPFile( source );
285 main argument processing function for bsp conversion
288 int ConvertBSPMain( int argc, char **argv )
291 int (*convertFunc)( char * );
295 convertFunc = ConvertBSPToASE;
300 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
305 for( i = 1; i < (argc - 1); i++ )
307 // -format map|ase|...
308 if( !strcmp( argv[ i ], "-format" ) )
311 if( !Q_stricmp( argv[ i ], "ase" ) )
312 convertFunc = ConvertBSPToASE;
313 else if( !Q_stricmp( argv[ i ], "map" ) )
314 convertFunc = ConvertBSPToMap;
316 Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
321 strcpy( source, ExpandArg( argv[ i ] ) );
322 StripExtension( source );
323 DefaultExtension( source, ".bsp" );
327 Sys_Printf( "Loading %s\n", source );
329 // ydnar: load surface file
330 //% LoadSurfaceExtraFile( source );
332 LoadBSPFile( source );
334 // parse bsp entities
338 return convertFunc( source );
342 int Check_BSP_Options( int argc, char **argv ){
345 for ( i = 1 ; i < argc ; i++ )
347 if ( !strcmp( argv[i],"-glview" ) ) {
350 else if ( !strcmp( argv[i], "-draw" ) ) {
351 Sys_Printf( "drawflag = true\n" );
354 else if ( !strcmp( argv[i], "-noweld" ) ) {
355 Sys_Printf( "noweld = true\n" );
358 else if ( !strcmp( argv[i], "-nocsg" ) ) {
359 Sys_Printf( "nocsg = true\n" );
362 else if ( !strcmp( argv[i], "-noshare" ) ) {
363 Sys_Printf( "noshare = true\n" );
366 else if ( !strcmp( argv[i], "-notjunc" ) ) {
367 Sys_Printf( "notjunc = true\n" );
370 else if ( !strcmp( argv[i], "-nowater" ) ) {
371 Sys_Printf( "nowater = true\n" );
374 else if ( !strcmp( argv[i], "-noopt" ) ) {
375 Sys_Printf( "noopt = true\n" );
378 else if ( !strcmp( argv[i], "-noprune" ) ) {
379 Sys_Printf( "noprune = true\n" );
382 else if ( !strcmp( argv[i], "-nofill" ) ) {
383 Sys_Printf( "nofill = true\n" );
386 else if ( !strcmp( argv[i], "-nomerge" ) ) {
387 Sys_Printf( "nomerge = true\n" );
390 else if ( !strcmp( argv[i], "-nosubdiv" ) ) {
391 Sys_Printf( "nosubdiv = true\n" );
394 else if ( !strcmp( argv[i], "-nodetail" ) ) {
395 Sys_Printf( "nodetail = true\n" );
398 else if ( !strcmp( argv[i], "-fulldetail" ) ) {
399 Sys_Printf( "fulldetail = true\n" );
402 else if ( !strcmp( argv[i], "-onlyents" ) ) {
403 Sys_Printf( "onlyents = true\n" );
406 else if ( !strcmp( argv[i], "-micro" ) ) {
407 microvolume = atof( argv[i + 1] );
408 Sys_Printf( "microvolume = %f\n", microvolume );
411 else if ( !strcmp( argv[i], "-leaktest" ) ) {
412 Sys_Printf( "leaktest = true\n" );
415 else if ( !strcmp( argv[i], "-verboseentities" ) ) {
416 Sys_Printf( "verboseentities = true\n" );
417 verboseentities = true;
419 else if ( !strcmp( argv[i], "-chop" ) ) {
420 subdivide_size = atof( argv[i + 1] );
421 Sys_Printf( "subdivide_size = %f\n", subdivide_size );
424 else if ( !strcmp( argv[i], "-block" ) ) {
425 block_xl = block_xh = atoi( argv[i + 1] );
426 block_yl = block_yh = atoi( argv[i + 2] );
427 Sys_Printf( "block: %i,%i\n", block_xl, block_yl );
430 else if ( !strcmp( argv[i], "-blocks" ) ) {
431 block_xl = atoi( argv[i + 1] );
432 block_yl = atoi( argv[i + 2] );
433 block_xh = atoi( argv[i + 3] );
434 block_yh = atoi( argv[i + 4] );
435 Sys_Printf( "blocks: %i,%i to %i,%i\n",
436 block_xl, block_yl, block_xh, block_yh );
439 else if ( !strcmp( argv[i],"-tmpout" ) ) {
440 strcpy( outbase, "/tmp" );
451 int Check_VIS_Options( int argc, char **argv ){
454 for ( i = 1 ; i < argc ; i++ )
456 if ( !strcmp( argv[i], "-fast" ) ) {
457 Sys_Printf( "fastvis = true\n" );
460 else if ( !strcmp( argv[i], "-level" ) ) {
461 testlevel = atoi( argv[i + 1] );
462 Sys_Printf( "testlevel = %i\n", testlevel );
465 else if ( !strcmp( argv[i],"-nosort" ) ) {
466 Sys_Printf( "nosort = true\n" );
469 else if ( !strcmp( argv[i],"-tmpin" ) ) {
470 strcpy( inbase, "/tmp" );
472 else if ( !strcmp( argv[i],"-tmpout" ) ) {
473 strcpy( outbase, "/tmp" );
483 int Check_RAD_Options( int argc, char **argv ){
486 for ( i = 1 ; i < argc ; i++ )
488 if ( !strcmp( argv[i],"-dump" ) ) {
491 else if ( !strcmp( argv[i],"-bounce" ) ) {
492 numbounce = atoi( argv[i + 1] );
495 else if ( !strcmp( argv[i],"-extra" ) ) {
497 Sys_Printf( "extrasamples = true\n" );
499 else if ( !strcmp( argv[i],"-chop" ) ) {
500 subdiv = atoi( argv[i + 1] );
503 else if ( !strcmp( argv[i],"-scale" ) ) {
504 lightscale = atof( argv[i + 1] );
507 else if ( !strcmp( argv[i],"-direct" ) ) {
508 direct_scale *= atof( argv[i + 1] );
509 Sys_Printf( "direct light scaling at %f\n", direct_scale );
512 else if ( !strcmp( argv[i],"-entity" ) ) {
513 entity_scale *= atof( argv[i + 1] );
514 Sys_Printf( "entity light scaling at %f\n", entity_scale );
517 else if ( !strcmp( argv[i],"-glview" ) ) {
519 Sys_Printf( "glview = true\n" );
521 else if ( !strcmp( argv[i],"-nopvs" ) ) {
523 Sys_Printf( "nopvs = true\n" );
525 else if ( !strcmp( argv[i],"-ambient" ) ) {
526 ambient = atof( argv[i + 1] ) * 128;
529 else if ( !strcmp( argv[i],"-maxlight" ) ) {
530 maxlight = atof( argv[i + 1] ) * 128;
533 else if ( !strcmp( argv[i],"-tmpin" ) ) {
534 strcpy( inbase, "/tmp" );
536 else if ( !strcmp( argv[i],"-tmpout" ) ) {
537 strcpy( outbase, "/tmp" );
551 int main( int argc, char **argv ){
558 qboolean do_info = qfalse;
559 qboolean do_bsp = qfalse;
560 qboolean do_vis = qfalse;
561 qboolean do_rad = qfalse;
564 /* we want consistent 'randomness' */
568 start = I_FloatTime();
570 Sys_Printf( "\nQ2Map - Ver. 1.0\n" );
573 //atexit( ExitQ3Map );
578 Sys_Printf( " %s: -game [quake2,heretic2] -fs_basepath basepath -info -bsp -vis -rad mapname\n",argv[0] );
581 /* read general options first */
582 for ( i = 1; i < argc; i++ )
585 if ( !strcmp( argv[ i ], "-connect" ) ) {
587 Broadcast_Setup( argv[ i ] );
591 else if ( !strcmp( argv[ i ], "-v" ) ) {
596 else if ( !strcmp( argv[ i ], "-threads" ) ) {
598 numthreads = atoi( argv[ i ] );
600 else if ( !strcmp( argv[ i ], "-game" ) ) {
602 strncpy( game, argv[ i ], 64 );
607 /* set number of threads */
610 /* ydnar: new path initialization */
611 InitPaths( &argc, argv );
613 /* read compiling options */
614 for ( i = 1; i < argc; i++ )
617 if ( !strcmp( argv[ i ], "-info" ) ) {
622 if ( !strcmp( argv[ i ], "-bsp" ) ) {
625 alt_argv = (char **) ( argv + i );
626 Check_BSP_Options( alt_argc, alt_argv );
630 if ( !strcmp( argv[ i ], "-vis" ) ) {
633 alt_argv = (char **) ( argv + i );
634 Check_VIS_Options( alt_argc, alt_argv );
638 if ( !strcmp( argv[ i ], "-rad" ) ) {
641 alt_argv = (char **) ( argv + i );
642 Check_RAD_Options( alt_argc, alt_argv );
646 if ( game[0] == 0 ) {
647 strncpy( game, "quake2", 7 );
650 Sys_Printf( "Game: %s\n", game );
652 if ( !do_info && !do_bsp && !do_vis && !do_rad ) {
653 Sys_FPrintf( SYS_ERR, "ERROR: -bsp, -vis, -light, nor -info specified.\nWhat to you want me to do?\n\n" );
657 mapname = argv[argc - 1];
676 total_time = (int) ( end - start );
677 Sys_Printf( "\nTotal Time: " );
678 if ( total_time > 59 ) {
679 Sys_Printf( "%d Minutes ", total_time / 60 );
681 Sys_Printf( "%d Seconds\n", total_time % 60 );
683 /* shut down connection */
684 Broadcast_Shutdown();
686 /* return any error code */