diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp index 334c5c22..f77275e0 100644 --- a/tools/quake3/q3map2/bspfile_abstract.cpp +++ b/tools/quake3/q3map2/bspfile_abstract.cpp @@ -112,7 +112,7 @@ void SetDrawSurfaces( int n ){ void BSPFilesCleanup(){ free( bspDrawVerts ); free( bspDrawSurfaces ); - free( bspLightBytes ); + bspLightBytes.clear(); free( bspGridPoints ); } @@ -502,8 +502,8 @@ void PrintBSPFileSizes( void ){ numBSPDrawIndexes, (int) ( numBSPDrawIndexes * sizeof( *bspDrawIndexes ) ) ); Sys_Printf( "\n" ); - Sys_Printf( "%9d lightmaps %9d\n", - numBSPLightBytes / ( g_game->lightmapSize * g_game->lightmapSize * 3 ), numBSPLightBytes ); + Sys_Printf( "%9zu lightmaps %9zu\n", + bspLightBytes.size() / ( g_game->lightmapSize * g_game->lightmapSize * 3 ), bspLightBytes.size() ); Sys_Printf( "%9d lightgrid %9d *\n", numBSPGridPoints, (int) ( numBSPGridPoints * sizeof( *bspGridPoints ) ) ); Sys_Printf( " visibility %9d\n", diff --git a/tools/quake3/q3map2/bspfile_ibsp.cpp b/tools/quake3/q3map2/bspfile_ibsp.cpp index 40585384..14bc2c7f 100644 --- a/tools/quake3/q3map2/bspfile_ibsp.cpp +++ b/tools/quake3/q3map2/bspfile_ibsp.cpp @@ -422,9 +422,7 @@ void LoadIBSPFile( const char *filename ){ numBSPVisBytes = CopyLump( (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes, 1 ); // TODO fix overflow - numBSPLightBytes = GetLumpElements( (bspHeader_t*) header, LUMP_LIGHTMAPS, 1 ); // TODO change to CopyLump_Allocate - bspLightBytes = safe_malloc( numBSPLightBytes ); - CopyLump( (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes, 1 ); + CopyLump( (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes ); CopyLump( (bspHeader_t*) header, LUMP_ENTITIES, bspEntData ); @@ -524,7 +522,7 @@ void WriteIBSPFile( const char *filename ){ AddDrawVertsLump( file, header ); AddDrawSurfacesLump( file, header ); AddLump( file, (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes, numBSPVisBytes ); - AddLump( file, (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes, numBSPLightBytes ); + AddLump( file, header->lumps[LUMP_LIGHTMAPS], bspLightBytes ); AddLightGridLumps( file, header ); AddLump( file, header->lumps[LUMP_ENTITIES], bspEntData ); AddLump( file, (bspHeader_t*) header, LUMP_FOGS, bspFogs, numBSPFogs * sizeof( bspFog_t ) ); diff --git a/tools/quake3/q3map2/bspfile_rbsp.cpp b/tools/quake3/q3map2/bspfile_rbsp.cpp index c35e69a2..ebe0cf08 100644 --- a/tools/quake3/q3map2/bspfile_rbsp.cpp +++ b/tools/quake3/q3map2/bspfile_rbsp.cpp @@ -256,9 +256,7 @@ void LoadRBSPFile( const char *filename ){ numBSPVisBytes = CopyLump( (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes, 1 ); - numBSPLightBytes = GetLumpElements( (bspHeader_t*) header, LUMP_LIGHTMAPS, 1 ); - bspLightBytes = safe_malloc( numBSPLightBytes ); - CopyLump( (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes, 1 ); + CopyLump( (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes ); CopyLump( (bspHeader_t*) header, LUMP_ENTITIES, bspEntData ); @@ -316,7 +314,7 @@ void WriteRBSPFile( const char *filename ){ AddLump( file, (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts, numBSPDrawVerts * sizeof( bspDrawVerts[ 0 ] ) ); AddLump( file, (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces, numBSPDrawSurfaces * sizeof( bspDrawSurfaces[ 0 ] ) ); AddLump( file, (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes, numBSPVisBytes ); - AddLump( file, (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes, numBSPLightBytes ); + AddLump( file, header->lumps[LUMP_LIGHTMAPS], bspLightBytes ); AddLightGridLumps( file, header ); AddLump( file, header->lumps[LUMP_ENTITIES], bspEntData ); AddLump( file, (bspHeader_t*) header, LUMP_FOGS, bspFogs, numBSPFogs * sizeof( bspFog_t ) ); diff --git a/tools/quake3/q3map2/convert_json.cpp b/tools/quake3/q3map2/convert_json.cpp index 463a7e7d..fe6be506 100644 --- a/tools/quake3/q3map2/convert_json.cpp +++ b/tools/quake3/q3map2/convert_json.cpp @@ -329,7 +329,7 @@ static void write_json( const char *directory ){ } { doc.RemoveAllMembers(); - for_indexed( auto&& index : Span( bspLightBytes, numBSPLightBytes ) ){ + for_indexed( const auto& index : bspLightBytes ){ rapidjson::Value value( rapidjson::kObjectType ); value.AddMember( "Num", index, all ); doc.AddMember( rapidjson::Value( StringOutputStream( 16 )( "LightByte#", i ).c_str(), all ), value, all ); @@ -539,13 +539,10 @@ static void read_json( const char *directory ){ } { const auto doc = load_json( StringOutputStream( 256 )( directory, "LightBytes.json" ) ); - static std::vector items; for( auto&& obj : doc.GetObj() ){ - auto&& item = items.emplace_back(); + auto&& item = bspLightBytes.emplace_back(); item = obj.value["Num"].GetInt(); } - bspLightBytes = items.data(); - numBSPLightBytes = items.size(); } { const auto doc = load_json( StringOutputStream( 256 )( directory, "entities.json" ) ); diff --git a/tools/quake3/q3map2/lightmaps_ydnar.cpp b/tools/quake3/q3map2/lightmaps_ydnar.cpp index 7c4ddeff..9aa4c45d 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.cpp +++ b/tools/quake3/q3map2/lightmaps_ydnar.cpp @@ -120,7 +120,7 @@ void ExportLightmaps( void ){ StripExtension( dirname ); /* sanity check */ - if ( bspLightBytes == NULL ) { + if ( bspLightBytes.empty() ) { Sys_Warning( "No BSP lightmap data\n" ); return; } @@ -129,7 +129,7 @@ void ExportLightmaps( void ){ Q_mkdir( dirname ); /* iterate through the lightmaps */ - for ( i = 0, lightmap = bspLightBytes; lightmap < ( bspLightBytes + numBSPLightBytes ); i++, lightmap += ( g_game->lightmapSize * g_game->lightmapSize * 3 ) ) + for ( i = 0, lightmap = bspLightBytes.data(); lightmap < ( bspLightBytes.data() + bspLightBytes.size() ); i++, lightmap += ( g_game->lightmapSize * g_game->lightmapSize * 3 ) ) { /* write a tga image out */ sprintf( filename, "%s/lightmap_%04d.tga", dirname, i ); @@ -202,7 +202,7 @@ int ImportLightmapsMain( Args& args ){ StripExtension( dirname ); /* sanity check */ - if ( bspLightBytes == NULL ) { + if ( bspLightBytes.empty() ) { Error( "No lightmap data" ); } @@ -210,7 +210,7 @@ int ImportLightmapsMain( Args& args ){ Q_mkdir( dirname ); /* iterate through the lightmaps */ - for ( i = 0, lightmap = bspLightBytes; lightmap < ( bspLightBytes + numBSPLightBytes ); i++, lightmap += ( g_game->lightmapSize * g_game->lightmapSize * 3 ) ) + for ( i = 0, lightmap = bspLightBytes.data(); lightmap < ( bspLightBytes.data() + bspLightBytes.size() ); i++, lightmap += ( g_game->lightmapSize * g_game->lightmapSize * 3 ) ) { /* read a tga image */ sprintf( filename, "%s/lightmap_%04d.tga", dirname, i ); @@ -2967,16 +2967,13 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ timer_start = I_FloatTime(); /* count the bsp lightmaps and allocate space */ - free( bspLightBytes ); const size_t gameLmSize = g_game->lightmapSize * g_game->lightmapSize * sizeof( Vector3b ); if ( numBSPLightmaps == 0 || externalLightmaps ) { - numBSPLightBytes = 0; - bspLightBytes = NULL; + bspLightBytes.clear(); } else { - numBSPLightBytes = numBSPLightmaps * gameLmSize; - bspLightBytes = safe_calloc( numBSPLightBytes ); + bspLightBytes = decltype( bspLightBytes )( numBSPLightmaps * gameLmSize, 0 ); } /* walk the list of output lightmaps */ @@ -3000,12 +2997,12 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ /* is this a valid bsp lightmap? */ if ( olm->lightmapNum >= 0 && !externalLightmaps ) { /* copy lighting data */ - lb = bspLightBytes + ( olm->lightmapNum * gameLmSize ); + lb = bspLightBytes.data() + ( olm->lightmapNum * gameLmSize ); memcpy( lb, olm->bspLightBytes, gameLmSize ); /* copy direction data */ if ( deluxemap ) { - lb = bspLightBytes + ( ( olm->lightmapNum + 1 ) * gameLmSize ); + lb = bspLightBytes.data() + ( ( olm->lightmapNum + 1 ) * gameLmSize ); memcpy( lb, olm->bspDirBytes, gameLmSize ); } } @@ -3345,7 +3342,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ Sys_Printf( "done.\n" ); /* calc num stored */ - numStored = numBSPLightBytes / 3; + numStored = bspLightBytes.size() / 3; efficiency = ( numStored <= 0 ) ? 0 : (float) numUsed / (float) numStored; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 3efa3ceb..1a42df1b 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -2354,8 +2354,7 @@ Q_EXTERN std::vector bspBrushes; Q_EXTERN std::vector bspBrushSides; -Q_EXTERN int numBSPLightBytes Q_ASSIGN( 0 ); -Q_EXTERN byte *bspLightBytes Q_ASSIGN( NULL ); +Q_EXTERN std::vector bspLightBytes; Q_EXTERN int numBSPGridPoints Q_ASSIGN( 0 ); Q_EXTERN bspGridPoint_t *bspGridPoints Q_ASSIGN( NULL );