]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/lightmaps_ydnar.c
reduce more diff noise
[xonotic/netradiant.git] / tools / quake3 / q3map2 / lightmaps_ydnar.c
index 3db1a7f0f0b4da5682e62473e9896fb38bda91ec..1b28ca06935e860ddefddc1b3e536f0f23870960 100644 (file)
@@ -35,7 +35,7 @@
 
 /* dependencies */
 #include "q3map2.h"
-
+#include <glib.h>
 
 
 
@@ -127,7 +127,7 @@ void ExportLightmaps( void ){
 
        /* sanity check */
        if ( bspLightBytes == NULL ) {
-               Sys_Printf( "WARNING: No BSP lightmap data\n" );
+               Sys_FPrintf( SYS_WRN, "WARNING: No BSP lightmap data\n" );
                return;
        }
 
@@ -226,7 +226,7 @@ int ImportLightmapsMain( int argc, char **argv ){
                buffer = NULL;
                len = vfsLoadFile( filename, (void*) &buffer, -1 );
                if ( len < 0 ) {
-                       Sys_Printf( "WARNING: Unable to load image %s\n", filename );
+                       Sys_FPrintf( SYS_WRN, "WARNING: Unable to load image %s\n", filename );
                        continue;
                }
 
@@ -237,11 +237,11 @@ int ImportLightmapsMain( int argc, char **argv ){
 
                /* sanity check it */
                if ( pixels == NULL ) {
-                       Sys_Printf( "WARNING: Unable to load image %s\n", filename );
+                       Sys_FPrintf( SYS_WRN, "WARNING: Unable to load image %s\n", filename );
                        continue;
                }
                if ( width != game->lightmapSize || height != game->lightmapSize ) {
-                       Sys_Printf( "WARNING: Image %s is not the right size (%d, %d) != (%d, %d)\n",
+                       Sys_FPrintf( SYS_WRN, "WARNING: Image %s is not the right size (%d, %d) != (%d, %d)\n",
                                                filename, width, height, game->lightmapSize, game->lightmapSize );
                }
 
@@ -525,7 +525,7 @@ qboolean AddPatchToRawLightmap( int num, rawLightmap_t *lm ){
        length = 0;
        for ( x = 0; x < ( mesh->width - 1 ); x++ )
                length += widthTable[ x ];
-       lm->w = ceil( length / lm->sampleSize ) + 1;
+       lm->w = lm->sampleSize != 0 ? ceil( length / lm->sampleSize ) + 1 : 0;
        if ( lm->w < ds->patchWidth ) {
                lm->w = ds->patchWidth;
        }
@@ -538,7 +538,7 @@ qboolean AddPatchToRawLightmap( int num, rawLightmap_t *lm ){
        length = 0;
        for ( y = 0; y < ( mesh->height - 1 ); y++ )
                length += heightTable[ y ];
-       lm->h = ceil( length / lm->sampleSize ) + 1;
+       lm->h = lm->sampleSize != 0 ? ceil( length / lm->sampleSize ) + 1 : 0;
        if ( lm->h < ds->patchHeight ) {
                lm->h = ds->patchHeight;
        }
@@ -752,7 +752,7 @@ qboolean AddSurfaceToRawLightmap( int num, rawLightmap_t *lm ){
 
        /* check for bogus axis */
        if ( faxis[ axisNum ] == 0.0f ) {
-               Sys_Printf( "WARNING: ProjectSurfaceLightmap: Chose a 0 valued axis\n" );
+               Sys_FPrintf( SYS_WRN, "WARNING: ProjectSurfaceLightmap: Chose a 0 valued axis\n" );
                lm->w = lm->h = 0;
                return qfalse;
        }
@@ -890,7 +890,6 @@ static int CompareSurfaceInfo( const void *a, const void *b ){
                return -1;
        }
 
-
        /* then lightmap sample size */
        if ( aInfo->sampleSize < bInfo->sampleSize ) {
                return 1;
@@ -971,7 +970,7 @@ void SetupSurfaceLightmaps( void ){
                superSample = 1;
        }
        else if ( superSample > 8 ) {
-               Sys_Printf( "WARNING: Insane supersampling amount (%d) detected.\n", superSample );
+               Sys_FPrintf( SYS_WRN, "WARNING: Insane supersampling amount (%d) detected.\n", superSample );
                superSample = 8;
        }
 
@@ -1976,7 +1975,7 @@ static void SetupOutLightmap( rawLightmap_t *lm, outLightmap_t *olm ){
  */
 
 #define LIGHTMAP_RESERVE_COUNT 1
-static void FindOutLightmaps( rawLightmap_t *lm ){
+static void FindOutLightmaps( rawLightmap_t *lm, qboolean fastAllocate ){
        int i, j, k, lightmapNum, xMax, yMax, x = -1, y = -1, sx, sy, ox, oy, offset;
        outLightmap_t       *olm;
        surfaceInfo_t       *info;
@@ -1984,6 +1983,7 @@ static void FindOutLightmaps( rawLightmap_t *lm ){
        vec3_t color, direction;
        byte                *pixel;
        qboolean ok;
+       int xIncrement, yIncrement;
 
 
        /* set default lightmap number (-3 = LIGHTMAP_BY_VERTEX) */
@@ -2094,6 +2094,13 @@ static void FindOutLightmaps( rawLightmap_t *lm ){
                                        continue;
                                }
 
+                               /* if fast allocation, skip lightmap files that are more than 90% complete */
+                               if ( fastAllocate == qtrue ) {
+                                       if (olm->freeLuxels < (olm->customWidth * olm->customHeight) / 10) {
+                                               continue;
+                                       }
+                               }
+
                                /* don't store non-custom raw lightmaps on custom bsp lightmaps */
                                if ( olm->customWidth != lm->customWidth ||
                                         olm->customHeight != lm->customHeight ) {
@@ -2111,10 +2118,20 @@ static void FindOutLightmaps( rawLightmap_t *lm ){
                                        yMax = ( olm->customHeight - lm->h ) + 1;
                                }
 
+                               /* if fast allocation, do not test allocation on every pixels, especially for large lightmaps */
+                               if ( fastAllocate == qtrue ) {
+                                       xIncrement = MAX(1, lm->w / 15);
+                                       yIncrement = MAX(1, lm->h / 15);
+                               }
+                               else {
+                                       xIncrement = 1;
+                                       yIncrement = 1;
+                               }
+
                                /* walk the origin around the lightmap */
-                               for ( y = 0; y < yMax; y++ )
+                               for ( y = 0; y < yMax; y += yIncrement )
                                {
-                                       for ( x = 0; x < xMax; x++ )
+                                       for ( x = 0; x < xMax; x += xIncrement )
                                        {
                                                /* find a fine tract of lauhnd */
                                                ok = TestOutLightmapStamp( lm, lightmapNum, olm, x, y );
@@ -2324,6 +2341,8 @@ static int CompareRawLightmap( const void *a, const void *b ){
        return 0;
 }
 
+
+
 void FillOutLightmap( outLightmap_t *olm ){
        int x, y;
        int ofs;
@@ -2436,12 +2455,14 @@ void FillOutLightmap( outLightmap_t *olm ){
        }
 }
 
+
+
 /*
    StoreSurfaceLightmaps()
    stores the surface lightmaps into the bsp as byte rgb triplets
  */
 
-void StoreSurfaceLightmaps( void ){
+void StoreSurfaceLightmaps( qboolean fastAllocate ){
        int i, j, k, x, y, lx, ly, sx, sy, *cluster, mappedSamples;
        int style, size, lightmapNum, lightmapNum2;
        float               *normal, *luxel, *bspLuxel, *bspLuxel2, *radLuxel, samples, occludedSamples;
@@ -2459,8 +2480,8 @@ void StoreSurfaceLightmaps( void ){
        char dirname[ 1024 ], filename[ 1024 ];
        shaderInfo_t        *csi;
        char lightmapName[ 128 ];
-       const char              *rgbGenValues[ 256 ];
-       const char              *alphaGenValues[ 256 ];
+       const char          *rgbGenValues[ 256 ];
+       const char          *alphaGenValues[ 256 ];
 
 
        /* note it */
@@ -2483,7 +2504,7 @@ void StoreSurfaceLightmaps( void ){
           ----------------------------------------------------------------- */
 
        /* note it */
-       Sys_Printf( "Subsampling..." );
+       Sys_FPrintf( SYS_VRB, "Subsampling..." );
 
        /* walk the list of raw lightmaps */
        numUsed = 0;
@@ -2951,7 +2972,7 @@ void StoreSurfaceLightmaps( void ){
 
        if ( noCollapse == qfalse && deluxemap == qfalse ) {
                /* note it */
-               Sys_Printf( "collapsing..." );
+               Sys_FPrintf( SYS_VRB, "collapsing..." );
 
                /* set all twin refs to null */
                for ( i = 0; i < numRawLightmaps; i++ )
@@ -3020,7 +3041,7 @@ void StoreSurfaceLightmaps( void ){
           ----------------------------------------------------------------- */
 
        /* note it */
-       Sys_Printf( "sorting..." );
+       Sys_FPrintf( SYS_VRB, "sorting..." );
 
        /* allocate a new sorted list */
        if ( sortLightmaps == NULL ) {
@@ -3037,7 +3058,7 @@ void StoreSurfaceLightmaps( void ){
           ----------------------------------------------------------------- */
 
        /* note it */
-       Sys_Printf( "allocating..." );
+       Sys_FPrintf( SYS_VRB, "allocating..." );
 
        /* kill all existing output lightmaps */
        if ( outLightmaps != NULL ) {
@@ -3059,7 +3080,7 @@ void StoreSurfaceLightmaps( void ){
        for ( i = 0; i < numRawLightmaps; i++ )
        {
                lm = &rawLightmaps[ sortLightmaps[ i ] ];
-               FindOutLightmaps( lm );
+               FindOutLightmaps( lm, fastAllocate );
        }
 
        /* set output numbers in twinned lightmaps */
@@ -3090,7 +3111,7 @@ void StoreSurfaceLightmaps( void ){
           ----------------------------------------------------------------- */
 
        /* note it */
-       Sys_Printf( "storing..." );
+       Sys_FPrintf( SYS_VRB, "storing..." );
 
        /* count the bsp lightmaps and allocate space */
        if ( bspLightBytes != NULL ) {
@@ -3160,7 +3181,7 @@ void StoreSurfaceLightmaps( void ){
        }
 
        if ( numExtLightmaps > 0 ) {
-               Sys_Printf( "\n" );
+               Sys_FPrintf( SYS_VRB, "\n" );
        }
 
        /* delete unused external lightmaps */
@@ -3181,7 +3202,7 @@ void StoreSurfaceLightmaps( void ){
           ----------------------------------------------------------------- */
 
        /* note it */
-       Sys_Printf( "projecting..." );
+       Sys_FPrintf( SYS_VRB, "projecting..." );
 
        /* walk the list of surfaces */
        for ( i = 0; i < numBSPDrawSurfaces; i++ )
@@ -3460,7 +3481,7 @@ void StoreSurfaceLightmaps( void ){
        }
 
        /* finish */
-       Sys_Printf( "done.\n" );
+       Sys_FPrintf( SYS_VRB, "done.\n" );
 
        /* calc num stored */
        numStored = numBSPLightBytes / 3;