]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/lightmaps_ydnar.c
Merge branch 'master' into master-merge
[xonotic/netradiant.git] / tools / quake3 / q3map2 / lightmaps_ydnar.c
index 70e59b2f36e148da80b9e57161ebde8380e01d19..ee9902460b505c2912fc182f571986a4308a44b3 100644 (file)
@@ -695,16 +695,33 @@ qboolean AddSurfaceToRawLightmap( int num, rawLightmap_t *lm ){
                }
        }
 
-       if ( sampleSize != lm->sampleSize && lmLimitSize == 0 ) {
-               Sys_FPrintf( SYS_VRB,"WARNING: surface at (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) too large for desired samplesize/lightmapsize/lightmapscale combination, increased samplesize from %d to %d\n",
-                                        info->mins[0],
-                                        info->mins[1],
-                                        info->mins[2],
-                                        info->maxs[0],
-                                        info->maxs[1],
-                                        info->maxs[2],
-                                        lm->sampleSize,
-                                        (int) sampleSize );
+       if ( sampleSize != lm->sampleSize && lmLimitSize == 0 ){
+               if ( debugSampleSize == 1 || lm->customWidth > 128 ){
+                       Sys_FPrintf( SYS_VRB,"WARNING: surface at (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) too large for desired samplesize/lightmapsize/lightmapscale combination, increased samplesize from %d to %d\n",
+                                               info->mins[0],
+                                               info->mins[1],
+                                               info->mins[2],
+                                               info->maxs[0],
+                                               info->maxs[1],
+                                               info->maxs[2],
+                                               lm->sampleSize,
+                                               (int) sampleSize );
+               }
+               else if ( debugSampleSize == 0 ){
+                       Sys_FPrintf( SYS_VRB,"WARNING: surface at (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) too large for desired samplesize/lightmapsize/lightmapscale combination, increased samplesize from %d to %d\n",
+                                               info->mins[0],
+                                               info->mins[1],
+                                               info->mins[2],
+                                               info->maxs[0],
+                                               info->maxs[1],
+                                               info->maxs[2],
+                                               lm->sampleSize,
+                                               (int) sampleSize );
+                       debugSampleSize--;
+               }
+               else{
+                       debugSampleSize--;
+               }
        }
 
        /* set actual sample size */
@@ -1089,7 +1106,8 @@ void SetupSurfaceLightmaps( void ){
                        /* determine if surface requires a lightmap */
                        if ( ds->surfaceType == MST_TRIANGLE_SOUP ||
                                 ds->surfaceType == MST_FOLIAGE ||
-                                ( info->si->compileFlags & C_VERTEXLIT ) ) {
+                               ( info->si->compileFlags & C_VERTEXLIT ) ||
+                               nolm == qtrue ) {
                                numSurfsVertexLit++;
                        }
                        else
@@ -1196,6 +1214,10 @@ void SetupSurfaceLightmaps( void ){
                FinishRawLightmap( lm );
        }
 
+       if ( debugSampleSize < -1 ){
+               Sys_FPrintf( SYS_VRB, "+%d similar occurrences;\t-debugSampleSize to show ones\n", -debugSampleSize - 1 );
+       }
+
        /* allocate vertex luxel storage */
        for ( k = 0; k < MAX_LIGHTMAPS; k++ )
        {
@@ -2151,6 +2173,10 @@ static void FindOutLightmaps( rawLightmap_t *lm, qboolean fastAllocate ){
                        /* allocate LIGHTMAP_RESERVE_COUNT new output lightmaps */
                        numOutLightmaps += LIGHTMAP_RESERVE_COUNT;
                        olm = safe_malloc( numOutLightmaps * sizeof( outLightmap_t ) );
+                       if ( !olm ){
+                               Error( "FindOutLightmaps: Failed to allocate memory.\n" );
+                       }
+
                        if ( outLightmaps != NULL && numOutLightmaps > LIGHTMAP_RESERVE_COUNT ) {
                                memcpy( olm, outLightmaps, ( numOutLightmaps - LIGHTMAP_RESERVE_COUNT ) * sizeof( outLightmap_t ) );
                                free( outLightmaps );
@@ -2299,6 +2325,16 @@ static int CompareRawLightmap( const void *a, const void *b ){
        /* get min number of surfaces */
        min = ( alm->numLightSurfaces < blm->numLightSurfaces ? alm->numLightSurfaces : blm->numLightSurfaces );
 
+//#define allocate_bigger_first
+#ifdef allocate_bigger_first
+       /* compare size, allocate bigger first */
+       // fastAllocate commit part: can kick fps by unique lightmap/shader combinations*=~2 + bigger compile time
+       //return -diff; makes packing faster and rough
+       diff = ( blm->w * blm->h ) - ( alm->w * alm->h );
+       if ( diff != 0 ) {
+               return diff;
+       }
+#endif
        /* iterate */
        for ( i = 0; i < min; i++ )
        {
@@ -2320,13 +2356,13 @@ static int CompareRawLightmap( const void *a, const void *b ){
        if ( diff ) {
                return diff;
        }
-
+#ifndef allocate_bigger_first
        /* compare size */
        diff = ( blm->w * blm->h ) - ( alm->w * alm->h );
        if ( diff != 0 ) {
                return diff;
        }
-
+#endif
        /* must be equivalent */
        return 0;
 }
@@ -2445,15 +2481,13 @@ void FillOutLightmap( outLightmap_t *olm ){
        }
 }
 
-
-
 /*
    StoreSurfaceLightmaps()
    stores the surface lightmaps into the bsp as byte rgb triplets
  */
 
 void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
-       int i, j, k, x, y, lx, ly, sx, sy, *cluster, mappedSamples;
+       int i, j, k, x, y, lx, ly, sx, sy, *cluster, mappedSamples, timer_start;
        int style, size, lightmapNum, lightmapNum2;
        float               *normal, *luxel, *bspLuxel, *bspLuxel2, *radLuxel, samples, occludedSamples;
        vec3_t sample, occludedSample, dirSample, colorMins, colorMaxs;
@@ -2496,6 +2530,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
        /* note it */
        Sys_FPrintf( SYS_VRB, "Subsampling..." );
 
+       timer_start = I_FloatTime();
+
        /* walk the list of raw lightmaps */
        numUsed = 0;
        numTwins = 0;
@@ -2829,6 +2865,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                }
        }
 
+       Sys_FPrintf( SYS_VRB, "%d.", (int) ( I_FloatTime() - timer_start ) );
+
        /* -----------------------------------------------------------------
           convert modelspace deluxemaps to tangentspace
           ----------------------------------------------------------------- */
@@ -2838,6 +2876,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                        vec3_t worldUp, myNormal, myTangent, myBinormal;
                        float dist;
 
+                       timer_start = I_FloatTime();
+
                        Sys_Printf( "converting..." );
 
                        for ( i = 0; i < numRawLightmaps; i++ )
@@ -2907,6 +2947,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                                        }
                                }
                        }
+
+                       Sys_FPrintf( SYS_VRB, "%d.", (int) ( I_FloatTime() - timer_start ) );
                }
        }
 
@@ -2963,6 +3005,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                /* note it */
                Sys_FPrintf( SYS_VRB, "collapsing..." );
 
+               timer_start = I_FloatTime();
+
                /* set all twin refs to null */
                for ( i = 0; i < numRawLightmaps; i++ )
                {
@@ -3023,6 +3067,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                                }
                        }
                }
+
+               Sys_FPrintf( SYS_VRB, "%d.", (int) ( I_FloatTime() - timer_start ) );
        }
 
        /* -----------------------------------------------------------------
@@ -3032,6 +3078,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
        /* note it */
        Sys_FPrintf( SYS_VRB, "sorting..." );
 
+       timer_start = I_FloatTime();
+
        /* allocate a new sorted list */
        if ( sortLightmaps == NULL ) {
                sortLightmaps = safe_malloc( numRawLightmaps * sizeof( int ) );
@@ -3042,6 +3090,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                sortLightmaps[ i ] = i;
        qsort( sortLightmaps, numRawLightmaps, sizeof( int ), CompareRawLightmap );
 
+       Sys_FPrintf( SYS_VRB, "%d.", (int) ( I_FloatTime() - timer_start ) );
+
        /* -----------------------------------------------------------------
           allocate output lightmaps
           ----------------------------------------------------------------- */
@@ -3050,6 +3100,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                /* note it */
                Sys_FPrintf( SYS_VRB, "allocating..." );
 
+       timer_start = I_FloatTime();
+
                /* kill all existing output lightmaps */
                if ( outLightmaps != NULL ) {
                        for ( i = 0; i < numOutLightmaps; i++ )
@@ -3097,6 +3149,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                }
        }
 
+       Sys_FPrintf( SYS_VRB, "%d.", (int) ( I_FloatTime() - timer_start ) );
+
        /* -----------------------------------------------------------------
           store output lightmaps
           ----------------------------------------------------------------- */
@@ -3105,6 +3159,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                /* note it */
                Sys_FPrintf( SYS_VRB, "storing..." );
 
+       timer_start = I_FloatTime();
+
                /* count the bsp lightmaps and allocate space */
                if ( bspLightBytes != NULL ) {
                        free( bspLightBytes );
@@ -3189,6 +3245,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                }
        }
 
+       Sys_FPrintf( SYS_VRB, "%d.", (int) ( I_FloatTime() - timer_start ) );
+
        /* -----------------------------------------------------------------
           project the lightmaps onto the bsp surfaces
           ----------------------------------------------------------------- */
@@ -3197,6 +3255,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                /* note it */
                Sys_FPrintf( SYS_VRB, "projecting..." );
 
+       timer_start = I_FloatTime();
+
                /* walk the list of surfaces */
                for ( i = 0; i < numBSPDrawSurfaces; i++ )
                {
@@ -3475,6 +3535,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){
                }
        }
 
+       Sys_FPrintf( SYS_VRB, "%d.", (int) ( I_FloatTime() - timer_start ) );
+
        /* finish */
        Sys_FPrintf( SYS_VRB, "done.\n" );