]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/lightmaps_ydnar.c
skinfiles: use the VFS
[xonotic/netradiant.git] / tools / quake3 / q3map2 / lightmaps_ydnar.c
index 8ea7aa39b9aa29be29404c7a4229e284b8ef2e02..d30906f6a827ddfaec2c7233f461dbabcae5ca08 100644 (file)
@@ -678,14 +678,14 @@ qboolean AddSurfaceToRawLightmap( int num, rawLightmap_t *lm )
                size[ i ] = (maxs[ i ] - mins[ i ]) / sampleSize + 1.0f;
                
                /* hack (god this sucks) */
-               if( size[ i ] > lm->customWidth || size[ i ] > lm->customHeight )
+               if( size[ i ] > lm->customWidth || size[ i ] > lm->customHeight  || (lmLimitSize && size[i] > lmLimitSize))
                {
                        i = -1;
                        sampleSize += 1.0f;
                }
        }
 
-       if(sampleSize != lm->sampleSize)
+       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],
@@ -1918,9 +1918,10 @@ FindOutLightmaps()
 for a given surface lightmap, find output lightmap pages and positions for it
 */
 
+#define LIGHTMAP_RESERVE_COUNT 1
 static void FindOutLightmaps( rawLightmap_t *lm )
 {
-       int                                     i, j, lightmapNum, xMax, yMax, x, y, sx, sy, ox, oy, offset, temp;
+       int                                     i, j, k, lightmapNum, xMax, yMax, x, y, sx, sy, ox, oy, offset;
        outLightmap_t           *olm;
        surfaceInfo_t           *info;
        float                           *luxel, *deluxel;
@@ -2015,7 +2016,11 @@ static void FindOutLightmaps( rawLightmap_t *lm )
                        y = 0;
                        
                        /* walk the list of lightmap pages */
-                       for( i = 0; i < numOutLightmaps; i++ )
+                       if(lightmapSearchBlockSize <= 0 || numOutLightmaps < LIGHTMAP_RESERVE_COUNT)
+                               i = 0;
+                       else
+                               i = ((numOutLightmaps - LIGHTMAP_RESERVE_COUNT) / lightmapSearchBlockSize) * lightmapSearchBlockSize;
+                       for( ; i < numOutLightmaps; i++ )
                        {
                                /* get the output lightmap */
                                olm = &outLightmaps[ i ];
@@ -2069,22 +2074,22 @@ static void FindOutLightmaps( rawLightmap_t *lm )
                /* no match? */
                if( ok == qfalse )
                {
-                       /* allocate two new output lightmaps */
-                       numOutLightmaps += 2;
+                       /* allocate LIGHTMAP_RESERVE_COUNT new output lightmaps */
+                       numOutLightmaps += LIGHTMAP_RESERVE_COUNT;
                        olm = safe_malloc( numOutLightmaps * sizeof( outLightmap_t ) );
-                       if( outLightmaps != NULL && numOutLightmaps > 2 )
+                       if( outLightmaps != NULL && numOutLightmaps > LIGHTMAP_RESERVE_COUNT )
                        {
-                               memcpy( olm, outLightmaps, (numOutLightmaps - 2) * sizeof( outLightmap_t ) );
+                               memcpy( olm, outLightmaps, (numOutLightmaps - LIGHTMAP_RESERVE_COUNT) * sizeof( outLightmap_t ) );
                                free( outLightmaps );
                        }
                        outLightmaps = olm;
                        
                        /* initialize both out lightmaps */
-                       SetupOutLightmap( lm, &outLightmaps[ numOutLightmaps - 2 ] );
-                       SetupOutLightmap( lm, &outLightmaps[ numOutLightmaps - 1 ] );
+                       for(k = numOutLightmaps - LIGHTMAP_RESERVE_COUNT; k < numOutLightmaps; ++k)
+                               SetupOutLightmap( lm, &outLightmaps[ k ] );
                        
                        /* set out lightmap */
-                       i = numOutLightmaps - 2;
+                       i = numOutLightmaps - LIGHTMAP_RESERVE_COUNT;
                        olm = &outLightmaps[ i ];
                        
                        /* set stamp xy origin to the first surface lightmap */
@@ -2188,21 +2193,12 @@ static void FindOutLightmaps( rawLightmap_t *lm )
                                if( deluxemap )
                                {
                                        /* normalize average light direction */
-                                       if( VectorNormalize( deluxel, direction ) )
-                                       {
-                                               /* encode [-1,1] in [0,255] */
-                                               pixel = olm->bspDirBytes + (((oy * olm->customWidth) + ox) * 3);
-                                               for( i = 0; i < 3; i++ )
-                                               {
-                                                       temp = (direction[ i ] + 1.0f) * 127.5f;
-                                                       if( temp < 0 )
-                                                               pixel[ i ] = 0;
-                                                       else if( temp > 255 )
-                                                               pixel[ i ] = 255;
-                                                       else
-                                                               pixel[ i ] = temp;
-                                               }
-                                       }
+                                       pixel = olm->bspDirBytes + (((oy * olm->customWidth) + ox) * 3);
+                                       VectorScale( deluxel, 1000.0f, direction );
+                                       VectorNormalize( direction, direction );
+                                       VectorScale( direction, 127.5f, direction );
+                                       for( i = 0; i < 3; i++ )
+                                               pixel[ i ] = (byte)( 127.5f + direction[ i ] );
                                }
                        }
                }