2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
\r
5 This file is part of GtkRadiant.
\r
7 GtkRadiant is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 GtkRadiant is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with GtkRadiant; if not, write to the Free Software
\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
21 -------------------------------------------------------------------------------
\r
23 This code has been altered significantly from its original form, to support
\r
24 several games based on the Quake III Arena engine, in the form of "Q3Map2."
\r
26 ------------------------------------------------------------------------------- */
\r
42 returns a pseudorandom number between 0 and 1
\r
45 vec_t Random( void )
\r
47 return (vec_t) rand() / RAND_MAX;
\r
57 static void ExitQ3Map( void )
\r
60 if( mapDrawSurfs != NULL )
\r
61 free( mapDrawSurfs );
\r
68 emits statistics about the bsp file
\r
71 int BSPInfo( int count, char **fileNames )
\r
74 char source[ 1024 ], ext[ 64 ];
\r
82 Sys_Printf( "No files to dump info for.\n");
\r
86 /* enable info mode */
\r
89 /* walk file list */
\r
90 for( i = 0; i < count; i++ )
\r
92 Sys_Printf( "---------------------------------\n" );
\r
94 /* mangle filename and get size */
\r
95 strcpy( source, fileNames[ i ] );
\r
96 ExtractFileExtension( source, ext );
\r
97 if( !Q_stricmp( ext, "map" ) )
\r
98 StripExtension( source );
\r
99 DefaultExtension( source, ".bsp" );
\r
100 f = fopen( source, "rb" );
\r
103 size = Q_filelength (f);
\r
109 /* load the bsp file and print lump sizes */
\r
110 Sys_Printf( "%s\n", source );
\r
111 LoadBSPFile( source );
\r
112 PrintBSPFileSizes();
\r
115 Sys_Printf( "\n" );
\r
116 Sys_Printf( " total %9d\n", size );
\r
117 Sys_Printf( " %9d KB\n", size / 1024 );
\r
118 Sys_Printf( " %9d MB\n", size / (1024 * 1024) );
\r
120 Sys_Printf( "---------------------------------\n" );
\r
131 amaze and confuse your enemies with wierd scaled maps!
\r
134 int ScaleBSPMain( int argc, char **argv )
\r
145 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
\r
150 scale = atof( argv[ argc - 2 ] );
\r
151 if( scale == 0.0f )
\r
153 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
\r
154 Sys_Printf( "Non-zero scale value required.\n" );
\r
158 /* do some path mangling */
\r
159 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
\r
160 StripExtension( source );
\r
161 DefaultExtension( source, ".bsp" );
\r
164 Sys_Printf( "Loading %s\n", source );
\r
165 LoadBSPFile( source );
\r
169 Sys_Printf( "--- ScaleBSP ---\n" );
\r
170 Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
\r
172 /* scale entity keys */
\r
173 for( i = 0; i < numBSPEntities && i < numEntities; i++ )
\r
176 GetVectorForKey( &entities[ i ], "origin", vec );
\r
177 if( (vec[ 0 ] + vec[ 1 ] + vec[ 2 ]) )
\r
179 VectorScale( vec, scale, vec );
\r
180 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
\r
181 SetKeyValue( &entities[ i ], "origin", str );
\r
184 /* scale door lip */
\r
185 f = FloatForKey( &entities[ i ], "lip" );
\r
189 sprintf( str, "%f", f );
\r
190 SetKeyValue( &entities[ i ], "lip", str );
\r
195 for( i = 0; i < numBSPModels; i++ )
\r
197 VectorScale( bspModels[ i ].mins, scale, bspModels[ i ].mins );
\r
198 VectorScale( bspModels[ i ].maxs, scale, bspModels[ i ].maxs );
\r
202 for( i = 0; i < numBSPNodes; i++ )
\r
204 VectorScale( bspNodes[ i ].mins, scale, bspNodes[ i ].mins );
\r
205 VectorScale( bspNodes[ i ].maxs, scale, bspNodes[ i ].maxs );
\r
209 for( i = 0; i < numBSPLeafs; i++ )
\r
211 VectorScale( bspLeafs[ i ].mins, scale, bspLeafs[ i ].mins );
\r
212 VectorScale( bspLeafs[ i ].maxs, scale, bspLeafs[ i ].maxs );
\r
215 /* scale drawverts */
\r
216 for( i = 0; i < numBSPDrawVerts; i++ )
\r
217 VectorScale( bspDrawVerts[ i ].xyz, scale, bspDrawVerts[ i ].xyz );
\r
220 for( i = 0; i < numBSPPlanes; i++ )
\r
221 bspPlanes[ i ].dist *= scale;
\r
223 /* scale gridsize */
\r
224 GetVectorForKey( &entities[ 0 ], "gridsize", vec );
\r
225 if( (vec[ 0 ] + vec[ 1 ] + vec[ 2 ]) == 0.0f )
\r
226 VectorCopy( gridSize, vec );
\r
227 VectorScale( vec, scale, vec );
\r
228 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
\r
229 SetKeyValue( &entities[ 0 ], "gridsize", str );
\r
231 /* write the bsp */
\r
233 StripExtension( source );
\r
234 DefaultExtension( source, "_s.bsp" );
\r
235 Sys_Printf( "Writing %s\n", source );
\r
236 WriteBSPFile( source );
\r
238 /* return to sender */
\r
246 main argument processing function for bsp conversion
\r
249 int ConvertBSPMain( int argc, char **argv )
\r
252 int (*convertFunc)( char * );
\r
256 convertFunc = ConvertBSPToASE;
\r
261 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
\r
265 /* process arguments */
\r
266 for( i = 1; i < (argc - 1); i++ )
\r
268 /* -format map|ase|... */
\r
269 if( !strcmp( argv[ i ], "-format" ) )
\r
272 if( !Q_stricmp( argv[ i ], "ase" ) )
\r
273 convertFunc = ConvertBSPToASE;
\r
274 else if( !Q_stricmp( argv[ i ], "map" ) )
\r
275 convertFunc = ConvertBSPToMap;
\r
277 Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
\r
281 /* clean up map name */
\r
282 strcpy( source, ExpandArg( argv[ i ] ) );
\r
283 StripExtension( source );
\r
284 DefaultExtension( source, ".bsp" );
\r
288 Sys_Printf( "Loading %s\n", source );
\r
290 /* ydnar: load surface file */
\r
291 //% LoadSurfaceExtraFile( source );
\r
293 LoadBSPFile( source );
\r
295 /* parse bsp entities */
\r
299 return convertFunc( source );
\r
309 int main( int argc, char **argv )
\r
315 /* we want consistent 'randomness' */
\r
319 start = I_FloatTime();
\r
321 /* this was changed to emit version number over the network */
\r
322 printf( Q3MAP_VERSION "\n" );
\r
324 /* set exit call */
\r
325 atexit( ExitQ3Map );
\r
327 /* read general options first */
\r
328 for( i = 1; i < argc; i++ )
\r
331 if( !strcmp( argv[ i ], "-connect" ) )
\r
335 Broadcast_Setup( argv[ i ] );
\r
340 else if( !strcmp( argv[ i ], "-v" ) )
\r
347 else if( !strcmp( argv[ i ], "-force" ) )
\r
353 /* patch subdivisions */
\r
354 else if( !strcmp( argv[ i ], "-subdivisions" ) )
\r
358 patchSubdivisions = atoi( argv[ i ] );
\r
360 if( patchSubdivisions <= 0 )
\r
361 patchSubdivisions = 1;
\r
365 else if( !strcmp( argv[ i ], "-threads" ) )
\r
369 numthreads = atoi( argv[ i ] );
\r
374 /* init model library */
\r
376 PicoSetMallocFunc( safe_malloc );
\r
377 PicoSetFreeFunc( free );
\r
378 PicoSetPrintFunc( PicoPrintFunc );
\r
379 PicoSetLoadFileFunc( PicoLoadFileFunc );
\r
380 PicoSetFreeFileFunc( free );
\r
382 /* set number of threads */
\r
383 ThreadSetDefault();
\r
385 /* generate sinusoid jitter table */
\r
386 for( i = 0; i < MAX_JITTERS; i++ )
\r
388 jitters[ i ] = sin( i * 139.54152147 );
\r
389 //% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
\r
392 /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
\r
393 and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
\r
395 Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
\r
396 Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
\r
397 Sys_Printf( "GtkRadiant - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
\r
398 Sys_Printf( "%s\n", Q3MAP_MOTD );
\r
400 /* ydnar: new path initialization */
\r
401 InitPaths( &argc, argv );
\r
403 /* check if we have enough options left to attempt something */
\r
405 Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
\r
408 if( !strcmp( argv[ 1 ], "-info" ) )
\r
409 r = BSPInfo( argc - 2, argv + 2 );
\r
412 else if( !strcmp( argv[ 1 ], "-vis" ) )
\r
413 r = VisMain( argc - 1, argv + 1 );
\r
416 else if( !strcmp( argv[ 1 ], "-light" ) )
\r
417 r = LightMain( argc - 1, argv + 1 );
\r
420 else if( !strcmp( argv[ 1 ], "-vlight" ) )
\r
422 Sys_Printf( "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
\r
423 argv[ 1 ] = "-fast"; /* eek a hack */
\r
424 r = LightMain( argc, argv );
\r
427 /* ydnar: lightmap export */
\r
428 else if( !strcmp( argv[ 1 ], "-export" ) )
\r
429 r = ExportLightmapsMain( argc - 1, argv + 1 );
\r
431 /* ydnar: lightmap import */
\r
432 else if( !strcmp( argv[ 1 ], "-import" ) )
\r
433 r = ImportLightmapsMain( argc - 1, argv + 1 );
\r
435 /* ydnar: bsp scaling */
\r
436 else if( !strcmp( argv[ 1 ], "-scale" ) )
\r
437 r = ScaleBSPMain( argc - 1, argv + 1 );
\r
439 /* ydnar: bsp conversion */
\r
440 else if( !strcmp( argv[ 1 ], "-convert" ) )
\r
441 r = ConvertBSPMain( argc - 1, argv + 1 );
\r
443 /* ydnar: otherwise create a bsp */
\r
445 r = BSPMain( argc, argv );
\r
448 end = I_FloatTime();
\r
449 Sys_Printf( "%9.0f seconds elapsed\n", end - start );
\r
451 /* shut down connection */
\r
452 Broadcast_Shutdown();
\r
454 /* return any error code */
\r