2 Copyright (C) 1999-2006 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 qboolean fastvis;
64 extern qboolean nosort;
68 extern qboolean dumppatches;
70 extern qboolean extrasamples;
72 extern float lightscale;
73 extern float direct_scale;
74 extern float entity_scale;
75 extern qboolean nopvs;
77 extern float maxlight;
80 void InitPaths( int *argc, char **argv );
84 returns a pseudorandom number between 0 and 1
89 return (vec_t) rand() / RAND_MAX;
99 static void ExitQ2Map( void )
102 if( mapDrawSurfs != NULL )
103 free( mapDrawSurfs );
110 emits statistics about the bsp file
115 char source[ 1024 ], ext[ 64 ];
119 Sys_Printf ("\n----- INFO ----\n\n");
122 if( mapname == NULL )
124 Sys_Printf( "No files to dump info for.\n");
128 /* enable info mode */
132 /* mangle filename and get size */
133 strcpy( source, mapname );
134 ExtractFileExtension( source, ext );
135 if( !Q_stricmp( ext, "map" ) )
136 StripExtension( source );
137 DefaultExtension( source, ".bsp" );
138 f = fopen( source, "rb" );
141 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 )
346 for (i=1 ; i<argc ; i++)
348 if (!strcmp(argv[i],"-glview"))
352 else if (!strcmp(argv[i], "-draw"))
354 Sys_Printf ("drawflag = true\n");
357 else if (!strcmp(argv[i], "-noweld"))
359 Sys_Printf ("noweld = true\n");
362 else if (!strcmp(argv[i], "-nocsg"))
364 Sys_Printf ("nocsg = true\n");
367 else if (!strcmp(argv[i], "-noshare"))
369 Sys_Printf ("noshare = true\n");
372 else if (!strcmp(argv[i], "-notjunc"))
374 Sys_Printf ("notjunc = true\n");
377 else if (!strcmp(argv[i], "-nowater"))
379 Sys_Printf ("nowater = true\n");
382 else if (!strcmp(argv[i], "-noopt"))
384 Sys_Printf ("noopt = true\n");
387 else if (!strcmp(argv[i], "-noprune"))
389 Sys_Printf ("noprune = true\n");
392 else if (!strcmp(argv[i], "-nofill"))
394 Sys_Printf ("nofill = true\n");
397 else if (!strcmp(argv[i], "-nomerge"))
399 Sys_Printf ("nomerge = true\n");
402 else if (!strcmp(argv[i], "-nosubdiv"))
404 Sys_Printf ("nosubdiv = true\n");
407 else if (!strcmp(argv[i], "-nodetail"))
409 Sys_Printf ("nodetail = true\n");
412 else if (!strcmp(argv[i], "-fulldetail"))
414 Sys_Printf ("fulldetail = true\n");
417 else if (!strcmp(argv[i], "-onlyents"))
419 Sys_Printf ("onlyents = true\n");
422 else if (!strcmp(argv[i], "-micro"))
424 microvolume = atof(argv[i+1]);
425 Sys_Printf ("microvolume = %f\n", microvolume);
428 else if (!strcmp(argv[i], "-leaktest"))
430 Sys_Printf ("leaktest = true\n");
433 else if (!strcmp(argv[i], "-verboseentities"))
435 Sys_Printf ("verboseentities = true\n");
436 verboseentities = true;
438 else if (!strcmp(argv[i], "-chop"))
440 subdivide_size = atof(argv[i+1]);
441 Sys_Printf ("subdivide_size = %f\n", subdivide_size);
444 else if (!strcmp(argv[i], "-block"))
446 block_xl = block_xh = atoi(argv[i+1]);
447 block_yl = block_yh = atoi(argv[i+2]);
448 Sys_Printf ("block: %i,%i\n", block_xl, block_yl);
451 else if (!strcmp(argv[i], "-blocks"))
453 block_xl = atoi(argv[i+1]);
454 block_yl = atoi(argv[i+2]);
455 block_xh = atoi(argv[i+3]);
456 block_yh = atoi(argv[i+4]);
457 Sys_Printf ("blocks: %i,%i to %i,%i\n",
458 block_xl, block_yl, block_xh, block_yh);
461 else if (!strcmp (argv[i],"-tmpout"))
463 strcpy (outbase, "/tmp");
473 int Check_VIS_Options( int argc, char **argv )
477 for (i=1 ; i<argc ; i++)
479 if (!strcmp(argv[i], "-fast"))
481 Sys_Printf ("fastvis = true\n");
484 else if (!strcmp(argv[i], "-level"))
486 testlevel = atoi(argv[i+1]);
487 Sys_Printf ("testlevel = %i\n", testlevel);
490 else if (!strcmp (argv[i],"-nosort"))
492 Sys_Printf ("nosort = true\n");
495 else if (!strcmp (argv[i],"-tmpin"))
496 strcpy (inbase, "/tmp");
497 else if (!strcmp (argv[i],"-tmpout"))
498 strcpy (outbase, "/tmp");
506 int Check_RAD_Options( int argc, char **argv )
510 for (i=1 ; i<argc ; i++)
512 if (!strcmp(argv[i],"-dump"))
514 else if (!strcmp(argv[i],"-bounce"))
516 numbounce = atoi (argv[i+1]);
519 else if (!strcmp(argv[i],"-extra"))
522 Sys_Printf ("extrasamples = true\n");
524 else if (!strcmp(argv[i],"-chop"))
526 subdiv = atoi (argv[i+1]);
529 else if (!strcmp(argv[i],"-scale"))
531 lightscale = atof (argv[i+1]);
534 else if (!strcmp(argv[i],"-direct"))
536 direct_scale *= atof(argv[i+1]);
537 Sys_Printf ("direct light scaling at %f\n", direct_scale);
540 else if (!strcmp(argv[i],"-entity"))
542 entity_scale *= atof(argv[i+1]);
543 Sys_Printf ("entity light scaling at %f\n", entity_scale);
546 else if (!strcmp(argv[i],"-glview"))
549 Sys_Printf ("glview = true\n");
551 else if (!strcmp(argv[i],"-nopvs"))
554 Sys_Printf ("nopvs = true\n");
556 else if (!strcmp(argv[i],"-ambient"))
558 ambient = atof (argv[i+1]) * 128;
561 else if (!strcmp(argv[i],"-maxlight"))
563 maxlight = atof (argv[i+1]) * 128;
566 else if (!strcmp (argv[i],"-tmpin"))
567 strcpy (inbase, "/tmp");
568 else if (!strcmp (argv[i],"-tmpout"))
569 strcpy (outbase, "/tmp");
581 int main( int argc, char **argv )
589 qboolean do_info=qfalse;
590 qboolean do_bsp=qfalse;
591 qboolean do_vis=qfalse;
592 qboolean do_rad=qfalse;
595 /* we want consistent 'randomness' */
599 start = I_FloatTime();
601 Sys_Printf( "\nQ2Map - Ver. 1.0\n" );
604 //atexit( ExitQ3Map );
610 Sys_Printf(" %s: -game [quake2,heretic2] -fs_basepath basepath -info -bsp -vis -rad mapname\n",argv[0]);
613 /* read general options first */
614 for( i = 1; i < argc; i++ )
617 if( !strcmp( argv[ i ], "-connect" ) )
620 Broadcast_Setup( argv[ i ] );
624 else if( !strcmp( argv[ i ], "-v" ) )
630 else if( !strcmp( argv[ i ], "-threads" ) )
633 numthreads = atoi( argv[ i ] );
635 else if( !strcmp( argv[ i ], "-game" ) )
638 strncpy (game, argv[ i ] , 64);
643 /* set number of threads */
646 /* ydnar: new path initialization */
647 InitPaths( &argc, argv );
649 /* read compiling options */
650 for( i = 1; i < argc; i++ )
653 if( !strcmp( argv[ i ], "-info" ) )
659 if( !strcmp( argv[ i ], "-bsp" ) )
663 alt_argv= (char **) ( argv + i );
664 Check_BSP_Options( alt_argc, alt_argv );
668 if( !strcmp( argv[ i ], "-vis" ) )
672 alt_argv= (char **) ( argv + i );
673 Check_VIS_Options( alt_argc, alt_argv );
677 if( !strcmp( argv[ i ], "-rad" ) )
681 alt_argv= (char **) ( argv + i );
682 Check_RAD_Options( alt_argc, alt_argv );
687 strncpy( game, "quake2", 7);
689 Sys_Printf("Game: %s\n", game);
691 if ( !do_info && !do_bsp && !do_vis && !do_rad)
692 Sys_Printf("ERROR: -bsp, -vis, -light, nor -info specified.\nWhat to you want me to do?\n\n");
695 mapname=argv[argc-1];
710 total_time = (int) (end-start);
711 Sys_Printf("\nTotal Time: ");
712 if ( total_time > 59 )
713 Sys_Printf("%d Minutes ", total_time/60 );
714 Sys_Printf( "%d Seconds\n", total_time%60 );
716 /* shut down connection */
717 Broadcast_Shutdown();
719 /* return any error code */