diff --git a/tools/quake3/q3map2/light_ydnar.cpp b/tools/quake3/q3map2/light_ydnar.cpp index 7a98b697..14b8fe34 100644 --- a/tools/quake3/q3map2/light_ydnar.cpp +++ b/tools/quake3/q3map2/light_ydnar.cpp @@ -159,19 +159,15 @@ Vector3b ColorToBytes( const Vector3& color, float scale ){ void SmoothNormals( void ){ int i, j, k, f, fOld, start; float shadeAngle, defaultShadeAngle, maxShadeAngle; - bspDrawSurface_t *ds; - shaderInfo_t *si; - float *shadeAngles; - byte *smoothed; int indexes[ MAX_SAMPLES ]; Vector3 votes[ MAX_SAMPLES ]; /* allocate shade angle table */ - shadeAngles = safe_calloc( numBSPDrawVerts * sizeof( float ) ); + std::vector shadeAngles( numBSPDrawVerts, 0 ); /* allocate smoothed table */ - smoothed = safe_calloc( ( numBSPDrawVerts / 8 ) + 1 ); + std::vector smoothed( numBSPDrawVerts, false ); /* set default shade angle */ defaultShadeAngle = degrees_to_radians( shadeAngleDegrees ); @@ -182,10 +178,10 @@ void SmoothNormals( void ){ for ( i = 0; i < numBSPDrawSurfaces; i++ ) { /* get drawsurf */ - ds = &bspDrawSurfaces[ i ]; + bspDrawSurface_t& ds = bspDrawSurfaces[ i ]; /* get shader for shade angle */ - si = surfaceInfos[ i ].si; + const shaderInfo_t *si = surfaceInfos[ i ].si; if ( si->shadeAngleDegrees ) { shadeAngle = degrees_to_radians( si->shadeAngleDegrees ); } @@ -195,26 +191,24 @@ void SmoothNormals( void ){ value_maximize( maxShadeAngle, shadeAngle ); /* flag its verts */ - for ( j = 0; j < ds->numVerts; j++ ) + for ( j = 0; j < ds.numVerts; j++ ) { - f = ds->firstVert + j; + f = ds.firstVert + j; shadeAngles[ f ] = shadeAngle; - if ( ds->surfaceType == MST_TRIANGLE_SOUP ) { - smoothed[ f >> 3 ] |= ( 1 << ( f & 7 ) ); + if ( ds.surfaceType == MST_TRIANGLE_SOUP ) { + smoothed[ f ] = true; } } /* ydnar: optional force-to-trisoup */ - if ( trisoup && ds->surfaceType == MST_PLANAR ) { - ds->surfaceType = MST_TRIANGLE_SOUP; - ds->lightmapNum[ 0 ] = -3; + if ( trisoup && ds.surfaceType == MST_PLANAR ) { + ds.surfaceType = MST_TRIANGLE_SOUP; + ds.lightmapNum[ 0 ] = -3; } } /* bail if no surfaces have a shade angle */ if ( maxShadeAngle == 0 ) { - free( shadeAngles ); - free( smoothed ); return; } @@ -233,7 +227,7 @@ void SmoothNormals( void ){ } /* already smoothed? */ - if ( smoothed[ i >> 3 ] & ( 1 << ( i & 7 ) ) ) { + if ( smoothed[ i ] ) { continue; } @@ -246,7 +240,7 @@ void SmoothNormals( void ){ for ( j = i; j < numBSPDrawVerts && numVerts < MAX_SAMPLES; j++ ) { /* already smoothed? */ - if ( smoothed[ j >> 3 ] & ( 1 << ( j & 7 ) ) ) { + if ( smoothed[ j ] ) { continue; } @@ -270,7 +264,7 @@ void SmoothNormals( void ){ indexes[ numVerts++ ] = j; /* flag vertex */ - smoothed[ j >> 3 ] |= ( 1 << ( j & 7 ) ); + smoothed[ j ] = true; /* see if this normal has already been voted */ for ( k = 0; k < numVotes; k++ ) @@ -301,10 +295,6 @@ void SmoothNormals( void ){ } } - /* free the tables */ - free( shadeAngles ); - free( smoothed ); - /* print time */ Sys_Printf( " (%i)\n", (int) ( I_FloatTime() - start ) ); } diff --git a/tools/quake3/q3map2/surface_meta.cpp b/tools/quake3/q3map2/surface_meta.cpp index 850958e0..2d0f3a46 100644 --- a/tools/quake3/q3map2/surface_meta.cpp +++ b/tools/quake3/q3map2/surface_meta.cpp @@ -1098,8 +1098,6 @@ void SmoothMetaTriangles( void ){ int i, j, k, f, fOld, start, numSmoothed; float shadeAngle, defaultShadeAngle, maxShadeAngle; metaTriangle_t *tri; - float *shadeAngles; - byte *smoothed; int indexes[ MAX_SAMPLES ]; Vector3 votes[ MAX_SAMPLES ]; @@ -1107,10 +1105,10 @@ void SmoothMetaTriangles( void ){ Sys_FPrintf( SYS_VRB, "--- SmoothMetaTriangles ---\n" ); /* allocate shade angle table */ - shadeAngles = safe_calloc( numMetaVerts * sizeof( float ) ); + std::vector shadeAngles( numMetaVerts, 0 ); /* allocate smoothed table */ - smoothed = safe_calloc( ( numMetaVerts / 8 ) + 1 ); + std::vector smoothed( numMetaVerts, false ); /* set default shade angle */ defaultShadeAngle = degrees_to_radians( npDegrees ); @@ -1142,7 +1140,7 @@ void SmoothMetaTriangles( void ){ { shadeAngles[ tri->indexes[ j ] ] = shadeAngle; if ( shadeAngle <= 0 ) { - smoothed[ tri->indexes[ j ] >> 3 ] |= ( 1 << ( tri->indexes[ j ] & 7 ) ); + smoothed[ tri->indexes[ j ] ] = true; } } } @@ -1150,8 +1148,6 @@ void SmoothMetaTriangles( void ){ /* bail if no surfaces have a shade angle */ if ( maxShadeAngle <= 0 ) { Sys_FPrintf( SYS_VRB, "No smoothing angles specified, aborting\n" ); - free( shadeAngles ); - free( smoothed ); return; } @@ -1171,7 +1167,7 @@ void SmoothMetaTriangles( void ){ } /* already smoothed? */ - if ( smoothed[ i >> 3 ] & ( 1 << ( i & 7 ) ) ) { + if ( smoothed[ i ] ) { continue; } @@ -1184,7 +1180,7 @@ void SmoothMetaTriangles( void ){ for ( j = i; j < numMetaVerts && numVerts < MAX_SAMPLES; j++ ) { /* already smoothed? */ - if ( smoothed[ j >> 3 ] & ( 1 << ( j & 7 ) ) ) { + if ( smoothed[ j ] ) { continue; } @@ -1206,7 +1202,7 @@ void SmoothMetaTriangles( void ){ indexes[ numVerts++ ] = j; /* flag vertex */ - smoothed[ j >> 3 ] |= ( 1 << ( j & 7 ) ); + smoothed[ j ] = true; /* see if this normal has already been voted */ for ( k = 0; k < numVotes; k++ ) @@ -1238,10 +1234,6 @@ void SmoothMetaTriangles( void ){ } } - /* free the tables */ - free( shadeAngles ); - free( smoothed ); - /* print time */ Sys_FPrintf( SYS_VRB, " (%d)\n", (int) ( I_FloatTime() - start ) );