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 ) {
101 int main( int argc, char **argv ){
106 /* we want consistent 'randomness' */
110 start = I_FloatTime();
112 /* this was changed to emit version number over the network */
113 printf( Q3MAP_VERSION "\n" );
118 /* read general options first */
119 for ( i = 1; i < argc; i++ )
122 if ( !strcmp( argv[ i ], "-h" ) || !strcmp( argv[ i ], "--help" )
123 || !strcmp( argv[ i ], "-help" ) ) {
129 if ( !strcmp( argv[ i ], "-connect" ) ) {
132 Broadcast_Setup( argv[ i ] );
137 else if ( !strcmp( argv[ i ], "-v" ) ) {
145 else if ( !strcmp( argv[ i ], "-force" ) ) {
150 /* patch subdivisions */
151 else if ( !strcmp( argv[ i ], "-subdivisions" ) ) {
154 patchSubdivisions = atoi( argv[ i ] );
156 if ( patchSubdivisions <= 0 ) {
157 patchSubdivisions = 1;
162 else if ( !strcmp( argv[ i ], "-threads" ) ) {
165 numthreads = atoi( argv[ i ] );
170 /* init model library */
172 PicoSetMallocFunc( safe_malloc );
173 PicoSetFreeFunc( free );
174 PicoSetPrintFunc( PicoPrintFunc );
175 PicoSetLoadFileFunc( PicoLoadFileFunc );
176 PicoSetFreeFileFunc( free );
178 /* set number of threads */
181 /* generate sinusoid jitter table */
182 for ( i = 0; i < MAX_JITTERS; i++ )
184 jitters[ i ] = sin( i * 139.54152147 );
185 //% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
188 /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
189 and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
191 Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
192 Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
193 Sys_Printf( "NetRadiant - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
194 Sys_Printf( "%s\n", Q3MAP_MOTD );
196 /* ydnar: new path initialization */
197 InitPaths( &argc, argv );
199 /* set game options */
200 if ( !patchSubdivisions ) {
201 patchSubdivisions = game->patchSubdivisions;
204 /* check if we have enough options left to attempt something */
206 Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
210 if ( !strcmp( argv[ 1 ], "-fixaas" ) ) {
211 r = FixAASMain( argc - 1, argv + 1 );
215 else if ( !strcmp( argv[ 1 ], "-analyze" ) ) {
216 r = AnalyzeBSPMain( argc - 1, argv + 1 );
220 else if ( !strcmp( argv[ 1 ], "-info" ) ) {
221 r = BSPInfoMain( argc - 2, argv + 2 );
225 else if ( !strcmp( argv[ 1 ], "-vis" ) ) {
226 r = VisMain( argc - 1, argv + 1 );
230 else if ( !strcmp( argv[ 1 ], "-light" ) ) {
231 r = LightMain( argc - 1, argv + 1 );
235 else if ( !strcmp( argv[ 1 ], "-vlight" ) ) {
236 Sys_FPrintf( SYS_WRN, "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
237 argv[ 1 ] = "-fast"; /* eek a hack */
238 r = LightMain( argc, argv );
241 /* QBall: export entities */
242 else if ( !strcmp( argv[ 1 ], "-exportents" ) ) {
243 r = ExportEntitiesMain( argc - 1, argv + 1 );
246 /* ydnar: lightmap export */
247 else if ( !strcmp( argv[ 1 ], "-export" ) ) {
248 r = ExportLightmapsMain( argc - 1, argv + 1 );
251 /* ydnar: lightmap import */
252 else if ( !strcmp( argv[ 1 ], "-import" ) ) {
253 r = ImportLightmapsMain( argc - 1, argv + 1 );
256 /* ydnar: bsp scaling */
257 else if ( !strcmp( argv[ 1 ], "-scale" ) ) {
258 r = ScaleBSPMain( argc - 1, argv + 1 );
261 /* ydnar: bsp conversion */
262 else if ( !strcmp( argv[ 1 ], "-convert" ) ) {
263 r = ConvertBSPMain( argc - 1, argv + 1 );
267 else if ( !strcmp( argv[ 1 ], "-minimap" ) ) {
268 r = MiniMapBSPMain( argc - 1, argv + 1 );
271 /* ydnar: otherwise create a bsp */
273 r = BSPMain( argc, argv );
278 Sys_Printf( "%9.0f seconds elapsed\n", end - start );
280 /* shut down connection */
281 Broadcast_Shutdown();
283 /* return any error code */