|
|
@ -312,7 +312,7 @@ delta_info_t *Delta_FindStruct( const char *name ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
if( !name || !name[0] ) |
|
|
|
if( !COM_CheckString( name )) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < NUM_FIELDS( dt_info ); i++ ) |
|
|
|
for( i = 0; i < NUM_FIELDS( dt_info ); i++ ) |
|
|
@ -431,8 +431,12 @@ qboolean Delta_AddField( const char *pStructName, const char *pName, int flags, |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( !Q_strcmp( pField->name, pName )) |
|
|
|
if( !Q_strcmp( pField->name, pName )) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Con_Reportf( "Delta_Add: %s->%s already existing\n", pStructName, pName ); |
|
|
|
// update existed field
|
|
|
|
return false; // field already exist
|
|
|
|
pField->flags = flags; |
|
|
|
|
|
|
|
pField->bits = bits; |
|
|
|
|
|
|
|
pField->multiplier = mul; |
|
|
|
|
|
|
|
pField->post_multiplier = post_mul; |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -474,7 +478,7 @@ void Delta_WriteTableField( sizebuf_t *msg, int tableIndex, const delta_t *pFiel |
|
|
|
|
|
|
|
|
|
|
|
Assert( pField != NULL ); |
|
|
|
Assert( pField != NULL ); |
|
|
|
|
|
|
|
|
|
|
|
if( !pField->name || !*pField->name ) |
|
|
|
if( !COM_CheckString( pField->name )) |
|
|
|
return; // not initialized ?
|
|
|
|
return; // not initialized ?
|
|
|
|
|
|
|
|
|
|
|
|
dt = Delta_FindStructByIndex( tableIndex ); |
|
|
|
dt = Delta_FindStructByIndex( tableIndex ); |
|
|
@ -626,7 +630,6 @@ qboolean Delta_ParseField( char **delta_script, const delta_field_t *pInfo, delt |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// read delta-bits
|
|
|
|
// read delta-bits
|
|
|
|
|
|
|
|
|
|
|
|
if(( *delta_script = COM_ParseFile( *delta_script, token )) == NULL ) |
|
|
|
if(( *delta_script = COM_ParseFile( *delta_script, token )) == NULL ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Con_DPrintf( S_ERROR "Delta_ReadField: %s field bits argument is missing\n", pField->name ); |
|
|
|
Con_DPrintf( S_ERROR "Delta_ReadField: %s field bits argument is missing\n", pField->name ); |
|
|
@ -781,13 +784,8 @@ void Delta_InitFields( void ) |
|
|
|
|
|
|
|
|
|
|
|
Delta_ParseTable( &pfile, dt, encodeDll, encodeFunc ); |
|
|
|
Delta_ParseTable( &pfile, dt, encodeDll, encodeFunc ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Mem_Free( afile ); |
|
|
|
Mem_Free( afile ); |
|
|
|
#if 0 |
|
|
|
|
|
|
|
// adding some required fields that user may forget or don't know how to specified
|
|
|
|
|
|
|
|
Delta_AddField( "event_t", "velocity[0]", DT_SIGNED | DT_FLOAT, 16, 8.0f, 1.0f ); |
|
|
|
|
|
|
|
Delta_AddField( "event_t", "velocity[1]", DT_SIGNED | DT_FLOAT, 16, 8.0f, 1.0f ); |
|
|
|
|
|
|
|
Delta_AddField( "event_t", "velocity[2]", DT_SIGNED | DT_FLOAT, 16, 8.0f, 1.0f ); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Delta_Init( void ) |
|
|
|
void Delta_Init( void ) |
|
|
@ -894,73 +892,18 @@ Delta_ClampIntegerField |
|
|
|
prevent data to out of range |
|
|
|
prevent data to out of range |
|
|
|
===================== |
|
|
|
===================== |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int Delta_ClampIntegerField( int iValue, qboolean bSigned, int bits ) |
|
|
|
int Delta_ClampIntegerField( delta_t *pField, int iValue, qboolean bSigned, int numbits ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch( bits ) |
|
|
|
#ifdef _DEBUG |
|
|
|
|
|
|
|
if( numbits < 32 && abs( iValue ) >= (uint)BIT( numbits )) |
|
|
|
|
|
|
|
Msg( "%s %d overflow %d\n", pField->name, abs( iValue ), (uint)BIT( numbits )); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
if( numbits < 32 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case 1: |
|
|
|
int signbits = bSigned ? (numbits - 1) : numbits; |
|
|
|
iValue = bound( 0, (byte)iValue, 1 ); |
|
|
|
int maxnum = BIT( signbits ) - 1; |
|
|
|
break; |
|
|
|
int minnum = bSigned ? -maxnum : 0; |
|
|
|
case 2: |
|
|
|
iValue = bound( minnum, iValue, maxnum ); |
|
|
|
if( bSigned ) iValue = bound( -2, (short)iValue, 1 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 3 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 3: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -4, (short)iValue, 3 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 7 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 4: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -8, (short)iValue, 7 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 15 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 5: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -16, (short)iValue, 15 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 31 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 6: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -32, (short)iValue, 31 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 63 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 7: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -64, (short)iValue, 63 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 127 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 8: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -128, (short)iValue, 127 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 255 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 9: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -256, (short)iValue, 255 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 511 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 10: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -512, (short)iValue, 511 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 1023 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 11: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -1024, (short)iValue, 1023 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 2047 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 12: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -2048, (short)iValue, 2047 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 4095 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 13: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -4096, (short)iValue, 4095 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 8191 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 14: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -8192, (short)iValue, 8191 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 16383 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 15: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -16384, (short)iValue, 16383 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 32767 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 16: |
|
|
|
|
|
|
|
if( bSigned ) iValue = bound( -32768, (short)iValue, 32767 ); |
|
|
|
|
|
|
|
else iValue = bound( 0, (word)iValue, 65535 ); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return iValue; // clamped;
|
|
|
|
return iValue; // clamped;
|
|
|
@ -1002,8 +945,8 @@ qboolean Delta_CompareField( delta_t *pField, void *from, void *to, float timeba |
|
|
|
toF = *(byte *)((byte *)to + pField->offset ); |
|
|
|
toF = *(byte *)((byte *)to + pField->offset ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fromF = Delta_ClampIntegerField( fromF, bSigned, pField->bits ); |
|
|
|
fromF = Delta_ClampIntegerField( pField, fromF, bSigned, pField->bits ); |
|
|
|
toF = Delta_ClampIntegerField( toF, bSigned, pField->bits ); |
|
|
|
toF = Delta_ClampIntegerField( pField, toF, bSigned, pField->bits ); |
|
|
|
if( pField->multiplier != 1.0f ) fromF *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) fromF *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) toF *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) toF *= pField->multiplier; |
|
|
|
} |
|
|
|
} |
|
|
@ -1020,8 +963,8 @@ qboolean Delta_CompareField( delta_t *pField, void *from, void *to, float timeba |
|
|
|
toF = *(word *)((byte *)to + pField->offset ); |
|
|
|
toF = *(word *)((byte *)to + pField->offset ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fromF = Delta_ClampIntegerField( fromF, bSigned, pField->bits ); |
|
|
|
fromF = Delta_ClampIntegerField( pField, fromF, bSigned, pField->bits ); |
|
|
|
toF = Delta_ClampIntegerField( toF, bSigned, pField->bits ); |
|
|
|
toF = Delta_ClampIntegerField( pField, toF, bSigned, pField->bits ); |
|
|
|
if( pField->multiplier != 1.0f ) fromF *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) fromF *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) toF *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) toF *= pField->multiplier; |
|
|
|
} |
|
|
|
} |
|
|
@ -1038,8 +981,8 @@ qboolean Delta_CompareField( delta_t *pField, void *from, void *to, float timeba |
|
|
|
toF = *(uint *)((byte *)to + pField->offset ); |
|
|
|
toF = *(uint *)((byte *)to + pField->offset ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fromF = Delta_ClampIntegerField( fromF, bSigned, pField->bits ); |
|
|
|
fromF = Delta_ClampIntegerField( pField, fromF, bSigned, pField->bits ); |
|
|
|
toF = Delta_ClampIntegerField( toF, bSigned, pField->bits ); |
|
|
|
toF = Delta_ClampIntegerField( pField, toF, bSigned, pField->bits ); |
|
|
|
if( pField->multiplier != 1.0f ) fromF *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) fromF *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) toF *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) toF *= pField->multiplier; |
|
|
|
} |
|
|
|
} |
|
|
@ -1175,21 +1118,21 @@ qboolean Delta_WriteField( sizebuf_t *msg, delta_t *pField, void *from, void *to |
|
|
|
if( pField->flags & DT_BYTE ) |
|
|
|
if( pField->flags & DT_BYTE ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
iValue = *(byte *)((byte *)to + pField->offset ); |
|
|
|
iValue = *(byte *)((byte *)to + pField->offset ); |
|
|
|
iValue = Delta_ClampIntegerField( iValue, bSigned, pField->bits ); |
|
|
|
iValue = Delta_ClampIntegerField( pField, iValue, bSigned, pField->bits ); |
|
|
|
if( pField->multiplier != 1.0f ) iValue *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) iValue *= pField->multiplier; |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
} |
|
|
|
} |
|
|
|
else if( pField->flags & DT_SHORT ) |
|
|
|
else if( pField->flags & DT_SHORT ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
iValue = *(word *)((byte *)to + pField->offset ); |
|
|
|
iValue = *(word *)((byte *)to + pField->offset ); |
|
|
|
iValue = Delta_ClampIntegerField( iValue, bSigned, pField->bits ); |
|
|
|
iValue = Delta_ClampIntegerField( pField, iValue, bSigned, pField->bits ); |
|
|
|
if( pField->multiplier != 1.0f ) iValue *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) iValue *= pField->multiplier; |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
} |
|
|
|
} |
|
|
|
else if( pField->flags & DT_INTEGER ) |
|
|
|
else if( pField->flags & DT_INTEGER ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
iValue = *(uint *)((byte *)to + pField->offset ); |
|
|
|
iValue = *(uint *)((byte *)to + pField->offset ); |
|
|
|
iValue = Delta_ClampIntegerField( iValue, bSigned, pField->bits ); |
|
|
|
iValue = Delta_ClampIntegerField( pField, iValue, bSigned, pField->bits ); |
|
|
|
if( pField->multiplier != 1.0f ) iValue *= pField->multiplier; |
|
|
|
if( pField->multiplier != 1.0f ) iValue *= pField->multiplier; |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
} |
|
|
|
} |
|
|
@ -1197,6 +1140,7 @@ qboolean Delta_WriteField( sizebuf_t *msg, delta_t *pField, void *from, void *to |
|
|
|
{ |
|
|
|
{ |
|
|
|
flValue = *(float *)((byte *)to + pField->offset ); |
|
|
|
flValue = *(float *)((byte *)to + pField->offset ); |
|
|
|
iValue = (int)(flValue * pField->multiplier); |
|
|
|
iValue = (int)(flValue * pField->multiplier); |
|
|
|
|
|
|
|
iValue = Delta_ClampIntegerField( pField, iValue, bSigned, pField->bits ); |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
} |
|
|
|
} |
|
|
|
else if( pField->flags & DT_ANGLE ) |
|
|
|
else if( pField->flags & DT_ANGLE ) |
|
|
@ -1212,7 +1156,7 @@ qboolean Delta_WriteField( sizebuf_t *msg, delta_t *pField, void *from, void *to |
|
|
|
flValue = *(float *)((byte *)to + pField->offset ); |
|
|
|
flValue = *(float *)((byte *)to + pField->offset ); |
|
|
|
flTime = Q_rint( timebase * 100.0f ) - Q_rint( flValue * 100.0f ); |
|
|
|
flTime = Q_rint( timebase * 100.0f ) - Q_rint( flValue * 100.0f ); |
|
|
|
iValue = (uint)abs( flTime ); |
|
|
|
iValue = (uint)abs( flTime ); |
|
|
|
|
|
|
|
iValue = Delta_ClampIntegerField( pField, iValue, bSigned, pField->bits ); |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
} |
|
|
|
} |
|
|
|
else if( pField->flags & DT_TIMEWINDOW_BIG ) |
|
|
|
else if( pField->flags & DT_TIMEWINDOW_BIG ) |
|
|
@ -1220,7 +1164,7 @@ qboolean Delta_WriteField( sizebuf_t *msg, delta_t *pField, void *from, void *to |
|
|
|
flValue = *(float *)((byte *)to + pField->offset ); |
|
|
|
flValue = *(float *)((byte *)to + pField->offset ); |
|
|
|
flTime = Q_rint( timebase * pField->multiplier ) - Q_rint( flValue * pField->multiplier ); |
|
|
|
flTime = Q_rint( timebase * pField->multiplier ) - Q_rint( flValue * pField->multiplier ); |
|
|
|
iValue = (uint)abs( flTime ); |
|
|
|
iValue = (uint)abs( flTime ); |
|
|
|
|
|
|
|
iValue = Delta_ClampIntegerField( pField, iValue, bSigned, pField->bits ); |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
MSG_WriteBitLong( msg, iValue, pField->bits, bSigned ); |
|
|
|
} |
|
|
|
} |
|
|
|
else if( pField->flags & DT_STRING ) |
|
|
|
else if( pField->flags & DT_STRING ) |
|
|
|