mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-23 05:14:15 +00:00
engine: common: net_encode: fix Delta_CompareField to include integer clamping, in case if no updates happen in significant bits
This commit is contained in:
parent
f5b9826fd9
commit
6a7b330463
@ -948,6 +948,7 @@ static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, doubl
|
|||||||
uint8_t *from_field = (uint8_t *)from + pField->offset;
|
uint8_t *from_field = (uint8_t *)from + pField->offset;
|
||||||
uint8_t *to_field = (uint8_t *)to + pField->offset;
|
uint8_t *to_field = (uint8_t *)to + pField->offset;
|
||||||
uint field_type = pField->flags & ~DT_SIGNED;
|
uint field_type = pField->flags & ~DT_SIGNED;
|
||||||
|
int signbit = FBitSet( pField->flags, DT_SIGNED ) ? 1 : 0;
|
||||||
int fromF;
|
int fromF;
|
||||||
int toF;
|
int toF;
|
||||||
|
|
||||||
@ -957,29 +958,68 @@ static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, doubl
|
|||||||
switch( field_type )
|
switch( field_type )
|
||||||
{
|
{
|
||||||
case DT_BYTE:
|
case DT_BYTE:
|
||||||
return *to_field == *from_field;
|
if( signbit )
|
||||||
|
{
|
||||||
|
fromF = *(int8_t *)from_field;
|
||||||
|
toF = *(int8_t *)to_field;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fromF = *(uint8_t *)from_field;
|
||||||
|
toF = *(uint8_t *)to_field;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case DT_SHORT:
|
case DT_SHORT:
|
||||||
return *(uint16_t *)to_field == *(uint16_t *)from_field;
|
if( signbit )
|
||||||
|
{
|
||||||
|
fromF = *(int16_t *)from_field;
|
||||||
|
toF = *(int16_t *)to_field;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fromF = *(uint16_t *)from_field;
|
||||||
|
toF = *(uint16_t *)to_field;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case DT_INTEGER:
|
case DT_INTEGER:
|
||||||
|
if( signbit )
|
||||||
|
{
|
||||||
|
fromF = *(int32_t *)from_field;
|
||||||
|
toF = *(int32_t *)to_field;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fromF = *(uint32_t *)from_field;
|
||||||
|
toF = *(uint32_t *)to_field;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case DT_ANGLE:
|
case DT_ANGLE:
|
||||||
case DT_FLOAT:
|
case DT_FLOAT:
|
||||||
return *(uint32_t *)to_field == *(uint32_t *)from_field;
|
return *(uint32_t *)to_field == *(uint32_t *)from_field;
|
||||||
case DT_TIMEWINDOW_8:
|
case DT_TIMEWINDOW_8:
|
||||||
fromF = (int)((*(float *)from_field) * 100.0f );
|
fromF = Q_rint((*(float *)from_field) * 100.0f );
|
||||||
toF = (int)((*(float *)to_field) * 100.0f );
|
toF = Q_rint((*(float *)to_field) * 100.0f );
|
||||||
return toF == fromF;
|
return fromF == toF;
|
||||||
case DT_TIMEWINDOW_BIG:
|
case DT_TIMEWINDOW_BIG:
|
||||||
fromF = (int)((*(float *)from_field) * pField->multiplier );
|
fromF = Q_rint((*(float *)from_field) * 1000.0f );
|
||||||
toF = (int)((*(float *)to_field) * pField->multiplier );
|
toF = Q_rint((*(float *)to_field) * 1000.0f );
|
||||||
return toF == fromF;
|
return fromF == toF;
|
||||||
case DT_STRING:
|
case DT_STRING:
|
||||||
return Q_strcmp( to_field, from_field ) == 0;
|
return Q_strcmp( to_field, from_field ) == 0;
|
||||||
default:
|
default:
|
||||||
break;
|
Con_Reportf( S_ERROR "bad field %s type: %d\n", pField->name, pField->flags );
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Con_Reportf( S_ERROR "bad field %s type: %d\n", pField->name, pField->flags );
|
// if fields are equal, no need to clamp, return immediately
|
||||||
return false;
|
if( toF == fromF )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// clamp integer fields
|
||||||
|
fromF = Delta_ClampIntegerField( pField, fromF, signbit, pField->bits );
|
||||||
|
toF = Delta_ClampIntegerField( pField, toF, signbit, pField->bits );
|
||||||
|
|
||||||
|
return toF == fromF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user