diff --git a/docs/Complete_list_of_command_line_parameters.htm b/docs/Complete_list_of_command_line_parameters.htm
index afbfcae9..572239ea 100644
--- a/docs/Complete_list_of_command_line_parameters.htm
+++ b/docs/Complete_list_of_command_line_parameters.htm
@@ -181,7 +181,6 @@ td.formatted_questions ol { margin-top: 0px; margin-bottom: 0px; }
-light ... filename.map: Switch that enters this stage
- -vlight ... filename.map: Deprecated alias for -light -fast ... filename.map
-approx N: Vertex light approximation tolerance (never use in conjunction with deluxemapping)
-areascale F, -area F: Scaling factor for area lights (surfacelight)
-border: Add a red border to lightmaps for debugging
diff --git a/tools/quake3/q3map2/autopk3.cpp b/tools/quake3/q3map2/autopk3.cpp
index 1ada2595..53d75847 100644
--- a/tools/quake3/q3map2/autopk3.cpp
+++ b/tools/quake3/q3map2/autopk3.cpp
@@ -129,15 +129,12 @@ static inline void parseEXblock( StrList* list, const char *exName ){
}
static void parseEXfile( const char* filename, StrList* ExTextures, StrList* ExShaders, StrList* ExShaderfiles, StrList* ExSounds, StrList* ExVideos ){
- char exName[ 1024 ];
- ExtractFilePath( g_q3map2path, exName );
- strcat( exName, filename );
- Sys_Printf( "Loading %s\n", exName );
+ Sys_Printf( "Loading %s\n", filename );
byte *buffer;
- const int size = TryLoadFile( exName, (void**) &buffer );
+ const int size = TryLoadFile( filename, (void**) &buffer );
if ( size < 0 ) {
- Sys_Warning( "Unable to load exclusions file %s.\n", exName );
+ Sys_Warning( "Unable to load exclusions file %s.\n", filename );
}
else{
/* parse the file */
@@ -153,22 +150,22 @@ static void parseEXfile( const char* filename, StrList* ExTextures, StrList* ExS
/* blocks */
if ( striEqual( token, "textures" ) ){
- parseEXblock( ExTextures, exName );
+ parseEXblock( ExTextures, filename );
}
else if ( striEqual( token, "shaders" ) ){
- parseEXblock( ExShaders, exName );
+ parseEXblock( ExShaders, filename );
}
else if ( striEqual( token, "shaderfiles" ) ){
- parseEXblock( ExShaderfiles, exName );
+ parseEXblock( ExShaderfiles, filename );
}
else if ( striEqual( token, "sounds" ) ){
- parseEXblock( ExSounds, exName );
+ parseEXblock( ExSounds, filename );
}
else if ( striEqual( token, "videos" ) ){
- parseEXblock( ExVideos, exName );
+ parseEXblock( ExVideos, filename );
}
else{
- Error( "ReadExclusionsFile: %s, line %d: unknown block name!\nValid ones are: textures, shaders, shaderfiles, sounds, videos.", exName, scriptline );
+ Error( "ReadExclusionsFile: %s, line %d: unknown block name!\nValid ones are: textures, shaders, shaderfiles, sounds, videos.", filename, scriptline );
}
}
@@ -200,34 +197,32 @@ static bool packTexture( const char* texname, const char* packname, const int co
-char g_q3map2path[1024];
-
/*
pk3BSPMain()
map autopackager, works for Q3 type of shaders and ents
*/
-int pk3BSPMain( int argc, char **argv ){
+int pk3BSPMain( Args& args ){
int i, compLevel = 10;
bool dbg = false, png = false, packFAIL = false;
/* process arguments */
- for ( i = 1; i < ( argc - 1 ); ++i ){
- if ( striEqual( argv[ i ], "-dbg" ) ) {
+ const char *fileName = args.takeBack();
+ {
+ if ( args.takeArg( "-dbg" ) ) {
dbg = true;
}
- else if ( striEqual( argv[ i ], "-png" ) ) {
+ if ( args.takeArg( "-png" ) ) {
png = true;
}
- else if ( striEqual( argv[ i ], "-complevel" ) ) {
- compLevel = std::clamp( atoi( argv[ i + 1 ] ), -1, 10 );
- i++;
+ if ( args.takeArg( "-complevel" ) ) {
+ compLevel = std::clamp( atoi( args.takeNext() ), -1, 10 );
Sys_Printf( "Compression level set to %i\n", compLevel );
}
}
/* do some path mangling */
- strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
+ strcpy( source, ExpandArg( fileName ) );
path_set_extension( source, ".bsp" );
/* load the bsp */
@@ -342,7 +337,7 @@ int pk3BSPMain( int argc, char **argv ){
char* ExReasonShaderFile[4096] = { NULL };
{
- parseEXfile( stream( g_game->arg, ".exclude" ), ExTextures, ExShaders, ExShaderfiles, ExSounds, ExVideos );
+ parseEXfile( stream( PathFilenameless( args.getArg0() ), g_game->arg, ".exclude" ), ExTextures, ExShaders, ExShaderfiles, ExSounds, ExVideos );
for ( i = 0; i < ExTextures->n; ++i ){
if( !StrList_find( ExShaders, ExTextures->s[i] ) )
@@ -752,25 +747,25 @@ int pk3BSPMain( int argc, char **argv ){
works for Q3 type of shaders and ents
*/
-int repackBSPMain( int argc, char **argv ){
+int repackBSPMain( Args& args ){
int i, j, compLevel = 0;
bool dbg = false, png = false, analyze = false;
char str[ 1024 ];
StringOutputStream stream( 256 );
/* process arguments */
- for ( i = 1; i < ( argc - 1 ); ++i ){
- if ( striEqual( argv[ i ], "-dbg" ) ) {
+ const char *fileName = args.takeBack();
+ {
+ if ( args.takeArg( "-dbg" ) ) {
dbg = true;
}
- else if ( striEqual( argv[ i ], "-png" ) ) {
+ if ( args.takeArg( "-png" ) ) {
png = true;
}
- else if ( striEqual( argv[ i ], "-analyze" ) ) { // only analyze bsps and exit
+ if ( args.takeArg( "-analyze" ) ) { // only analyze bsps and exit
analyze = true;
}
- else if ( striEqual( argv[ i ], "-complevel" ) ) {
- compLevel = std::clamp( atoi( argv[ i + 1 ] ), -1, 10 );
- i++;
+ if ( args.takeArg( "-complevel" ) ) {
+ compLevel = std::clamp( atoi( args.takeNext() ), -1, 10 );
Sys_Printf( "Compression level set to %i\n", compLevel );
}
}
@@ -784,7 +779,7 @@ int repackBSPMain( int argc, char **argv ){
StrList* ExPureTextures = StrList_allocate( 4096 );
{
- parseEXfile( stream( g_game->arg, ".exclude" ), ExTextures, ExShaders, ExShaderfiles, ExSounds, ExVideos );
+ parseEXfile( stream( PathFilenameless( args.getArg0() ), g_game->arg, ".exclude" ), ExTextures, ExShaders, ExShaderfiles, ExSounds, ExVideos );
for ( i = 0; i < ExTextures->n; ++i ){
if( !StrList_find( ExShaders, ExTextures->s[i] ) )
@@ -821,7 +816,7 @@ int repackBSPMain( int argc, char **argv ){
StrList* rExSounds = StrList_allocate( 8192 );
StrList* rExVideos = StrList_allocate( 4096 );
- parseEXfile( "repack.exclude", rExTextures, rExShaders, rExShaderfiles, rExSounds, rExVideos );
+ parseEXfile( stream( PathFilenameless( args.getArg0() ), "repack.exclude" ), rExTextures, rExShaders, rExShaderfiles, rExSounds, rExVideos );
if( dbg ){
Sys_Printf( "\n\trExTextures....%i\n", rExTextures->n );
@@ -848,7 +843,7 @@ int repackBSPMain( int argc, char **argv ){
char (*bspList)[1024] = safe_malloc( bspListSize * sizeof( bspList[0] ) );
/* do some path mangling */
- strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
+ strcpy( source, ExpandArg( fileName ) );
if ( striEqual( path_get_filename_base_end( source ), ".bsp" ) ){
strcpy( bspList[bspListN], source );
bspListN++;
diff --git a/tools/quake3/q3map2/autopk3.h b/tools/quake3/q3map2/autopk3.h
index b5d40959..b7e31d09 100644
--- a/tools/quake3/q3map2/autopk3.h
+++ b/tools/quake3/q3map2/autopk3.h
@@ -19,12 +19,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#if !defined( INCLUDED_AUTOPK3_H )
-#define INCLUDED_AUTOPK3_H
+#pragma once
-extern char g_q3map2path[1024];
-
-int pk3BSPMain( int argc, char **argv );
-int repackBSPMain( int argc, char **argv );
-
-#endif
+int pk3BSPMain( Args& args );
+int repackBSPMain( Args& args );
diff --git a/tools/quake3/q3map2/bsp.cpp b/tools/quake3/q3map2/bsp.cpp
index 63817bb9..130cca9d 100644
--- a/tools/quake3/q3map2/bsp.cpp
+++ b/tools/quake3/q3map2/bsp.cpp
@@ -649,15 +649,12 @@ void OnlyEnts( void ){
handles creation of a bsp from a map file
*/
-int BSPMain( int argc, char **argv ){
- int i;
+int BSPMain( Args& args ){
char tempSource[ 1024 ];
bool onlyents = false;
- if ( argc >= 2 && striEqual( argv[ 1 ], "-bsp" ) ) {
+ if ( args.takeFront( "-bsp" ) ) {
Sys_Printf( "-bsp argument unnecessary\n" );
- argv++;
- argc--;
}
/* note it */
@@ -680,244 +677,228 @@ int BSPMain( int argc, char **argv ){
keepLights = g_game->keepLights;
/* process arguments */
- for ( i = 1; i < ( argc - 1 ); i++ )
+ /* fixme: print more useful usage here */
+ if ( args.empty() ) {
+ Error( "usage: q3map2 [options] mapfile" );
+ }
+
+ const char *fileName = args.takeBack();
+ auto argsToInject = args.getVector();
{
- if ( striEqual( argv[ i ], "-onlyents" ) ) {
+ while ( args.takeArg( "-onlyents" ) ) {
Sys_Printf( "Running entity-only compile\n" );
onlyents = true;
}
- else if ( striEqual( argv[ i ], "-tempname" ) ) {
- strcpy( tempSource, argv[ ++i ] );
+ while ( args.takeArg( "-tempname" ) ) {
+ strcpy( tempSource, args.takeNext() );
}
- else if ( striEqual( argv[ i ], "-nowater" ) ) {
+ while ( args.takeArg( "-nowater" ) ) {
Sys_Printf( "Disabling water\n" );
nowater = true;
}
- else if ( striEqual( argv[ i ], "-keeplights" ) ) {
+ while ( args.takeArg( "-keeplights" ) ) {
keepLights = true;
Sys_Printf( "Leaving light entities on map after compile\n" );
}
- else if ( striEqual( argv[ i ], "-nodetail" ) ) {
+ while ( args.takeArg( "-nodetail" ) ) {
Sys_Printf( "Ignoring detail brushes\n" ) ;
nodetail = true;
}
- else if ( striEqual( argv[ i ], "-fulldetail" ) ) {
+ while ( args.takeArg( "-fulldetail" ) ) {
Sys_Printf( "Turning detail brushes into structural brushes\n" );
fulldetail = true;
}
- else if ( striEqual( argv[ i ], "-nofog" ) ) {
+ while ( args.takeArg( "-nofog" ) ) {
Sys_Printf( "Fog volumes disabled\n" );
nofog = true;
}
- else if ( striEqual( argv[ i ], "-nosubdivide" ) ) {
+ while ( args.takeArg( "-nosubdivide" ) ) {
Sys_Printf( "Disabling brush face subdivision\n" );
nosubdivide = true;
}
- else if ( striEqual( argv[ i ], "-leaktest" ) ) {
+ while ( args.takeArg( "-leaktest" ) ) {
Sys_Printf( "Leaktest enabled\n" );
leaktest = true;
}
- else if ( striEqual( argv[ i ], "-verboseentities" ) ) {
+ while ( args.takeArg( "-verboseentities" ) ) {
Sys_Printf( "Verbose entities enabled\n" );
verboseEntities = true;
}
- else if ( striEqual( argv[ i ], "-nocurves" ) ) {
+ while ( args.takeArg( "-nocurves" ) ) {
Sys_Printf( "Ignoring curved surfaces (patches)\n" );
noCurveBrushes = true;
}
- else if ( striEqual( argv[ i ], "-notjunc" ) ) {
+ while ( args.takeArg( "-notjunc" ) ) {
Sys_Printf( "T-junction fixing disabled\n" );
notjunc = true;
}
- else if ( striEqual( argv[ i ], "-fakemap" ) ) {
+ while ( args.takeArg( "-fakemap" ) ) {
Sys_Printf( "Generating fakemap.map\n" );
fakemap = true;
}
- else if ( striEqual( argv[ i ], "-samplesize" ) ) {
- sampleSize = std::max( 1, atoi( argv[ i + 1 ] ) );
- i++;
+ while ( args.takeArg( "-samplesize" ) ) {
+ sampleSize = std::max( 1, atoi( args.takeNext() ) );
Sys_Printf( "Lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
}
- else if ( striEqual( argv[ i ], "-minsamplesize" ) ) {
- minSampleSize = std::max( 1, atoi( argv[ i + 1 ] ) );
- i++;
+ while ( args.takeArg( "-minsamplesize" ) ) {
+ minSampleSize = std::max( 1, atoi( args.takeNext() ) );
Sys_Printf( "Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize );
}
- else if ( striEqual( argv[ i ], "-custinfoparms" ) ) {
+ while ( args.takeArg( "-custinfoparms" ) ) {
Sys_Printf( "Custom info parms enabled\n" );
useCustomInfoParms = true;
}
/* sof2 args */
- else if ( striEqual( argv[ i ], "-rename" ) ) {
+ while ( args.takeArg( "-rename" ) ) {
Sys_Printf( "Appending _bsp suffix to misc_model shaders (SOF2)\n" );
renameModelShaders = true;
}
/* ydnar args */
- else if ( striEqual( argv[ i ], "-ne" ) ) {
- normalEpsilon = atof( argv[ i + 1 ] );
- i++;
+ while ( args.takeArg( "-ne" ) ) {
+ normalEpsilon = atof( args.takeNext() );
Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
}
- else if ( striEqual( argv[ i ], "-de" ) ) {
- distanceEpsilon = atof( argv[ i + 1 ] );
- i++;
+ while ( args.takeArg( "-de" ) ) {
+ distanceEpsilon = atof( args.takeNext() );
Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
}
- else if ( striEqual( argv[ i ], "-mv" ) ) {
- maxLMSurfaceVerts = std::max( 3, atoi( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-mv" ) ) {
+ maxLMSurfaceVerts = std::max( 3, atoi( args.takeNext() ) );
value_maximize( maxSurfaceVerts, maxLMSurfaceVerts );
- i++;
Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
}
- else if ( striEqual( argv[ i ], "-mi" ) ) {
- maxSurfaceIndexes = std::max( 3, atoi( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-mi" ) ) {
+ maxSurfaceIndexes = std::max( 3, atoi( args.takeNext() ) );
Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
- i++;
}
- else if ( striEqual( argv[ i ], "-np" ) ) {
- npDegrees = std::max( 0.0, atof( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-np" ) ) {
+ npDegrees = std::max( 0.0, atof( args.takeNext() ) );
if ( npDegrees > 0.0f ) {
Sys_Printf( "Forcing nonplanar surfaces with a breaking angle of %f degrees\n", npDegrees );
}
- i++;
}
- else if ( striEqual( argv[ i ], "-snap" ) ) {
- bevelSnap = std::max( 0, atoi( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-snap" ) ) {
+ bevelSnap = std::max( 0, atoi( args.takeNext() ) );
if ( bevelSnap > 0 ) {
Sys_Printf( "Snapping brush bevel planes to %d units\n", bevelSnap );
}
- i++;
}
- else if ( striEqual( argv[ i ], "-nohint" ) ) {
+ while ( args.takeArg( "-nohint" ) ) {
Sys_Printf( "Hint brushes disabled\n" );
noHint = true;
}
- else if ( striEqual( argv[ i ], "-flat" ) ) {
+ while ( args.takeArg( "-flat" ) ) {
Sys_Printf( "Flatshading enabled\n" );
flat = true;
}
- else if ( striEqual( argv[ i ], "-celshader" ) ) {
- ++i;
- if ( !strEmpty( argv[ i ] ) ) {
- globalCelShader( "textures/", argv[ i ] );
- }
- else{
- globalCelShader.clear();
- }
+ while ( args.takeArg( "-celshader" ) ) {
+ globalCelShader( "textures/", args.takeNext() );
Sys_Printf( "Global cel shader set to \"%s\"\n", globalCelShader.c_str() );
}
- else if ( striEqual( argv[ i ], "-meta" ) ) {
+ while ( args.takeArg( "-meta" ) ) {
Sys_Printf( "Creating meta surfaces from brush faces\n" );
meta = true;
}
- else if ( striEqual( argv[ i ], "-metaadequatescore" ) ) {
- metaAdequateScore = std::max( -1, atoi( argv[ i + 1 ] ) );
- i++;
+ while ( args.takeArg( "-metaadequatescore" ) ) {
+ metaAdequateScore = std::max( -1, atoi( args.takeNext() ) );
if ( metaAdequateScore >= 0 ) {
Sys_Printf( "Setting ADEQUATE meta score to %d (see surface_meta.c)\n", metaAdequateScore );
}
}
- else if ( striEqual( argv[ i ], "-metagoodscore" ) ) {
- metaGoodScore = std::max( -1, atoi( argv[ i + 1 ] ) );
- i++;
+ while ( args.takeArg( "-metagoodscore" ) ) {
+ metaGoodScore = std::max( -1, atoi( args.takeNext() ) );
if ( metaGoodScore >= 0 ) {
Sys_Printf( "Setting GOOD meta score to %d (see surface_meta.c)\n", metaGoodScore );
}
}
- else if ( striEqual( argv[ i ], "-patchmeta" ) ) {
+ while ( args.takeArg( "-patchmeta" ) ) {
Sys_Printf( "Creating meta surfaces from patches\n" );
patchMeta = true;
}
- else if ( striEqual( argv[ i ], "-flares" ) ) {
+ while ( args.takeArg( "-flares" ) ) {
Sys_Printf( "Flare surfaces enabled\n" );
emitFlares = true;
}
- else if ( striEqual( argv[ i ], "-noflares" ) ) {
+ while ( args.takeArg( "-noflares" ) ) {
Sys_Printf( "Flare surfaces disabled\n" );
emitFlares = false;
}
- else if ( striEqual( argv[ i ], "-skyfix" ) ) {
+ while ( args.takeArg( "-skyfix" ) ) {
Sys_Printf( "GL_CLAMP sky fix/hack/workaround enabled\n" );
skyFixHack = true;
}
- else if ( striEqual( argv[ i ], "-debugsurfaces" ) ) {
+ while ( args.takeArg( "-debugsurfaces" ) ) {
Sys_Printf( "emitting debug surfaces\n" );
debugSurfaces = true;
}
- else if ( striEqual( argv[ i ], "-debuginset" ) ) {
+ while ( args.takeArg( "-debuginset" ) ) {
Sys_Printf( "Debug surface triangle insetting enabled\n" );
debugInset = true;
}
- else if ( striEqual( argv[ i ], "-debugportals" ) ) {
+ while ( args.takeArg( "-debugportals" ) ) {
Sys_Printf( "Debug portal surfaces enabled\n" );
debugPortals = true;
}
- else if ( striEqual( argv[ i ], "-debugclip" ) ) {
+ while ( args.takeArg( "-debugclip" ) ) {
Sys_Printf( "Debug model clip enabled\n" );
debugClip = true;
}
- else if ( striEqual( argv[ i ], "-clipdepth" ) ) {
- clipDepthGlobal = atof( argv[ i + 1 ] );
- i++;
+ while ( args.takeArg( "-clipdepth" ) ) {
+ clipDepthGlobal = atof( args.takeNext() );
Sys_Printf( "Model autoclip thickness set to %.3f\n", clipDepthGlobal );
}
- else if ( striEqual( argv[ i ], "-sRGBtex" ) ) {
+ while ( args.takeArg( "-sRGBtex" ) ) {
texturesRGB = true;
Sys_Printf( "Textures are in sRGB\n" );
}
- else if ( striEqual( argv[ i ], "-nosRGBtex" ) ) {
+ while ( args.takeArg( "-nosRGBtex" ) ) {
texturesRGB = false;
Sys_Printf( "Textures are linear\n" );
}
- else if ( striEqual( argv[ i ], "-sRGBcolor" ) ) {
+ while ( args.takeArg( "-sRGBcolor" ) ) {
colorsRGB = true;
Sys_Printf( "Colors are in sRGB\n" );
}
- else if ( striEqual( argv[ i ], "-nosRGBcolor" ) ) {
+ while ( args.takeArg( "-nosRGBcolor" ) ) {
colorsRGB = false;
Sys_Printf( "Colors are linear\n" );
}
- else if ( striEqual( argv[ i ], "-nosRGB" ) ) {
+ while ( args.takeArg( "-nosRGB" ) ) {
texturesRGB = false;
Sys_Printf( "Textures are linear\n" );
colorsRGB = false;
Sys_Printf( "Colors are linear\n" );
}
- else if ( striEqual( argv[ i ], "-altsplit" ) ) {
+ while ( args.takeArg( "-altsplit" ) ) {
Sys_Printf( "Alternate BSP splitting (by 27) enabled\n" );
bspAlternateSplitWeights = true;
}
- else if ( striEqual( argv[ i ], "-deep" ) ) {
+ while ( args.takeArg( "-deep" ) ) {
Sys_Printf( "Deep BSP tree generation enabled\n" );
deepBSP = true;
}
- else if ( striEqual( argv[ i ], "-maxarea" ) ) {
+ while ( args.takeArg( "-maxarea" ) ) {
Sys_Printf( "Max Area face surface generation enabled\n" );
maxAreaFaceSurface = true;
}
- else if ( striEqual( argv[ i ], "-noob" ) ) {
+ while ( args.takeArg( "-noob" ) ) {
Sys_Printf( "No oBs!\n" );
noob = true;
}
- else if ( striEqual( argv[ i ], "-autocaulk" ) ) {
+ while ( args.takeArg( "-autocaulk" ) ) {
Sys_Printf( "\trunning in autocaulk mode\n" );
g_autocaulk = true;
}
- else
+ while( !args.empty() )
{
- Sys_Warning( "Unknown option \"%s\"\n", argv[ i ] );
+ Sys_Warning( "Unknown option \"%s\"\n", args.takeFront() );
}
}
- /* fixme: print more useful usage here */
- if ( i != ( argc - 1 ) ) {
- Error( "usage: q3map2 [options] mapfile" );
- }
-
/* copy source name */
- strcpy( source, ExpandArg( argv[ i ] ) );
+ strcpy( source, ExpandArg( fileName ) );
StripExtension( source );
/* ydnar: set default sample size */
@@ -929,7 +910,7 @@ int BSPMain( int argc, char **argv ){
//% remove( StringOutputStream( 256 )( source, ".srf" ) ); /* ydnar */
/* expand mapname */
- strcpy( name, ExpandArg( argv[ i ] ) );
+ strcpy( name, ExpandArg( fileName ) );
if ( !striEqual( path_get_filename_base_end( name ), ".reg" ) ) { /* not .reg */
/* if we are doing a full map, delete the last saved region map */
remove( StringOutputStream( 256 )( source, ".reg" ) );
@@ -956,7 +937,7 @@ int BSPMain( int argc, char **argv ){
}
/* div0: inject command line parameters */
- InjectCommandLine( argv, 1, argc - 1 );
+ InjectCommandLine( "-bsp", argsToInject );
/* ydnar: decal setup */
ProcessDecals();
diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp
index 09ad234f..7ff5e5bd 100644
--- a/tools/quake3/q3map2/bspfile_abstract.cpp
+++ b/tools/quake3/q3map2/bspfile_abstract.cpp
@@ -595,41 +595,21 @@ void ParseEntities( void ){
/*
* must be called before UnparseEntities
*/
-void InjectCommandLine( char **argv, int beginArgs, int endArgs ){
- char newCommandLine[1024];
- const char *inpos;
- char *outpos = newCommandLine;
- char *sentinel = newCommandLine + sizeof( newCommandLine ) - 1;
- int i;
+void InjectCommandLine( const char *stage, const std::vector& args ){
+ auto str = StringOutputStream( 256 )( entities[ 0 ].valueForKey( "_q3map2_cmdline" ) ); // read previousCommandLine
+ if( !str.empty() )
+ str << "; ";
- if ( nocmdline ){
- return;
- }
- if ( entities[ 0 ].read_keyvalue( inpos, "_q3map2_cmdline" ) ) { // read previousCommandLine
- while ( outpos != sentinel && *inpos )
- *outpos++ = *inpos++;
- if ( outpos != sentinel ) {
- *outpos++ = ';';
- }
- if ( outpos != sentinel ) {
- *outpos++ = ' ';
- }
+ str << stage;
+
+ for ( const char *c : args ) {
+ str << ' ';
+ for( ; !strEmpty( c ); ++c )
+ if ( *c != '\\' && *c != '"' && *c != ';' && (unsigned char) *c >= ' ' )
+ str << *c;
}
- for ( i = beginArgs; i < endArgs; ++i )
- {
- if ( outpos != sentinel && i != beginArgs ) {
- *outpos++ = ' ';
- }
- inpos = argv[i];
- while ( outpos != sentinel && *inpos )
- if ( *inpos != '\\' && *inpos != '"' && *inpos != ';' && (unsigned char) *inpos >= ' ' ) {
- *outpos++ = *inpos++;
- }
- }
-
- *outpos = 0;
- entities[0].setKeyValue( "_q3map2_cmdline", newCommandLine );
+ entities[0].setKeyValue( "_q3map2_cmdline", str );
entities[0].setKeyValue( "_q3map2_version", Q3MAP_VERSION );
}
diff --git a/tools/quake3/q3map2/convert_bsp.cpp b/tools/quake3/q3map2/convert_bsp.cpp
index f8791227..9fe97ff4 100644
--- a/tools/quake3/q3map2/convert_bsp.cpp
+++ b/tools/quake3/q3map2/convert_bsp.cpp
@@ -43,29 +43,20 @@ static void AAS_DData( unsigned char *data, int size ){
resets an aas checksum to match the given BSP
*/
-int FixAAS( int argc, char **argv ){
+int FixAAS( Args& args ){
int length, checksum;
void *buffer;
- FILE *file;
char aas[ 1024 ];
- const char **ext;
- const char *exts[] =
- {
- ".aas",
- "_b0.aas",
- "_b1.aas",
- NULL
- };
/* arg checking */
- if ( argc < 2 ) {
+ if ( args.empty() ) {
Sys_Printf( "Usage: q3map2 -fixaas [-v] \n" );
return 0;
}
/* do some path mangling */
- strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
+ strcpy( source, ExpandArg( args.takeBack() ) );
path_set_extension( source, ".bsp" );
/* note it */
@@ -81,17 +72,15 @@ int FixAAS( int argc, char **argv ){
AAS_DData( (unsigned char *) &checksum, 4 );
/* write checksum to aas */
- ext = exts;
- while ( *ext )
+ for( auto&& ext : { ".aas", "_b0.aas", "_b1.aas" } )
{
/* mangle name */
strcpy( aas, source );
- path_set_extension( aas, *ext );
+ path_set_extension( aas, ext );
Sys_Printf( "Trying %s\n", aas );
- ext++;
/* fix it */
- file = fopen( aas, "r+b" );
+ FILE *file = fopen( aas, "r+b" );
if ( !file ) {
continue;
}
@@ -126,7 +115,7 @@ struct abspLumpTest_t
const char *name;
};
-int AnalyzeBSP( int argc, char **argv ){
+int AnalyzeBSP( Args& args ){
abspHeader_t *header;
int size, i, version, offset, length, lumpInt, count;
char ident[ 5 ];
@@ -155,23 +144,19 @@ int AnalyzeBSP( int argc, char **argv ){
/* arg checking */
- if ( argc < 2 ) {
+ if ( args.empty() ) {
Sys_Printf( "Usage: q3map2 -analyze [-lumpswap] [-v] \n" );
return 0;
}
/* process arguments */
- for ( i = 1; i < ( argc - 1 ); i++ )
- {
- /* -format map|ase|... */
- if ( striEqual( argv[ i ], "-lumpswap" ) ) {
- Sys_Printf( "Swapped lump structs enabled\n" );
- lumpSwap = true;
- }
+ while ( args.takeArg( "-lumpswap" ) ) {
+ Sys_Printf( "Swapped lump structs enabled\n" );
+ lumpSwap = true;
}
/* clean up map name */
- strcpy( source, ExpandArg( argv[ i ] ) );
+ strcpy( source, ExpandArg( args.takeBack() ) );
Sys_Printf( "Loading %s\n", source );
/* load the file */
@@ -273,35 +258,30 @@ int AnalyzeBSP( int argc, char **argv ){
emits statistics about the bsp file
*/
-int BSPInfo( int count, char **fileNames ){
- int i;
+int BSPInfo( Args& args ){
char source[ 1024 ];
- int size;
- FILE *f;
/* dummy check */
- if ( count < 1 ) {
+ if ( args.empty() ) {
Sys_Printf( "No files to dump info for.\n" );
return -1;
}
/* walk file list */
- for ( i = 0; i < count; i++ )
+ while ( !args.empty() )
{
Sys_Printf( "---------------------------------\n" );
/* mangle filename and get size */
- strcpy( source, fileNames[ i ] );
+ const char *fileName = args.takeFront();
+ strcpy( source, fileName );
path_set_extension( source, ".bsp" );
- f = fopen( source, "rb" );
- if ( f ) {
+ int size = 0;
+ if ( FILE *f = fopen( source, "rb" ); f != nullptr ) {
size = Q_filelength( f );
fclose( f );
}
- else{
- size = 0;
- }
/* load the bsp file and print lump sizes */
Sys_Printf( "%s\n", source );
@@ -317,8 +297,7 @@ int BSPInfo( int count, char **fileNames ){
Sys_Printf( "---------------------------------\n" );
}
- /* return count */
- return i;
+ return 0;
}
@@ -394,7 +373,7 @@ static void ExtrapolateTexcoords( const float *axyz, const float *ast,
amaze and confuse your enemies with weird scaled maps!
*/
-int ScaleBSPMain( int argc, char **argv ){
+int ScaleBSPMain( Args& args ){
int i, j;
float f, a;
Vector3 scale;
@@ -407,34 +386,30 @@ int ScaleBSPMain( int argc, char **argv ){
/* arg checking */
- if ( argc < 3 ) {
+ if ( args.size() < 2 ) {
Sys_Printf( "Usage: q3map2 [-v] -scale [-tex] [-spawn_ref ] \n" );
return 0;
}
texscale = false;
- for ( i = 1; i < argc - 2; ++i )
+ const char *fileName = args.takeBack();
+ const auto argsToInject = args.getVector();
{
- if ( striEqual( argv[i], "-tex" ) ) {
+ if ( args.takeArg( "-tex" ) ) {
texscale = true;
}
- else if ( striEqual( argv[i], "-spawn_ref" ) ) {
- spawn_ref = atof( argv[i + 1] );
- ++i;
- }
- else{
- break;
+ if ( args.takeArg( "-spawn_ref" ) ) {
+ spawn_ref = atof( args.takeNext() );
}
}
/* get scale */
- // if(argc-2 >= i) // always true
- scale[2] = scale[1] = scale[0] = atof( argv[ argc - 2 ] );
- if ( argc - 3 >= i ) {
- scale[1] = scale[0] = atof( argv[ argc - 3 ] );
+ scale[2] = scale[1] = scale[0] = atof( args.takeBack() );
+ if ( !args.empty() ) {
+ scale[1] = scale[0] = atof( args.takeBack() );
}
- if ( argc - 4 >= i ) {
- scale[0] = atof( argv[ argc - 4 ] );
+ if ( !args.empty() ) {
+ scale[0] = atof( args.takeBack() );
}
uniform = ( ( scale[0] == scale[1] ) && ( scale[1] == scale[2] ) );
@@ -446,7 +421,7 @@ int ScaleBSPMain( int argc, char **argv ){
}
/* do some path mangling */
- strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
+ strcpy( source, ExpandArg( fileName ) );
path_set_extension( source, ".bsp" );
/* load the bsp */
@@ -463,11 +438,11 @@ int ScaleBSPMain( int argc, char **argv ){
{
/* scale origin */
if ( e.read_keyvalue( vec, "origin" ) ) {
- if ( entities[i].classname_prefixed( "info_player_" ) ) {
+ if ( e.classname_prefixed( "info_player_" ) ) {
vec[2] += spawn_ref;
}
vec *= scale;
- if ( entities[i].classname_prefixed( "info_player_" ) ) {
+ if ( e.classname_prefixed( "info_player_" ) ) {
vec[2] -= spawn_ref;
}
sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
@@ -602,7 +577,7 @@ int ScaleBSPMain( int argc, char **argv ){
entities[ 0 ].setKeyValue( "gridsize", str );
/* inject command line parameters */
- InjectCommandLine( argv, 0, argc - 1 );
+ InjectCommandLine( "-scale", argsToInject );
/* write the bsp */
UnparseEntities();
@@ -620,7 +595,7 @@ int ScaleBSPMain( int argc, char **argv ){
shifts a map: for testing physics with huge coordinates
*/
-int ShiftBSPMain( int argc, char **argv ){
+int ShiftBSPMain( Args& args ){
int i;
Vector3 shift;
Vector3 vec;
@@ -628,23 +603,26 @@ int ShiftBSPMain( int argc, char **argv ){
/* arg checking */
- if ( argc < 3 ) {
+ if ( args.size() < 2 ) {
Sys_Printf( "Usage: q3map2 [-v] -shift \n" );
return 0;
}
+ const char *fileName = args.takeBack();
+ const auto argsToInject = args.getVector();
+
/* get shift */
- shift[2] = shift[1] = shift[0] = atof( argv[ argc - 2 ] );
- if ( argc - 3 >= 1 ) {
- shift[1] = shift[0] = atof( argv[ argc - 3 ] );
+ shift[2] = shift[1] = shift[0] = atof( args.takeBack() );
+ if ( !args.empty() ) {
+ shift[1] = shift[0] = atof( args.takeBack() );
}
- if ( argc - 4 >= 1 ) {
- shift[0] = atof( argv[ argc - 4 ] );
+ if ( !args.empty() ) {
+ shift[0] = atof( args.takeBack() );
}
/* do some path mangling */
- strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
+ strcpy( source, ExpandArg( fileName ) );
path_set_extension( source, ".bsp" );
/* load the bsp */
@@ -704,7 +682,7 @@ int ShiftBSPMain( int argc, char **argv ){
// fixme: engine says 'light grid mismatch', unless translation is multiple of grid size
/* inject command line parameters */
- InjectCommandLine( argv, 0, argc - 1 );
+ InjectCommandLine( "-shift", argsToInject );
/* write the bsp */
UnparseEntities();
@@ -807,8 +785,7 @@ void PseudoCompileBSP( bool need_tree ){
main argument processing function for bsp conversion
*/
-int ConvertBSPMain( int argc, char **argv ){
- int i;
+int ConvertBSPMain( Args& args ){
int ( *convertFunc )( char * );
const game_t *convertGame;
bool map_allowed, force_bsp, force_map;
@@ -822,76 +799,74 @@ int ConvertBSPMain( int argc, char **argv ){
force_map = false;
/* arg checking */
- if ( argc < 2 ) {
+ if ( args.empty() ) {
Sys_Printf( "Usage: q3map2 -convert [-format ] [-shadersasbitmap|-lightmapsastexcoord|-deluxemapsastexcoord] [-readbsp|-readmap [-meta|-patchmeta]] [-v] \n" );
return 0;
}
/* process arguments */
- for ( i = 1; i < ( argc - 1 ); i++ )
+ const char *fileName = args.takeBack();
{
/* -format map|ase|... */
- if ( striEqual( argv[ i ], "-format" ) ) {
- i++;
- if ( striEqual( argv[ i ], "ase" ) ) {
+ while ( args.takeArg( "-format" ) ) {
+ const char *fmt = args.takeNext();
+ if ( striEqual( fmt, "ase" ) ) {
convertFunc = ConvertBSPToASE;
map_allowed = false;
}
- else if ( striEqual( argv[ i ], "obj" ) ) {
+ else if ( striEqual( fmt, "obj" ) ) {
convertFunc = ConvertBSPToOBJ;
map_allowed = false;
}
- else if ( striEqual( argv[ i ], "map_bp" ) ) {
+ else if ( striEqual( fmt, "map_bp" ) ) {
convertFunc = ConvertBSPToMap_BP;
map_allowed = true;
}
- else if ( striEqual( argv[ i ], "map" ) ) {
+ else if ( striEqual( fmt, "map" ) ) {
convertFunc = ConvertBSPToMap;
map_allowed = true;
}
else
{
- convertGame = GetGame( argv[ i ] );
+ convertGame = GetGame( fmt );
map_allowed = false;
if ( convertGame == NULL ) {
- Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
+ Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", fmt );
}
}
}
- else if ( striEqual( argv[ i ], "-ne" ) ) {
- normalEpsilon = atof( argv[ i + 1 ] );
- i++;
+ while ( args.takeArg( "-ne" ) ) {
+ normalEpsilon = atof( args.takeNext() );
Sys_Printf( "Normal epsilon set to %lf\n", normalEpsilon );
}
- else if ( striEqual( argv[ i ], "-de" ) ) {
- distanceEpsilon = atof( argv[ i + 1 ] );
- i++;
+ while ( args.takeArg( "-de" ) ) {
+ distanceEpsilon = atof( args.takeNext() );
Sys_Printf( "Distance epsilon set to %lf\n", distanceEpsilon );
}
- else if ( striEqual( argv[ i ], "-shaderasbitmap" ) || striEqual( argv[ i ], "-shadersasbitmap" ) ) {
+ while ( args.takeArg( "-shaderasbitmap", "-shadersasbitmap" ) ) {
shadersAsBitmap = true;
}
- else if ( striEqual( argv[ i ], "-lightmapastexcoord" ) || striEqual( argv[ i ], "-lightmapsastexcoord" ) ) {
+ while ( args.takeArg( "-lightmapastexcoord", "-lightmapsastexcoord" ) ) {
lightmapsAsTexcoord = true;
}
- else if ( striEqual( argv[ i ], "-deluxemapastexcoord" ) || striEqual( argv[ i ], "-deluxemapsastexcoord" ) ) {
+ while ( args.takeArg( "-deluxemapastexcoord", "-deluxemapsastexcoord" ) ) {
lightmapsAsTexcoord = true;
deluxemap = true;
}
- else if ( striEqual( argv[ i ], "-readbsp" ) ) {
+ while ( args.takeArg( "-readbsp" ) ) {
force_bsp = true;
}
- else if ( striEqual( argv[ i ], "-readmap" ) ) {
+ while ( args.takeArg( "-readmap" ) ) {
force_map = true;
}
- else if ( striEqual( argv[ i ], "-meta" ) ) {
+ while ( args.takeArg( "-meta" ) ) {
meta = true;
}
- else if ( striEqual( argv[ i ], "-patchmeta" ) ) {
+ while ( args.takeArg( "-patchmeta" ) ) {
meta = true;
patchMeta = true;
}
- else if ( striEqual( argv[ i ], "-fast" ) ) {
+ while ( args.takeArg( "-fast" ) ) {
fast = true;
}
}
@@ -899,7 +874,7 @@ int ConvertBSPMain( int argc, char **argv ){
LoadShaderInfo();
/* clean up map name */
- strcpy( source, ExpandArg( argv[i] ) );
+ strcpy( source, ExpandArg( fileName ) );
if ( !map_allowed && !force_map ) {
force_bsp = true;
diff --git a/tools/quake3/q3map2/exportents.cpp b/tools/quake3/q3map2/exportents.cpp
index 474ad556..c1308abc 100644
--- a/tools/quake3/q3map2/exportents.cpp
+++ b/tools/quake3/q3map2/exportents.cpp
@@ -72,15 +72,15 @@ void ExportEntities( void ){
exports the entities to a text file (.ent)
*/
-int ExportEntitiesMain( int argc, char **argv ){
+int ExportEntitiesMain( Args& args ){
/* arg checking */
- if ( argc < 2 ) {
+ if ( args.empty() ) {
Sys_Printf( "Usage: q3map2 -exportents [-v] \n" );
return 0;
}
/* do some path mangling */
- strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
+ strcpy( source, ExpandArg( args.takeBack() ) );
path_set_extension( source, ".bsp" );
/* load the bsp */
diff --git a/tools/quake3/q3map2/help.cpp b/tools/quake3/q3map2/help.cpp
index b0f03665..ae3a1079 100644
--- a/tools/quake3/q3map2/help.cpp
+++ b/tools/quake3/q3map2/help.cpp
@@ -160,7 +160,6 @@ void HelpLight()
{
struct HelpOption light[] = {
{"-light [options] ", "Switch that enters this stage"},
- {"-vlight [options] ", "Deprecated alias for `-light -fast` ... filename.map"},
{"-approx ", "Vertex light approximation tolerance (never use in conjunction with deluxemapping)"},
{"-areascale ", "Scaling factor for area lights (surfacelight)"},
{"-border", "Add a red border to lightmaps for debugging"},
diff --git a/tools/quake3/q3map2/light.cpp b/tools/quake3/q3map2/light.cpp
index 37603c74..87110306 100644
--- a/tools/quake3/q3map2/light.cpp
+++ b/tools/quake3/q3map2/light.cpp
@@ -1915,8 +1915,7 @@ void LightWorld( bool fastAllocate ){
main routine for light processing
*/
-int LightMain( int argc, char **argv ){
- int i;
+int LightMain( Args& args ){
float f;
int lightmapMergeSize = 0;
bool lightSamplesInsist = false;
@@ -2016,159 +2015,145 @@ int LightMain( int argc, char **argv ){
Sys_Printf( "--- ProcessCommandLine ---\n" );
/* process commandline arguments */
- for ( i = 1; i < ( argc - 1 ); i++ )
+ const char *fileName = args.takeBack();
+ const auto argsToInject = args.getVector();
{
/* lightsource scaling */
- if ( striEqual( argv[ i ], "-point" ) || striEqual( argv[ i ], "-pointscale" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-point", "-pointscale" ) ) {
+ f = atof( args.takeNext() );
pointScale *= f;
spotScale *= f;
Sys_Printf( "Spherical point (entity) light scaled by %f to %f\n", f, pointScale );
Sys_Printf( "Spot point (entity) light scaled by %f to %f\n", f, spotScale );
- i++;
}
- else if ( striEqual( argv[ i ], "-spherical" ) || striEqual( argv[ i ], "-sphericalscale" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-spherical", "-sphericalscale" ) ) {
+ f = atof( args.takeNext() );
pointScale *= f;
Sys_Printf( "Spherical point (entity) light scaled by %f to %f\n", f, pointScale );
- i++;
}
- else if ( striEqual( argv[ i ], "-spot" ) || striEqual( argv[ i ], "-spotscale" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-spot", "-spotscale" ) ) {
+ f = atof( args.takeNext() );
spotScale *= f;
Sys_Printf( "Spot point (entity) light scaled by %f to %f\n", f, spotScale );
- i++;
}
- else if ( striEqual( argv[ i ], "-area" ) || striEqual( argv[ i ], "-areascale" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-area", "-areascale" ) ) {
+ f = atof( args.takeNext() );
areaScale *= f;
Sys_Printf( "Area (shader) light scaled by %f to %f\n", f, areaScale );
- i++;
}
- else if ( striEqual( argv[ i ], "-sky" ) || striEqual( argv[ i ], "-skyscale" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-sky", "-skyscale" ) ) {
+ f = atof( args.takeNext() );
skyScale *= f;
Sys_Printf( "Sky/sun light scaled by %f to %f\n", f, skyScale );
- i++;
}
- else if ( striEqual( argv[ i ], "-vertexscale" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-vertexscale" ) ) {
+ f = atof( args.takeNext() );
vertexglobalscale *= f;
Sys_Printf( "Vertexlight scaled by %f to %f\n", f, vertexglobalscale );
- i++;
}
- else if ( striEqual( argv[ i ], "-backsplash" ) && i < ( argc - 3 ) ) {
- g_backsplashFractionScale = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-backsplash" ) ) {
+ g_backsplashFractionScale = atof( args.takeNext() );
Sys_Printf( "Area lights backsplash fraction scaled by %f\n", g_backsplashFractionScale );
- f = atof( argv[ i + 2 ] );
+ f = atof( args.takeNext() );
if ( f >= -900.0f ){
g_backsplashDistance = f;
Sys_Printf( "Area lights backsplash distance set globally to %f\n", g_backsplashDistance );
}
- i+=2;
}
- else if ( striEqual( argv[ i ], "-nolm" ) ) {
+ while ( args.takeArg( "-nolm" ) ) {
nolm = true;
Sys_Printf( "No lightmaps yo\n" );
}
- else if ( striEqual( argv[ i ], "-bouncecolorratio" ) ) {
- bounceColorRatio = std::clamp( atof( argv[ i + 1 ] ), 0.0, 1.0 );
+ while ( args.takeArg( "-bouncecolorratio" ) ) {
+ bounceColorRatio = std::clamp( atof( args.takeNext() ), 0.0, 1.0 );
Sys_Printf( "Bounce color ratio set to %f\n", bounceColorRatio );
- i++;
}
- else if ( striEqual( argv[ i ], "-bouncescale" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-bouncescale" ) ) {
+ f = atof( args.takeNext() );
bounceScale *= f;
Sys_Printf( "Bounce (radiosity) light scaled by %f to %f\n", f, bounceScale );
- i++;
}
- else if ( striEqual( argv[ i ], "-scale" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-scale" ) ) {
+ f = atof( args.takeNext() );
pointScale *= f;
spotScale *= f;
areaScale *= f;
skyScale *= f;
bounceScale *= f;
Sys_Printf( "All light scaled by %f\n", f );
- i++;
}
- else if ( striEqual( argv[ i ], "-gridscale" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-gridscale" ) ) {
+ f = atof( args.takeNext() );
Sys_Printf( "Grid lightning scaled by %f\n", f );
gridScale *= f;
- i++;
}
- else if ( striEqual( argv[ i ], "-gridambientscale" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-gridambientscale" ) ) {
+ f = atof( args.takeNext() );
Sys_Printf( "Grid ambient lightning scaled by %f\n", f );
gridAmbientScale *= f;
- i++;
}
- else if ( striEqual( argv[ i ], "-griddirectionality" ) ) {
- gridDirectionality = std::min( 1.0, atof( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-griddirectionality" ) ) {
+ gridDirectionality = std::min( 1.0, atof( args.takeNext() ) );
value_minimize( gridAmbientDirectionality, gridDirectionality );
Sys_Printf( "Grid directionality is %f\n", gridDirectionality );
- i++;
}
- else if ( striEqual( argv[ i ], "-gridambientdirectionality" ) ) {
- gridAmbientDirectionality = std::max( -1.0, atof( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-gridambientdirectionality" ) ) {
+ gridAmbientDirectionality = std::max( -1.0, atof( args.takeNext() ) );
value_maximize( gridDirectionality, gridAmbientDirectionality );
Sys_Printf( "Grid ambient directionality is %f\n", gridAmbientDirectionality );
- i++;
}
- else if ( striEqual( argv[ i ], "-gamma" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-gamma" ) ) {
+ f = atof( args.takeNext() );
lightmapGamma = f;
Sys_Printf( "Lighting gamma set to %f\n", lightmapGamma );
- i++;
}
- else if ( striEqual( argv[ i ], "-sRGBlight" ) ) {
+ while ( args.takeArg( "-sRGBlight" ) ) {
lightmapsRGB = true;
Sys_Printf( "Lighting is in sRGB\n" );
}
- else if ( striEqual( argv[ i ], "-nosRGBlight" ) ) {
+ while ( args.takeArg( "-nosRGBlight" ) ) {
lightmapsRGB = false;
Sys_Printf( "Lighting is linear\n" );
}
- else if ( striEqual( argv[ i ], "-sRGBtex" ) ) {
+ while ( args.takeArg( "-sRGBtex" ) ) {
texturesRGB = true;
Sys_Printf( "Textures are in sRGB\n" );
}
- else if ( striEqual( argv[ i ], "-nosRGBtex" ) ) {
+ while ( args.takeArg( "-nosRGBtex" ) ) {
texturesRGB = false;
Sys_Printf( "Textures are linear\n" );
}
- else if ( striEqual( argv[ i ], "-sRGBcolor" ) ) {
+ while ( args.takeArg( "-sRGBcolor" ) ) {
colorsRGB = true;
Sys_Printf( "Colors are in sRGB\n" );
}
- else if ( striEqual( argv[ i ], "-nosRGBcolor" ) ) {
+ while ( args.takeArg( "-nosRGBcolor" ) ) {
colorsRGB = false;
Sys_Printf( "Colors are linear\n" );
}
- else if ( striEqual( argv[ i ], "-sRGB" ) ) {
+ while ( args.takeArg( "-sRGB" ) ) {
lightmapsRGB = true;
Sys_Printf( "Lighting is in sRGB\n" );
texturesRGB = true;
@@ -2177,7 +2162,7 @@ int LightMain( int argc, char **argv ){
Sys_Printf( "Colors are in sRGB\n" );
}
- else if ( striEqual( argv[ i ], "-nosRGB" ) ) {
+ while ( args.takeArg( "-nosRGB" ) ) {
lightmapsRGB = false;
Sys_Printf( "Lighting is linear\n" );
texturesRGB = false;
@@ -2186,127 +2171,116 @@ int LightMain( int argc, char **argv ){
Sys_Printf( "Colors are linear\n" );
}
- else if ( striEqual( argv[ i ], "-exposure" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-exposure" ) ) {
+ f = atof( args.takeNext() );
lightmapExposure = f;
Sys_Printf( "Lighting exposure set to %f\n", lightmapExposure );
- i++;
}
- else if ( striEqual( argv[ i ], "-compensate" ) ) {
- f = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-compensate" ) ) {
+ f = atof( args.takeNext() );
if ( f <= 0.0f ) {
f = 1.0f;
}
lightmapCompensate = f;
Sys_Printf( "Lighting compensation set to 1/%f\n", lightmapCompensate );
- i++;
}
/* Lightmaps brightness */
- else if( striEqual( argv[ i ], "-brightness" ) ){
- lightmapBrightness = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-brightness" ) ){
+ lightmapBrightness = atof( args.takeNext() );
Sys_Printf( "Scaling lightmaps brightness by %f\n", lightmapBrightness );
- i++;
}
/* Lighting contrast */
- else if( striEqual( argv[ i ], "-contrast" ) ){
- lightmapContrast = std::clamp( atof( argv[ i + 1 ] ), -255.0, 255.0 );
+ while ( args.takeArg( "-contrast" ) ){
+ lightmapContrast = std::clamp( atof( args.takeNext() ), -255.0, 255.0 );
Sys_Printf( "Lighting contrast set to %f\n", lightmapContrast );
- i++;
/* change to factor in range of 0 to 129.5 */
lightmapContrast = ( 259 * ( lightmapContrast + 255 ) ) / ( 255 * ( 259 - lightmapContrast ) );
}
/* Lighting saturation */
- else if( striEqual( argv[ i ], "-saturation" ) ){
- g_lightmapSaturation = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-saturation" ) ){
+ g_lightmapSaturation = atof( args.takeNext() );
Sys_Printf( "Lighting saturation set to %f\n", g_lightmapSaturation );
- i++;
}
/* ydnar switches */
- else if ( striEqual( argv[ i ], "-bounce" ) ) {
- bounce = std::max( 0, atoi( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-bounce" ) ) {
+ bounce = std::max( 0, atoi( args.takeNext() ) );
if ( bounce > 0 ) {
Sys_Printf( "Radiosity enabled with %d bounce(s)\n", bounce );
}
- i++;
}
- else if ( striEqual( argv[ i ], "-supersample" ) || striEqual( argv[ i ], "-super" ) ) {
- superSample = std::max( 1, atoi( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-supersample", "-super" ) ) {
+ superSample = std::max( 1, atoi( args.takeNext() ) );
if ( superSample > 1 ) {
Sys_Printf( "Ordered-grid supersampling enabled with %d sample(s) per lightmap texel\n", ( superSample * superSample ) );
}
- i++;
}
- else if ( striEqual( argv[ i ], "-randomsamples" ) ) {
+ while ( args.takeArg( "-randomsamples" ) ) {
lightRandomSamples = true;
Sys_Printf( "Random sampling enabled\n", lightRandomSamples );
}
- else if ( striEqual( argv[ i ], "-samples" ) ) {
- lightSamplesInsist = ( *argv[i + 1] == '+' );
- lightSamples = std::max( 1, atoi( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-samples" ) ) {
+ const char *arg = args.takeNext();
+ lightSamplesInsist = ( *arg == '+' );
+ lightSamples = std::max( 1, atoi( arg ) );
if ( lightSamples > 1 ) {
Sys_Printf( "Adaptive supersampling enabled with %d sample(s) per lightmap texel\n", lightSamples );
}
- i++;
}
- else if ( striEqual( argv[ i ], "-samplessearchboxsize" ) ) {
- lightSamplesSearchBoxSize = std::clamp( atoi( argv[ i + 1 ] ), 1, 4 ); /* more makes no sense */
+ while ( args.takeArg( "-samplessearchboxsize" ) ) {
+ lightSamplesSearchBoxSize = std::clamp( atoi( args.takeNext() ), 1, 4 ); /* more makes no sense */
if ( lightSamplesSearchBoxSize != 1 )
Sys_Printf( "Adaptive supersampling uses %f times the normal search box size\n", lightSamplesSearchBoxSize );
- i++;
}
- else if ( striEqual( argv[ i ], "-filter" ) ) {
+ while ( args.takeArg( "-filter" ) ) {
filter = true;
Sys_Printf( "Lightmap filtering enabled\n" );
}
- else if ( striEqual( argv[ i ], "-dark" ) ) {
+ while ( args.takeArg( "-dark" ) ) {
dark = true;
Sys_Printf( "Dark lightmap seams enabled\n" );
}
- else if ( striEqual( argv[ i ], "-shadeangle" ) ) {
- shadeAngleDegrees = std::max( 0.0, atof( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-shadeangle" ) ) {
+ shadeAngleDegrees = std::max( 0.0, atof( args.takeNext() ) );
if ( shadeAngleDegrees > 0.0f ) {
shade = true;
Sys_Printf( "Phong shading enabled with a breaking angle of %f degrees\n", shadeAngleDegrees );
}
- i++;
}
- else if ( striEqual( argv[ i ], "-thresh" ) ) {
- subdivideThreshold = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-thresh" ) ) {
+ subdivideThreshold = atof( args.takeNext() );
if ( subdivideThreshold < 0 ) {
subdivideThreshold = DEFAULT_SUBDIVIDE_THRESHOLD;
}
else{
Sys_Printf( "Subdivision threshold set at %.3f\n", subdivideThreshold );
}
- i++;
}
- else if ( striEqual( argv[ i ], "-approx" ) ) {
- approximateTolerance = std::max( 0, atoi( argv[ i + 1 ] ) );
+ while ( args.takeArg( "-approx" ) ) {
+ approximateTolerance = std::max( 0, atoi( args.takeNext() ) );
if ( approximateTolerance > 0 ) {
Sys_Printf( "Approximating lightmaps within a byte tolerance of %d\n", approximateTolerance );
}
- i++;
}
- else if ( striEqual( argv[ i ], "-deluxe" ) || striEqual( argv[ i ], "-deluxemap" ) ) {
+ while ( args.takeArg( "-deluxe", "-deluxemap" ) ) {
deluxemap = true;
Sys_Printf( "Generating deluxemaps for average light direction\n" );
}
- else if ( striEqual( argv[ i ], "-deluxemode" ) ) {
- deluxemode = atoi( argv[ i + 1 ] );
+ while ( args.takeArg( "-deluxemode" ) ) {
+ deluxemode = atoi( args.takeNext() );
if ( deluxemode != 1 ) {
Sys_Printf( "Generating modelspace deluxemaps\n" );
deluxemode = 0;
@@ -2314,27 +2288,24 @@ int LightMain( int argc, char **argv ){
else{
Sys_Printf( "Generating tangentspace deluxemaps\n" );
}
- i++;
}
- else if ( striEqual( argv[ i ], "-nodeluxe" ) || striEqual( argv[ i ], "-nodeluxemap" ) ) {
+ while ( args.takeArg( "-nodeluxe", "-nodeluxemap" ) ) {
deluxemap = false;
Sys_Printf( "Disabling generating of deluxemaps for average light direction\n" );
}
- else if ( striEqual( argv[ i ], "-external" ) ) {
+ while ( args.takeArg( "-external" ) ) {
externalLightmaps = true;
Sys_Printf( "Storing all lightmaps externally\n" );
}
- else if ( striEqual( argv[ i ], "-lightmapsize" )
- || striEqual( argv[ i ], "-extlmhacksize" ) ) {
- const bool extlmhack = striEqual( argv[ i ], "-extlmhacksize" );
+ bool extlmhack = false;
+ while ( args.takeArg( "-lightmapsize" )
+ || ( extlmhack = args.takeArg( "-extlmhacksize" ) ) ) {
- lmCustomSizeW = lmCustomSizeH = atoi( argv[ i + 1 ] );
- if( i + 2 < argc - 1 && argv[ i + 2 ][0] != '-' && 0 != atoi( argv[ i + 2 ] ) ){
- lmCustomSizeH = atoi( argv[ i + 2 ] );
- i++;
+ lmCustomSizeW = lmCustomSizeH = atoi( args.takeNext() );
+ if( args.nextAvailable() && 0 != atoi( args.next() ) ){ // optional second dimension
+ lmCustomSizeH = atoi( args.takeNext() );
}
- i++;
/* must be a power of 2 and greater than 2 */
if ( ( ( lmCustomSizeW - 1 ) & lmCustomSizeW ) || lmCustomSizeW < 2 ||
( ( lmCustomSizeH - 1 ) & lmCustomSizeH ) || lmCustomSizeH < 2 ) {
@@ -2352,107 +2323,102 @@ int LightMain( int argc, char **argv ){
}
}
- else if ( striEqual( argv[ i ], "-rawlightmapsizelimit" ) ) {
- lmLimitSize = atoi( argv[ i + 1 ] );
-
- i++;
+ while ( args.takeArg( "-rawlightmapsizelimit" ) ) {
+ lmLimitSize = atoi( args.takeNext() );
Sys_Printf( "Raw lightmap size limit set to %d x %d pixels\n", lmLimitSize, lmLimitSize );
}
- else if ( striEqual( argv[ i ], "-lightmapdir" ) ) {
- lmCustomDir = argv[i + 1];
- i++;
+ while ( args.takeArg( "-lightmapdir" ) ) {
+ lmCustomDir = args.takeNext();
Sys_Printf( "Lightmap directory set to %s\n", lmCustomDir );
externalLightmaps = true;
Sys_Printf( "Storing all lightmaps externally\n" );
}
/* ydnar: add this to suppress warnings */
- else if ( striEqual( argv[ i ], "-custinfoparms" ) ) {
+ while ( args.takeArg( "-custinfoparms" ) ) {
Sys_Printf( "Custom info parms enabled\n" );
useCustomInfoParms = true;
}
- else if ( striEqual( argv[ i ], "-wolf" ) ) {
+ while ( args.takeArg( "-wolf" ) ) {
/* -game should already be set */
wolfLight = true;
Sys_Printf( "Enabling Wolf lighting model (linear default)\n" );
}
- else if ( striEqual( argv[ i ], "-q3" ) ) {
+ while ( args.takeArg( "-q3" ) ) {
/* -game should already be set */
wolfLight = false;
Sys_Printf( "Enabling Quake 3 lighting model (nonlinear default)\n" );
}
- else if ( striEqual( argv[ i ], "-extradist" ) ) {
- extraDist = std::max( 0.0, atof( argv[ i + 1 ] ) );
- i++;
+ while ( args.takeArg( "-extradist" ) ) {
+ extraDist = std::max( 0.0, atof( args.takeNext() ) );
Sys_Printf( "Default extra radius set to %f units\n", extraDist );
}
- else if ( striEqual( argv[ i ], "-sunonly" ) ) {
+ while ( args.takeArg( "-sunonly" ) ) {
sunOnly = true;
Sys_Printf( "Only computing sunlight\n" );
}
- else if ( striEqual( argv[ i ], "-bounceonly" ) ) {
+ while ( args.takeArg( "-bounceonly" ) ) {
bounceOnly = true;
Sys_Printf( "Storing bounced light (radiosity) only\n" );
}
- else if ( striEqual( argv[ i ], "-nocollapse" ) ) {
+ while ( args.takeArg( "-nocollapse" ) ) {
noCollapse = true;
Sys_Printf( "Identical lightmap collapsing disabled\n" );
}
- else if ( striEqual( argv[ i ], "-nolightmapsearch" ) ) {
+ while ( args.takeArg( "-nolightmapsearch" ) ) {
lightmapSearchBlockSize = 1;
Sys_Printf( "No lightmap searching - all lightmaps will be sequential\n" );
}
- else if ( striEqual( argv[ i ], "-lightmapsearchpower" ) ) {
- lightmapMergeSize = ( g_game->lightmapSize << atoi( argv[i + 1] ) );
- ++i;
- Sys_Printf( "Restricted lightmap searching enabled - optimize for lightmap merge power %d (size %d)\n", atoi( argv[i] ), lightmapMergeSize );
+ while ( args.takeArg( "-lightmapsearchpower" ) ) {
+ const int power = atoi( args.takeNext() );
+ lightmapMergeSize = ( g_game->lightmapSize << power );
+ Sys_Printf( "Restricted lightmap searching enabled - optimize for lightmap merge power %d (size %d)\n", power, lightmapMergeSize );
}
- else if ( striEqual( argv[ i ], "-lightmapsearchblocksize" ) ) {
- lightmapSearchBlockSize = atoi( argv[i + 1] );
- ++i;
+ while ( args.takeArg( "-lightmapsearchblocksize" ) ) {
+ lightmapSearchBlockSize = atoi( args.takeNext() );
Sys_Printf( "Restricted lightmap searching enabled - block size set to %d\n", lightmapSearchBlockSize );
}
- else if ( striEqual( argv[ i ], "-shade" ) ) {
+ while ( args.takeArg( "-shade" ) ) {
shade = true;
Sys_Printf( "Phong shading enabled\n" );
}
- else if ( striEqual( argv[ i ], "-bouncegrid" ) ) {
+ while ( args.takeArg( "-bouncegrid" ) ) {
bouncegrid = true;
if ( bounce > 0 ) {
Sys_Printf( "Grid lighting with radiosity enabled\n" );
}
}
- else if ( striEqual( argv[ i ], "-smooth" ) ) {
+ while ( args.takeArg( "-smooth" ) ) {
lightSamples = EXTRA_SCALE;
Sys_Printf( "The -smooth argument is deprecated, use \"-samples 2\" instead\n" );
}
- else if ( striEqual( argv[ i ], "-nofastpoint" ) ) {
+ while ( args.takeArg( "-nofastpoint" ) ) {
fastpoint = false;
Sys_Printf( "Automatic fast mode for point lights disabled\n" );
}
- else if ( striEqual( argv[ i ], "-fast" ) ) {
+ while ( args.takeArg( "-fast" ) ) {
fast = true;
fastgrid = true;
fastbounce = true;
Sys_Printf( "Fast mode enabled for all area lights\n" );
}
- else if ( striEqual( argv[ i ], "-faster" ) ) {
+ while ( args.takeArg( "-faster" ) ) {
faster = true;
fast = true;
fastgrid = true;
@@ -2460,198 +2426,193 @@ int LightMain( int argc, char **argv ){
Sys_Printf( "Faster mode enabled\n" );
}
-// else if ( striEqual( argv[ i ], "-fastallocate" ) ) {
+// while ( args.takeArg( "-fastallocate" ) ) {
// fastAllocate = true;
// Sys_Printf( "Fast allocation mode enabled\n" );
// }
- else if ( striEqual( argv[ i ], "-slowallocate" ) ) {
+ while ( args.takeArg( "-slowallocate" ) ) {
fastAllocate = false;
Sys_Printf( "Slow allocation mode enabled\n" );
}
- else if ( striEqual( argv[ i ], "-fastgrid" ) ) {
+ while ( args.takeArg( "-fastgrid" ) ) {
fastgrid = true;
Sys_Printf( "Fast grid lighting enabled\n" );
}
- else if ( striEqual( argv[ i ], "-fastbounce" ) ) {
+ while ( args.takeArg( "-fastbounce" ) ) {
fastbounce = true;
Sys_Printf( "Fast bounce mode enabled\n" );
}
- else if ( striEqual( argv[ i ], "-cheap" ) ) {
+ while ( args.takeArg( "-cheap" ) ) {
cheap = true;
cheapgrid = true;
Sys_Printf( "Cheap mode enabled\n" );
}
- else if ( striEqual( argv[ i ], "-cheapgrid" ) ) {
+ while ( args.takeArg( "-cheapgrid" ) ) {
cheapgrid = true;
Sys_Printf( "Cheap grid mode enabled\n" );
}
- else if ( striEqual( argv[ i ], "-normalmap" ) ) {
+ while ( args.takeArg( "-normalmap" ) ) {
normalmap = true;
Sys_Printf( "Storing normal map instead of lightmap\n" );
}
- else if ( striEqual( argv[ i ], "-trisoup" ) ) {
+ while ( args.takeArg( "-trisoup" ) ) {
trisoup = true;
Sys_Printf( "Converting brush faces to triangle soup\n" );
}
- else if ( striEqual( argv[ i ], "-debug" ) ) {
+ while ( args.takeArg( "-debug" ) ) {
debug = true;
Sys_Printf( "Lightmap debugging enabled\n" );
}
- else if ( striEqual( argv[ i ], "-debugsurfaces" ) || striEqual( argv[ i ], "-debugsurface" ) ) {
+ while ( args.takeArg( "-debugsurfaces", "-debugsurface" ) ) {
debugSurfaces = true;
Sys_Printf( "Lightmap surface debugging enabled\n" );
}
- else if ( striEqual( argv[ i ], "-debugaxis" ) ) {
+ while ( args.takeArg( "-debugaxis" ) ) {
debugAxis = true;
Sys_Printf( "Lightmap axis debugging enabled\n" );
}
- else if ( striEqual( argv[ i ], "-debugcluster" ) ) {
+ while ( args.takeArg( "-debugcluster" ) ) {
debugCluster = true;
Sys_Printf( "Luxel cluster debugging enabled\n" );
}
- else if ( striEqual( argv[ i ], "-debugorigin" ) ) {
+ while ( args.takeArg( "-debugorigin" ) ) {
debugOrigin = true;
Sys_Printf( "Luxel origin debugging enabled\n" );
}
- else if ( striEqual( argv[ i ], "-debugdeluxe" ) ) {
+ while ( args.takeArg( "-debugdeluxe" ) ) {
deluxemap = true;
debugDeluxemap = true;
Sys_Printf( "Deluxemap debugging enabled\n" );
}
- else if ( striEqual( argv[ i ], "-export" ) ) {
+ while ( args.takeArg( "-export" ) ) {
exportLightmaps = true;
Sys_Printf( "Exporting lightmaps\n" );
}
- else if ( striEqual( argv[ i ], "-notrace" ) ) {
+ while ( args.takeArg( "-notrace" ) ) {
noTrace = true;
Sys_Printf( "Shadow occlusion disabled\n" );
}
- else if ( striEqual( argv[ i ], "-patchshadows" ) ) {
+ while ( args.takeArg( "-patchshadows" ) ) {
patchShadows = true;
Sys_Printf( "Patch shadow casting enabled\n" );
}
- else if ( striEqual( argv[ i ], "-extra" ) ) {
+ while ( args.takeArg( "-extra" ) ) {
superSample = EXTRA_SCALE; /* ydnar */
Sys_Printf( "The -extra argument is deprecated, use \"-super 2\" instead\n" );
}
- else if ( striEqual( argv[ i ], "-extrawide" ) ) {
+ while ( args.takeArg( "-extrawide" ) ) {
superSample = EXTRAWIDE_SCALE; /* ydnar */
filter = true; /* ydnar */
Sys_Printf( "The -extrawide argument is deprecated, use \"-filter [-super 2]\" instead\n" );
}
- else if ( striEqual( argv[ i ], "-samplesize" ) ) {
- sampleSize = std::max( 1, atoi( argv[ i + 1 ] ) );
- i++;
+ while ( args.takeArg( "-samplesize" ) ) {
+ sampleSize = std::max( 1, atoi( args.takeNext() ) );
Sys_Printf( "Default lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
}
- else if ( striEqual( argv[ i ], "-minsamplesize" ) ) {
- minSampleSize = std::max( 1, atoi( argv[ i + 1 ] ) );
- i++;
+ while ( args.takeArg( "-minsamplesize" ) ) {
+ minSampleSize = std::max( 1, atoi( args.takeNext() ) );
Sys_Printf( "Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize );
}
- else if ( striEqual( argv[ i ], "-samplescale" ) ) {
- sampleScale = atoi( argv[ i + 1 ] );
- i++;
+ while ( args.takeArg( "-samplescale" ) ) {
+ sampleScale = atoi( args.takeNext() );
Sys_Printf( "Lightmaps sample scale set to %d\n", sampleScale );
}
- else if ( striEqual( argv[ i ], "-debugsamplesize" ) ) {
+ while ( args.takeArg( "-debugsamplesize" ) ) {
debugSampleSize = 1;
Sys_Printf( "debugging Lightmaps SampleSize\n" );
}
- else if ( striEqual( argv[ i ], "-novertex" ) ) {
- noVertexLighting = 1;
- f = atof( argv[ i + 1 ] );
- if ( f != 0 && f < 1 ) {
- noVertexLighting = f;
- i++;
+ while ( args.takeArg( "-novertex" ) ) {
+ if ( args.nextAvailable() && atof( args.next() ) != 0 ) { /* optional value to set */
+ noVertexLighting = std::clamp( atof( args.takeNext() ), 0.0, 1.0 );
Sys_Printf( "Setting vertex lighting globally to %f\n", noVertexLighting );
}
else{
+ noVertexLighting = 1;
Sys_Printf( "Disabling vertex lighting\n" );
}
}
- else if ( striEqual( argv[ i ], "-nogrid" ) ) {
+ while ( args.takeArg( "-nogrid" ) ) {
noGridLighting = true;
Sys_Printf( "Disabling grid lighting\n" );
}
- else if ( striEqual( argv[ i ], "-border" ) ) {
+ while ( args.takeArg( "-border" ) ) {
lightmapBorder = true;
Sys_Printf( "Adding debug border to lightmaps\n" );
}
- else if ( striEqual( argv[ i ], "-nosurf" ) ) {
+ while ( args.takeArg( "-nosurf" ) ) {
noSurfaces = true;
Sys_Printf( "Not tracing against surfaces\n" );
}
- else if ( striEqual( argv[ i ], "-dump" ) ) {
+ while ( args.takeArg( "-dump" ) ) {
dump = true;
Sys_Printf( "Dumping radiosity lights into numbered prefabs\n" );
}
- else if ( striEqual( argv[ i ], "-lomem" ) ) {
+ while ( args.takeArg( "-lomem" ) ) {
loMem = true;
Sys_Printf( "Enabling low-memory (potentially slower) lighting mode\n" );
}
- else if ( striEqual( argv[ i ], "-lightanglehl" ) ) {
- if ( ( atoi( argv[ i + 1 ] ) != 0 ) != lightAngleHL ) {
- lightAngleHL = ( atoi( argv[ i + 1 ] ) != 0 );
+ while ( args.takeArg( "-lightanglehl" ) ) {
+ const bool enable = ( atoi( args.takeNext() ) != 0 );
+ if ( enable != lightAngleHL ) {
+ lightAngleHL = enable;
if ( lightAngleHL ) {
Sys_Printf( "Enabling half lambert light angle attenuation\n" );
}
else{
Sys_Printf( "Disabling half lambert light angle attenuation\n" );
}
- i++;
}
}
- else if ( striEqual( argv[ i ], "-nostyle" ) || striEqual( argv[ i ], "-nostyles" ) ) {
+ while ( args.takeArg( "-nostyle", "-nostyles" ) ) {
noStyles = true;
Sys_Printf( "Disabling lightstyles\n" );
}
- else if ( striEqual( argv[ i ], "-style" ) || striEqual( argv[ i ], "-styles" ) ) {
+ while ( args.takeArg( "-style", "-styles" ) ) {
noStyles = false;
Sys_Printf( "Enabling lightstyles\n" );
}
- else if ( striEqual( argv[ i ], "-cpma" ) ) {
+ while ( args.takeArg( "-cpma" ) ) {
cpmaHack = true;
Sys_Printf( "Enabling Challenge Pro Mode Asstacular Vertex Lighting Mode (tm)\n" );
}
- else if ( striEqual( argv[ i ], "-floodlight" ) ) {
+ while ( args.takeArg( "-floodlight" ) ) {
floodlighty = true;
Sys_Printf( "FloodLighting enabled\n" );
}
- else if ( striEqual( argv[ i ], "-debugnormals" ) ) {
+ while ( args.takeArg( "-debugnormals" ) ) {
debugnormals = true;
Sys_Printf( "DebugNormals enabled\n" );
}
- else if ( striEqual( argv[ i ], "-lowquality" ) ) {
+ while ( args.takeArg( "-lowquality" ) ) {
floodlight_lowquality = true;
Sys_Printf( "Low Quality FloodLighting enabled\n" );
}
/* r7: dirtmapping */
- else if ( striEqual( argv[ i ], "-dirty" ) ) {
+ while ( args.takeArg( "-dirty" ) ) {
dirty = true;
Sys_Printf( "Dirtmapping enabled\n" );
}
- else if ( striEqual( argv[ i ], "-dirtdebug" ) || striEqual( argv[ i ], "-debugdirt" ) ) {
+ while ( args.takeArg( "-dirtdebug", "-debugdirt" ) ) {
dirtDebug = true;
Sys_Printf( "Dirtmap debugging enabled\n" );
}
- else if ( striEqual( argv[ i ], "-dirtmode" ) ) {
- dirtMode = atoi( argv[ i + 1 ] );
+ while ( args.takeArg( "-dirtmode" ) ) {
+ dirtMode = atoi( args.takeNext() );
if ( dirtMode != 0 && dirtMode != 1 ) {
dirtMode = 0;
}
@@ -2661,49 +2622,45 @@ int LightMain( int argc, char **argv ){
else{
Sys_Printf( "Enabling ordered dirtmapping\n" );
}
- i++;
}
- else if ( striEqual( argv[ i ], "-dirtdepth" ) ) {
- dirtDepth = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-dirtdepth" ) ) {
+ dirtDepth = atof( args.takeNext() );
if ( dirtDepth <= 0.0f ) {
dirtDepth = 128.0f;
}
Sys_Printf( "Dirtmapping depth set to %.1f\n", dirtDepth );
- i++;
}
- else if ( striEqual( argv[ i ], "-dirtscale" ) ) {
- dirtScale = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-dirtscale" ) ) {
+ dirtScale = atof( args.takeNext() );
if ( dirtScale <= 0.0f ) {
dirtScale = 1.0f;
}
Sys_Printf( "Dirtmapping scale set to %.1f\n", dirtScale );
- i++;
}
- else if ( striEqual( argv[ i ], "-dirtgain" ) ) {
- dirtGain = atof( argv[ i + 1 ] );
+ while ( args.takeArg( "-dirtgain" ) ) {
+ dirtGain = atof( args.takeNext() );
if ( dirtGain <= 0.0f ) {
dirtGain = 1.0f;
}
Sys_Printf( "Dirtmapping gain set to %.1f\n", dirtGain );
- i++;
}
- else if ( striEqual( argv[ i ], "-trianglecheck" ) ) {
+ while ( args.takeArg( "-trianglecheck" ) ) {
lightmapTriangleCheck = true;
}
- else if ( striEqual( argv[ i ], "-extravisnudge" ) ) {
+ while ( args.takeArg( "-extravisnudge" ) ) {
lightmapExtraVisClusterNudge = true;
}
- else if ( striEqual( argv[ i ], "-fill" ) ) {
+ while ( args.takeArg( "-fill" ) ) {
lightmapFill = true;
Sys_Printf( "Filling lightmap colors from surrounding pixels to improve JPEG compression\n" );
}
- else if ( striEqual( argv[ i ], "-fillpink" ) ) {
+ while ( args.takeArg( "-fillpink" ) ) {
lightmapPink = true;
}
/* unhandled args */
- else
+ while( !args.empty() )
{
- Sys_Warning( "Unknown argument \"%s\"\n", argv[ i ] );
+ Sys_Warning( "Unknown argument \"%s\"\n", args.takeFront() );
}
}
@@ -2751,10 +2708,10 @@ int LightMain( int argc, char **argv ){
}
/* clean up map name */
- strcpy( source, ExpandArg( argv[ i ] ) );
+ strcpy( source, ExpandArg( fileName ) );
path_set_extension( source, ".bsp" );
- strcpy( name, ExpandArg( argv[ i ] ) );
+ strcpy( name, ExpandArg( fileName ) );
if ( !striEqual( path_get_filename_base_end( name ), ".reg" ) ) { /* not .reg */
path_set_extension( name, ".map" );
}
@@ -2779,7 +2736,7 @@ int LightMain( int argc, char **argv ){
ParseEntities();
/* inject command line parameters */
- InjectCommandLine( argv, 0, argc - 1 );
+ InjectCommandLine( "-light", argsToInject );
/* load map file */
if ( !entities[ 0 ].boolForKey( "_keepLights" ) ) {
diff --git a/tools/quake3/q3map2/lightmaps_ydnar.cpp b/tools/quake3/q3map2/lightmaps_ydnar.cpp
index b08965de..a80c4dce 100644
--- a/tools/quake3/q3map2/lightmaps_ydnar.cpp
+++ b/tools/quake3/q3map2/lightmaps_ydnar.cpp
@@ -145,15 +145,15 @@ void ExportLightmaps( void ){
exports the lightmaps as a list of numbered tga images
*/
-int ExportLightmapsMain( int argc, char **argv ){
+int ExportLightmapsMain( Args& args ){
/* arg checking */
- if ( argc < 2 ) {
+ if ( args.empty() ) {
Sys_Printf( "Usage: q3map2 -export [-v] \n" );
return 0;
}
/* do some path mangling */
- strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
+ strcpy( source, ExpandArg( args.takeBack() ) );
path_set_extension( source, ".bsp" );
/* load the bsp */
@@ -174,20 +174,20 @@ int ExportLightmapsMain( int argc, char **argv ){
imports the lightmaps from a list of numbered tga images
*/
-int ImportLightmapsMain( int argc, char **argv ){
+int ImportLightmapsMain( Args& args ){
int i, x, y, len, width, height;
char dirname[ 1024 ], filename[ 1024 ];
byte *lightmap, *buffer, *pixels, *in, *out;
/* arg checking */
- if ( argc < 2 ) {
+ if ( args.empty() ) {
Sys_Printf( "Usage: q3map2 -import [-v] \n" );
return 0;
}
/* do some path mangling */
- strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
+ strcpy( source, ExpandArg( args.takeBack() ) );
path_set_extension( source, ".bsp" );
/* load the bsp */
diff --git a/tools/quake3/q3map2/main.cpp b/tools/quake3/q3map2/main.cpp
index 02c7ff4b..c6e972a6 100644
--- a/tools/quake3/q3map2/main.cpp
+++ b/tools/quake3/q3map2/main.cpp
@@ -59,7 +59,7 @@ static void ExitQ3Map( void ){
*/
int main( int argc, char **argv ){
- int i, r;
+ int r;
double start, end;
#ifdef WIN32
@@ -78,70 +78,40 @@ int main( int argc, char **argv ){
/* set exit call */
atexit( ExitQ3Map );
+ Args args( argc, argv );
+
/* read general options first */
- for ( i = 1; i < argc; i++ )
{
/* -help */
- if ( striEqual( argv[ i ], "-h" ) || striEqual( argv[ i ], "--help" )
- || striEqual( argv[ i ], "-help" ) ) {
- HelpMain( ( i + 1 < argc ) ? argv[ i + 1 ] : NULL );
+ if ( args.takeArg( "-h", "--help", "-help" ) ) {
+ HelpMain( args.nextAvailable()? args.takeNext() : nullptr );
return 0;
}
/* -connect */
- if ( striEqual( argv[ i ], "-connect" ) ) {
- if ( ++i >= argc || !argv[ i ] ) {
- Error( "Out of arguments: No address specified after %s", argv[ i - 1 ] );
- }
- argv[ i - 1 ] = NULL;
- Broadcast_Setup( argv[ i ] );
- argv[ i ] = NULL;
+ if ( args.takeArg( "-connect" ) ) {
+ Broadcast_Setup( args.takeNext() );
}
/* verbose */
- else if ( striEqual( argv[ i ], "-v" ) ) {
- if ( !verbose ) {
- verbose = true;
- argv[ i ] = NULL;
- }
+ if ( args.takeArg( "-v" ) ) { // test just once: leave other possible -v for -vis
+ verbose = true;
}
/* force */
- else if ( striEqual( argv[ i ], "-force" ) ) {
+ while ( args.takeArg( "-force" ) ) {
force = true;
- argv[ i ] = NULL;
}
/* patch subdivisions */
- else if ( striEqual( argv[ i ], "-subdivisions" ) ) {
- if ( ++i >= argc || !argv[ i ] ) {
- Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] );
- }
- argv[ i - 1 ] = NULL;
- patchSubdivisions = atoi( argv[ i ] );
- argv[ i ] = NULL;
- if ( patchSubdivisions <= 0 ) {
- patchSubdivisions = 1;
- }
+ while ( args.takeArg( "-subdivisions" ) ) {
+ patchSubdivisions = std::max( atoi( args.takeNext() ), 1 );
}
/* threads */
- else if ( striEqual( argv[ i ], "-threads" ) ) {
- if ( ++i >= argc || !argv[ i ] ) {
- Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] );
- }
- argv[ i - 1 ] = NULL;
- numthreads = atoi( argv[ i ] );
- argv[ i ] = NULL;
+ while ( args.takeArg( "-threads" ) ) {
+ numthreads = atoi( args.takeNext() );
}
-
- else if( striEqual( argv[ i ], "-nocmdline" ) )
- {
- Sys_Printf( "noCmdLine\n" );
- nocmdline = true;
- argv[ i ] = NULL;
- }
-
}
/* init model library */
@@ -151,7 +121,7 @@ int main( int argc, char **argv ){
ThreadSetDefault();
/* generate sinusoid jitter table */
- for ( i = 0; i < MAX_JITTERS; i++ )
+ for ( int i = 0; i < MAX_JITTERS; i++ )
{
jitters[ i ] = sin( i * 139.54152147 );
//% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
@@ -164,12 +134,10 @@ int main( int argc, char **argv ){
Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
Sys_Printf( "NetRadiant - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
Sys_Printf( "%s\n", Q3MAP_MOTD );
- Sys_Printf( "%s\n", argv[0] );
-
- strcpy( g_q3map2path, argv[0] ); // fuer autopk3 functions
+ Sys_Printf( "%s\n", args.getArg0() );
/* ydnar: new path initialization */
- InitPaths( &argc, argv );
+ InitPaths( args );
/* set game options */
if ( !patchSubdivisions ) {
@@ -177,90 +145,83 @@ int main( int argc, char **argv ){
}
/* check if we have enough options left to attempt something */
- if ( argc < 2 ) {
- Error( "Usage: %s [general options] [options] mapfile\n%s -help for help", argv[ 0 ], argv[ 0 ] );
+ if ( args.empty() ) {
+ Error( "Usage: %s [general options] [options] mapfile\n%s -help for help", args.getArg0(), args.getArg0() );
}
/* fixaas */
- if ( striEqual( argv[ 1 ], "-fixaas" ) ) {
- r = FixAAS( argc - 1, argv + 1 );
+ if ( args.takeFront( "-fixaas" ) ) {
+ r = FixAAS( args );
}
/* analyze */
- else if ( striEqual( argv[ 1 ], "-analyze" ) ) {
- r = AnalyzeBSP( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-analyze" ) ) {
+ r = AnalyzeBSP( args );
}
/* info */
- else if ( striEqual( argv[ 1 ], "-info" ) ) {
- r = BSPInfo( argc - 2, argv + 2 );
+ else if ( args.takeFront( "-info" ) ) {
+ r = BSPInfo( args );
}
/* vis */
- else if ( striEqual( argv[ 1 ], "-vis" ) ) {
- r = VisMain( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-vis" ) ) {
+ r = VisMain( args );
}
/* light */
- else if ( striEqual( argv[ 1 ], "-light" ) ) {
- r = LightMain( argc - 1, argv + 1 );
- }
-
- /* vlight */
- else if ( striEqual( argv[ 1 ], "-vlight" ) ) {
- Sys_Warning( "VLight is no longer supported, defaulting to -light -fast instead\n\n" );
- argv[ 1 ] = "-fast"; /* eek a hack */
- r = LightMain( argc, argv );
+ else if ( args.takeFront( "-light" ) ) {
+ r = LightMain( args );
}
/* QBall: export entities */
- else if ( striEqual( argv[ 1 ], "-exportents" ) ) {
- r = ExportEntitiesMain( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-exportents" ) ) {
+ r = ExportEntitiesMain( args );
}
/* ydnar: lightmap export */
- else if ( striEqual( argv[ 1 ], "-export" ) ) {
- r = ExportLightmapsMain( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-export" ) ) {
+ r = ExportLightmapsMain( args );
}
/* ydnar: lightmap import */
- else if ( striEqual( argv[ 1 ], "-import" ) ) {
- r = ImportLightmapsMain( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-import" ) ) {
+ r = ImportLightmapsMain( args );
}
/* ydnar: bsp scaling */
- else if ( striEqual( argv[ 1 ], "-scale" ) ) {
- r = ScaleBSPMain( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-scale" ) ) {
+ r = ScaleBSPMain( args );
}
/* bsp shifting */
- else if ( striEqual( argv[ 1 ], "-shift" ) ) {
- r = ShiftBSPMain( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-shift" ) ) {
+ r = ShiftBSPMain( args );
}
/* autopacking */
- else if ( striEqual( argv[ 1 ], "-pk3" ) ) {
- r = pk3BSPMain( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-pk3" ) ) {
+ r = pk3BSPMain( args );
}
/* repacker */
- else if ( striEqual( argv[ 1 ], "-repack" ) ) {
- r = repackBSPMain( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-repack" ) ) {
+ r = repackBSPMain( args );
}
/* ydnar: bsp conversion */
- else if ( striEqual( argv[ 1 ], "-convert" ) ) {
- r = ConvertBSPMain( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-convert" ) ) {
+ r = ConvertBSPMain( args );
}
/* div0: minimap */
- else if ( striEqual( argv[ 1 ], "-minimap" ) ) {
- r = MiniMapBSPMain( argc - 1, argv + 1 );
+ else if ( args.takeFront( "-minimap" ) ) {
+ r = MiniMapBSPMain( args );
}
/* ydnar: otherwise create a bsp */
else{
- r = BSPMain( argc, argv );
+ r = BSPMain( args );
}
/* emit time */
diff --git a/tools/quake3/q3map2/minimap.cpp b/tools/quake3/q3map2/minimap.cpp
index ddda23e4..c87c34b2 100644
--- a/tools/quake3/q3map2/minimap.cpp
+++ b/tools/quake3/q3map2/minimap.cpp
@@ -449,7 +449,7 @@ void MergeRelativePath( char *out, const char *absolute, const char *relative ){
strcpy( out + ( endpos - absolute + 1 ), relative );
}
-int MiniMapBSPMain( int argc, char **argv ){
+int MiniMapBSPMain( Args& args ){
char minimapFilename[1024];
char basename[1024];
char path[1024];
@@ -460,18 +460,18 @@ int MiniMapBSPMain( int argc, char **argv ){
byte *data4b, *p;
float *q;
int x, y;
- int i;
EMiniMapMode mode;
bool keepaspect;
/* arg checking */
- if ( argc < 2 ) {
+ if ( args.empty() ) {
Sys_Printf( "Usage: q3map2 [-v] -minimap [-size n] [-sharpen f] [-samples n | -random n] [-o filename.tga] [-minmax Xmin Ymin Zmin Xmax Ymax Zmax] \n" );
return 0;
}
/* load the BSP first */
- strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
+ const char *fileName = args.takeBack();
+ strcpy( source, ExpandArg( fileName ) );
path_set_extension( source, ".bsp" );
Sys_Printf( "Loading %s\n", source );
//BeginMapShaderFile( source ); //do not delete q3map2_*.shader on minimap generation
@@ -497,93 +497,82 @@ int MiniMapBSPMain( int argc, char **argv ){
minimap.contrast = 1.0;
/* process arguments */
- for ( i = 1; i < ( argc - 1 ); i++ )
{
- if ( striEqual( argv[ i ], "-size" ) ) {
- minimap.width = minimap.height = atoi( argv[i + 1] );
- i++;
+ while( args.takeArg( "-size" ) ) {
+ minimap.width = minimap.height = atoi( args.takeNext() );
Sys_Printf( "Image size set to %i\n", minimap.width );
}
- else if ( striEqual( argv[ i ], "-sharpen" ) ) {
- minimapSharpen = atof( argv[i + 1] );
- i++;
+ while( args.takeArg( "-sharpen" ) ) {
+ minimapSharpen = atof( args.takeNext() );
Sys_Printf( "Sharpening coefficient set to %f\n", minimapSharpen );
}
- else if ( striEqual( argv[ i ], "-samples" ) ) {
- minimap.samples = atoi( argv[i + 1] );
- i++;
+ while( args.takeArg( "-samples" ) ) {
+ minimap.samples = atoi( args.takeNext() );
Sys_Printf( "Samples set to %i\n", minimap.samples );
free( minimap.sample_offsets );
minimap.sample_offsets = safe_malloc( 2 * sizeof( *minimap.sample_offsets ) * minimap.samples );
MiniMapMakeSampleOffsets();
}
- else if ( striEqual( argv[ i ], "-random" ) ) {
- minimap.samples = atoi( argv[i + 1] );
- i++;
+ while( args.takeArg( "-random" ) ) {
+ minimap.samples = atoi( args.takeNext() );
Sys_Printf( "Random samples set to %i\n", minimap.samples );
free( minimap.sample_offsets );
minimap.sample_offsets = NULL;
}
- else if ( striEqual( argv[ i ], "-border" ) ) {
- border = atof( argv[i + 1] );
- i++;
+ while( args.takeArg( "-border" ) ) {
+ border = atof( args.takeNext() );
Sys_Printf( "Border set to %f\n", border );
}
- else if ( striEqual( argv[ i ], "-keepaspect" ) ) {
+ while( args.takeArg( "-keepaspect" ) ) {
keepaspect = true;
Sys_Printf( "Keeping aspect ratio by letterboxing\n", border );
}
- else if ( striEqual( argv[ i ], "-nokeepaspect" ) ) {
+ while( args.takeArg( "-nokeepaspect" ) ) {
keepaspect = false;
Sys_Printf( "Not keeping aspect ratio\n", border );
}
- else if ( striEqual( argv[ i ], "-o" ) ) {
- strcpy( minimapFilename, argv[i + 1] );
- i++;
+ while( args.takeArg( "-o" ) ) {
+ strcpy( minimapFilename, args.takeNext() );
Sys_Printf( "Output file name set to %s\n", minimapFilename );
}
- else if ( striEqual( argv[ i ], "-minmax" ) && i < ( argc - 7 ) ) {
- mins[0] = atof( argv[i + 1] );
- mins[1] = atof( argv[i + 2] );
- mins[2] = atof( argv[i + 3] );
- maxs[0] = atof( argv[i + 4] );
- maxs[1] = atof( argv[i + 5] );
- maxs[2] = atof( argv[i + 6] );
- i += 6;
+ while( args.takeArg( "-minmax" ) ) {
+ mins[0] = atof( args.takeNext() );
+ mins[1] = atof( args.takeNext() );
+ mins[2] = atof( args.takeNext() );
+ maxs[0] = atof( args.takeNext() );
+ maxs[1] = atof( args.takeNext() );
+ maxs[2] = atof( args.takeNext() );
Sys_Printf( "Map mins/maxs overridden\n" );
}
- else if ( striEqual( argv[ i ], "-gray" ) ) {
+ while( args.takeArg( "-gray" ) ) {
mode = EMiniMapMode::Gray;
Sys_Printf( "Writing as white-on-black image\n" );
}
- else if ( striEqual( argv[ i ], "-black" ) ) {
+ while( args.takeArg( "-black" ) ) {
mode = EMiniMapMode::Black;
Sys_Printf( "Writing as black alpha image\n" );
}
- else if ( striEqual( argv[ i ], "-white" ) ) {
+ while( args.takeArg( "-white" ) ) {
mode = EMiniMapMode::White;
Sys_Printf( "Writing as white alpha image\n" );
}
- else if ( striEqual( argv[ i ], "-boost" ) && i < ( argc - 2 ) ) {
- minimap.boost = atof( argv[i + 1] );
- i++;
+ while( args.takeArg( "-boost" ) ) {
+ minimap.boost = atof( args.takeNext() );
Sys_Printf( "Contrast boost set to %f\n", minimap.boost );
}
- else if ( striEqual( argv[ i ], "-brightness" ) && i < ( argc - 2 ) ) {
- minimap.brightness = atof( argv[i + 1] );
- i++;
+ while( args.takeArg( "-brightness" ) ) {
+ minimap.brightness = atof( args.takeNext() );
Sys_Printf( "Brightness set to %f\n", minimap.brightness );
}
- else if ( striEqual( argv[ i ], "-contrast" ) && i < ( argc - 2 ) ) {
- minimap.contrast = atof( argv[i + 1] );
- i++;
+ while( args.takeArg( "-contrast" ) ) {
+ minimap.contrast = atof( args.takeNext() );
Sys_Printf( "Contrast set to %f\n", minimap.contrast );
}
- else if ( striEqual( argv[ i ], "-autolevel" ) ) {
+ while( args.takeArg( "-autolevel" ) ) {
autolevel = true;
Sys_Printf( "Auto level enabled\n", border );
}
- else if ( striEqual( argv[ i ], "-noautolevel" ) ) {
+ while( args.takeArg( "-noautolevel" ) ) {
autolevel = false;
Sys_Printf( "Auto level disabled\n", border );
}
diff --git a/tools/quake3/q3map2/path_init.cpp b/tools/quake3/q3map2/path_init.cpp
index 3c3b271d..918b671f 100644
--- a/tools/quake3/q3map2/path_init.cpp
+++ b/tools/quake3/q3map2/path_init.cpp
@@ -168,7 +168,7 @@ void LokiInitPaths( const char *argv0, CopiedString& homePath, CopiedString& ins
returns NULL if no match found
*/
-const game_t *GetGame( char *arg ){
+const game_t *GetGame( const char *arg ){
/* dummy check */
if ( strEmptyOrNull( arg ) ) {
return NULL;
@@ -281,7 +281,7 @@ void AddHomeBasePath( std::vector& basePaths, const char *homePath
will remove any arguments it uses
*/
-void InitPaths( int *argc, char **argv ){
+void InitPaths( Args& args ){
std::vector basePaths;
std::vector gamePaths;
std::vector pakPaths;
@@ -290,7 +290,6 @@ void InitPaths( int *argc, char **argv ){
CopiedString installPath;
const char *homeBasePath = nullptr;
- int i, j, k;
const char *baseGame = nullptr;
StringOutputStream stream( 256 );
@@ -299,129 +298,77 @@ void InitPaths( int *argc, char **argv ){
Sys_FPrintf( SYS_VRB, "--- InitPaths ---\n" );
/* get the install path for backup */
- LokiInitPaths( argv[ 0 ], homePath, installPath );
+ LokiInitPaths( args.getArg0(), homePath, installPath );
/* set game to default (q3a) */
g_game = &g_games[ 0 ];
/* parse through the arguments and extract those relevant to paths */
- for ( i = 0; i < *argc; i++ )
{
- /* check for null */
- if ( argv[ i ] == NULL ) {
- continue;
- }
-
/* -game */
- if ( striEqual( argv[ i ], "-game" ) ) {
- if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
- Error( "Out of arguments: No game specified after %s", argv[ i - 1 ] );
- }
- g_game = GetGame( argv[ i ] );
+ while ( args.takeArg( "-game" ) ) {
+ g_game = GetGame( args.takeNext() );
if ( g_game == NULL ) {
g_game = &g_games[ 0 ];
}
- argv[ i - 1 ] = argv[ i ] = NULL;
}
/* -fs_forbiddenpath */
- else if ( striEqual( argv[ i ], "-fs_forbiddenpath" ) ) {
- if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
- Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
- }
- g_strForbiddenDirs.emplace_back( argv[i] );
- argv[ i - 1 ] = argv[ i ] = NULL;
+ while ( args.takeArg( "-fs_forbiddenpath" ) ) {
+ g_strForbiddenDirs.emplace_back( args.takeNext() );
}
/* -fs_basepath */
- else if ( striEqual( argv[ i ], "-fs_basepath" ) ) {
- if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
- Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
- }
- AddBasePath( basePaths, argv[ i ] );
- argv[ i - 1 ] = argv[ i ] = NULL;
+ while ( args.takeArg( "-fs_basepath" ) ) {
+ AddBasePath( basePaths, args.takeNext() );
}
/* -fs_game */
- else if ( striEqual( argv[ i ], "-fs_game" ) ) {
- if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
- Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
- }
- insert_unique( gamePaths, stream( DirectoryCleaned( argv[i] ) ) );
- argv[ i - 1 ] = argv[ i ] = NULL;
+ while ( args.takeArg( "-fs_game" ) ) {
+ insert_unique( gamePaths, stream( DirectoryCleaned( args.takeNext() ) ) );
}
/* -fs_basegame */
- else if ( striEqual( argv[ i ], "-fs_basegame" ) ) {
- if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
- Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
- }
- baseGame = argv[ i ];
- argv[ i - 1 ] = argv[ i ] = NULL;
+ while ( args.takeArg( "-fs_basegame" ) ) {
+ baseGame = args.takeNext();
}
/* -fs_home */
- else if ( striEqual( argv[ i ], "-fs_home" ) ) {
- if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
- Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
- }
- homePath = argv[i];
- argv[ i - 1 ] = argv[ i ] = NULL;
+ while ( args.takeArg( "-fs_home" ) ) {
+ homePath = args.takeNext();
}
/* -fs_homebase */
- else if ( striEqual( argv[ i ], "-fs_homebase" ) ) {
- if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
- Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
- }
- homeBasePath = argv[i];
- argv[ i - 1 ] = argv[ i ] = NULL;
+ while ( args.takeArg( "-fs_homebase" ) ) {
+ homeBasePath = args.takeNext();
}
/* -fs_homepath - sets both of them */
- else if ( striEqual( argv[ i ], "-fs_homepath" ) ) {
- if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
- Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
- }
- homePath = argv[i];
+ while ( args.takeArg( "-fs_homepath" ) ) {
+ homePath = args.takeNext();
homeBasePath = ".";
- argv[ i - 1 ] = argv[ i ] = NULL;
}
/* -fs_pakpath */
- else if ( striEqual( argv[ i ], "-fs_pakpath" ) ) {
- if ( ++i >= *argc || strEmptyOrNull( argv[ i ] ) ) {
- Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
- }
- insert_unique( pakPaths, stream( DirectoryCleaned( argv[i] ) ) );
- argv[ i - 1 ] = argv[ i ] = NULL;
+ while ( args.takeArg( "-fs_pakpath" ) ) {
+ insert_unique( pakPaths, stream( DirectoryCleaned( args.takeNext() ) ) );
}
}
- /* remove processed arguments */
- for ( i = 0, j = 0, k = 0; i < *argc && j < *argc; i++, j++ )
- {
- for ( ; j < *argc && argv[ j ] == NULL; j++ ){
- }
- argv[ i ] = argv[ j ];
- if ( argv[ i ] != NULL ) {
- k++;
- }
- }
- *argc = k;
-
/* add standard game path */
insert_unique( gamePaths, stream( DirectoryCleaned( baseGame == nullptr? g_game->gamePath : baseGame ) ) );
/* if there is no base path set, figure it out */
if ( basePaths.empty() ) {
/* this is another crappy replacement for SetQdirFromPath() */
- for ( i = 0; i < *argc && basePaths.empty(); i++ )
+ auto argv = args.getVector();
+ argv.insert( argv.cbegin(), args.getArg0() );
+ for ( auto&& arg : argv )
{
/* extract the arg */
- stream( DirectoryCleaned( argv[ i ] ) );
- Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", g_game->magic, stream.c_str(), i );
+ stream( DirectoryCleaned( arg ) );
+ Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\"...\n", g_game->magic, stream.c_str() );
/* check for the game's magic word */
char* found = strIstr( stream.c_str(), g_game->magic );
if( found ){
@@ -431,6 +378,8 @@ void InitPaths( int *argc, char **argv ){
strClear( found );
/* add this as a base path */
AddBasePath( basePaths, stream.c_str() );
+ if( !basePaths.empty() )
+ break;
}
}
diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h
index 95cb456d..d97d93b4 100644
--- a/tools/quake3/q3map2/q3map2.h
+++ b/tools/quake3/q3map2/q3map2.h
@@ -1403,6 +1403,81 @@ struct surfaceInfo_t
int firstSurfaceCluster, numSurfaceClusters;
};
+
+class Args
+{
+private:
+ const char *m_arg0;
+ std::vector m_args;
+ std::vector::const_iterator m_next;
+ const char *m_current;
+public:
+ Args( int argc, char **argv ){
+ ENSURE( argc > 0 );
+ m_arg0 = argv[0];
+ m_args = { argv + 1, argv + argc };
+ }
+ const char *getArg0() const {
+ return m_arg0;
+ }
+ std::vector getVector(){
+ return m_args;
+ }
+ template
+ bool takeArg( Args... args ){
+ const std::array array = { args ... };
+ for( auto&& arg : array )
+ for( auto it = m_args.cbegin(); it != m_args.cend(); ++it )
+ if( striEqual( *it, arg ) ){
+ m_current = *it;
+ m_next = m_args.erase( it );
+ return true;
+ }
+ return false;
+ }
+ /* next three are only valid after takeArg() == true */
+ const char *takeNext(){
+ if( m_next == m_args.cend() )
+ Error( "Out of arguments: No parameters specified after %s", m_current );
+ const char *ret = *m_next;
+ m_next = m_args.erase( m_next );
+ return ret;
+ }
+ bool nextAvailable() const {
+ return( m_next != m_args.cend() );
+ }
+ const char *next() const {
+ return *m_next;
+ }
+ /* --- */
+ size_t size() const {
+ return m_args.size();
+ }
+ bool empty() const {
+ return size() == 0;
+ }
+ bool takeFront( const char *arg ){
+ if( !m_args.empty() && striEqual( m_args.front(), arg ) ){
+ m_args.erase( m_args.cbegin() );
+ return true;
+ }
+ return false;
+ }
+ const char *takeFront(){
+ ENSURE( !m_args.empty() );
+ const char *ret = m_args.front();
+ m_args.erase( m_args.cbegin() );
+ return ret;
+ }
+ const char *takeBack(){
+ ENSURE( !m_args.empty() );
+ const char *ret = m_args.back();
+ m_args.pop_back();
+ return ret;
+ }
+};
+
+
/* -------------------------------------------------------------------------------
prototypes
@@ -1418,24 +1493,24 @@ void HelpMain(const char* arg);
void HelpGames();
/* path_init.c */
-const game_t *GetGame( char *arg );
-void InitPaths( int *argc, char **argv );
+const game_t *GetGame( const char *arg );
+void InitPaths( Args& args );
/* bsp.c */
-int BSPMain( int argc, char **argv );
+int BSPMain( Args& args );
/* minimap.c */
-int MiniMapBSPMain( int argc, char **argv );
+int MiniMapBSPMain( Args& args );
/* convert_bsp.c */
-int FixAAS( int argc, char **argv );
-int AnalyzeBSP( int argc, char **argv );
-int BSPInfo( int count, char **fileNames );
-int ScaleBSPMain( int argc, char **argv );
-int ShiftBSPMain( int argc, char **argv );
-int ConvertBSPMain( int argc, char **argv );
+int FixAAS( Args& args );
+int AnalyzeBSP( Args& args );
+int BSPInfo( Args& args );
+int ScaleBSPMain( Args& args );
+int ShiftBSPMain( Args& args );
+int ConvertBSPMain( Args& args );
/* convert_map.c */
int ConvertBSPToMap( char *bspName );
@@ -1652,7 +1727,7 @@ std::array TextureAxisFromPlane( const plane_t& plane );
/* vis.c */
fixedWinding_t *NewFixedWinding( int points );
-int VisMain( int argc, char **argv );
+int VisMain( Args& args );
/* visflow.c */
int CountBits( byte *bits, int numbits );
@@ -1671,7 +1746,7 @@ float PointToPolygonFormFactor( const Vector3& point, cons
int LightContributionToSample( trace_t *trace );
void LightingAtSample( trace_t * trace, byte styles[ MAX_LIGHTMAPS ], Vector3 (&colors)[ MAX_LIGHTMAPS ] );
bool LightContributionToPoint( trace_t *trace );
-int LightMain( int argc, char **argv );
+int LightMain( Args& args );
/* light_trace.c */
@@ -1724,8 +1799,8 @@ void CreateTraceLightsForSurface( int num, trace_t *trace
/* lightmaps_ydnar.c */
void ExportLightmaps( void );
-int ExportLightmapsMain( int argc, char **argv );
-int ImportLightmapsMain( int argc, char **argv );
+int ExportLightmapsMain( Args& args );
+int ImportLightmapsMain( Args& args );
void SetupSurfaceLightmaps( void );
void StitchSurfaceLightmaps( void );
@@ -1734,7 +1809,7 @@ void StoreSurfaceLightmaps( bool fastAllocate );
/* exportents.c */
void ExportEntities( void );
-int ExportEntitiesMain( int argc, char **argv );
+int ExportEntitiesMain( Args& args );
/* image.c */
@@ -1793,7 +1868,7 @@ void PrintEntity( const entity_t *ent );
entity_t *FindTargetEntity( const char *target );
void GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows );
-void InjectCommandLine( char **argv, int beginArgs, int endArgs );
+void InjectCommandLine( const char *stage, const std::vector& args );
@@ -1852,7 +1927,6 @@ Q_EXTERN bool skyFixHack Q_ASSIGN( false ); /* ydnar */
Q_EXTERN bool bspAlternateSplitWeights Q_ASSIGN( false ); /* 27 */
Q_EXTERN bool deepBSP Q_ASSIGN( false ); /* div0 */
Q_EXTERN bool maxAreaFaceSurface Q_ASSIGN( false ); /* divVerent */
-Q_EXTERN bool nocmdline Q_ASSIGN( false );
Q_EXTERN int patchSubdivisions Q_ASSIGN( 8 ); /* ydnar: -patchmeta subdivisions */
@@ -2070,7 +2144,7 @@ Q_EXTERN bool exportLightmaps Q_ASSIGN( false );
Q_EXTERN bool externalLightmaps Q_ASSIGN( false );
Q_EXTERN int lmCustomSizeW Q_ASSIGN( LIGHTMAP_WIDTH );
Q_EXTERN int lmCustomSizeH Q_ASSIGN( LIGHTMAP_WIDTH );
-Q_EXTERN char * lmCustomDir Q_ASSIGN( NULL );
+Q_EXTERN const char * lmCustomDir Q_ASSIGN( NULL );
Q_EXTERN int lmLimitSize Q_ASSIGN( 0 );
Q_EXTERN bool dirty Q_ASSIGN( false );
diff --git a/tools/quake3/q3map2/vis.cpp b/tools/quake3/q3map2/vis.cpp
index 314e8dc2..a5d5c389 100644
--- a/tools/quake3/q3map2/vis.cpp
+++ b/tools/quake3/q3map2/vis.cpp
@@ -1022,75 +1022,74 @@ void LoadPortals( char *name ){
VisMain
===========
*/
-int VisMain( int argc, char **argv ){
+int VisMain( Args& args ){
char portalfile[1024];
- int i;
/* note it */
Sys_Printf( "--- Vis ---\n" );
/* process arguments */
- for ( i = 1 ; i < ( argc - 1 ) ; i++ )
+ if ( args.empty() ) {
+ Error( "usage: vis [-threads #] [-level 0-4] [-fast] [-v] bspfile" );
+ }
+ const char *fileName = args.takeBack();
+ const auto argsToInject = args.getVector();
{
- if ( striEqual( argv[i], "-fast" ) ) {
+ while ( args.takeArg( "-fast" ) ) {
Sys_Printf( "fastvis = true\n" );
fastvis = true;
}
- else if ( striEqual( argv[i], "-merge" ) ) {
+ while ( args.takeArg( "-merge" ) ) {
Sys_Printf( "merge = true\n" );
mergevis = true;
}
- else if ( striEqual( argv[i], "-mergeportals" ) ) {
+ while ( args.takeArg( "-mergeportals" ) ) {
Sys_Printf( "mergeportals = true\n" );
mergevisportals = true;
}
- else if ( striEqual( argv[i], "-nopassage" ) ) {
+ while ( args.takeArg( "-nopassage" ) ) {
Sys_Printf( "nopassage = true\n" );
noPassageVis = true;
}
- else if ( striEqual( argv[i], "-passageOnly" ) ) {
+ while ( args.takeArg( "-passageOnly" ) ) {
Sys_Printf( "passageOnly = true\n" );
passageVisOnly = true;
}
- else if ( striEqual( argv[i], "-nosort" ) ) {
+ while ( args.takeArg( "-nosort" ) ) {
Sys_Printf( "nosort = true\n" );
nosort = true;
}
- else if ( striEqual( argv[i], "-saveprt" ) ) {
+ while ( args.takeArg( "-saveprt" ) ) {
Sys_Printf( "saveprt = true\n" );
saveprt = true;
}
- else if ( striEqual( argv[ i ], "-v" ) ) {
+ while ( args.takeArg( "-v" ) ) {
debugCluster = true;
Sys_Printf( "Extra verbose mode enabled\n" );
}
/* ydnar: -hint to merge all but hint portals */
- else if ( striEqual( argv[ i ], "-hint" ) ) {
+ while ( args.takeArg( "-hint" ) ) {
Sys_Printf( "hint = true\n" );
hint = true;
mergevis = true;
}
- else
+ while( !args.empty() )
{
- Sys_Warning( "Unknown option \"%s\"\n", argv[ i ] );
+ Sys_Warning( "Unknown option \"%s\"\n", args.takeFront() );
}
}
- if ( i != argc - 1 ) {
- Error( "usage: vis [-threads #] [-level 0-4] [-fast] [-v] bspfile" );
- }
-
/* load the bsp */
- strcpy( source, ExpandArg( argv[ i ] ) );
+ strcpy( source, ExpandArg( fileName ) );
path_set_extension( source, ".bsp" );
Sys_Printf( "Loading %s\n", source );
LoadBSPFile( source );
/* load the portal file */
- strcpy( portalfile, ExpandArg( argv[ i ] ) );
+ strcpy( portalfile, ExpandArg( fileName ) );
path_set_extension( portalfile, ".prt" );
Sys_Printf( "Loading %s\n", portalfile );
LoadPortals( portalfile );
@@ -1105,7 +1104,7 @@ int VisMain( int argc, char **argv ){
ParseEntities();
/* inject command line parameters */
- InjectCommandLine( argv, 0, argc - 1 );
+ InjectCommandLine( "-vis", argsToInject );
UnparseEntities();
if ( mergevis ) {