mirror of
https://github.com/FWGS/xash3d-fwgs
synced 2025-01-26 02:20:54 +01:00
engine: common: net_encode: rewrite Delta_CompareField to be more efficient
This commit is contained in:
parent
aee5e46516
commit
82addf11bb
@ -941,129 +941,41 @@ 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;
|
uint8_t *from_field = (uint8_t *)from + pField->offset;
|
||||||
float val_a, val_b;
|
uint8_t *to_field = (uint8_t *)to + pField->offset;
|
||||||
int fromF, toF;
|
uint field_type = pField->flags & ~DT_SIGNED;
|
||||||
|
int fromF;
|
||||||
Assert( pField != NULL );
|
int toF;
|
||||||
Assert( from != NULL );
|
|
||||||
Assert( to != NULL );
|
|
||||||
|
|
||||||
if( pField->bInactive )
|
if( pField->bInactive )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
fromF = toF = 0;
|
switch( field_type )
|
||||||
|
|
||||||
if( pField->flags & DT_BYTE )
|
|
||||||
{
|
{
|
||||||
if( pField->flags & DT_SIGNED )
|
case DT_BYTE:
|
||||||
{
|
return *to_field == *from_field;
|
||||||
fromF = *(int8_t *)((int8_t *)from + pField->offset );
|
case DT_SHORT:
|
||||||
toF = *(int8_t *)((int8_t *)to + pField->offset );
|
return *(uint16_t *)to_field == *(uint16_t *)from_field;
|
||||||
}
|
case DT_INTEGER:
|
||||||
else
|
case DT_ANGLE:
|
||||||
{
|
case DT_FLOAT:
|
||||||
fromF = *(uint8_t *)((int8_t *)from + pField->offset );
|
return *(uint32_t *)to_field == *(uint32_t *)from_field;
|
||||||
toF = *(uint8_t *)((int8_t *)to + pField->offset );
|
case DT_TIMEWINDOW_8:
|
||||||
|
fromF = (int)((*(float *)from_field) * 100.0f );
|
||||||
|
toF = (int)((*(float *)to_field) * 100.0f );
|
||||||
|
return toF == fromF;
|
||||||
|
case DT_TIMEWINDOW_BIG:
|
||||||
|
fromF = (int)((*(float *)from_field) * pField->multiplier );
|
||||||
|
toF = (int)((*(float *)to_field) * pField->multiplier );
|
||||||
|
return toF == fromF;
|
||||||
|
case DT_STRING:
|
||||||
|
return Q_strcmp( to_field, from_field ) == 0;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromF = Delta_ClampIntegerField( pField, fromF, bSigned, pField->bits );
|
Con_Reportf( S_ERROR "bad field %s type: %d\n", pField->name, pField->flags );
|
||||||
toF = Delta_ClampIntegerField( pField, toF, bSigned, pField->bits );
|
return false;
|
||||||
|
|
||||||
if( !Q_equal(pField->multiplier, 1.0) )
|
|
||||||
fromF *= pField->multiplier;
|
|
||||||
|
|
||||||
if( !Q_equal( pField->multiplier, 1.0 ) )
|
|
||||||
toF *= pField->multiplier;
|
|
||||||
}
|
|
||||||
else if( pField->flags & DT_SHORT )
|
|
||||||
{
|
|
||||||
if( pField->flags & DT_SIGNED )
|
|
||||||
{
|
|
||||||
fromF = *(int16_t *)((int8_t *)from + pField->offset );
|
|
||||||
toF = *(int16_t *)((int8_t *)to + pField->offset );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fromF = *(uint16_t *)((int8_t *)from + pField->offset );
|
|
||||||
toF = *(uint16_t *)((int8_t *)to + pField->offset );
|
|
||||||
}
|
|
||||||
|
|
||||||
fromF = Delta_ClampIntegerField( pField, fromF, bSigned, pField->bits );
|
|
||||||
toF = Delta_ClampIntegerField( pField, toF, bSigned, pField->bits );
|
|
||||||
|
|
||||||
if( !Q_equal( pField->multiplier, 1.0 ) )
|
|
||||||
fromF *= pField->multiplier;
|
|
||||||
|
|
||||||
if( !Q_equal( pField->multiplier, 1.0 ) )
|
|
||||||
toF *= pField->multiplier;
|
|
||||||
}
|
|
||||||
else if( pField->flags & DT_INTEGER )
|
|
||||||
{
|
|
||||||
if( pField->flags & DT_SIGNED )
|
|
||||||
{
|
|
||||||
fromF = *(int32_t *)((int8_t *)from + pField->offset );
|
|
||||||
toF = *(int32_t *)((int8_t *)to + pField->offset );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fromF = *(uint32_t *)((int8_t *)from + pField->offset );
|
|
||||||
toF = *(uint32_t *)((int8_t *)to + pField->offset );
|
|
||||||
}
|
|
||||||
fromF = Delta_ClampIntegerField( pField, fromF, bSigned, pField->bits );
|
|
||||||
toF = Delta_ClampIntegerField( pField, toF, bSigned, pField->bits );
|
|
||||||
if( !Q_equal( pField->multiplier, 1.0 ) )
|
|
||||||
fromF *= pField->multiplier;
|
|
||||||
if( !Q_equal( pField->multiplier, 1.0 ) )
|
|
||||||
toF *= pField->multiplier;
|
|
||||||
}
|
|
||||||
else if( pField->flags & ( DT_ANGLE|DT_FLOAT ))
|
|
||||||
{
|
|
||||||
// don't convert floats to integers
|
|
||||||
fromF = *((int *)((byte *)from + pField->offset ));
|
|
||||||
toF = *((int *)((byte *)to + pField->offset ));
|
|
||||||
}
|
|
||||||
else if( pField->flags & DT_TIMEWINDOW_8 )
|
|
||||||
{
|
|
||||||
val_a = Q_rint((*(float *)((byte *)from + pField->offset )) * 100.0 );
|
|
||||||
val_b = Q_rint((*(float *)((byte *)to + pField->offset )) * 100.0 );
|
|
||||||
val_a -= Q_rint(timebase * 100.0);
|
|
||||||
val_b -= Q_rint(timebase * 100.0);
|
|
||||||
fromF = FloatAsInt( val_a );
|
|
||||||
toF = FloatAsInt( val_b );
|
|
||||||
}
|
|
||||||
else if( pField->flags & DT_TIMEWINDOW_BIG )
|
|
||||||
{
|
|
||||||
val_a = (*(float *)((byte *)from + pField->offset ));
|
|
||||||
val_b = (*(float *)((byte *)to + pField->offset ));
|
|
||||||
|
|
||||||
if( !Q_equal( pField->multiplier, 1.0 ) )
|
|
||||||
{
|
|
||||||
val_a *= pField->multiplier;
|
|
||||||
val_b *= pField->multiplier;
|
|
||||||
val_a = (timebase * pField->multiplier) - val_a;
|
|
||||||
val_b = (timebase * pField->multiplier) - val_b;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
val_a = timebase - val_a;
|
|
||||||
val_b = timebase - val_b;
|
|
||||||
}
|
|
||||||
|
|
||||||
fromF = FloatAsInt( val_a );
|
|
||||||
toF = FloatAsInt( val_b );
|
|
||||||
}
|
|
||||||
else if( pField->flags & DT_STRING )
|
|
||||||
{
|
|
||||||
// compare strings
|
|
||||||
char *s1 = (char *)((byte *)from + pField->offset );
|
|
||||||
char *s2 = (char *)((byte *)to + pField->offset );
|
|
||||||
|
|
||||||
// 0 is equal, otherwise not equal
|
|
||||||
toF = Q_strcmp( s1, s2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( fromF == toF ) ? true : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user