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 ------------------------------------------------------------------------------- */
43 returns a pseudorandom number between 0 and 1
47 return (vec_t) rand() / RAND_MAX;
51 char *Q_strncpyz( char *dst, const char *src, size_t len ) {
56 strncpy( dst, src, len );
57 dst[ len - 1 ] = '\0';
62 char *Q_strcat( char *dst, size_t dlen, const char *src ) {
63 size_t n = strlen( dst );
66 abort(); /* buffer overflow */
69 return Q_strncpyz( dst + n, src, dlen - n );
73 char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
74 size_t n = strlen( dst );
77 abort(); /* buffer overflow */
80 return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) );
88 static void ExitQ3Map( void ){
90 if ( mapDrawSurfs != NULL ) {
100 int main( int argc, char **argv ){
105 /* we want consistent 'randomness' */
109 start = I_FloatTime();
111 /* this was changed to emit version number over the network */
112 printf( Q3MAP_VERSION "\n" );
117 /* read general options first */
118 for ( i = 1; i < argc; i++ )
121 if ( !strcmp( argv[ i ], "-h" ) || !strcmp( argv[ i ], "--help" )
122 || !strcmp( argv[ i ], "-help" ) ) {
128 if ( !strcmp( argv[ i ], "-connect" ) ) {
131 Broadcast_Setup( argv[ i ] );
136 else if ( !strcmp( argv[ i ], "-v" ) ) {
144 else if ( !strcmp( argv[ i ], "-force" ) ) {
149 /* patch subdivisions */
150 else if ( !strcmp( argv[ i ], "-subdivisions" ) ) {
153 patchSubdivisions = atoi( argv[ i ] );
155 if ( patchSubdivisions <= 0 ) {
156 patchSubdivisions = 1;
161 else if ( !strcmp( argv[ i ], "-threads" ) ) {
164 numthreads = atoi( argv[ i ] );
169 /* init model library */
171 PicoSetMallocFunc( safe_malloc );
172 PicoSetFreeFunc( free );
173 PicoSetPrintFunc( PicoPrintFunc );
174 PicoSetLoadFileFunc( PicoLoadFileFunc );
175 PicoSetFreeFileFunc( free );
177 /* set number of threads */
180 /* generate sinusoid jitter table */
181 for ( i = 0; i < MAX_JITTERS; i++ )
183 jitters[ i ] = sin( i * 139.54152147 );
184 //% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
187 /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
188 and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
190 Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
191 Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
192 Sys_Printf( "NetRadiant - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
193 Sys_Printf( "%s\n", Q3MAP_MOTD );
195 /* ydnar: new path initialization */
196 InitPaths( &argc, argv );
198 /* set game options */
199 if ( !patchSubdivisions ) {
200 patchSubdivisions = game->patchSubdivisions;
203 /* check if we have enough options left to attempt something */
205 Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
209 if ( !strcmp( argv[ 1 ], "-fixaas" ) ) {
210 r = FixAASMain( argc - 1, argv + 1 );
214 else if ( !strcmp( argv[ 1 ], "-analyze" ) ) {
215 r = AnalyzeBSPMain( argc - 1, argv + 1 );
219 else if ( !strcmp( argv[ 1 ], "-info" ) ) {
220 r = BSPInfoMain( argc - 2, argv + 2 );
224 else if ( !strcmp( argv[ 1 ], "-vis" ) ) {
225 r = VisMain( argc - 1, argv + 1 );
229 else if ( !strcmp( argv[ 1 ], "-light" ) ) {
230 r = LightMain( argc - 1, argv + 1 );
234 else if ( !strcmp( argv[ 1 ], "-vlight" ) ) {
235 Sys_FPrintf( SYS_WRN, "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
236 argv[ 1 ] = "-fast"; /* eek a hack */
237 r = LightMain( argc, argv );
240 /* QBall: export entities */
241 else if ( !strcmp( argv[ 1 ], "-exportents" ) ) {
242 r = ExportEntitiesMain( argc - 1, argv + 1 );
245 /* ydnar: lightmap export */
246 else if ( !strcmp( argv[ 1 ], "-export" ) ) {
247 r = ExportLightmapsMain( argc - 1, argv + 1 );
250 /* ydnar: lightmap import */
251 else if ( !strcmp( argv[ 1 ], "-import" ) ) {
252 r = ImportLightmapsMain( argc - 1, argv + 1 );
255 /* ydnar: bsp scaling */
256 else if ( !strcmp( argv[ 1 ], "-scale" ) ) {
257 r = ScaleBSPMain( argc - 1, argv + 1 );
260 /* ydnar: bsp conversion */
261 else if ( !strcmp( argv[ 1 ], "-convert" ) ) {
262 r = ConvertBSPMain( argc - 1, argv + 1 );
266 else if ( !strcmp( argv[ 1 ], "-minimap" ) ) {
267 r = MiniMapBSPMain( argc - 1, argv + 1 );
270 /* ydnar: otherwise create a bsp */
272 r = BSPMain( argc, argv );
277 Sys_Printf( "%9.0f seconds elapsed\n", end - start );
279 /* shut down connection */
280 Broadcast_Shutdown();
282 /* return any error code */