From 78baf568ae7eefe99a116965c73791eda5379645 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 10 Oct 2019 04:21:50 +0300 Subject: [PATCH] engine: more double promotion fixes --- engine/client/cl_main.c | 3 ++- engine/client/in_touch.c | 24 ++++++++++++------------ engine/common/gamma.c | 2 +- engine/common/net_chan.c | 2 +- engine/server/sv_client.c | 2 +- engine/server/sv_main.c | 2 +- engine/server/sv_pmove.c | 2 +- public/crtlib.c | 6 +++++- public/mathlib.h | 9 +++++++-- ref_gl/gl_rsurf.c | 2 +- ref_gl/gl_studio.c | 4 ++-- 11 files changed, 34 insertions(+), 24 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 8b190ca6..667d0b90 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -2939,7 +2939,8 @@ void CL_AdjustClock( void ) if( fabs( cl.timedelta ) >= 0.001f ) { - double msec, adjust, sign; + double msec, adjust; + float sign; msec = ( cl.timedelta * 1000.0f ); sign = ( msec < 0 ) ? 1.0f : -1.0f; diff --git a/engine/client/in_touch.c b/engine/client/in_touch.c index 104c468e..17afada9 100644 --- a/engine/client/in_touch.c +++ b/engine/client/in_touch.c @@ -876,18 +876,18 @@ void Touch_DeleteProfile_f( void ) void Touch_InitEditor( void ) { - float x = 0.1 * (SCR_H/SCR_W); - float y = 0.05; + float x = 0.1f * (SCR_H/SCR_W); + float y = 0.05f; Touch_ClearList( &touch.list_edit ); - Touch_AddButton( &touch.list_edit, "close", "touch_default/edit_close.tga", "touch_disableedit", 0, y, x, y + 0.1, (byte*)"\xff\xff\xff\xff" )->flags |= TOUCH_FL_NOEDIT; - Touch_AddButton( &touch.list_edit, "close", "#Close and save", "", x, y, x + 0.2, y + 0.1, (byte*)"\xff\xff\xff\xff" )->flags |= TOUCH_FL_NOEDIT; - y += 0.2; - Touch_AddButton( &touch.list_edit, "cancel", "touch_default/edit_reset.tga", "touch_reloadconfig", 0, y, x, y + 0.1, (byte*)"\xff\xff\xff\xff" )->flags |= TOUCH_FL_NOEDIT; - Touch_AddButton( &touch.list_edit, "close", "#Cancel and reset", "", x, y, x + 0.2, y + 0.1, (byte*)"\xff\xff\xff\xff" )->flags |= TOUCH_FL_NOEDIT; - y += 0.2; - touch.hidebutton = Touch_AddButton( &touch.list_edit, "showhide", "touch_default/edit_hide.tga", "touch_toggleselection", 0, y, x, y + 0.1, (byte*)"\xff\xff\xff\xff" ); + Touch_AddButton( &touch.list_edit, "close", "touch_default/edit_close.tga", "touch_disableedit", 0, y, x, y + 0.1f, (byte*)"\xff\xff\xff\xff" )->flags |= TOUCH_FL_NOEDIT; + Touch_AddButton( &touch.list_edit, "close", "#Close and save", "", x, y, x + 0.2f, y + 0.1f, (byte*)"\xff\xff\xff\xff" )->flags |= TOUCH_FL_NOEDIT; + y += 0.2f; + Touch_AddButton( &touch.list_edit, "cancel", "touch_default/edit_reset.tga", "touch_reloadconfig", 0, y, x, y + 0.1f, (byte*)"\xff\xff\xff\xff" )->flags |= TOUCH_FL_NOEDIT; + Touch_AddButton( &touch.list_edit, "close", "#Cancel and reset", "", x, y, x + 0.2f, y + 0.1f, (byte*)"\xff\xff\xff\xff" )->flags |= TOUCH_FL_NOEDIT; + y += 0.2f; + touch.hidebutton = Touch_AddButton( &touch.list_edit, "showhide", "touch_default/edit_hide.tga", "touch_toggleselection", 0, y, x, y + 0.1f, (byte*)"\xff\xff\xff\xff" ); touch.hidebutton->flags |= TOUCH_FL_HIDE | TOUCH_FL_NOEDIT; } @@ -1439,13 +1439,13 @@ static void Touch_Motion( touchEventType type, int fingerID, float x, float y, f { touch.wheel_amount += touch.wheel_horizontal ? dx : dy; - if( touch.wheel_amount > 0.1 ) + if( touch.wheel_amount > 0.1f ) { Cbuf_AddText( touch.wheel_down ); touch.wheel_count++; touch.wheel_amount = 0; } - if( touch.wheel_amount < -0.1 ) + if( touch.wheel_amount < -0.1f ) { Cbuf_AddText( touch.wheel_up ); touch.wheel_count++; @@ -1499,7 +1499,7 @@ static void Touch_Motion( touchEventType type, int fingerID, float x, float y, f // save angle, modify only velocity dabs = sqrt( dx * dx + dy * dy ); - if( dabs < 0.000001 ) + if( dabs < 0.000001f ) return; // no motion, avoid division by zero dcos = dx / dabs; diff --git a/engine/common/gamma.c b/engine/common/gamma.c index 8dcc2b88..103156eb 100644 --- a/engine/common/gamma.c +++ b/engine/common/gamma.c @@ -64,7 +64,7 @@ void BuildGammaTable( float lightgamma, float brightness ) for( i = 0; i < 256; i++ ) { - f = 255.0 * pow(( float )i / 255.0f, TEXGAMMA ); + f = 255.0f * pow(( float )i / 255.0f, TEXGAMMA ); inf = (int)(f + 0.5f); texgammatable[i] = bound( 0, inf, 255 ); } diff --git a/engine/common/net_chan.c b/engine/common/net_chan.c index 79ebb836..c75e1c2f 100644 --- a/engine/common/net_chan.c +++ b/engine/common/net_chan.c @@ -605,7 +605,7 @@ void Netchan_UpdateFlow( netchan_t *chan ) } pflow->kbytespersec = (faccumulatedtime == 0.0f) ? 0.0f : bytes / faccumulatedtime / 1024.0f; - pflow->avgkbytespersec = pflow->avgkbytespersec * FLOW_AVG + pflow->kbytespersec * (1.0 - FLOW_AVG); + pflow->avgkbytespersec = pflow->avgkbytespersec * FLOW_AVG + pflow->kbytespersec * (1.0f - FLOW_AVG); } } diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index 58ecc912..04b95001 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -2527,7 +2527,7 @@ void SV_ExecuteClientMessage( sv_client_t *cl, sizebuf_t *msg ) if( frame->senttime == 0.0f ) frame->ping_time = 0.0f; // don't skew ping based on signon stuff either - if(( host.realtime - cl->connection_started ) < 2.0f && ( frame->ping_time > 0.0 )) + if(( host.realtime - cl->connection_started ) < 2.0f && ( frame->ping_time > 0.0f )) frame->ping_time = 0.0f; cl->latency = SV_CalcClientTime( cl ); diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index 57a20617..37fc7cb5 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -579,7 +579,7 @@ qboolean SV_RunGameFrame( void ) if( sv_fps.value != 0.0f ) { - double fps = (1.0 / (double)( sv_fps.value - 0.01 )); // FP issues + double fps = (1.0 / (double)( sv_fps.value - 0.01f )); // FP issues int numFrames = 0; while( sv.time_residual >= fps ) diff --git a/engine/server/sv_pmove.c b/engine/server/sv_pmove.c index a02e1178..54b7cdf9 100644 --- a/engine/server/sv_pmove.c +++ b/engine/server/sv_pmove.c @@ -917,7 +917,7 @@ void SV_SetupMoveInterpolant( sv_client_t *cl ) break; } - if( i == SV_UPDATE_BACKUP || finalpush - frame->senttime > 1.0 ) + if( i == SV_UPDATE_BACKUP || finalpush - frame->senttime > 1.0f ) { memset( svgame.interp, 0, sizeof( svgame.interp )); has_update = false; diff --git a/public/crtlib.c b/public/crtlib.c index 97b70a10..a4bd64d5 100644 --- a/public/crtlib.c +++ b/public/crtlib.c @@ -21,6 +21,10 @@ GNU General Public License for more details. #include #include "stdio.h" #include "crtlib.h" +#ifdef HAVE_TGMATH_H +#include +#endif + void Q_strnupr( const char *in, char *out, size_t size_out ) { if( size_out == 0 ) return; @@ -652,7 +656,7 @@ char *Q_pretifymem( float value, int digitsafterdecimal ) digitsafterdecimal = max( digitsafterdecimal, 0 ); // if it's basically integral, don't do any decimals - if( fabs( value - (int)value ) < 0.00001 ) + if( fabs( value - (int)value ) < 0.00001f ) { Q_sprintf( val, "%i%s", (int)value, suffix ); } diff --git a/public/mathlib.h b/public/mathlib.h index 0f80e358..4a9e730e 100644 --- a/public/mathlib.h +++ b/public/mathlib.h @@ -33,7 +33,7 @@ GNU General Public License for more details. #endif #ifndef M_PI2 -#define M_PI2 (float)6.28318530717958647692 +#define M_PI2 ((float)(M_PI * 2)) #endif #define M_PI_F ((float)(M_PI)) @@ -73,8 +73,13 @@ GNU General Public License for more details. #define Q_floor( a ) ((float)(int)(a)) #define Q_ceil( a ) ((float)(int)((a) + 1)) #define Q_round( x, y ) (floor( x / y + 0.5f ) * y ) -#define Q_rint(x) ((x) < 0 ? ((int)((x)-0.5f)) : ((int)((x)+0.5f))) +#define Q_rint(x) ((x) < 0.0f ? ((int)((x)-0.5f)) : ((int)((x)+0.5f))) + +#ifdef isnan // check for C99 isnan +#define IS_NAN isnan +#else #define IS_NAN(x) (((*(int *)&x) & (255<<23)) == (255<<23)) +#endif #define ALIGN( x, a ) ((( x ) + (( size_t )( a ) - 1 )) & ~(( size_t )( a ) - 1 )) diff --git a/ref_gl/gl_rsurf.c b/ref_gl/gl_rsurf.c index 6939dffe..e3124753 100644 --- a/ref_gl/gl_rsurf.c +++ b/ref_gl/gl_rsurf.c @@ -805,7 +805,7 @@ void DrawGLPoly( glpoly_t *p, float xScale, float yScale ) } texture = R_GetTexture( glState.currentTextures[glState.activeTMU] ); - flRate = abs( flConveyorSpeed ) / (float)texture->srcWidth; + flRate = fabs( flConveyorSpeed ) / (float)texture->srcWidth; flAngle = ( flConveyorSpeed >= 0 ) ? 180 : 0; SinCos( flAngle * ( M_PI_F / 180.0f ), &sy, &cy ); diff --git a/ref_gl/gl_studio.c b/ref_gl/gl_studio.c index d78978dd..0eb3f297 100644 --- a/ref_gl/gl_studio.c +++ b/ref_gl/gl_studio.c @@ -883,7 +883,7 @@ void R_StudioMergeBones( cl_entity_t *e, model_t *m_pSubModel ) matrix3x4 bonematrix; static vec4_t q[MAXSTUDIOBONES]; static float pos[MAXSTUDIOBONES][3]; - double f; + float f; if( e->curstate.sequence >= m_pStudioHeader->numseq ) e->curstate.sequence = 0; @@ -936,7 +936,7 @@ StudioSetupBones */ void R_StudioSetupBones( cl_entity_t *e ) { - double f; + float f; mstudiobone_t *pbones; mstudioseqdesc_t *pseqdesc; mstudioanim_t *panim;