]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/bspfile_abstract.c
bikeshedding: reduce diff noise with Garux tree
[xonotic/netradiant.git] / tools / quake3 / q3map2 / bspfile_abstract.c
index cea3239af0a3bed3594b530c0a16820eff3a8a27..675aef6d3abd6d971333d720b2aa42a2649c9f64 100644 (file)
@@ -89,9 +89,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 +100,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( bspDrawVert_t ) );
+       bspDrawSurfaces = safe_malloc0_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" );
 }
 
 void SetDrawSurfaces( int n ){
@@ -115,9 +111,7 @@ void SetDrawSurfaces( int n ){
        numBSPDrawSurfaces = n;
        numBSPDrawSurfacesBuffer = numBSPDrawSurfaces;
 
-       bspDrawSurfaces = safe_malloc_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" );
-
-       memset( bspDrawSurfaces, 0, n * sizeof( bspDrawVert_t ) );
+       bspDrawSurfaces = safe_malloc0_info( sizeof( bspDrawSurface_t ) * numBSPDrawSurfacesBuffer, "IncDrawSurfaces" );
 }
 
 void BSPFilesCleanup(){
@@ -268,7 +262,7 @@ int GetLumpElements( bspHeader_t *header, int lump, int size ){
        /* check for odd size */
        if ( header->lumps[ lump ].length % size ) {
                if ( force ) {
-                       Sys_Printf( "WARNING: GetLumpElements: odd lump size (%d) in lump %d\n", header->lumps[ lump ].length, lump );
+                       Sys_FPrintf( SYS_WRN, "WARNING: GetLumpElements: odd lump size (%d) in lump %d\n", header->lumps[ lump ].length, lump );
                        return 0;
                }
                else{
@@ -312,7 +306,7 @@ int CopyLump( bspHeader_t *header, int lump, void *dest, int size ){
        }
        if ( length % size ) {
                if ( force ) {
-                       Sys_Printf( "WARNING: CopyLump: odd lump size (%d) in lump %d\n", length, lump );
+                       Sys_FPrintf( SYS_WRN, "WARNING: CopyLump: odd lump size (%d) in lump %d\n", length, lump );
                        return 0;
                }
                else{
@@ -341,14 +335,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 );
 }
 
 
@@ -497,8 +493,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 ) ) {
@@ -581,6 +576,8 @@ void ParseEntities( void ){
        numBSPEntities = numEntities;
 }
 
+
+
 /*
  * must be called before UnparseEntities
  */
@@ -622,6 +619,8 @@ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){
        SetKeyValue( &entities[0], "_q3map2_version", Q3MAP_VERSION );
 }
 
+
+
 /*
    UnparseEntities()
    generates the dentdata string from all the entities.
@@ -748,6 +747,8 @@ void SetKeyValue( entity_t *ent, const char *key, const char *value ){
        ep->value = copystring( value );
 }
 
+
+
 /*
    KeyExists()
    returns true if entity has this key
@@ -768,6 +769,8 @@ qboolean KeyExists( const entity_t *ent, const char *key ){
        return qfalse;
 }
 
+
+
 /*
    ValueForKey()
    gets the value for an entity key