diff --git a/tools/quake3/q3map2/autopk3.cpp b/tools/quake3/q3map2/autopk3.cpp index 36fdd3b6..18bc0fb9 100644 --- a/tools/quake3/q3map2/autopk3.cpp +++ b/tools/quake3/q3map2/autopk3.cpp @@ -986,10 +986,7 @@ int repackBSPMain( Args& args ){ bspShaders.clear(); - free( bspEntData ); - bspEntData = NULL; - bspEntDataSize = 0; - allocatedBSPEntData = 0; + bspEntData.clear(); numBSPFogs = 0; } diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp index 1681c349..13aa1ac3 100644 --- a/tools/quake3/q3map2/bspfile_abstract.cpp +++ b/tools/quake3/q3map2/bspfile_abstract.cpp @@ -474,8 +474,8 @@ void PrintBSPFileSizes( void ){ numBSPFogs, (int) ( numBSPFogs * sizeof( bspFog_t ) ) ); Sys_Printf( "%9d planes %9d\n", numBSPPlanes, (int) ( numBSPPlanes * sizeof( bspPlane_t ) ) ); - Sys_Printf( "%9zu entdata %9d\n", - entities.size(), bspEntDataSize ); + Sys_Printf( "%9zu entdata %9zu\n", + entities.size(), bspEntData.size() ); Sys_Printf( "\n" ); Sys_Printf( "%9d nodes %9d\n", @@ -597,7 +597,7 @@ bool ParseEntity( void ){ void ParseEntities( void ){ entities.clear(); - ParseFromMemory( bspEntData, bspEntDataSize ); + ParseFromMemory( bspEntData.data(), bspEntData.size() ); while ( ParseEntity() ) ; /* ydnar: set number of bsp entities in case a map is loaded on top */ @@ -666,9 +666,7 @@ void UnparseEntities( void ){ } /* save out */ - bspEntDataSize = data.end() - data.begin() + 1; - AUTOEXPAND_BY_REALLOC( bspEntData, bspEntDataSize, allocatedBSPEntData, 1024 ); - strcpy( bspEntData, data ); + bspEntData = { data.begin(), data.end() + 1 }; // include '\0' } diff --git a/tools/quake3/q3map2/bspfile_ibsp.cpp b/tools/quake3/q3map2/bspfile_ibsp.cpp index 65b13a9c..01fcd12f 100644 --- a/tools/quake3/q3map2/bspfile_ibsp.cpp +++ b/tools/quake3/q3map2/bspfile_ibsp.cpp @@ -465,7 +465,7 @@ void LoadIBSPFile( const char *filename ){ bspLightBytes = safe_malloc( numBSPLightBytes ); CopyLump( (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes, 1 ); - bspEntDataSize = CopyLump_Allocate( (bspHeader_t*) header, LUMP_ENTITIES, (void **) &bspEntData, 1, &allocatedBSPEntData ); + CopyLump( (bspHeader_t*) header, LUMP_ENTITIES, bspEntData ); CopyLightGridLumps( header ); @@ -511,7 +511,7 @@ void PartialLoadIBSPFile( const char *filename ){ numBSPFogs = CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs, sizeof( bspFog_t ) ); // TODO fix overflow - bspEntDataSize = CopyLump_Allocate( (bspHeader_t*) header, LUMP_ENTITIES, (void **) &bspEntData, 1, &allocatedBSPEntData ); + CopyLump( (bspHeader_t*) header, LUMP_ENTITIES, bspEntData ); /* free the file buffer */ free( header ); @@ -565,7 +565,7 @@ void WriteIBSPFile( const char *filename ){ AddLump( file, (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes, numBSPVisBytes ); AddLump( file, (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes, numBSPLightBytes ); AddLightGridLumps( file, header ); - AddLump( file, (bspHeader_t*) header, LUMP_ENTITIES, bspEntData, bspEntDataSize ); + AddLump( file, header->lumps[LUMP_ENTITIES], bspEntData ); AddLump( file, (bspHeader_t*) header, LUMP_FOGS, bspFogs, numBSPFogs * sizeof( bspFog_t ) ); AddLump( file, (bspHeader_t*) header, LUMP_DRAWINDEXES, bspDrawIndexes, numBSPDrawIndexes * sizeof( bspDrawIndexes[ 0 ] ) ); diff --git a/tools/quake3/q3map2/bspfile_rbsp.cpp b/tools/quake3/q3map2/bspfile_rbsp.cpp index 7c275f3e..59fde573 100644 --- a/tools/quake3/q3map2/bspfile_rbsp.cpp +++ b/tools/quake3/q3map2/bspfile_rbsp.cpp @@ -260,7 +260,7 @@ void LoadRBSPFile( const char *filename ){ bspLightBytes = safe_malloc( numBSPLightBytes ); CopyLump( (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes, 1 ); - bspEntDataSize = CopyLump_Allocate( (bspHeader_t*) header, LUMP_ENTITIES, (void **) &bspEntData, 1, &allocatedBSPEntData ); + CopyLump( (bspHeader_t*) header, LUMP_ENTITIES, bspEntData ); CopyLightGridLumps( header ); @@ -318,7 +318,7 @@ void WriteRBSPFile( const char *filename ){ AddLump( file, (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes, numBSPVisBytes ); AddLump( file, (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes, numBSPLightBytes ); AddLightGridLumps( file, header ); - AddLump( file, (bspHeader_t*) header, LUMP_ENTITIES, bspEntData, bspEntDataSize ); + AddLump( file, header->lumps[LUMP_ENTITIES], bspEntData ); AddLump( file, (bspHeader_t*) header, LUMP_FOGS, bspFogs, numBSPFogs * sizeof( bspFog_t ) ); AddLump( file, (bspHeader_t*) header, LUMP_DRAWINDEXES, bspDrawIndexes, numBSPDrawIndexes * sizeof( bspDrawIndexes[ 0 ] ) ); diff --git a/tools/quake3/q3map2/exportents.cpp b/tools/quake3/q3map2/exportents.cpp index c1308abc..1cd1259e 100644 --- a/tools/quake3/q3map2/exportents.cpp +++ b/tools/quake3/q3map2/exportents.cpp @@ -50,7 +50,7 @@ void ExportEntities( void ){ Sys_FPrintf( SYS_VRB, "--- ExportEntities ---\n" ); /* sanity check */ - if ( bspEntData == NULL || bspEntDataSize == 0 ) { + if ( bspEntData.empty() ) { Sys_Warning( "No BSP entity data. aborting...\n" ); return; } @@ -58,10 +58,10 @@ void ExportEntities( void ){ /* write it */ auto filename = StringOutputStream( 256 )( PathExtensionless( source ), ".ent" ); Sys_Printf( "Writing %s\n", filename.c_str() ); - Sys_FPrintf( SYS_VRB, "(%d bytes)\n", bspEntDataSize ); + Sys_FPrintf( SYS_VRB, "(%zu bytes)\n", bspEntData.size() ); FILE *file = SafeOpenWrite( filename, "wt" ); - fprintf( file, "%s\n", bspEntData ); + fprintf( file, "%s\n", bspEntData.data() ); fclose( file ); } diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 68720faa..e1420a1c 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -2338,9 +2338,7 @@ Q_EXTERN std::vector bspModels; Q_EXTERN std::vector bspShaders; -Q_EXTERN int bspEntDataSize Q_ASSIGN( 0 ); -Q_EXTERN int allocatedBSPEntData Q_ASSIGN( 0 ); -Q_EXTERN char *bspEntData Q_ASSIGN( 0 ); +Q_EXTERN std::vector bspEntData; Q_EXTERN int numBSPLeafs Q_ASSIGN( 0 ); Q_EXTERN bspLeaf_t bspLeafs[ MAX_MAP_LEAFS ];