From 070161fd13695a2328f3b42ff3b61f2a8ec3f8a1 Mon Sep 17 00:00:00 2001 From: Garux Date: Thu, 25 Jul 2019 19:23:13 +0300 Subject: [PATCH] shorten code --- libs/mathlib.h | 1 + tools/quake3/q3map2/light.c | 8 +------- tools/quake3/q3map2/light_ydnar.c | 26 ++++++-------------------- 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/libs/mathlib.h b/libs/mathlib.h index 8ed115d6..9d855f9d 100644 --- a/libs/mathlib.h +++ b/libs/mathlib.h @@ -80,6 +80,7 @@ extern const vec3_t g_vec3_axis_z; #define VectorNegate( a,b ) ( ( b )[0] = -( a )[0],( b )[1] = -( a )[1],( b )[2] = -( a )[2] ) #define CrossProduct( a,b,c ) ( ( c )[0] = ( a )[1] * ( b )[2] - ( a )[2] * ( b )[1],( c )[1] = ( a )[2] * ( b )[0] - ( a )[0] * ( b )[2],( c )[2] = ( a )[0] * ( b )[1] - ( a )[1] * ( b )[0] ) #define VectorClear( x ) ( ( x )[0] = ( x )[1] = ( x )[2] = 0 ) +#define VectorMax( x ) ( ( ( x )[0] > ( x )[1] ) ? ( ( ( x )[0] > ( x )[2] ) ? ( x )[0] : ( x )[2] ) : ( ( ( x )[1] > ( x )[2] ) ? ( x )[1] : ( x )[2] ) ) #define FLOAT_SNAP( f,snap ) ( (float)( floor( ( f ) / ( snap ) + 0.5 ) * ( snap ) ) ) #define FLOAT_TO_INTEGER( f ) ( (float)( floor( ( f ) + 0.5 ) ) ) diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index fa7a9c11..e50d609a 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -2426,13 +2426,7 @@ int LightMain( int argc, char **argv ){ /* Lighting contrast */ else if( !strcmp( argv[ i ], "-contrast" ) ){ f = atof( argv[ i + 1 ] ); - lightmapContrast = f; - if( lightmapContrast > 255 ){ - lightmapContrast = 255; - } - else if( lightmapContrast < -255 ){ - lightmapContrast = -255; - } + lightmapContrast = f > 255? 255 : f < -255? -255 : f; Sys_Printf( "Lighting contrast set to %f\n", lightmapContrast ); i++; /* change to factor in range of 0 to 129.5 */ diff --git a/tools/quake3/q3map2/light_ydnar.c b/tools/quake3/q3map2/light_ydnar.c index dddb3517..a053368a 100644 --- a/tools/quake3/q3map2/light_ydnar.c +++ b/tools/quake3/q3map2/light_ydnar.c @@ -77,13 +77,7 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale ){ if ( lightmapExposure == 0 ) { /* clamp with color normalization */ - max = sample[ 0 ]; - if ( sample[ 1 ] > max ) { - max = sample[ 1 ]; - } - if ( sample[ 2 ] > max ) { - max = sample[ 2 ]; - } + max = VectorMax( sample ); if ( max > 255.0f ) { VectorScale( sample, ( 255.0f / max ), sample ); } @@ -93,13 +87,7 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale ){ inv = 1.f / lightmapExposure; //Exposure - max = sample[ 0 ]; - if ( sample[ 1 ] > max ) { - max = sample[ 1 ]; - } - if ( sample[ 2 ] > max ) { - max = sample[ 2 ]; - } + max = VectorMax( sample ); dif = ( 1 - exp( -max * inv ) ) * 255; @@ -129,12 +117,10 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale ){ sample[i] = 0; } } - if ( ( sample[0] > 255 ) || ( sample[1] > 255 ) || ( sample[2] > 255 ) ) { - max = sample[0] > sample[1] ? sample[0] : sample[1]; - max = max > sample[2] ? max : sample[2]; - sample[0] = sample[0] * 255 / max; - sample[1] = sample[1] * 255 / max; - sample[2] = sample[2] * 255 / max; + /* clamp with color normalization */ + max = VectorMax( sample ); + if ( max > 255.0f ) { + VectorScale( sample, ( 255.0f / max ), sample ); } }