From 3aca84b7e55ab6d79b30bb6b2ad5d97cfd8fde30 Mon Sep 17 00:00:00 2001 From: divverent Date: Sun, 8 Feb 2009 19:35:57 +0000 Subject: [PATCH] q3map2: inject the invocation commandline into keys of the worldspawn entity (to allow easier recompiling of the map) git-svn-id: svn://svn.icculus.org/netradiant/trunk@181 61c419a2-8eb2-4b30-bcec-8cead039b335 --- tools/quake3/q3map2/bsp.c | 5 +++- tools/quake3/q3map2/bspfile_abstract.c | 37 ++++++++++++++++++++++++++ tools/quake3/q3map2/light.c | 4 +++ tools/quake3/q3map2/main.c | 3 +++ tools/quake3/q3map2/q3map2.h | 2 ++ tools/quake3/q3map2/vis.c | 4 +++ 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/tools/quake3/q3map2/bsp.c b/tools/quake3/q3map2/bsp.c index 2b29ff5e..9b695d02 100644 --- a/tools/quake3/q3map2/bsp.c +++ b/tools/quake3/q3map2/bsp.c @@ -613,7 +613,7 @@ this is probably broken unless teamed with a radiant version that preserves enti void OnlyEnts( void ) { char out[ 1024 ]; - + // TODO save and restore _q3map2_cmdline when doing this /* note it */ Sys_Printf( "--- OnlyEnts ---\n" ); @@ -913,6 +913,9 @@ int BSPMain( int argc, char **argv ) else LoadMapFile( name, qfalse ); + /* div0: inject command line parameters */ + InjectCommandLine(argv, 1, argc - 1); + /* ydnar: decal setup */ ProcessDecals(); diff --git a/tools/quake3/q3map2/bspfile_abstract.c b/tools/quake3/q3map2/bspfile_abstract.c index 5b515fc8..e2904186 100644 --- a/tools/quake3/q3map2/bspfile_abstract.c +++ b/tools/quake3/q3map2/bspfile_abstract.c @@ -578,7 +578,44 @@ void ParseEntities( void ) numBSPEntities = numEntities; } +/* + * must be called before UnparseEntities + */ +void InjectCommandLine(char **argv, int beginArgs, int endArgs) +{ + const char *previousCommandLine; + char newCommandLine[1024]; + const char *inpos; + char *outpos = newCommandLine; + char *sentinel = newCommandLine + sizeof(newCommandLine) - 1; + int i; + + previousCommandLine = ValueForKey(&entities[0], "_q3map2_cmdline"); + if(previousCommandLine && *previousCommandLine) + { + inpos = previousCommandLine; + while(outpos != sentinel && *inpos) + *outpos++ = *inpos++; + if(outpos != sentinel) + *outpos++ = ';'; + if(outpos != sentinel) + *outpos++ = ' '; + } + 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; + SetKeyValue(&entities[0], "_q3map2_cmdline", newCommandLine); + SetKeyValue(&entities[0], "_q3map2_version", Q3MAP_VERSION); +} /* UnparseEntities() diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 8fbfd1e1..49aaebfe 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -1750,6 +1750,7 @@ void LightWorld( void ) { /* store off the bsp between bounces */ StoreSurfaceLightmaps(); + UnparseEntities(); Sys_Printf( "Writing %s\n", source ); WriteBSPFile( source ); @@ -2368,6 +2369,9 @@ int LightMain( int argc, char **argv ) /* parse bsp entities */ ParseEntities(); + + /* inject command line parameters */ + InjectCommandLine(argv, 0, argc - 1); /* load map file */ value = ValueForKey( &entities[ 0 ], "_keepLights" ); diff --git a/tools/quake3/q3map2/main.c b/tools/quake3/q3map2/main.c index 9e4f3659..44b0c821 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -473,6 +473,9 @@ int ScaleBSPMain( int argc, char **argv ) VectorScale( vec, scale, vec ); sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); SetKeyValue( &entities[ 0 ], "gridsize", str ); + + /* inject command line parameters */ + InjectCommandLine(argv, 0, argc - 1); /* write the bsp */ UnparseEntities(); diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 2fe5f7b8..8c972554 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1811,6 +1811,8 @@ vec_t FloatForKey( const entity_t *ent, const char *key ); void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec ); 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); + /* bspfile_ibsp.c */ diff --git a/tools/quake3/q3map2/vis.c b/tools/quake3/q3map2/vis.c index dc764ba8..566706a9 100644 --- a/tools/quake3/q3map2/vis.c +++ b/tools/quake3/q3map2/vis.c @@ -1107,6 +1107,10 @@ int VisMain (int argc, char **argv) /* ydnar: for getting far plane */ ParseEntities(); + /* inject command line parameters */ + InjectCommandLine(argv, 0, argc - 1); + UnparseEntities(); + if( mergevis ) { MergeLeaves(); -- 2.39.2