]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/light_bounce.c
Merge commit '9c4c8b725fdca551dc9379b77ebd9c498d0c6f28' into master-merge
[xonotic/netradiant.git] / tools / quake3 / q3map2 / light_bounce.c
index d1b3fbd24be03c629ca15b7700c98a40f41ccd12..18d1f0a4c236650d2de4e718fe58ca581efdde24 100644 (file)
@@ -195,6 +195,23 @@ static void RadClipWindingEpsilon( radWinding_t *in, vec3_t normal, vec_t dist,
 
 
 
+/*
+   Modulo1IfNegative()
+   Previously the bias computation was doing:
+
+      while ( f < 0.0f ) {
+         f += 1.0f;
+      }
+
+   That may end in infinite loop in some case.
+   It may also be slower because of useless loops.
+   I don't know what that computation is for.
+   -- illwieckz
+*/
+float Modulo1IfNegative( float f ){
+       return f < 0.0f ? f - floor( f ) : f;
+}
+
 
 
 /*
@@ -204,10 +221,8 @@ static void RadClipWindingEpsilon( radWinding_t *in, vec3_t normal, vec_t dist,
  */
 
 qboolean RadSampleImage( byte *pixels, int width, int height, float st[ 2 ], float color[ 4 ] ){
-       float sto[ 2 ];
        int x, y;
 
-
        /* clear color first */
        color[ 0 ] = color[ 1 ] = color[ 2 ] = color[ 3 ] = 255;
 
@@ -216,18 +231,10 @@ qboolean RadSampleImage( byte *pixels, int width, int height, float st[ 2 ], flo
                return qfalse;
        }
 
-       /* bias st */
-       sto[ 0 ] = st[ 0 ];
-       while ( sto[ 0 ] < 0.0f )
-               sto[ 0 ] += 1.0f;
-       sto[ 1 ] = st[ 1 ];
-       while ( sto[ 1 ] < 0.0f )
-               sto[ 1 ] += 1.0f;
-
        /* get offsets */
-       x = ( (float) width * sto[ 0 ] ) + 0.5f;
+       x = ( (float) width * Modulo1IfNegative( st[ 0 ] ) ) + 0.5f;
        x %= width;
-       y = ( (float) height * sto[ 1 ] )  + 0.5f;
+       y = ( (float) height * Modulo1IfNegative( st[ 1 ] ) ) + 0.5f;
        y %= height;
 
        /* get pixel */
@@ -536,8 +543,7 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
        }
 
        /* create a light */
-       light = safe_malloc( sizeof( *light ) );
-       memset( light, 0, sizeof( *light ) );
+       light = safe_malloc0( sizeof( *light ) );
 
        /* attach it */
        ThreadLock();
@@ -583,8 +589,7 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
                /* optionally create a point splashsplash light for first pass */
                if ( original && si->backsplashFraction > 0 ) {
                        /* allocate a new point light */
-                       splash = safe_malloc( sizeof( *splash ) );
-                       memset( splash, 0, sizeof( *splash ) );
+                       splash = safe_malloc0( sizeof( *splash ) );
                        splash->next = lights;
                        lights = splash;