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 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
114 char source[ 1024 ], ext[ 64 ];
118 Sys_Printf( "\n----- INFO ----\n\n" );
121 if ( mapname == NULL ) {
122 Sys_Printf( "No files to dump info for.\n" );
126 /* enable info mode */
130 /* mangle filename and get size */
131 strcpy( source, mapname );
132 ExtractFileExtension( source, ext );
133 if ( !Q_stricmp( ext, "map" ) ) {
134 StripExtension( source );
136 DefaultExtension( source, ".bsp" );
137 f = fopen( source, "rb" );
139 size = Q_filelength( f );
146 /* load the bsp file and print lump sizes */
147 Sys_Printf( "Map: %s\n\n", source );
149 Sys_Printf( "-----------------------------------------------------\n" );
151 LoadBSPFile( source );
154 Sys_Printf( "-----------------------------------------------------\n" );
157 Sys_Printf( "Total: %d B = %.3f kB = %.3f MB\n", size, size / 1024.0, size / ( 1024.0 * 1024.0 ) );
159 Sys_Printf( "-----------------------------------------------------\n" );
169 amaze and confuse your enemies with wierd scaled maps!
172 int ScaleBSPMain( int argc, char **argv )
183 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
188 scale = atof( argv[ argc - 2 ] );
191 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
192 Sys_Printf( "Non-zero scale value required.\n" );
196 // do some path mangling
197 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
198 StripExtension( source );
199 DefaultExtension( source, ".bsp" );
202 Sys_Printf( "Loading %s\n", source );
203 LoadBSPFile( source );
207 Sys_Printf( "--- ScaleBSP ---\n" );
208 Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
211 for( i = 0; i < numBSPEntities && i < numEntities; i++ )
214 GetVectorForKey( &entities[ i ], "origin", vec );
215 if( (vec[ 0 ] + vec[ 1 ] + vec[ 2 ]) )
217 VectorScale( vec, scale, vec );
218 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
219 SetKeyValue( &entities[ i ], "origin", str );
223 f = FloatForKey( &entities[ i ], "lip" );
227 sprintf( str, "%f", f );
228 SetKeyValue( &entities[ i ], "lip", str );
233 for( i = 0; i < numBSPModels; i++ )
235 VectorScale( bspModels[ i ].mins, scale, bspModels[ i ].mins );
236 VectorScale( bspModels[ i ].maxs, scale, bspModels[ i ].maxs );
240 for( i = 0; i < numBSPNodes; i++ )
242 VectorScale( bspNodes[ i ].mins, scale, bspNodes[ i ].mins );
243 VectorScale( bspNodes[ i ].maxs, scale, bspNodes[ i ].maxs );
247 for( i = 0; i < numBSPLeafs; i++ )
249 VectorScale( bspLeafs[ i ].mins, scale, bspLeafs[ i ].mins );
250 VectorScale( bspLeafs[ i ].maxs, scale, bspLeafs[ i ].maxs );
254 for( i = 0; i < numBSPDrawVerts; i++ )
255 VectorScale( bspDrawVerts[ i ].xyz, scale, bspDrawVerts[ i ].xyz );
258 for( i = 0; i < numBSPPlanes; i++ )
259 bspPlanes[ i ].dist *= scale;
262 GetVectorForKey( &entities[ 0 ], "gridsize", vec );
263 if( (vec[ 0 ] + vec[ 1 ] + vec[ 2 ]) == 0.0f )
264 VectorCopy( gridSize, vec );
265 VectorScale( vec, scale, vec );
266 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
267 SetKeyValue( &entities[ 0 ], "gridsize", str );
271 StripExtension( source );
272 DefaultExtension( source, "_s.bsp" );
273 Sys_Printf( "Writing %s\n", source );
274 WriteBSPFile( source );
284 main argument processing function for bsp conversion
287 int ConvertBSPMain( int argc, char **argv )
290 int (*convertFunc)( char * );
294 convertFunc = ConvertBSPToASE;
299 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
304 for( i = 1; i < (argc - 1); i++ )
306 // -format map|ase|...
307 if( !strcmp( argv[ i ], "-format" ) )
310 if( !Q_stricmp( argv[ i ], "ase" ) )
311 convertFunc = ConvertBSPToASE;
312 else if( !Q_stricmp( argv[ i ], "map" ) )
313 convertFunc = ConvertBSPToMap;
315 Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
320 strcpy( source, ExpandArg( argv[ i ] ) );
321 StripExtension( source );
322 DefaultExtension( source, ".bsp" );
326 Sys_Printf( "Loading %s\n", source );
328 // ydnar: load surface file
329 //% LoadSurfaceExtraFile( source );
331 LoadBSPFile( source );
333 // parse bsp entities
337 return convertFunc( source );
341 int Check_BSP_Options( int argc, char **argv ){
344 for ( i = 1 ; i < argc ; i++ )
346 if ( !strcmp( argv[i],"-glview" ) ) {
349 else if ( !strcmp( argv[i], "-draw" ) ) {
350 Sys_Printf( "drawflag = true\n" );
353 else if ( !strcmp( argv[i], "-noweld" ) ) {
354 Sys_Printf( "noweld = true\n" );
357 else if ( !strcmp( argv[i], "-nocsg" ) ) {
358 Sys_Printf( "nocsg = true\n" );
361 else if ( !strcmp( argv[i], "-noshare" ) ) {
362 Sys_Printf( "noshare = true\n" );
365 else if ( !strcmp( argv[i], "-notjunc" ) ) {
366 Sys_Printf( "notjunc = true\n" );
369 else if ( !strcmp( argv[i], "-nowater" ) ) {
370 Sys_Printf( "nowater = true\n" );
373 else if ( !strcmp( argv[i], "-noopt" ) ) {
374 Sys_Printf( "noopt = true\n" );
377 else if ( !strcmp( argv[i], "-noprune" ) ) {
378 Sys_Printf( "noprune = true\n" );
381 else if ( !strcmp( argv[i], "-nofill" ) ) {
382 Sys_Printf( "nofill = true\n" );
385 else if ( !strcmp( argv[i], "-nomerge" ) ) {
386 Sys_Printf( "nomerge = true\n" );
389 else if ( !strcmp( argv[i], "-nosubdiv" ) ) {
390 Sys_Printf( "nosubdiv = true\n" );
393 else if ( !strcmp( argv[i], "-nodetail" ) ) {
394 Sys_Printf( "nodetail = true\n" );
397 else if ( !strcmp( argv[i], "-fulldetail" ) ) {
398 Sys_Printf( "fulldetail = true\n" );
401 else if ( !strcmp( argv[i], "-onlyents" ) ) {
402 Sys_Printf( "onlyents = true\n" );
405 else if ( !strcmp( argv[i], "-micro" ) ) {
406 microvolume = atof( argv[i + 1] );
407 Sys_Printf( "microvolume = %f\n", microvolume );
410 else if ( !strcmp( argv[i], "-leaktest" ) ) {
411 Sys_Printf( "leaktest = true\n" );
414 else if ( !strcmp( argv[i], "-verboseentities" ) ) {
415 Sys_Printf( "verboseentities = true\n" );
416 verboseentities = true;
418 else if ( !strcmp( argv[i], "-chop" ) ) {
419 subdivide_size = atof( argv[i + 1] );
420 Sys_Printf( "subdivide_size = %f\n", subdivide_size );
423 else if ( !strcmp( argv[i], "-block" ) ) {
424 block_xl = block_xh = atoi( argv[i + 1] );
425 block_yl = block_yh = atoi( argv[i + 2] );
426 Sys_Printf( "block: %i,%i\n", block_xl, block_yl );
429 else if ( !strcmp( argv[i], "-blocks" ) ) {
430 block_xl = atoi( argv[i + 1] );
431 block_yl = atoi( argv[i + 2] );
432 block_xh = atoi( argv[i + 3] );
433 block_yh = atoi( argv[i + 4] );
434 Sys_Printf( "blocks: %i,%i to %i,%i\n",
435 block_xl, block_yl, block_xh, block_yh );
438 else if ( !strcmp( argv[i],"-tmpout" ) ) {
439 strcpy( outbase, "/tmp" );
450 int Check_VIS_Options( int argc, char **argv ){
453 for ( i = 1 ; i < argc ; i++ )
455 if ( !strcmp( argv[i], "-fast" ) ) {
456 Sys_Printf( "fastvis = true\n" );
459 else if ( !strcmp( argv[i], "-level" ) ) {
460 testlevel = atoi( argv[i + 1] );
461 Sys_Printf( "testlevel = %i\n", testlevel );
464 else if ( !strcmp( argv[i],"-nosort" ) ) {
465 Sys_Printf( "nosort = true\n" );
468 else if ( !strcmp( argv[i],"-tmpin" ) ) {
469 strcpy( inbase, "/tmp" );
471 else if ( !strcmp( argv[i],"-tmpout" ) ) {
472 strcpy( outbase, "/tmp" );
482 int Check_RAD_Options( int argc, char **argv ){
485 for ( i = 1 ; i < argc ; i++ )
487 if ( !strcmp( argv[i],"-dump" ) ) {
490 else if ( !strcmp( argv[i],"-bounce" ) ) {
491 numbounce = atoi( argv[i + 1] );
494 else if ( !strcmp( argv[i],"-extra" ) ) {
496 Sys_Printf( "extrasamples = true\n" );
498 else if ( !strcmp( argv[i],"-chop" ) ) {
499 subdiv = atoi( argv[i + 1] );
502 else if ( !strcmp( argv[i],"-scale" ) ) {
503 lightscale = atof( argv[i + 1] );
506 else if ( !strcmp( argv[i],"-direct" ) ) {
507 direct_scale *= atof( argv[i + 1] );
508 Sys_Printf( "direct light scaling at %f\n", direct_scale );
511 else if ( !strcmp( argv[i],"-entity" ) ) {
512 entity_scale *= atof( argv[i + 1] );
513 Sys_Printf( "entity light scaling at %f\n", entity_scale );
516 else if ( !strcmp( argv[i],"-glview" ) ) {
518 Sys_Printf( "glview = true\n" );
520 else if ( !strcmp( argv[i],"-nopvs" ) ) {
522 Sys_Printf( "nopvs = true\n" );
524 else if ( !strcmp( argv[i],"-ambient" ) ) {
525 ambient = atof( argv[i + 1] ) * 128;
528 else if ( !strcmp( argv[i],"-maxlight" ) ) {
529 maxlight = atof( argv[i + 1] ) * 128;
532 else if ( !strcmp( argv[i],"-tmpin" ) ) {
533 strcpy( inbase, "/tmp" );
535 else if ( !strcmp( argv[i],"-tmpout" ) ) {
536 strcpy( outbase, "/tmp" );
550 int main( int argc, char **argv ){
557 qboolean do_info = qfalse;
558 qboolean do_bsp = qfalse;
559 qboolean do_vis = qfalse;
560 qboolean do_rad = qfalse;
563 /* we want consistent 'randomness' */
567 start = I_FloatTime();
569 Sys_Printf( "\nQ2Map - Ver. 1.0\n" );
572 //atexit( ExitQ3Map );
577 Sys_Printf( " %s: -game [quake2,heretic2] -fs_basepath basepath -info -bsp -vis -rad mapname\n",argv[0] );
580 /* read general options first */
581 for ( i = 1; i < argc; i++ )
584 if ( !strcmp( argv[ i ], "-connect" ) ) {
586 Broadcast_Setup( argv[ i ] );
590 else if ( !strcmp( argv[ i ], "-v" ) ) {
595 else if ( !strcmp( argv[ i ], "-threads" ) ) {
597 numthreads = atoi( argv[ i ] );
599 else if ( !strcmp( argv[ i ], "-game" ) ) {
601 strncpy( game, argv[ i ], 64 );
606 /* set number of threads */
609 /* ydnar: new path initialization */
610 InitPaths( &argc, argv );
612 /* read compiling options */
613 for ( i = 1; i < argc; i++ )
616 if ( !strcmp( argv[ i ], "-info" ) ) {
621 if ( !strcmp( argv[ i ], "-bsp" ) ) {
624 alt_argv = (char **) ( argv + i );
625 Check_BSP_Options( alt_argc, alt_argv );
629 if ( !strcmp( argv[ i ], "-vis" ) ) {
632 alt_argv = (char **) ( argv + i );
633 Check_VIS_Options( alt_argc, alt_argv );
637 if ( !strcmp( argv[ i ], "-rad" ) ) {
640 alt_argv = (char **) ( argv + i );
641 Check_RAD_Options( alt_argc, alt_argv );
645 if ( game[0] == 0 ) {
646 strncpy( game, "quake2", 7 );
649 Sys_Printf( "Game: %s\n", game );
651 if ( !do_info && !do_bsp && !do_vis && !do_rad ) {
652 Sys_FPrintf( SYS_ERR, "ERROR: -bsp, -vis, -light, nor -info specified.\nWhat to you want me to do?\n\n" );
656 mapname = argv[argc - 1];
675 total_time = (int) ( end - start );
676 Sys_Printf( "\nTotal Time: " );
677 if ( total_time > 59 ) {
678 Sys_Printf( "%d Minutes ", total_time / 60 );
680 Sys_Printf( "%d Seconds\n", total_time % 60 );
682 /* shut down connection */
683 Broadcast_Shutdown();
685 /* return any error code */