mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-26 23:04:21 +00:00
Revert "engine: common: net_encode: rewrite Delta_CompareField to be more efficient"
This reverts commit 82addf11bb325d100b676d01f5a001c95d8e1dc1.
This commit is contained in:
parent
acc113309c
commit
bdc2390d41
@ -948,41 +948,129 @@ 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 )
|
||||||
{
|
{
|
||||||
uint8_t *from_field = (uint8_t *)from + pField->offset;
|
qboolean bSigned = ( pField->flags & DT_SIGNED ) ? true : false;
|
||||||
uint8_t *to_field = (uint8_t *)to + pField->offset;
|
float val_a, val_b;
|
||||||
uint field_type = pField->flags & ~DT_SIGNED;
|
int fromF, toF;
|
||||||
int fromF;
|
|
||||||
int toF;
|
Assert( pField != NULL );
|
||||||
|
Assert( from != NULL );
|
||||||
|
Assert( to != NULL );
|
||||||
|
|
||||||
if( pField->bInactive )
|
if( pField->bInactive )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
switch( field_type )
|
fromF = toF = 0;
|
||||||
|
|
||||||
|
if( pField->flags & DT_BYTE )
|
||||||
{
|
{
|
||||||
case DT_BYTE:
|
if( pField->flags & DT_SIGNED )
|
||||||
return *to_field == *from_field;
|
{
|
||||||
case DT_SHORT:
|
fromF = *(int8_t *)((int8_t *)from + pField->offset );
|
||||||
return *(uint16_t *)to_field == *(uint16_t *)from_field;
|
toF = *(int8_t *)((int8_t *)to + pField->offset );
|
||||||
case DT_INTEGER:
|
}
|
||||||
case DT_ANGLE:
|
else
|
||||||
case DT_FLOAT:
|
{
|
||||||
return *(uint32_t *)to_field == *(uint32_t *)from_field;
|
fromF = *(uint8_t *)((int8_t *)from + pField->offset );
|
||||||
case DT_TIMEWINDOW_8:
|
toF = *(uint8_t *)((int8_t *)to + pField->offset );
|
||||||
fromF = (int)((*(float *)from_field) * 100.0f );
|
}
|
||||||
toF = (int)((*(float *)to_field) * 100.0f );
|
|
||||||
return toF == fromF;
|
fromF = Delta_ClampIntegerField( pField, fromF, bSigned, pField->bits );
|
||||||
case DT_TIMEWINDOW_BIG:
|
toF = Delta_ClampIntegerField( pField, toF, bSigned, pField->bits );
|
||||||
fromF = (int)((*(float *)from_field) * pField->multiplier );
|
|
||||||
toF = (int)((*(float *)to_field) * pField->multiplier );
|
if( !Q_equal(pField->multiplier, 1.0) )
|
||||||
return toF == fromF;
|
fromF *= pField->multiplier;
|
||||||
case DT_STRING:
|
|
||||||
return Q_strcmp( to_field, from_field ) == 0;
|
if( !Q_equal( pField->multiplier, 1.0 ) )
|
||||||
default:
|
toF *= pField->multiplier;
|
||||||
break;
|
}
|
||||||
|
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
Con_Reportf( S_ERROR "bad field %s type: %d\n", pField->name, pField->flags );
|
return ( fromF == toF ) ? true : false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user