Browse Source

engine: common: net_encode: fix usage of new Delta_ClampIntegerField, minor fixes

pull/2/head
Alibek Omarov 1 year ago
parent
commit
6ea8d141d9
  1. 42
      engine/common/net_encode.c

42
engine/common/net_encode.c

@ -948,7 +948,7 @@ assume from and to is valid
*/ */
static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, double timebase ) static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, double timebase )
{ {
qboolean bSigned = ( pField->flags & DT_SIGNED ) ? true : false; int signbit = ( pField->flags & DT_SIGNED ) ? 1 : 0;
float val_a, val_b; float val_a, val_b;
int fromF, toF; int fromF, toF;
@ -963,7 +963,7 @@ static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, doubl
if( pField->flags & DT_BYTE ) if( pField->flags & DT_BYTE )
{ {
if( pField->flags & DT_SIGNED ) if( signbit )
{ {
fromF = *(int8_t *)((int8_t *)from + pField->offset ); fromF = *(int8_t *)((int8_t *)from + pField->offset );
toF = *(int8_t *)((int8_t *)to + pField->offset ); toF = *(int8_t *)((int8_t *)to + pField->offset );
@ -974,18 +974,18 @@ static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, doubl
toF = *(uint8_t *)((int8_t *)to + pField->offset ); toF = *(uint8_t *)((int8_t *)to + pField->offset );
} }
fromF = Delta_ClampIntegerField( pField, fromF, bSigned, pField->bits ); fromF = Delta_ClampIntegerField( pField, fromF, signbit, pField->bits );
toF = Delta_ClampIntegerField( pField, toF, bSigned, pField->bits ); toF = Delta_ClampIntegerField( pField, toF, signbit, pField->bits );
if( !Q_equal(pField->multiplier, 1.0) ) if( !Q_equal(pField->multiplier, 1.0f ))
fromF *= pField->multiplier; fromF *= pField->multiplier;
if( !Q_equal( pField->multiplier, 1.0 ) ) if( !Q_equal( pField->multiplier, 1.0f ))
toF *= pField->multiplier; toF *= pField->multiplier;
} }
else if( pField->flags & DT_SHORT ) else if( pField->flags & DT_SHORT )
{ {
if( pField->flags & DT_SIGNED ) if( signbit )
{ {
fromF = *(int16_t *)((int8_t *)from + pField->offset ); fromF = *(int16_t *)((int8_t *)from + pField->offset );
toF = *(int16_t *)((int8_t *)to + pField->offset ); toF = *(int16_t *)((int8_t *)to + pField->offset );
@ -996,18 +996,18 @@ static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, doubl
toF = *(uint16_t *)((int8_t *)to + pField->offset ); toF = *(uint16_t *)((int8_t *)to + pField->offset );
} }
fromF = Delta_ClampIntegerField( pField, fromF, bSigned, pField->bits ); fromF = Delta_ClampIntegerField( pField, fromF, signbit, pField->bits );
toF = Delta_ClampIntegerField( pField, toF, bSigned, pField->bits ); toF = Delta_ClampIntegerField( pField, toF, signbit, pField->bits );
if( !Q_equal( pField->multiplier, 1.0 ) ) if( !Q_equal(pField->multiplier, 1.0f ))
fromF *= pField->multiplier; fromF *= pField->multiplier;
if( !Q_equal( pField->multiplier, 1.0 ) ) if( !Q_equal( pField->multiplier, 1.0f ))
toF *= pField->multiplier; toF *= pField->multiplier;
} }
else if( pField->flags & DT_INTEGER ) else if( pField->flags & DT_INTEGER )
{ {
if( pField->flags & DT_SIGNED ) if( signbit )
{ {
fromF = *(int32_t *)((int8_t *)from + pField->offset ); fromF = *(int32_t *)((int8_t *)from + pField->offset );
toF = *(int32_t *)((int8_t *)to + pField->offset ); toF = *(int32_t *)((int8_t *)to + pField->offset );
@ -1017,11 +1017,13 @@ static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, doubl
fromF = *(uint32_t *)((int8_t *)from + pField->offset ); fromF = *(uint32_t *)((int8_t *)from + pField->offset );
toF = *(uint32_t *)((int8_t *)to + pField->offset ); toF = *(uint32_t *)((int8_t *)to + pField->offset );
} }
fromF = Delta_ClampIntegerField( pField, fromF, bSigned, pField->bits ); fromF = Delta_ClampIntegerField( pField, fromF, signbit, pField->bits );
toF = Delta_ClampIntegerField( pField, toF, bSigned, pField->bits ); toF = Delta_ClampIntegerField( pField, toF, signbit, pField->bits );
if( !Q_equal( pField->multiplier, 1.0 ) )
if( !Q_equal(pField->multiplier, 1.0f ))
fromF *= pField->multiplier; fromF *= pField->multiplier;
if( !Q_equal( pField->multiplier, 1.0 ) )
if( !Q_equal( pField->multiplier, 1.0f ))
toF *= pField->multiplier; toF *= pField->multiplier;
} }
else if( pField->flags & ( DT_ANGLE|DT_FLOAT )) else if( pField->flags & ( DT_ANGLE|DT_FLOAT ))
@ -1032,8 +1034,8 @@ static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, doubl
} }
else if( pField->flags & DT_TIMEWINDOW_8 ) else if( pField->flags & DT_TIMEWINDOW_8 )
{ {
val_a = Q_rint((*(float *)((byte *)from + pField->offset )) * 100.0 ); val_a = Q_rint((*(float *)((byte *)from + pField->offset )) * 100.0f );
val_b = Q_rint((*(float *)((byte *)to + pField->offset )) * 100.0 ); val_b = Q_rint((*(float *)((byte *)to + pField->offset )) * 100.0f );
val_a -= Q_rint(timebase * 100.0); val_a -= Q_rint(timebase * 100.0);
val_b -= Q_rint(timebase * 100.0); val_b -= Q_rint(timebase * 100.0);
fromF = FloatAsInt( val_a ); fromF = FloatAsInt( val_a );
@ -1044,7 +1046,7 @@ static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, doubl
val_a = (*(float *)((byte *)from + pField->offset )); val_a = (*(float *)((byte *)from + pField->offset ));
val_b = (*(float *)((byte *)to + pField->offset )); val_b = (*(float *)((byte *)to + pField->offset ));
if( !Q_equal( pField->multiplier, 1.0 ) ) if( !Q_equal( pField->multiplier, 1.0f ))
{ {
val_a *= pField->multiplier; val_a *= pField->multiplier;
val_b *= pField->multiplier; val_b *= pField->multiplier;
@ -1070,7 +1072,7 @@ static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, doubl
toF = Q_strcmp( s1, s2 ); toF = Q_strcmp( s1, s2 );
} }
return ( fromF == toF ) ? true : false; return fromF == toF;
} }
/* /*

Loading…
Cancel
Save