]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/light.c
q3map2: use safe_malloc0 when safe_malloc is followed by a memset to 0 with the same...
[xonotic/netradiant.git] / tools / quake3 / q3map2 / light.c
index 0f55316498019126637409ffb2b268ddb0da8a0b..e43906e0aadfc87f34a0636f5424a66d3c65b4a3 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;
 
@@ -1857,14 +1854,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 +1885,13 @@ void SetupGrid( void ){
    does what it says...
  */
 
-void LightWorld( const char *BSPFilePath, qboolean fastAllocate ){
+void LightWorld( const char *BSPFilePath, qboolean fastLightmapSearch, 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 +2025,19 @@ void LightWorld( const char *BSPFilePath, qboolean fastAllocate ){
        /* radiosity */
        b = 1;
        bt = bounce;
+
        while ( bounce > 0 )
        {
+               qboolean storeForReal = !noBounceStore;
+
                /* store off the bsp between bounces */
-               StoreSurfaceLightmaps( fastAllocate );
+               StoreSurfaceLightmaps( fastLightmapSearch, 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 +2055,9 @@ void LightWorld( const char *BSPFilePath, qboolean fastAllocate ){
                SetupEnvelopes( qfalse, fastbounce );
                if ( numLights == 0 ) {
                        Sys_Printf( "No diffuse light to calculate, ending radiosity.\n" );
+                       if ( noBounceStore ) {
+                               break;
+                       }
                        return;
                }
 
@@ -2098,26 +2101,30 @@ void LightWorld( const char *BSPFilePath, qboolean fastAllocate ){
                bounce--;
                b++;
        }
+
        /* ydnar: store off lightmaps */
-       StoreSurfaceLightmaps( fastAllocate );
+       StoreSurfaceLightmaps( fastLightmapSearch, qtrue );
 }
 
 
 
-#ifdef SMOKINGUNS
-//added by spoon to get back the changed surfaceflags
-void LoadSurfaceFlags(char *filename){
+/*
+   LoadSurfaceFlags()
+   added by spoon to get back the changed surfaceflags
+   from tex file
+*/
+
+void LoadSurfaceFlags( char *filename ) {
        int i;
 
-       for(i=0; i<numBSPShaders;i++){
-               shaderInfo_t    *si;
+       for( i = 0; i < numBSPShaders; i++ ) {
+               shaderInfo_t *si;
 
                si = ShaderInfoForShader( bspShaders[i].shader );
 
-               bspShaders[i].surfaceFlags = si->surfaceFlags;
+               bspShaders[ i ].surfaceFlags = si->surfaceFlags;
        }
 }
-#endif
 
 
 
@@ -2136,7 +2143,8 @@ int LightMain( int argc, char **argv ){
        const char  *value;
        int lightmapMergeSize = 0;
        qboolean lightSamplesInsist = qfalse;
-       qboolean fastAllocate = qfalse;
+       qboolean fastLightmapSearch = qfalse;
+       qboolean noBounceStore = qfalse;
 
        /* note it */
        Sys_Printf( "--- Light ---\n" );
@@ -2598,6 +2606,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" );
@@ -2657,9 +2670,15 @@ int LightMain( int argc, char **argv ){
                        Sys_Printf( "Faster mode enabled\n" );
                }
 
-               else if ( !strcmp( argv[ i ], "-fastallocate" ) ) {
-                       fastAllocate = qtrue;
-                       Sys_Printf( "Fast allocation mode enabled\n" );
+               else if ( !strcmp( argv[ i ], "-fastlightmapsearch" ) || !strcmp( argv[ i ], "-fastallocate") ) {
+                       fastLightmapSearch = qtrue;
+
+                       if ( !strcmp( argv[ i ], "-fastallocate" ) ) {
+                               Sys_Printf( "The -fastallocate argument is deprecated, use \"-fastlightmapsearch\" instead\n" );
+                       }
+                       else {
+                               Sys_Printf( "Fast lightmap search enabled\n" );
+                       }
                }
 
                else if ( !strcmp( argv[ i ], "-fastgrid" ) ) {
@@ -3019,7 +3038,7 @@ int LightMain( int argc, char **argv ){
        SetupTraceNodes();
 
        /* light the world */
-       LightWorld( BSPFilePath, fastAllocate );
+       LightWorld( BSPFilePath, fastLightmapSearch, noBounceStore );
 
        /* write out the bsp */
        UnparseEntities();