From efa324ebe681e62f889635b9a9b66b8d524ff45a Mon Sep 17 00:00:00 2001 From: Garux Date: Mon, 27 Sep 2021 15:12:53 +0300 Subject: [PATCH] remove unused stuff --- tools/quake3/common/bspfile.cpp | 12 +-- tools/quake3/common/cmdlib.cpp | 18 ----- tools/quake3/common/cmdlib.h | 11 --- tools/quake3/common/imagelib.cpp | 4 +- tools/quake3/q3map2/bspfile_abstract.cpp | 95 ----------------------- tools/quake3/q3map2/bspfile_abstract.h | 4 +- tools/quake3/q3map2/bspfile_ibsp.cpp | 98 +++++++++--------------- tools/quake3/q3map2/bspfile_rbsp.cpp | 93 +++++++++------------- tools/quake3/q3map2/lightmaps_ydnar.cpp | 2 +- tools/quake3/q3map2/q3map2.h | 8 -- tools/quake3/q3map2/surface.cpp | 2 +- 11 files changed, 84 insertions(+), 263 deletions(-) diff --git a/tools/quake3/common/bspfile.cpp b/tools/quake3/common/bspfile.cpp index bf36ede7..fe4b08ed 100644 --- a/tools/quake3/common/bspfile.cpp +++ b/tools/quake3/common/bspfile.cpp @@ -95,7 +95,7 @@ void SetLightBytes( int n ){ return; } - lightBytes = safe_calloc_info( numLightBytes, "SetLightBytes" ); + lightBytes = safe_calloc( numLightBytes ); } void SetGridPoints( int n ){ @@ -107,7 +107,7 @@ void SetGridPoints( int n ){ return; } - gridData = safe_calloc_info( numGridPoints * 8, "SetGridPoints" ); + gridData = safe_calloc( numGridPoints * 8 ); } void IncDrawVerts(){ @@ -116,7 +116,7 @@ void IncDrawVerts(){ if ( drawVerts == 0 ) { numDrawVertsBuffer = MAX_MAP_DRAW_VERTS / 37; - drawVerts = safe_malloc_info( sizeof( drawVert_t ) * numDrawVertsBuffer, "IncDrawVerts" ); + drawVerts = safe_malloc( sizeof( drawVert_t ) * numDrawVertsBuffer ); } else if ( numDrawVerts > numDrawVertsBuffer ) { @@ -143,7 +143,7 @@ void SetDrawVerts( int n ){ numDrawVerts = numDrawVertsBuffer = n; - drawVerts = safe_calloc_info( sizeof( drawVert_t ) * numDrawVertsBuffer, "IncDrawVerts" ); + drawVerts = safe_calloc( sizeof( drawVert_t ) * numDrawVertsBuffer ); } void SetDrawSurfacesBuffer(){ @@ -151,7 +151,7 @@ void SetDrawSurfacesBuffer(){ numDrawSurfacesBuffer = MAX_MAP_DRAW_SURFS; - drawSurfaces = safe_calloc_info( sizeof( dsurface_t ) * numDrawSurfacesBuffer, "IncDrawSurfaces" ); + drawSurfaces = safe_calloc( sizeof( dsurface_t ) * numDrawSurfacesBuffer ); } void SetDrawSurfaces( int n ){ @@ -160,7 +160,7 @@ void SetDrawSurfaces( int n ){ numDrawSurfaces = numDrawSurfacesBuffer = n; - drawSurfaces = safe_calloc_info( sizeof( dsurface_t ) * numDrawSurfacesBuffer, "IncDrawSurfaces" ); + drawSurfaces = safe_calloc( sizeof( dsurface_t ) * numDrawSurfacesBuffer ); } void BspFilesCleanup(){ diff --git a/tools/quake3/common/cmdlib.cpp b/tools/quake3/common/cmdlib.cpp index e72272d5..4d2f7e51 100644 --- a/tools/quake3/common/cmdlib.cpp +++ b/tools/quake3/common/cmdlib.cpp @@ -47,7 +47,6 @@ #define BASEDIRNAME "quake" // assumed to have a 2 or 3 following -#ifdef SAFE_MALLOC void_ptr safe_malloc( size_t size ){ void *p = malloc( size ); if ( !p ) { @@ -56,14 +55,6 @@ void_ptr safe_malloc( size_t size ){ return p; } -void_ptr safe_malloc_info( size_t size, const char* info ){ - void *p = malloc( size ); - if ( !p ) { - Error( "%s: safe_malloc failed on allocation of %zu bytes", info, size ); - } - return p; -} - void_ptr safe_calloc( size_t size ){ void *p = calloc( 1, size ); if ( !p ) { @@ -72,15 +63,6 @@ void_ptr safe_calloc( size_t size ){ return p; } -void_ptr safe_calloc_info( size_t size, const char* info ){ - void *p = calloc( 1, size ); - if ( !p ) { - Error( "%s: safe_calloc failed on allocation of %zu bytes", info, size ); - } - return p; -} -#endif - /* =================== diff --git a/tools/quake3/common/cmdlib.h b/tools/quake3/common/cmdlib.h index 64ed3656..d7a24fa3 100644 --- a/tools/quake3/common/cmdlib.h +++ b/tools/quake3/common/cmdlib.h @@ -29,9 +29,6 @@ #include -#define SAFE_MALLOC -#ifdef SAFE_MALLOC - class void_ptr { private: @@ -46,15 +43,7 @@ public: }; void_ptr safe_malloc( size_t size ); -void_ptr safe_malloc_info( size_t size, const char* info ); void_ptr safe_calloc( size_t size ); -void_ptr safe_calloc_info( size_t size, const char* info ); -#else -#define safe_malloc( size ) malloc( size ) -#define safe_malloc_info( size, info ) malloc( size ) -#define safe_calloc( size ) calloc( 1, size ) -#define safe_calloc_info( size, info ) calloc( 1, size ) -#endif /* SAFE_MALLOC */ #define offsetof_array( TYPE, ARRAY_MEMBER, ARRAY_SIZE ) ( offsetof( TYPE, ARRAY_MEMBER[0] ) + sizeof( TYPE::ARRAY_MEMBER[0] ) * ARRAY_SIZE ) diff --git a/tools/quake3/common/imagelib.cpp b/tools/quake3/common/imagelib.cpp index 15339539..792a55b3 100644 --- a/tools/quake3/common/imagelib.cpp +++ b/tools/quake3/common/imagelib.cpp @@ -519,7 +519,7 @@ void LoadPCX( const char *filename, byte **pic, byte **palette, int *width, int return; } - out = safe_malloc_info( ( pcx->ymax + 1 ) * ( pcx->xmax + 1 ), "LoadPCX" ); + out = safe_malloc( ( pcx->ymax + 1 ) * ( pcx->xmax + 1 ) ); *pic = out; pix = out; @@ -1003,7 +1003,7 @@ void LoadTGABuffer( const byte *f, const byte *enddata, byte **pic, int *width, return; } - image_rgba = safe_malloc_info( image_width * image_height * 4, "LoadTGABuffer" ); + image_rgba = safe_malloc( image_width * image_height * 4 ); // If bit 5 of attributes isn't set, the image has been stored from bottom to top if ( ( targa_header.attributes & 0x20 ) == 0 ) { diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp index e2b9f3e6..ccfaa819 100644 --- a/tools/quake3/q3map2/bspfile_abstract.cpp +++ b/tools/quake3/q3map2/bspfile_abstract.cpp @@ -184,101 +184,6 @@ void SwapBSPFile( void ){ } } -/* - GetLumpElements() - gets the number of elements in a bsp lump - */ - -int GetLumpElements( bspHeader_t *header, int lump, int size ){ - /* check for odd size */ - if ( header->lumps[ lump ].length % size ) { - if ( force ) { - Sys_Warning( "GetLumpElements: odd lump size (%d) in lump %d\n", header->lumps[ lump ].length, lump ); - return 0; - } - else{ - Error( "GetLumpElements: odd lump size (%d) in lump %d", header->lumps[ lump ].length, lump ); - } - } - - /* return element count */ - return header->lumps[ lump ].length / size; -} - - - -/* - GetLump() - returns a pointer to the specified lump - */ - -void_ptr GetLump( bspHeader_t *header, int lump ){ - return (void*)( (byte*) header + header->lumps[ lump ].offset ); -} - - - -/* - CopyLump() - copies a bsp file lump into a destination buffer - */ - -int CopyLump( bspHeader_t *header, int lump, void *dest, int size ){ - int length, offset; - - - /* get lump length and offset */ - length = header->lumps[ lump ].length; - offset = header->lumps[ lump ].offset; - - /* handle erroneous cases */ - if ( length == 0 ) { - return 0; - } - if ( length % size ) { - if ( force ) { - Sys_Warning( "CopyLump: odd lump size (%d) in lump %d\n", length, lump ); - return 0; - } - else{ - Error( "CopyLump: odd lump size (%d) in lump %d", length, lump ); - } - } - - /* copy block of memory and return */ - memcpy( dest, (byte*) header + offset, length ); - return length / size; -} - -int CopyLump_Allocate( bspHeader_t *header, int lump, void **dest, int size, int *allocationVariable ){ - /* get lump length and offset */ - *allocationVariable = header->lumps[ lump ].length / size; - *dest = realloc( *dest, size * *allocationVariable ); - return CopyLump( header, lump, *dest, size ); -} - - -/* - AddLump() - adds a lump to an outgoing bsp file - */ - -void AddLump( FILE *file, bspHeader_t *header, int lumpNum, const void *data, int length ){ - bspLump_t *lump; - - /* add lump to bsp file header */ - lump = &header->lumps[ lumpNum ]; - lump->offset = LittleLong( ftell( file ) ); - lump->length = LittleLong( length ); - - /* write lump to file */ - SafeWrite( file, data, length ); - - /* write padding zeros */ - SafeWrite( file, std::array{}.data(), ( ( length + 3 ) & ~3 ) - length ); -} - - /* LoadBSPFile() diff --git a/tools/quake3/q3map2/bspfile_abstract.h b/tools/quake3/q3map2/bspfile_abstract.h index ac78282b..6e0493b4 100644 --- a/tools/quake3/q3map2/bspfile_abstract.h +++ b/tools/quake3/q3map2/bspfile_abstract.h @@ -62,12 +62,14 @@ void CopyLump( bspHeader_t *header, int lump, std::vector& data ){ const int offset = header->lumps[ lump ].offset; /* handle erroneous cases */ - if ( length == 0 ) { + if ( length <= 0 ) { + data.clear(); return; } if ( length % sizeof( SrcT ) ) { if ( force ) { Sys_Warning( "CopyLump: odd lump size (%d) in lump %d\n", length, lump ); + data.clear(); return; } else{ diff --git a/tools/quake3/q3map2/bspfile_ibsp.cpp b/tools/quake3/q3map2/bspfile_ibsp.cpp index c0d23434..c4a65b27 100644 --- a/tools/quake3/q3map2/bspfile_ibsp.cpp +++ b/tools/quake3/q3map2/bspfile_ibsp.cpp @@ -220,10 +220,10 @@ void LoadIBSPFile( const char *filename ){ LoadFile( filename, (void**) &header ); /* swap the header (except the first 4 bytes) */ - SwapBlock( (int*) ( (byte*) header + sizeof( int ) ), sizeof( *header ) - sizeof( int ) ); + SwapBlock( (int*) ( (byte*) header + 4 ), sizeof( *header ) - 4 ); /* make sure it matches the format we're trying to load */ - if ( !force && *( (int*) header->ident ) != *( (const int*) g_game->bspIdent ) ) { + if ( !force && (const int&) header->ident != (const int&) g_game->bspIdent ) { Error( "%s is not a %s file", filename, g_game->bspIdent ); } if ( !force && header->version != g_game->bspVersion ) { @@ -232,37 +232,21 @@ void LoadIBSPFile( const char *filename ){ /* load/convert lumps */ CopyLump( (bspHeader_t*) header, LUMP_SHADERS, bspShaders ); - CopyLump( (bspHeader_t*) header, LUMP_MODELS, bspModels ); - CopyLump( (bspHeader_t*) header, LUMP_PLANES, bspPlanes ); - CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs ); - CopyLump( (bspHeader_t*) header, LUMP_NODES, bspNodes ); - CopyLump( (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces ); - CopyLump( (bspHeader_t*) header, LUMP_LEAFBRUSHES, bspLeafBrushes ); - CopyLump( (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes ); - CopyLump( (bspHeader_t*) header, LUMP_BRUSHSIDES, bspBrushSides ); - CopyLump( (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts ); - CopyLump( (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces ); - CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs ); - CopyLump( (bspHeader_t*) header, LUMP_DRAWINDEXES, bspDrawIndexes ); - CopyLump( (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes ); - CopyLump( (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes ); - CopyLump( (bspHeader_t*) header, LUMP_ENTITIES, bspEntData ); - CopyLump( (bspHeader_t*) header, LUMP_LIGHTGRID, bspGridPoints ); /* advertisements */ @@ -290,10 +274,10 @@ void PartialLoadIBSPFile( const char *filename ){ LoadFile( filename, (void**) &header ); /* swap the header (except the first 4 bytes) */ - SwapBlock( (int*) ( (byte*) header + sizeof( int ) ), sizeof( *header ) - sizeof( int ) ); + SwapBlock( (int*) ( (byte*) header + 4 ), sizeof( *header ) - 4 ); /* make sure it matches the format we're trying to load */ - if ( !force && *( (int*) header->ident ) != *( (const int*) g_game->bspIdent ) ) { + if ( !force && (const int&) header->ident != (const int&) g_game->bspIdent ) { Error( "%s is not a %s file", filename, g_game->bspIdent ); } if ( !force && header->version != g_game->bspVersion ) { @@ -302,11 +286,8 @@ void PartialLoadIBSPFile( const char *filename ){ /* load/convert lumps */ CopyLump( (bspHeader_t*) header, LUMP_SHADERS, bspShaders ); - CopyLump( (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces ); - CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs ); - CopyLump( (bspHeader_t*) header, LUMP_ENTITIES, bspEntData ); /* free the file buffer */ @@ -319,62 +300,55 @@ void PartialLoadIBSPFile( const char *filename ){ */ void WriteIBSPFile( const char *filename ){ - ibspHeader_t outheader, *header; - FILE *file; - time_t t; - char marker[ 1024 ]; - int size; - - - /* set header */ - header = &outheader; - memset( header, 0, sizeof( *header ) ); + ibspHeader_t header{}; //% Swapfile(); /* set up header */ - *( (int*) (bspHeader_t*) header->ident ) = *( (const int*) g_game->bspIdent ); - header->version = LittleLong( g_game->bspVersion ); + (int&) header.ident = (const int&) g_game->bspIdent; + header.version = LittleLong( g_game->bspVersion ); /* write initial header */ - file = SafeOpenWrite( filename ); - SafeWrite( file, (bspHeader_t*) header, sizeof( *header ) ); /* overwritten later */ + FILE *file = SafeOpenWrite( filename ); + SafeWrite( file, &header, sizeof( header ) ); /* overwritten later */ - /* add marker lump */ - time( &t ); - /* asctime adds an implicit trailing \n */ - sprintf( marker, "I LOVE MY Q3MAP2 %s on %s", Q3MAP_VERSION, asctime( localtime( &t ) ) ); - AddLump( file, (bspHeader_t*) header, 0, marker, strlen( marker ) + 1 ); + { /* add marker lump */ + time_t t; + time( &t ); + /* asctime adds an implicit trailing \n */ + const auto marker = StringOutputStream( 256 )( "I LOVE MY Q3MAP2 ", Q3MAP_VERSION, " on ", asctime( localtime( &t ) ) ); + AddLump( file, header.lumps[0], std::vector( marker.begin(), marker.end() + 1 ) ); + } /* add lumps */ - AddLump( file, header->lumps[LUMP_SHADERS], bspShaders ); - AddLump( file, header->lumps[LUMP_PLANES], bspPlanes ); - AddLump( file, header->lumps[LUMP_LEAFS], bspLeafs ); - AddLump( file, header->lumps[LUMP_NODES], bspNodes ); - AddLump( file, header->lumps[LUMP_BRUSHES], bspBrushes ); - AddLump( file, header->lumps[LUMP_BRUSHSIDES], std::vector( bspBrushSides.begin(), bspBrushSides.end() ) ); - AddLump( file, header->lumps[LUMP_LEAFSURFACES], bspLeafSurfaces ); - AddLump( file, header->lumps[LUMP_LEAFBRUSHES], bspLeafBrushes ); - AddLump( file, header->lumps[LUMP_MODELS], bspModels ); - AddLump( file, header->lumps[LUMP_DRAWVERTS], std::vector( bspDrawVerts.begin(), bspDrawVerts.end() ) ); - AddLump( file, header->lumps[LUMP_SURFACES], std::vector( bspDrawSurfaces.begin(), bspDrawSurfaces.end() ) ); - AddLump( file, header->lumps[LUMP_VISIBILITY], bspVisBytes ); - AddLump( file, header->lumps[LUMP_LIGHTMAPS], bspLightBytes ); - AddLump( file, header->lumps[LUMP_LIGHTGRID], std::vector( bspGridPoints.begin(), bspGridPoints.end() ) ); - AddLump( file, header->lumps[LUMP_ENTITIES], bspEntData ); - AddLump( file, header->lumps[LUMP_FOGS], bspFogs ); - AddLump( file, header->lumps[LUMP_DRAWINDEXES], bspDrawIndexes ); + AddLump( file, header.lumps[LUMP_SHADERS], bspShaders ); + AddLump( file, header.lumps[LUMP_PLANES], bspPlanes ); + AddLump( file, header.lumps[LUMP_LEAFS], bspLeafs ); + AddLump( file, header.lumps[LUMP_NODES], bspNodes ); + AddLump( file, header.lumps[LUMP_BRUSHES], bspBrushes ); + AddLump( file, header.lumps[LUMP_BRUSHSIDES], std::vector( bspBrushSides.begin(), bspBrushSides.end() ) ); + AddLump( file, header.lumps[LUMP_LEAFSURFACES], bspLeafSurfaces ); + AddLump( file, header.lumps[LUMP_LEAFBRUSHES], bspLeafBrushes ); + AddLump( file, header.lumps[LUMP_MODELS], bspModels ); + AddLump( file, header.lumps[LUMP_DRAWVERTS], std::vector( bspDrawVerts.begin(), bspDrawVerts.end() ) ); + AddLump( file, header.lumps[LUMP_SURFACES], std::vector( bspDrawSurfaces.begin(), bspDrawSurfaces.end() ) ); + AddLump( file, header.lumps[LUMP_VISIBILITY], bspVisBytes ); + AddLump( file, header.lumps[LUMP_LIGHTMAPS], bspLightBytes ); + AddLump( file, header.lumps[LUMP_LIGHTGRID], std::vector( bspGridPoints.begin(), bspGridPoints.end() ) ); + AddLump( file, header.lumps[LUMP_ENTITIES], bspEntData ); + AddLump( file, header.lumps[LUMP_FOGS], bspFogs ); + AddLump( file, header.lumps[LUMP_DRAWINDEXES], bspDrawIndexes ); /* advertisements */ - AddLump( file, header->lumps[LUMP_ADVERTISEMENTS], bspAds ); + AddLump( file, header.lumps[LUMP_ADVERTISEMENTS], bspAds ); /* emit bsp size */ - size = ftell( file ); + const int size = ftell( file ); Sys_Printf( "Wrote %.1f MB (%d bytes)\n", (float) size / ( 1024 * 1024 ), size ); /* write the completed header */ fseek( file, 0, SEEK_SET ); - SafeWrite( file, header, sizeof( *header ) ); + SafeWrite( file, &header, sizeof( header ) ); /* close the file */ fclose( file ); diff --git a/tools/quake3/q3map2/bspfile_rbsp.cpp b/tools/quake3/q3map2/bspfile_rbsp.cpp index a79748e1..39bf3a8e 100644 --- a/tools/quake3/q3map2/bspfile_rbsp.cpp +++ b/tools/quake3/q3map2/bspfile_rbsp.cpp @@ -95,7 +95,7 @@ static void CopyLightGridLumps( rbspHeader_t *header ){ } -static void AddLightGridLumps( FILE *file, rbspHeader_t *header ){ +static void AddLightGridLumps( FILE *file, rbspHeader_t& header ){ /* allocate temporary buffers */ const size_t maxGridPoints = std::min( bspGridPoints.size(), size_t( MAX_MAP_GRID ) ); std::vector gridPoints; @@ -167,8 +167,8 @@ static void AddLightGridLumps( FILE *file, rbspHeader_t *header ){ a = LittleShort( a ); /* write lumps */ - AddLump( file, header->lumps[LUMP_LIGHTGRID], gridPoints ); - AddLump( file, header->lumps[LUMP_LIGHTARRAY], gridArray ); + AddLump( file, header.lumps[LUMP_LIGHTGRID], gridPoints ); + AddLump( file, header.lumps[LUMP_LIGHTARRAY], gridArray ); } @@ -186,10 +186,10 @@ void LoadRBSPFile( const char *filename ){ LoadFile( filename, (void**) &header ); /* swap the header (except the first 4 bytes) */ - SwapBlock( (int*) ( (byte*) header + sizeof( int ) ), sizeof( *header ) - sizeof( int ) ); + SwapBlock( (int*) ( (byte*) header + 4 ), sizeof( *header ) - 4 ); /* make sure it matches the format we're trying to load */ - if ( !force && *( (int*) header->ident ) != *( (const int*) g_game->bspIdent ) ) { + if ( !force && (const int&) header->ident != (const int&) g_game->bspIdent ) { Error( "%s is not a %s file", filename, g_game->bspIdent ); } if ( !force && header->version != g_game->bspVersion ) { @@ -198,37 +198,21 @@ void LoadRBSPFile( const char *filename ){ /* load/convert lumps */ CopyLump( (bspHeader_t*) header, LUMP_SHADERS, bspShaders ); - CopyLump( (bspHeader_t*) header, LUMP_MODELS, bspModels ); - CopyLump( (bspHeader_t*) header, LUMP_PLANES, bspPlanes ); - CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs ); - CopyLump( (bspHeader_t*) header, LUMP_NODES, bspNodes ); - CopyLump( (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces ); - CopyLump( (bspHeader_t*) header, LUMP_LEAFBRUSHES, bspLeafBrushes ); - CopyLump( (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes ); - CopyLump( (bspHeader_t*) header, LUMP_BRUSHSIDES, bspBrushSides ); - CopyLump( (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts ); - CopyLump( (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces ); - CopyLump( (bspHeader_t*) header, LUMP_FOGS, bspFogs ); - CopyLump( (bspHeader_t*) header, LUMP_DRAWINDEXES, bspDrawIndexes ); - CopyLump( (bspHeader_t*) header, LUMP_VISIBILITY, bspVisBytes ); - CopyLump( (bspHeader_t*) header, LUMP_LIGHTMAPS, bspLightBytes ); - CopyLump( (bspHeader_t*) header, LUMP_ENTITIES, bspEntData ); - CopyLightGridLumps( header ); /* free the file buffer */ @@ -243,59 +227,52 @@ void LoadRBSPFile( const char *filename ){ */ void WriteRBSPFile( const char *filename ){ - rbspHeader_t outheader, *header; - FILE *file; - time_t t; - char marker[ 1024 ]; - int size; - - - /* set header */ - header = &outheader; - memset( header, 0, sizeof( *header ) ); + rbspHeader_t header{}; //% Swapfile(); /* set up header */ - *( (int*) (bspHeader_t*) header->ident ) = *( (const int*) g_game->bspIdent ); - header->version = LittleLong( g_game->bspVersion ); + (int&) header.ident = (const int&) g_game->bspIdent; + header.version = LittleLong( g_game->bspVersion ); /* write initial header */ - file = SafeOpenWrite( filename ); - SafeWrite( file, (bspHeader_t*) header, sizeof( *header ) ); /* overwritten later */ + FILE *file = SafeOpenWrite( filename ); + SafeWrite( file, &header, sizeof( header ) ); /* overwritten later */ - /* add marker lump */ - time( &t ); - /* asctime adds an implicit trailing \n */ - sprintf( marker, "I LOVE MY Q3MAP2 %s on %s", Q3MAP_VERSION, asctime( localtime( &t ) ) ); - AddLump( file, (bspHeader_t*) header, 0, marker, strlen( marker ) + 1 ); + { /* add marker lump */ + time_t t; + time( &t ); + /* asctime adds an implicit trailing \n */ + const auto marker = StringOutputStream( 256 )( "I LOVE MY Q3MAP2 ", Q3MAP_VERSION, " on ", asctime( localtime( &t ) ) ); + AddLump( file, header.lumps[0], std::vector( marker.begin(), marker.end() + 1 ) ); + } /* add lumps */ - AddLump( file, header->lumps[LUMP_SHADERS], bspShaders ); - AddLump( file, header->lumps[LUMP_PLANES], bspPlanes ); - AddLump( file, header->lumps[LUMP_LEAFS], bspLeafs ); - AddLump( file, header->lumps[LUMP_NODES], bspNodes ); - AddLump( file, header->lumps[LUMP_BRUSHES], bspBrushes ); - AddLump( file, header->lumps[LUMP_BRUSHSIDES], bspBrushSides ); - AddLump( file, header->lumps[LUMP_LEAFSURFACES], bspLeafSurfaces ); - AddLump( file, header->lumps[LUMP_LEAFBRUSHES], bspLeafBrushes ); - AddLump( file, header->lumps[LUMP_MODELS], bspModels ); - AddLump( file, header->lumps[LUMP_DRAWVERTS], bspDrawVerts ); - AddLump( file, header->lumps[LUMP_SURFACES], bspDrawSurfaces ); - AddLump( file, header->lumps[LUMP_VISIBILITY], bspVisBytes ); - AddLump( file, header->lumps[LUMP_LIGHTMAPS], bspLightBytes ); + AddLump( file, header.lumps[LUMP_SHADERS], bspShaders ); + AddLump( file, header.lumps[LUMP_PLANES], bspPlanes ); + AddLump( file, header.lumps[LUMP_LEAFS], bspLeafs ); + AddLump( file, header.lumps[LUMP_NODES], bspNodes ); + AddLump( file, header.lumps[LUMP_BRUSHES], bspBrushes ); + AddLump( file, header.lumps[LUMP_BRUSHSIDES], bspBrushSides ); + AddLump( file, header.lumps[LUMP_LEAFSURFACES], bspLeafSurfaces ); + AddLump( file, header.lumps[LUMP_LEAFBRUSHES], bspLeafBrushes ); + AddLump( file, header.lumps[LUMP_MODELS], bspModels ); + AddLump( file, header.lumps[LUMP_DRAWVERTS], bspDrawVerts ); + AddLump( file, header.lumps[LUMP_SURFACES], bspDrawSurfaces ); + AddLump( file, header.lumps[LUMP_VISIBILITY], bspVisBytes ); + AddLump( file, header.lumps[LUMP_LIGHTMAPS], bspLightBytes ); AddLightGridLumps( file, header ); - AddLump( file, header->lumps[LUMP_ENTITIES], bspEntData ); - AddLump( file, header->lumps[LUMP_FOGS], bspFogs ); - AddLump( file, header->lumps[LUMP_DRAWINDEXES], bspDrawIndexes ); + AddLump( file, header.lumps[LUMP_ENTITIES], bspEntData ); + AddLump( file, header.lumps[LUMP_FOGS], bspFogs ); + AddLump( file, header.lumps[LUMP_DRAWINDEXES], bspDrawIndexes ); /* emit bsp size */ - size = ftell( file ); + const int size = ftell( file ); Sys_Printf( "Wrote %.1f MB (%d bytes)\n", (float) size / ( 1024 * 1024 ), size ); /* write the completed header */ fseek( file, 0, SEEK_SET ); - SafeWrite( file, header, sizeof( *header ) ); + SafeWrite( file, &header, sizeof( header ) ); /* close the file */ fclose( file ); diff --git a/tools/quake3/q3map2/lightmaps_ydnar.cpp b/tools/quake3/q3map2/lightmaps_ydnar.cpp index 5260a9c4..d42e5179 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.cpp +++ b/tools/quake3/q3map2/lightmaps_ydnar.cpp @@ -2039,7 +2039,7 @@ static void FindOutLightmaps( rawLightmap_t *lm, bool fastAllocate ){ if ( !ok ) { /* allocate LIGHTMAP_RESERVE_COUNT new output lightmaps */ numOutLightmaps += LIGHTMAP_RESERVE_COUNT; - olm = safe_malloc_info( numOutLightmaps * sizeof( outLightmap_t ), "FindOutLightmaps" ); + olm = safe_malloc( numOutLightmaps * sizeof( outLightmap_t ) ); if ( outLightmaps != NULL && numOutLightmaps > LIGHTMAP_RESERVE_COUNT ) { memcpy( olm, outLightmaps, ( numOutLightmaps - LIGHTMAP_RESERVE_COUNT ) * sizeof( outLightmap_t ) ); diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 76fc7492..8c7b5c7f 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1844,12 +1844,6 @@ shaderInfo_t *ShaderInfoForShaderNull( const char *shader ); /* bspfile_abstract.c */ void SwapBlock( int *block, int size ); -int GetLumpElements( bspHeader_t *header, int lump, int size ); -void_ptr GetLump( bspHeader_t *header, int lump ); -int CopyLump( bspHeader_t *header, int lump, void *dest, int size ); -int CopyLump_Allocate( bspHeader_t *header, int lump, void **dest, int size, int *allocationVariable ); -void AddLump( FILE *file, bspHeader_t *header, int lumpNum, const void *data, int length ); - void LoadBSPFile( const char *filename ); void PartialLoadBSPFile( const char *filename ); void WriteBSPFile( const char *filename ); @@ -2381,8 +2375,6 @@ Q_EXTERN std::vector bspAds; } \ while ( 0 ) -#define AUTOEXPAND_BY_REALLOC_BSP( suffix, def ) AUTOEXPAND_BY_REALLOC( bsp ## suffix, numBSP ## suffix, allocatedBSP ## suffix, def ) - #define AUTOEXPAND_BY_REALLOC_ADD( ptr, used, allocated, add ) \ do \ { \ diff --git a/tools/quake3/q3map2/surface.cpp b/tools/quake3/q3map2/surface.cpp index dc52d516..3a7c25ea 100644 --- a/tools/quake3/q3map2/surface.cpp +++ b/tools/quake3/q3map2/surface.cpp @@ -3310,7 +3310,7 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t& tree ){ Sys_FPrintf( SYS_VRB, "%9d maxarea'd face surfaces\n", numMaxAreaSurfaces ); Sys_FPrintf( SYS_VRB, "%9d surface models generated\n", numSurfaceModels ); Sys_FPrintf( SYS_VRB, "%9d skybox surfaces generated\n", numSkyboxSurfaces ); - for ( std::size_t i = 0; i < ARRAY_SIZE( numSurfacesByType ); i++ ) + for ( std::size_t i = 0; i < std::size( numSurfacesByType ); ++i ) Sys_FPrintf( SYS_VRB, "%9d %s surfaces\n", numSurfacesByType[ i ], surfaceTypeName( static_cast( i ) ) ); Sys_FPrintf( SYS_VRB, "%9d redundant indexes suppressed, saving %d Kbytes\n", numRedundantIndexes, ( numRedundantIndexes * 4 / 1024 ) );