]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/light.c
q3map2: switch back to fastallocate option name to reduce diff with NRC, keep compati...
[xonotic/netradiant.git] / tools / quake3 / q3map2 / light.c
index dd906c1ca89f369291a351ad65a2f6459aeb2601..99d794840f6787fa836f2450ea2060afc44a1b37 100644 (file)
@@ -107,8 +107,7 @@ static void CreateSunLight( sun_t *sun ){
 
                /* create a light */
                numSunLights++;
-               light = safe_malloc( sizeof( *light ) );
-               memset( light, 0, sizeof( *light ) );
+               light = safe_malloc0( sizeof( *light ) );
                light->next = lights;
                lights = light;
 
@@ -254,8 +253,7 @@ void CreateEntityLights( void ){
 
                /* create a light */
                numPointLights++;
-               light = safe_malloc( sizeof( *light ) );
-               memset( light, 0, sizeof( *light ) );
+               light = safe_malloc0( sizeof( *light ) );
                light->next = lights;
                lights = light;
 
@@ -592,8 +590,7 @@ void CreateSurfaceLights( void ){
                        VectorScale( origin, 0.5f, origin );
 
                        /* create a light */
-                       light = safe_malloc( sizeof( *light ) );
-                       memset( light, 0, sizeof( *light ) );
+                       light = safe_malloc0( sizeof( *light ) );
                        light->next = lights;
                        lights = light;
 
@@ -1774,7 +1771,17 @@ void TraceGrid( int num ){
                        }
 
                /* vortex: apply gridscale and gridambientscale here */
-               ColorToBytes( color, bgp->ambient[ i ], gridScale * gridAmbientScale );
+               if (gp->directed[i][0] || gp->directed[i][1] || gp->directed[i][2]) {
+                       /*
+                        * HACK: if there's a non-zero directed component, this
+                        * lightgrid cell is useful. However, ioq3 skips grid
+                        * cells with zero ambient. So let's force ambient to be
+                        * nonzero unless directed is zero too.
+                        */
+                       ColorToBytesNonZero(color, bgp->ambient[i], gridScale * gridAmbientScale);
+               } else {
+                       ColorToBytes(color, bgp->ambient[i], gridScale * gridAmbientScale);
+               }
                ColorToBytes( gp->directed[ i ], bgp->directed[ i ], gridScale );
        }
 
@@ -1857,14 +1864,12 @@ void SetupGrid( void ){
        numBSPGridPoints = numRawGridPoints;
 
        /* allocate lightgrid */
-       rawGridPoints = safe_malloc( numRawGridPoints * sizeof( *rawGridPoints ) );
-       memset( rawGridPoints, 0, numRawGridPoints * sizeof( *rawGridPoints ) );
+       rawGridPoints = safe_malloc0( numRawGridPoints * sizeof( *rawGridPoints ) );
 
        if ( bspGridPoints != NULL ) {
                free( bspGridPoints );
        }
-       bspGridPoints = safe_malloc( numBSPGridPoints * sizeof( *bspGridPoints ) );
-       memset( bspGridPoints, 0, numBSPGridPoints * sizeof( *bspGridPoints ) );
+       bspGridPoints = safe_malloc0( numBSPGridPoints * sizeof( *bspGridPoints ) );
 
        /* clear lightgrid */
        for ( i = 0; i < numRawGridPoints; i++ )
@@ -1890,14 +1895,13 @@ void SetupGrid( void ){
    does what it says...
  */
 
-void LightWorld( const char *BSPFilePath, qboolean fastLightmapSearch ){
+void LightWorld( const char *BSPFilePath, qboolean fastAllocate, qboolean noBounceStore ){
        vec3_t color;
        float f;
        int b, bt;
        qboolean minVertex, minGrid;
        const char  *value;
 
-
        /* ydnar: smooth normals */
        if ( shade ) {
                Sys_Printf( "--- SmoothNormals ---\n" );
@@ -2031,13 +2035,19 @@ void LightWorld( const char *BSPFilePath, qboolean fastLightmapSearch ){
        /* radiosity */
        b = 1;
        bt = bounce;
+
        while ( bounce > 0 )
        {
+               qboolean storeForReal = !noBounceStore;
+
                /* store off the bsp between bounces */
-               StoreSurfaceLightmaps( fastLightmapSearch );
+               StoreSurfaceLightmaps( fastAllocate, storeForReal );
                UnparseEntities();
-               Sys_Printf( "Writing %s\n", BSPFilePath );
-               WriteBSPFile( BSPFilePath );
+
+               if ( storeForReal ) {
+                       Sys_Printf( "Writing %s\n", BSPFilePath );
+                       WriteBSPFile( BSPFilePath );
+               }
 
                /* note it */
                Sys_Printf( "\n--- Radiosity (bounce %d of %d) ---\n", b, bt );
@@ -2055,6 +2065,9 @@ void LightWorld( const char *BSPFilePath, qboolean fastLightmapSearch ){
                SetupEnvelopes( qfalse, fastbounce );
                if ( numLights == 0 ) {
                        Sys_Printf( "No diffuse light to calculate, ending radiosity.\n" );
+                       if ( noBounceStore ) {
+                               break;
+                       }
                        return;
                }
 
@@ -2098,8 +2111,9 @@ void LightWorld( const char *BSPFilePath, qboolean fastLightmapSearch ){
                bounce--;
                b++;
        }
+
        /* ydnar: store off lightmaps */
-       StoreSurfaceLightmaps( fastLightmapSearch );
+       StoreSurfaceLightmaps( fastAllocate, qtrue );
 }
 
 
@@ -2139,7 +2153,8 @@ int LightMain( int argc, char **argv ){
        const char  *value;
        int lightmapMergeSize = 0;
        qboolean lightSamplesInsist = qfalse;
-       qboolean fastLightmapSearch = qfalse;
+       qboolean fastAllocate = qfalse;
+       qboolean noBounceStore = qfalse;
 
        /* note it */
        Sys_Printf( "--- Light ---\n" );
@@ -2558,7 +2573,9 @@ int LightMain( int argc, char **argv ){
 
                else if ( !strcmp( argv[ i ], "-lightmapdir" ) ) {
                        lmCustomDir = argv[i + 1];
+                       argv[ i ] = NULL;
                        i++;
+                       argv[ i ] = NULL;
                        Sys_Printf( "Lightmap directory set to %s\n", lmCustomDir );
                        externalLightmaps = qtrue;
                        Sys_Printf( "Storing all lightmaps externally\n" );
@@ -2601,6 +2618,11 @@ int LightMain( int argc, char **argv ){
                        Sys_Printf( "Storing bounced light (radiosity) only\n" );
                }
 
+               else if ( !strcmp( argv[ i ], "-nobouncestore" ) ) {
+                       noBounceStore = qtrue;
+                       Sys_Printf( "Do not store BSP, lightmap and shader files between bounces\n" );
+               }
+
                else if ( !strcmp( argv[ i ], "-nocollapse" ) ) {
                        noCollapse = qtrue;
                        Sys_Printf( "Identical lightmap collapsing disabled\n" );
@@ -2660,17 +2682,22 @@ int LightMain( int argc, char **argv ){
                        Sys_Printf( "Faster mode enabled\n" );
                }
 
-               else if ( !strcmp( argv[ i ], "-fastlightmapsearch" ) || !strcmp( argv[ i ], "-fastallocate") ) {
-                       fastLightmapSearch = qtrue;
+               else if ( !strcmp( argv[ i ], "-fastallocate" ) || !strcmp( argv[ i ], "-fastlightmapsearch" ) ) {
+                       fastAllocate = qtrue;
 
-                       if ( !strcmp( argv[ i ], "-fastallocate" ) ) {
-                               Sys_Printf( "The -fastallocate argument is deprecated, use \"-fastlightmapsearch\" instead\n" );
+                       if ( !strcmp( argv[ i ], "-fastlightmapsearch" ) ) {
+                               Sys_Printf( "The -fastlightmapsearch argument is deprecated, use \"-fastallocate\" instead\n" );
                        }
                        else {
-                               Sys_Printf( "Fast lightmap search enabled\n" );
+                               Sys_Printf( "Fast lightmap allocation mode enabled\n" );
                        }
                }
 
+               else if ( !strcmp( argv[ i ], "-slowallocate" ) ) {
+                       fastAllocate = qfalse;
+                       Sys_Printf( "Slow lightmap allocation mode enabled (default)\n" );
+               }
+
                else if ( !strcmp( argv[ i ], "-fastgrid" ) ) {
                        fastgrid = qtrue;
                        Sys_Printf( "Fast grid lighting enabled\n" );
@@ -2909,13 +2936,17 @@ int LightMain( int argc, char **argv ){
                else if ( !strcmp( argv[ i ], "-bspfile" ) )
                {
                        strcpy( BSPFilePath, argv[i + 1] );
+                       argv[ i ] = NULL;
                        i++;
+                       argv[ i ] = NULL;
                        Sys_Printf( "Use %s as bsp file\n", BSPFilePath );
                }
                else if ( !strcmp( argv[ i ], "-srffile" ) )
                {
                        strcpy( surfaceFilePath, argv[i + 1] );
+                       argv[ i ] = NULL;
                        i++;
+                       argv[ i ] = NULL;
                        Sys_Printf( "Use %s as surface file\n", surfaceFilePath );
                }
                /* unhandled args */
@@ -2971,6 +3002,11 @@ int LightMain( int argc, char **argv ){
                Sys_Printf( "Restricted lightmap searching enabled - block size adjusted to %d\n", lightmapSearchBlockSize );
        }
 
+       /* arg checking */
+       if ( i != ( argc - 1 ) ) {
+               Error( "usage: q3map -light [options] <bspfile>" );
+       }
+
        strcpy( source, ExpandArg( argv[ i ] ) );
        StripExtension( source );
        DefaultExtension( source, ".map" );
@@ -3028,7 +3064,7 @@ int LightMain( int argc, char **argv ){
        SetupTraceNodes();
 
        /* light the world */
-       LightWorld( BSPFilePath, fastLightmapSearch );
+       LightWorld( BSPFilePath, fastAllocate, noBounceStore );
 
        /* write out the bsp */
        UnparseEntities();