From edf3fcd398f9dd30cb20af8e885187a90744ec9e Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 6 Oct 2019 06:50:32 +0300 Subject: [PATCH] engine: common: explicitly cast literals to floats, include tgmath when needed --- engine/common/common.h | 12 ++++++------ engine/common/gamma.c | 11 +++++++---- engine/common/mod_bmodel.c | 8 ++++---- engine/common/mod_studio.c | 2 +- engine/common/net_chan.c | 4 ++-- engine/common/net_ws.c | 8 +++++--- engine/common/pm_surface.c | 2 +- engine/common/soundlib/libmpg/sample.h | 4 ++-- engine/common/soundlib/libmpg/synth.c | 6 +++--- 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/engine/common/common.h b/engine/common/common.h index d5e776cb..0b568410 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -122,13 +122,13 @@ typedef enum #define XASH_VERSION "0.99" // engine current version // PERFORMANCE INFO -#define MIN_FPS 20.0 // host minimum fps value for maxfps. -#define MAX_FPS 200.0 // upper limit for maxfps. -#define HOST_FPS 100.0 // multiplayer games typical fps +#define MIN_FPS 20.0f // host minimum fps value for maxfps. +#define MAX_FPS 200.0f // upper limit for maxfps. +#define HOST_FPS 100.0f // multiplayer games typical fps -#define MAX_FRAMETIME 0.25 -#define MIN_FRAMETIME 0.0001 -#define GAME_FPS 20.0 +#define MAX_FRAMETIME 0.25f +#define MIN_FRAMETIME 0.0001f +#define GAME_FPS 20.0f #define MAX_CMD_TOKENS 80 // cmd tokens #define MAX_ENTNUMBER 99999 // for server and client parsing diff --git a/engine/common/gamma.c b/engine/common/gamma.c index a7b7d010..8dcc2b88 100644 --- a/engine/common/gamma.c +++ b/engine/common/gamma.c @@ -14,7 +14,10 @@ GNU General Public License for more details. */ #include "common.h" -#include +#include "mathlib.h" +#ifdef HAVE_TGMATH_H +#include +#endif //----------------------------------------------------------------------------- // Gamma conversion support @@ -54,7 +57,7 @@ void BuildGammaTable( float lightgamma, float brightness ) else f = 0.125f + ((f - g3) / (1.0f - g3)) * 0.875f; // convert linear space to desired gamma space - inf = (int)( 255.0 * pow( f, g )); + inf = (int)( 255.0f * pow( f, g )); lightgammatable[i] = bound( 0, inf, 255 ); } @@ -69,10 +72,10 @@ void BuildGammaTable( float lightgamma, float brightness ) for( i = 0; i < 1024; i++ ) { // convert from screen gamma space to linear space - lineargammatable[i] = 1023 * pow( i / 1023.0, g1 ); + lineargammatable[i] = 1023 * pow( i / 1023.0f, g1 ); // convert from linear gamma space to screen space - screengammatable[i] = 1023 * pow( i / 1023.0, 1.0 / g1 ); + screengammatable[i] = 1023 * pow( i / 1023.0f, 1.0f / g1 ); } } diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index c7ab953a..095b3d44 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -1004,11 +1004,11 @@ static void Mod_LightMatrixFromTexMatrix( const mtexinfo_t *tx, float lmvecs[2][ } // put the lighting origin at center the of poly - VectorScale( lmvecs[0], (1.0 / lmscale), lmvecs[0] ); - VectorScale( lmvecs[1], -(1.0 / lmscale), lmvecs[1] ); + VectorScale( lmvecs[0], (1.0f / lmscale), lmvecs[0] ); + VectorScale( lmvecs[1], -(1.0f / lmscale), lmvecs[1] ); - lmvecs[0][3] = lmscale * 0.5; - lmvecs[1][3] = -lmscale * 0.5; + lmvecs[0][3] = lmscale * 0.5f; + lmvecs[1][3] = -lmscale * 0.5f; } /* diff --git a/engine/common/mod_studio.c b/engine/common/mod_studio.c index a90687ff..4af4d1fd 100644 --- a/engine/common/mod_studio.c +++ b/engine/common/mod_studio.c @@ -340,7 +340,7 @@ static void Mod_StudioCalcBoneAdj( float *adj, const byte *pcontroller ) case STUDIO_XR: case STUDIO_YR: case STUDIO_ZR: - adj[j] = value * (M_PI / 180.0f); + adj[j] = value * (M_PI_F / 180.0f); break; case STUDIO_X: case STUDIO_Y: diff --git a/engine/common/net_chan.c b/engine/common/net_chan.c index b0e2a7fb..79ebb836 100644 --- a/engine/common/net_chan.c +++ b/engine/common/net_chan.c @@ -25,7 +25,7 @@ GNU General Public License for more details. #define UDP_HEADER_SIZE 28 -#define FLOW_AVG ( 2.0 / 3.0 ) // how fast to converge flow estimates +#define FLOW_AVG ( 2.0f / 3.0f ) // how fast to converge flow estimates #define FLOW_INTERVAL 0.1 // don't compute more often than this #define MAX_RELIABLE_PAYLOAD 1400 // biggest packet that has frag and or reliable data @@ -1678,7 +1678,7 @@ void Netchan_TransmitBits( netchan_t *chan, int length, byte *data ) NET_SendPacketEx( chan->sock, MSG_GetNumBytesWritten( &send ), MSG_GetData( &send ), chan->remote_address, splitsize ); } - if( SV_Active() && sv_lan.value && sv_lan_rate.value > 1000.0 ) + if( SV_Active() && sv_lan.value && sv_lan_rate.value > 1000.0f ) fRate = 1.0f / sv_lan_rate.value; else fRate = 1.0f / chan->rate; diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index d75e7f38..b4d80758 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -888,7 +888,7 @@ static void NET_AdjustLag( void ) converge = dt * 200.0f; if( fabs( diff ) < converge ) converge = fabs( diff ); - if( diff < 0.0 ) + if( diff < 0.0f ) converge = -converge; net.fakelag += converge; } @@ -959,7 +959,7 @@ static qboolean NET_LagPacket( qboolean newdata, netsrc_t sock, netadr_t *from, while( pPacket != &net.lagdata[sock] ) { - if( pPacket->receivedtime <= curtime - ( net.fakelag / 1000.0 )) + if( pPacket->receivedtime <= curtime - ( net.fakelag / 1000.0f )) break; pPacket = pPacket->next; @@ -2054,8 +2054,10 @@ static qboolean HTTP_ProcessStream( httpfile_t *curfile ) // as after it will run in same frame if( curfile->checktime > 5 ) { + float speed = (float)curfile->lastchecksize / ( 5.0f * 1024 ); + curfile->checktime = 0; - Con_Reportf( "download speed %f KB/s\n", (float)curfile->lastchecksize / ( 5.0 * 1024 ) ); + Con_Reportf( "download speed %f KB/s\n", speed ); curfile->lastchecksize = 0; } } diff --git a/engine/common/pm_surface.c b/engine/common/pm_surface.c index 8e381a1c..382f4807 100644 --- a/engine/common/pm_surface.c +++ b/engine/common/pm_surface.c @@ -272,7 +272,7 @@ loc0: side = (front < 0); frac = front / (front - back); - frac = bound( 0.0, frac, 1.0 ); + frac = bound( 0.0f, frac, 1.0f ); VectorLerp( start, frac, stop, mid ); midf = p1f + ( p2f - p1f ) * frac; diff --git a/engine/common/soundlib/libmpg/sample.h b/engine/common/soundlib/libmpg/sample.h index 97a6c8a9..0b33c96b 100644 --- a/engine/common/soundlib/libmpg/sample.h +++ b/engine/common/soundlib/libmpg/sample.h @@ -35,7 +35,7 @@ static _inline int16_t ftoi16( float x ) #define REAL_TO_SHORT_ACCURATE( x ) ftoi16(x) #else // the "proper" rounding, plain C, a bit slow. -#define REAL_TO_SHORT_ACCURATE( x ) (short)((x) > 0.0 ? (x) + 0.5 : (x) - 0.5) +#define REAL_TO_SHORT_ACCURATE( x ) (short)((x) > 0.0f ? (x) + 0.5f : (x) - 0.5f) #endif // now define the normal rounding. @@ -45,4 +45,4 @@ static _inline int16_t ftoi16( float x ) #define REAL_TO_SHORT( x ) (short)( x ) #endif -#endif//SAMPLE_H \ No newline at end of file +#endif//SAMPLE_H diff --git a/engine/common/soundlib/libmpg/synth.c b/engine/common/soundlib/libmpg/synth.c index 4b9e81e1..9c294544 100644 --- a/engine/common/soundlib/libmpg/synth.c +++ b/engine/common/soundlib/libmpg/synth.c @@ -20,8 +20,8 @@ GNU General Public License for more details. #define BLOCK 0x40 // one decoding block is 64 samples. #define WRITE_SHORT_SAMPLE( samples, sum, clip ) \ - if(( sum ) > 32767.0 ) { *(samples) = 0x7fff; (clip)++; } \ - else if(( sum ) < -32768.0 ) { *(samples) = -0x8000; (clip)++; } \ + if(( sum ) > 32767.0f ) { *(samples) = 0x7fff; (clip)++; } \ + else if(( sum ) < -32768.0f ) { *(samples) = -0x8000; (clip)++; } \ else { *(samples) = REAL_TO_SHORT( sum ); } // main synth function, uses the plain dct64 @@ -308,4 +308,4 @@ int set_synth_functions( mpg123_handle_t *fr ) fr->make_decode_tables( fr ); return 0; -} \ No newline at end of file +}