Browse Source

engine: common: explicitly cast literals to floats, include tgmath when needed

pull/2/head
Alibek Omarov 5 years ago
parent
commit
edf3fcd398
  1. 12
      engine/common/common.h
  2. 11
      engine/common/gamma.c
  3. 8
      engine/common/mod_bmodel.c
  4. 2
      engine/common/mod_studio.c
  5. 4
      engine/common/net_chan.c
  6. 8
      engine/common/net_ws.c
  7. 2
      engine/common/pm_surface.c
  8. 2
      engine/common/soundlib/libmpg/sample.h
  9. 4
      engine/common/soundlib/libmpg/synth.c

12
engine/common/common.h

@ -122,13 +122,13 @@ typedef enum
#define XASH_VERSION "0.99" // engine current version #define XASH_VERSION "0.99" // engine current version
// PERFORMANCE INFO // PERFORMANCE INFO
#define MIN_FPS 20.0 // host minimum fps value for maxfps. #define MIN_FPS 20.0f // host minimum fps value for maxfps.
#define MAX_FPS 200.0 // upper limit for maxfps. #define MAX_FPS 200.0f // upper limit for maxfps.
#define HOST_FPS 100.0 // multiplayer games typical fps #define HOST_FPS 100.0f // multiplayer games typical fps
#define MAX_FRAMETIME 0.25 #define MAX_FRAMETIME 0.25f
#define MIN_FRAMETIME 0.0001 #define MIN_FRAMETIME 0.0001f
#define GAME_FPS 20.0 #define GAME_FPS 20.0f
#define MAX_CMD_TOKENS 80 // cmd tokens #define MAX_CMD_TOKENS 80 // cmd tokens
#define MAX_ENTNUMBER 99999 // for server and client parsing #define MAX_ENTNUMBER 99999 // for server and client parsing

11
engine/common/gamma.c

@ -14,7 +14,10 @@ GNU General Public License for more details.
*/ */
#include "common.h" #include "common.h"
#include <mathlib.h> #include "mathlib.h"
#ifdef HAVE_TGMATH_H
#include <tgmath.h>
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Gamma conversion support // Gamma conversion support
@ -54,7 +57,7 @@ void BuildGammaTable( float lightgamma, float brightness )
else f = 0.125f + ((f - g3) / (1.0f - g3)) * 0.875f; else f = 0.125f + ((f - g3) / (1.0f - g3)) * 0.875f;
// convert linear space to desired gamma space // 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 ); lightgammatable[i] = bound( 0, inf, 255 );
} }
@ -69,10 +72,10 @@ void BuildGammaTable( float lightgamma, float brightness )
for( i = 0; i < 1024; i++ ) for( i = 0; i < 1024; i++ )
{ {
// convert from screen gamma space to linear space // 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 // 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 );
} }
} }

8
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 // put the lighting origin at center the of poly
VectorScale( lmvecs[0], (1.0 / lmscale), lmvecs[0] ); VectorScale( lmvecs[0], (1.0f / lmscale), lmvecs[0] );
VectorScale( lmvecs[1], -(1.0 / lmscale), lmvecs[1] ); VectorScale( lmvecs[1], -(1.0f / lmscale), lmvecs[1] );
lmvecs[0][3] = lmscale * 0.5; lmvecs[0][3] = lmscale * 0.5f;
lmvecs[1][3] = -lmscale * 0.5; lmvecs[1][3] = -lmscale * 0.5f;
} }
/* /*

2
engine/common/mod_studio.c

@ -340,7 +340,7 @@ static void Mod_StudioCalcBoneAdj( float *adj, const byte *pcontroller )
case STUDIO_XR: case STUDIO_XR:
case STUDIO_YR: case STUDIO_YR:
case STUDIO_ZR: case STUDIO_ZR:
adj[j] = value * (M_PI / 180.0f); adj[j] = value * (M_PI_F / 180.0f);
break; break;
case STUDIO_X: case STUDIO_X:
case STUDIO_Y: case STUDIO_Y:

4
engine/common/net_chan.c

@ -25,7 +25,7 @@ GNU General Public License for more details.
#define UDP_HEADER_SIZE 28 #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 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 #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 ); 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; fRate = 1.0f / sv_lan_rate.value;
else fRate = 1.0f / chan->rate; else fRate = 1.0f / chan->rate;

8
engine/common/net_ws.c

@ -888,7 +888,7 @@ static void NET_AdjustLag( void )
converge = dt * 200.0f; converge = dt * 200.0f;
if( fabs( diff ) < converge ) if( fabs( diff ) < converge )
converge = fabs( diff ); converge = fabs( diff );
if( diff < 0.0 ) if( diff < 0.0f )
converge = -converge; converge = -converge;
net.fakelag += 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] ) while( pPacket != &net.lagdata[sock] )
{ {
if( pPacket->receivedtime <= curtime - ( net.fakelag / 1000.0 )) if( pPacket->receivedtime <= curtime - ( net.fakelag / 1000.0f ))
break; break;
pPacket = pPacket->next; pPacket = pPacket->next;
@ -2054,8 +2054,10 @@ static qboolean HTTP_ProcessStream( httpfile_t *curfile )
// as after it will run in same frame // as after it will run in same frame
if( curfile->checktime > 5 ) if( curfile->checktime > 5 )
{ {
float speed = (float)curfile->lastchecksize / ( 5.0f * 1024 );
curfile->checktime = 0; 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; curfile->lastchecksize = 0;
} }
} }

2
engine/common/pm_surface.c

@ -272,7 +272,7 @@ loc0:
side = (front < 0); side = (front < 0);
frac = front / (front - back); frac = front / (front - back);
frac = bound( 0.0, frac, 1.0 ); frac = bound( 0.0f, frac, 1.0f );
VectorLerp( start, frac, stop, mid ); VectorLerp( start, frac, stop, mid );
midf = p1f + ( p2f - p1f ) * frac; midf = p1f + ( p2f - p1f ) * frac;

2
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) #define REAL_TO_SHORT_ACCURATE( x ) ftoi16(x)
#else #else
// the "proper" rounding, plain C, a bit slow. // 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 #endif
// now define the normal rounding. // now define the normal rounding.

4
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 BLOCK 0x40 // one decoding block is 64 samples.
#define WRITE_SHORT_SAMPLE( samples, sum, clip ) \ #define WRITE_SHORT_SAMPLE( samples, sum, clip ) \
if(( sum ) > 32767.0 ) { *(samples) = 0x7fff; (clip)++; } \ if(( sum ) > 32767.0f ) { *(samples) = 0x7fff; (clip)++; } \
else if(( sum ) < -32768.0 ) { *(samples) = -0x8000; (clip)++; } \ else if(( sum ) < -32768.0f ) { *(samples) = -0x8000; (clip)++; } \
else { *(samples) = REAL_TO_SHORT( sum ); } else { *(samples) = REAL_TO_SHORT( sum ); }
// main synth function, uses the plain dct64 // main synth function, uses the plain dct64

Loading…
Cancel
Save