X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=tools%2Fquake3%2Fq3map2%2Fbspfile_abstract.c;h=55d358f0e69b65c9d5aa859bcb5036f12beb3d98;hb=76eb10a91476f04881e45560977a403cce8efcd6;hp=62c2b679bce4610e220acda29993e263dbeb10c8;hpb=19992696033a496e5c0925e950a29dc23de49b47;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/q3map2/bspfile_abstract.c b/tools/quake3/q3map2/bspfile_abstract.c index 62c2b679..55d358f0 100644 --- a/tools/quake3/q3map2/bspfile_abstract.c +++ b/tools/quake3/q3map2/bspfile_abstract.c @@ -68,14 +68,19 @@ void IncDrawVerts(){ } else if ( numBSPDrawVerts > numBSPDrawVertsBuffer ) { + bspDrawVert_t *newBspDrawVerts; + numBSPDrawVertsBuffer *= 3; // multiply by 1.5 numBSPDrawVertsBuffer /= 2; - bspDrawVerts = realloc( bspDrawVerts, sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer ); + newBspDrawVerts = realloc( bspDrawVerts, sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer ); - if ( !bspDrawVerts ) { + if ( !newBspDrawVerts ) { + free (bspDrawVerts); Error( "realloc() failed (IncDrawVerts)" ); } + + bspDrawVerts = newBspDrawVerts; } memset( bspDrawVerts + ( numBSPDrawVerts - 1 ), 0, sizeof( bspDrawVert_t ) ); @@ -89,9 +94,7 @@ void SetDrawVerts( int n ){ numBSPDrawVerts = n; numBSPDrawVertsBuffer = numBSPDrawVerts; - bspDrawVerts = safe_malloc_info( sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer, "IncDrawVerts" ); - - memset( bspDrawVerts, 0, n * sizeof( bspDrawVert_t ) ); + bspDrawVerts = safe_malloc0_info( sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer, "IncDrawVerts" ); } int numBSPDrawSurfacesBuffer = 0; @@ -102,9 +105,7 @@ void SetDrawSurfacesBuffer(){ numBSPDrawSurfacesBuffer = MAX_MAP_DRAW_SURFS; - bspDrawSurfaces = safe_malloc_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" ); - - memset( bspDrawSurfaces, 0, MAX_MAP_DRAW_SURFS * sizeof( bspDrawSurface_t ) ); + bspDrawSurfaces = safe_malloc0_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" ); } void SetDrawSurfaces( int n ){ @@ -115,9 +116,7 @@ void SetDrawSurfaces( int n ){ numBSPDrawSurfaces = n; numBSPDrawSurfacesBuffer = numBSPDrawSurfaces; - bspDrawSurfaces = safe_malloc_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" ); - - memset( bspDrawSurfaces, 0, n * sizeof( bspDrawSurface_t ) ); + bspDrawSurfaces = safe_malloc0_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" ); } void BSPFilesCleanup(){ @@ -263,8 +262,6 @@ void SwapBSPFile( void ){ } } - - /* GetLumpElements() gets the number of elements in a bsp lump @@ -347,14 +344,16 @@ int CopyLump_Allocate( bspHeader_t *header, int lump, void **dest, int size, int 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 + 3 ) & ~3 ); + SafeWrite( file, data, length ); + + /* write padding zeros */ + SafeWrite( file, (const byte[3]){ 0, 0, 0 }, ( ( length + 3 ) & ~3 ) - length ); } @@ -375,7 +374,37 @@ void LoadBSPFile( const char *filename ){ SwapBSPFile(); } +/* + PartialLoadBSPFile() + partially loads a bsp file into memory + for autopacker + */ + +void PartialLoadBSPFile( const char *filename ){ + /* dummy check */ + if ( game == NULL || game->load == NULL ) { + Error( "LoadBSPFile: unsupported BSP file format" ); + } + + /* load it, then byte swap the in-memory version */ + //game->load( filename ); + PartialLoadIBSPFile( filename ); + /* PartialSwapBSPFile() */ + int i, j; + shaderInfo_t *si; + + /* shaders (don't swap the name) */ + for ( i = 0; i < numBSPShaders ; i++ ) + { + bspShaders[ i ].contentFlags = LittleLong( bspShaders[ i ].contentFlags ); + bspShaders[ i ].surfaceFlags = LittleLong( bspShaders[ i ].surfaceFlags ); + } + + /* drawsurfs */ + /* note: rbsp files (and hence q3map2 abstract bsp) have byte lightstyles index arrays, this follows sof2map convention */ + SwapBlock( (int*) bspDrawSurfaces, numBSPDrawSurfaces * sizeof( bspDrawSurfaces[ 0 ] ) ); +} /* WriteBSPFile() @@ -503,8 +532,7 @@ epair_t *ParseEPair( void ){ /* allocate and clear new epair */ - e = safe_malloc( sizeof( epair_t ) ); - memset( e, 0, sizeof( epair_t ) ); + e = safe_malloc0( sizeof( epair_t ) ); /* handle key */ if ( strlen( token ) >= ( MAX_KEY - 1 ) ) { @@ -619,6 +647,9 @@ if (nocmdline) for ( i = beginArgs; i < endArgs; ++i ) { + if ( argv[i] == NULL ) { + continue; + } if ( outpos != sentinel && i != beginArgs ) { *outpos++ = ' '; }