2008-07-25 07:31:37 +00:00
|
|
|
/* -------------------------------------------------------------------------------
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
-------------------------------------------------------------------------------
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This code has been altered significantly from its original form, to support
|
|
|
|
several games based on the Quake III Arena engine, in the form of "Q3Map2."
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
------------------------------------------------------------------------------- */
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* marker */
|
|
|
|
#define MAIN_C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dependencies */
|
|
|
|
#include "q3map2.h"
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Random()
|
|
|
|
returns a pseudorandom number between 0 and 1
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
vec_t Random( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
return (vec_t) rand() / RAND_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 23:34:31 +00:00
|
|
|
char *Q_strncpyz( char *dst, const char *src, size_t len ) {
|
|
|
|
if ( len == 0 ) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy( dst, src, len );
|
|
|
|
dst[ len - 1 ] = '\0';
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *Q_strcat( char *dst, size_t dlen, const char *src ) {
|
|
|
|
size_t n = strlen( dst );
|
|
|
|
|
|
|
|
if ( n > dlen ) {
|
|
|
|
abort(); /* buffer overflow */
|
|
|
|
}
|
|
|
|
|
|
|
|
return Q_strncpyz( dst + n, src, dlen - n );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
|
|
|
|
size_t n = strlen( dst );
|
|
|
|
|
|
|
|
if ( n > dlen ) {
|
|
|
|
abort(); /* buffer overflow */
|
|
|
|
}
|
|
|
|
|
|
|
|
return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) );
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
ExitQ3Map()
|
|
|
|
cleanup routine
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ExitQ3Map( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
BSPFilesCleanup();
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapDrawSurfs != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
free( mapDrawSurfs );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
main()
|
|
|
|
q3map mojo...
|
|
|
|
*/
|
|
|
|
|
|
|
|
int main( int argc, char **argv ){
|
|
|
|
int i, r;
|
|
|
|
double start, end;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* we want consistent 'randomness' */
|
|
|
|
srand( 0 );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* start timer */
|
|
|
|
start = I_FloatTime();
|
|
|
|
|
|
|
|
/* this was changed to emit version number over the network */
|
|
|
|
printf( Q3MAP_VERSION "\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set exit call */
|
|
|
|
atexit( ExitQ3Map );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* read general options first */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 1; i < argc; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* -connect */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( argv[ i ], "-connect" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
argv[ i ] = NULL;
|
|
|
|
i++;
|
|
|
|
Broadcast_Setup( argv[ i ] );
|
|
|
|
argv[ i ] = NULL;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* verbose */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-v" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
verbose = qtrue;
|
|
|
|
argv[ i ] = NULL;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* force */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-force" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
force = qtrue;
|
|
|
|
argv[ i ] = NULL;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* patch subdivisions */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-subdivisions" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
argv[ i ] = NULL;
|
|
|
|
i++;
|
|
|
|
patchSubdivisions = atoi( argv[ i ] );
|
|
|
|
argv[ i ] = NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( patchSubdivisions <= 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
patchSubdivisions = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* threads */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-threads" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
argv[ i ] = NULL;
|
|
|
|
i++;
|
|
|
|
numthreads = atoi( argv[ i ] );
|
|
|
|
argv[ i ] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* init model library */
|
|
|
|
PicoInit();
|
|
|
|
PicoSetMallocFunc( safe_malloc );
|
|
|
|
PicoSetFreeFunc( free );
|
|
|
|
PicoSetPrintFunc( PicoPrintFunc );
|
|
|
|
PicoSetLoadFileFunc( PicoLoadFileFunc );
|
|
|
|
PicoSetFreeFileFunc( free );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set number of threads */
|
|
|
|
ThreadSetDefault();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* generate sinusoid jitter table */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < MAX_JITTERS; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
jitters[ i ] = sin( i * 139.54152147 );
|
|
|
|
//% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
|
|
|
|
and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
|
|
|
|
Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
|
|
|
|
Sys_Printf( "GtkRadiant - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
|
|
|
|
Sys_Printf( "%s\n", Q3MAP_MOTD );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: new path initialization */
|
|
|
|
InitPaths( &argc, argv );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* check if we have enough options left to attempt something */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( argc < 2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* fixaas */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( argv[ 1 ], "-fixaas" ) ) {
|
2016-02-12 19:31:15 +00:00
|
|
|
r = FixAASMain( argc - 1, argv + 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* analyze */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ 1 ], "-analyze" ) ) {
|
2016-02-12 19:19:57 +00:00
|
|
|
r = AnalyzeBSPMain( argc - 1, argv + 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* info */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ 1 ], "-info" ) ) {
|
2016-02-12 19:19:57 +00:00
|
|
|
r = BSPInfoMain( argc - 2, argv + 2 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* vis */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ 1 ], "-vis" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
r = VisMain( argc - 1, argv + 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* light */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ 1 ], "-light" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
r = LightMain( argc - 1, argv + 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* vlight */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ 1 ], "-vlight" ) ) {
|
2016-05-16 19:20:20 +00:00
|
|
|
Sys_FPrintf( SYS_WRN, "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
argv[ 1 ] = "-fast"; /* eek a hack */
|
2007-11-04 03:34:51 +00:00
|
|
|
r = LightMain( argc, argv );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2013-07-15 03:58:15 +00:00
|
|
|
/* QBall: export entities */
|
|
|
|
else if ( !strcmp( argv[ 1 ], "-exportents" ) ) {
|
|
|
|
r = ExportEntitiesMain( argc - 1, argv + 1 );
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: lightmap export */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ 1 ], "-export" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
r = ExportLightmapsMain( argc - 1, argv + 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: lightmap import */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ 1 ], "-import" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
r = ImportLightmapsMain( argc - 1, argv + 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: bsp scaling */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ 1 ], "-scale" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
r = ScaleBSPMain( argc - 1, argv + 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: bsp conversion */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ 1 ], "-convert" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
r = ConvertBSPMain( argc - 1, argv + 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 09:34:11 +00:00
|
|
|
/* div0: minimap */
|
2018-01-28 03:32:58 +00:00
|
|
|
else if ( !strcmp( argv[ 1 ], "-minimap" ) ) {
|
|
|
|
r = MiniMapBSPMain( argc - 1, argv + 1 );
|
|
|
|
}
|
2009-04-26 09:34:11 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: otherwise create a bsp */
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
r = BSPMain( argc, argv );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit time */
|
|
|
|
end = I_FloatTime();
|
|
|
|
Sys_Printf( "%9.0f seconds elapsed\n", end - start );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* shut down connection */
|
|
|
|
Broadcast_Shutdown();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* return any error code */
|
|
|
|
return r;
|
|
|
|
}
|