From 82d038f6d179b3c5ff74d4030ab6886b7977a276 Mon Sep 17 00:00:00 2001 From: Garux Date: Mon, 4 Oct 2021 09:59:17 +0300 Subject: [PATCH] remove global error prone char name[ 1024 ] --- tools/quake3/q3map2/bsp.cpp | 25 +++++++++++++------------ tools/quake3/q3map2/light.cpp | 11 +++++------ tools/quake3/q3map2/map.cpp | 2 +- tools/quake3/q3map2/model.cpp | 10 +++++----- tools/quake3/q3map2/q3map2.h | 3 +-- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/tools/quake3/q3map2/bsp.cpp b/tools/quake3/q3map2/bsp.cpp index 0936a1dd..0395eb02 100644 --- a/tools/quake3/q3map2/bsp.cpp +++ b/tools/quake3/q3map2/bsp.cpp @@ -582,7 +582,7 @@ void ProcessModels( void ){ this is probably broken unless teamed with a radiant version that preserves entity order */ -void OnlyEnts( void ){ +void OnlyEnts( const char *filename ){ /* note it */ Sys_Printf( "--- OnlyEnts ---\n" ); @@ -597,7 +597,7 @@ void OnlyEnts( void ){ entities.clear(); LoadShaderInfo(); - LoadMapFile( name, false, false ); + LoadMapFile( filename, false, false ); SetModelNumbers(); SetLightStyles(); @@ -883,19 +883,20 @@ int BSPMain( Args& args ){ remove( StringOutputStream( 256 )( source, ".lin" ) ); //% remove( StringOutputStream( 256 )( source, ".srf" ) ); /* ydnar */ - /* expand mapname */ - strcpy( name, ExpandArg( fileName ) ); - if ( !path_extension_is( name, "reg" ) ) { /* not .reg */ - /* if we are doing a full map, delete the last saved region map */ + /* if we are doing a full map, delete the last saved region map */ + if ( !path_extension_is( fileName, "reg" ) ) remove( StringOutputStream( 256 )( source, ".reg" ) ); - if ( !onlyents || !path_extension_is( name, "ent" ) ) { - path_set_extension( name, ".map" ); /* .reg and .ent are ok too */ - } - } + + /* expand mapname */ + StringOutputStream mapFileName( 256 ); + if ( path_extension_is( fileName, "reg" ) || ( onlyents && path_extension_is( fileName, "ent" ) ) ) + mapFileName << ExpandArg( fileName ); + else + mapFileName << PathExtensionless( ExpandArg( fileName ) ) << ".map"; /* if onlyents, just grab the entites and resave */ if ( onlyents ) { - OnlyEnts(); + OnlyEnts( mapFileName ); return 0; } @@ -907,7 +908,7 @@ int BSPMain( Args& args ){ LoadMapFile( tempSource, false, g_autocaulk ); } else{ - LoadMapFile( name, false, g_autocaulk ); + LoadMapFile( mapFileName, false, g_autocaulk ); } /* div0: inject command line parameters */ diff --git a/tools/quake3/q3map2/light.cpp b/tools/quake3/q3map2/light.cpp index 004ad443..039a8649 100644 --- a/tools/quake3/q3map2/light.cpp +++ b/tools/quake3/q3map2/light.cpp @@ -2676,11 +2676,6 @@ int LightMain( Args& args ){ strcpy( source, ExpandArg( fileName ) ); path_set_extension( source, ".bsp" ); - strcpy( name, ExpandArg( fileName ) ); - if ( !path_extension_is( name, "reg" ) ) { /* not .reg */ - path_set_extension( name, ".map" ); - } - /* ydnar: set default sample size */ SetDefaultSampleSize( sampleSize ); @@ -2705,7 +2700,11 @@ int LightMain( Args& args ){ /* load map file */ if ( !entities[ 0 ].boolForKey( "_keepLights" ) ) { - LoadMapFile( name, true, false ); + char *mapFileName = ExpandArg( fileName ); + if ( !path_extension_is( fileName, "reg" ) ) /* not .reg */ + path_set_extension( mapFileName, ".map" ); + + LoadMapFile( CopiedString( mapFileName ).c_str(), true, false ); } /* set the entity/model origins and init yDrawVerts */ diff --git a/tools/quake3/q3map2/map.cpp b/tools/quake3/q3map2/map.cpp index 9a04619f..ab644d1c 100644 --- a/tools/quake3/q3map2/map.cpp +++ b/tools/quake3/q3map2/map.cpp @@ -1668,7 +1668,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ loads a map file into a list of entities */ -void LoadMapFile( char *filename, bool onlyLights, bool noCollapseGroups ){ +void LoadMapFile( const char *filename, bool onlyLights, bool noCollapseGroups ){ FILE *file; int oldNumEntities = 0; diff --git a/tools/quake3/q3map2/model.cpp b/tools/quake3/q3map2/model.cpp index 8487d477..15839afa 100644 --- a/tools/quake3/q3map2/model.cpp +++ b/tools/quake3/q3map2/model.cpp @@ -418,7 +418,7 @@ static void make_brush_sides( const Plane3f plane, const Plane3f (&p)[3], const buildBrush.sides[4].planenum = FindFloatPlane( reverse, 0, NULL ); } -static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const mapDrawSurface_t *ds ){ +static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const mapDrawSurface_t *ds, const char *modelName ){ const int spf = ( spawnFlags & ( eClipFlags & ~eClipModel ) ); /* ydnar: giant hack land: generate clipping brushes for model triangles */ @@ -592,7 +592,7 @@ static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const const double lengthsSquared = vector3_length_squared( d1 ) * vector3_length_squared( d2 ); if ( lengthsSquared == 0 || ( vector3_length_squared( normal ) / lengthsSquared ) < 1e-8 ) { Sys_Warning( "triangle (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) of %s was not autoclipped: points on line\n", - points[0][0], points[0][1], points[0][2], points[1][0], points[1][1], points[1][2], points[2][0], points[2][1], points[2][2], name ); + points[0][0], points[0][1], points[0][2], points[1][0], points[1][1], points[1][2], points[2][0], points[2][1], points[2][2], modelName ); continue; } } @@ -935,7 +935,7 @@ static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const else { Sys_Warning( "triangle (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) of %s was not autoclipped\n", - points[0][0], points[0][1], points[0][2], points[1][0], points[1][1], points[1][2], points[2][0], points[2][1], points[2][2], name ); + points[0][0], points[0][1], points[0][2], points[1][0], points[1][1], points[1][2], points[2][0], points[2][1], points[2][2], modelName ); continue; } } @@ -975,7 +975,7 @@ default_CLIPMODEL: } else{ Sys_Warning( "triangle (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) of %s was not autoclipped\n", - points[0][0], points[0][1], points[0][2], points[1][0], points[1][1], points[1][2], points[2][0], points[2][1], points[2][2], name ); + points[0][0], points[0][1], points[0][2], points[1][0], points[1][1], points[1][2], points[2][0], points[2][1], points[2][2], modelName ); } } } @@ -1255,7 +1255,7 @@ void InsertModel( const char *name, int skin, int frame, const Matrix4& transfor /* set cel shader */ ds->celShader = celShader; - ClipModel( spawnFlags, clipDepth, si, ds ); + ClipModel( spawnFlags, clipDepth, si, ds, name ); } } diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index b5cbeaef..0b0ac0b7 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1559,7 +1559,7 @@ void PutMeshOnCurve( mesh_t in ); /* map.c */ -void LoadMapFile( char *filename, bool onlyLights, bool noCollapseGroups ); +void LoadMapFile( const char *filename, bool onlyLights, bool noCollapseGroups ); int FindFloatPlane( const Plane3f& plane, int numPoints, const Vector3 *points ); inline int FindFloatPlane( const Vector3& normal, float dist, int numPoints, const Vector3 *points ){ return FindFloatPlane( Plane3f( normal, dist ), numPoints, points ); @@ -1972,7 +1972,6 @@ inline int blockSize[ 3 ] = { 1024, 1024, 1024 }; /* sh Q_EXTERN CopiedString g_enginePath; -Q_EXTERN char name[ 1024 ]; Q_EXTERN char source[ 1024 ]; Q_EXTERN int sampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_SAMPLE_SIZE ); /* lightmap sample size in units */