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 ------------------------------------------------------------------------------- */
42 returns a pseudorandom number between 0 and 1
46 return (vec_t) rand() / RAND_MAX;
50 char *Q_strncpyz( char *dst, const char *src, size_t len ) {
55 strncpy( dst, src, len );
56 dst[ len - 1 ] = '\0';
61 char *Q_strcat( char *dst, size_t dlen, const char *src ) {
62 size_t n = strlen( dst );
65 abort(); /* buffer overflow */
68 return Q_strncpyz( dst + n, src, dlen - n );
72 char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
73 size_t n = strlen( dst );
76 abort(); /* buffer overflow */
79 return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) );
88 static void ExitQ3Map( void ){
90 if ( mapDrawSurfs != NULL ) {
98 shifts a map: works correctly only with axial faces, placed in positive half of axis
99 for testing physics with huge coordinates
102 int ShiftBSPMain( int argc, char **argv ){
110 float *old_xyzst = NULL;
116 Sys_Printf( "Usage: q3map [-v] -shift [-tex] [-spawn_ref <value>] <value> <mapname>\n" );
121 for ( i = 1; i < argc - 2; ++i )
123 if ( !strcmp( argv[i], "-tex" ) ) {
126 else if ( !strcmp( argv[i], "-spawn_ref" ) ) {
127 spawn_ref = atof( argv[i + 1] );
136 // if(argc-2 >= i) // always true
137 scale[2] = scale[1] = scale[0] = atof( argv[ argc - 2 ] );
138 if ( argc - 3 >= i ) {
139 scale[1] = scale[0] = atof( argv[ argc - 3 ] );
141 if ( argc - 4 >= i ) {
142 scale[0] = atof( argv[ argc - 4 ] );
145 uniform = ( ( scale[0] == scale[1] ) && ( scale[1] == scale[2] ) );
148 /* do some path mangling */
149 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
150 StripExtension( source );
151 DefaultExtension( source, ".bsp" );
154 Sys_Printf( "Loading %s\n", source );
155 LoadBSPFile( source );
159 Sys_Printf( "--- ShiftBSP ---\n" );
160 Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
162 /* shift entity keys */
163 for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
166 GetVectorForKey( &entities[ i ], "origin", vec );
167 if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) {
168 if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
174 if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
177 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
178 SetKeyValue( &entities[ i ], "origin", str );
184 for ( i = 0; i < numBSPModels; i++ )
186 bspModels[ i ].mins[0] += scale[0];
187 bspModels[ i ].mins[1] += scale[1];
188 bspModels[ i ].mins[2] += scale[2];
189 bspModels[ i ].maxs[0] += scale[0];
190 bspModels[ i ].maxs[1] += scale[1];
191 bspModels[ i ].maxs[2] += scale[2];
195 for ( i = 0; i < numBSPNodes; i++ )
197 bspNodes[ i ].mins[0] += scale[0];
198 bspNodes[ i ].mins[1] += scale[1];
199 bspNodes[ i ].mins[2] += scale[2];
200 bspNodes[ i ].maxs[0] += scale[0];
201 bspNodes[ i ].maxs[1] += scale[1];
202 bspNodes[ i ].maxs[2] += scale[2];
206 for ( i = 0; i < numBSPLeafs; i++ )
208 bspLeafs[ i ].mins[0] += scale[0];
209 bspLeafs[ i ].mins[1] += scale[1];
210 bspLeafs[ i ].mins[2] += scale[2];
211 bspLeafs[ i ].maxs[0] += scale[0];
212 bspLeafs[ i ].maxs[1] += scale[1];
213 bspLeafs[ i ].maxs[2] += scale[2];
216 /* shift drawverts */
217 for ( i = 0; i < numBSPDrawVerts; i++ )
219 bspDrawVerts[i].xyz[0] += scale[0];
220 bspDrawVerts[i].xyz[1] += scale[1];
221 bspDrawVerts[i].xyz[2] += scale[2];
228 for ( i = 0; i < numBSPPlanes; i++ )
230 //find point on plane
231 for ( j=0; j<3; j++ ){
232 if ( fabs( bspPlanes[ i ].normal[j] ) > 0.5 ){
233 point[j] = bspPlanes[ i ].dist / bspPlanes[ i ].normal[j];
234 point[(j+1)%3] = point[(j+2)%3] = 0;
239 for ( j=0; j<3; j++ ){
240 point[j] += scale[j];
242 //calc new plane dist
243 bspPlanes[ i ].dist = DotProduct( point, bspPlanes[ i ].normal );
248 GetVectorForKey( &entities[ 0 ], "gridsize", vec );
249 if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) {
250 VectorCopy( gridSize, vec );
255 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
256 SetKeyValue( &entities[ 0 ], "gridsize", str );
258 /* inject command line parameters */
259 InjectCommandLine( argv, 0, argc - 1 );
263 StripExtension( source );
264 DefaultExtension( source, "_sh.bsp" );
265 Sys_Printf( "Writing %s\n", source );
266 WriteBSPFile( source );
268 /* return to sender */
279 int main( int argc, char **argv ){
282 extern qboolean werror;
285 /* we want consistent 'randomness' */
289 start = I_FloatTime();
291 /* this was changed to emit version number over the network */
292 printf( Q3MAP_VERSION "\n" );
297 /* read general options first */
298 for ( i = 1; i < argc; i++ )
301 if ( !strcmp( argv[ i ], "-h" ) || !strcmp( argv[ i ], "--help" )
302 || !strcmp( argv[ i ], "-help" ) ) {
303 HelpMain( ( i + 1 < argc ) ? argv[ i + 1 ] : NULL );
308 if ( !strcmp( argv[ i ], "-connect" ) ) {
309 if ( ++i >= argc || !argv[ i ] ) {
310 Error( "Out of arguments: No address specified after %s", argv[ i - 1 ] );
312 argv[ i - 1 ] = NULL;
313 Broadcast_Setup( argv[ i ] );
318 else if ( !strcmp( argv[ i ], "-v" ) ) {
326 else if ( !strcmp( argv[ i ], "-force" ) ) {
331 /* make all warnings into errors */
332 else if ( !strcmp( argv[ i ], "-werror" ) ) {
337 /* patch subdivisions */
338 else if ( !strcmp( argv[ i ], "-subdivisions" ) ) {
339 if ( ++i >= argc || !argv[ i ] ) {
340 Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] );
342 argv[ i - 1 ] = NULL;
343 patchSubdivisions = atoi( argv[ i ] );
345 if ( patchSubdivisions <= 0 ) {
346 patchSubdivisions = 1;
351 else if ( !strcmp( argv[ i ], "-threads" ) ) {
352 if ( ++i >= argc || !argv[ i ] ) {
353 Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] );
355 argv[ i - 1 ] = NULL;
356 numthreads = atoi( argv[ i ] );
359 else if( !strcmp( argv[ i ], "-nocmdline" ) )
361 Sys_Printf( "noCmdLine\n" );
368 /* init model library */
370 PicoSetMallocFunc( safe_malloc );
371 PicoSetFreeFunc( free );
372 PicoSetPrintFunc( PicoPrintFunc );
373 PicoSetLoadFileFunc( PicoLoadFileFunc );
374 PicoSetFreeFileFunc( free );
376 /* set number of threads */
379 /* generate sinusoid jitter table */
380 for ( i = 0; i < MAX_JITTERS; i++ )
382 jitters[ i ] = sin( i * 139.54152147 );
383 //% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
386 /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
387 and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
389 Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
390 Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
391 Sys_Printf( RADIANT_NAME " - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
392 Sys_Printf( "%s\n", Q3MAP_MOTD );
394 /* ydnar: new path initialization */
395 InitPaths( &argc, argv );
397 /* set game options */
398 if ( !patchSubdivisions ) {
399 patchSubdivisions = game->patchSubdivisions;
402 /* check if we have enough options left to attempt something */
404 Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
408 if ( !strcmp( argv[ 1 ], "-fixaas" ) ) {
409 r = FixAASMain( argc - 1, argv + 1 );
413 else if ( !strcmp( argv[ 1 ], "-analyze" ) ) {
414 r = AnalyzeBSPMain( argc - 1, argv + 1 );
418 else if ( !strcmp( argv[ 1 ], "-info" ) ) {
419 r = BSPInfoMain( argc - 2, argv + 2 );
423 else if ( !strcmp( argv[ 1 ], "-vis" ) ) {
424 r = VisMain( argc - 1, argv + 1 );
428 else if ( !strcmp( argv[ 1 ], "-light" ) ) {
429 r = LightMain( argc - 1, argv + 1 );
433 else if ( !strcmp( argv[ 1 ], "-vlight" ) ) {
434 Sys_FPrintf( SYS_WRN, "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
435 argv[ 1 ] = "-fast"; /* eek a hack */
436 r = LightMain( argc, argv );
439 /* QBall: export entities */
440 else if ( !strcmp( argv[ 1 ], "-exportents" ) ) {
441 r = ExportEntitiesMain( argc - 1, argv + 1 );
444 /* ydnar: lightmap export */
445 else if ( !strcmp( argv[ 1 ], "-export" ) ) {
446 r = ExportLightmapsMain( argc - 1, argv + 1 );
449 /* ydnar: lightmap import */
450 else if ( !strcmp( argv[ 1 ], "-import" ) ) {
451 r = ImportLightmapsMain( argc - 1, argv + 1 );
454 /* ydnar: bsp scaling */
455 else if ( !strcmp( argv[ 1 ], "-scale" ) ) {
456 r = ScaleBSPMain( argc - 1, argv + 1 );
460 else if ( !strcmp( argv[ 1 ], "-shift" ) ) {
461 r = ShiftBSPMain( argc - 1, argv + 1 );
464 /* ydnar: bsp conversion */
465 else if ( !strcmp( argv[ 1 ], "-convert" ) ) {
466 r = ConvertBSPMain( argc - 1, argv + 1 );
470 else if ( !strcmp( argv[ 1 ], "-minimap" ) ) {
471 r = MiniMapBSPMain( argc - 1, argv + 1 );
474 /* ydnar: otherwise create a bsp */
476 /* used to write Smokin'Guns like tex file */
479 r = BSPMain( argc, argv );
484 Sys_Printf( "%9.0f seconds elapsed\n", end - start );
486 /* shut down connection */
487 Broadcast_Shutdown();
489 /* return any error code */