Browse Source

engine: common: net_encode: cosmetic changes, static-ize functions, move private macros

pull/2/head
Alibek Omarov 1 year ago
parent
commit
8d6ac3fad4
  1. 64
      engine/common/net_encode.c
  2. 21
      engine/common/net_encode.h

64
engine/common/net_encode.c

@ -28,6 +28,26 @@ GNU General Public License for more details.
#define DELTA_PATH "delta.lst" #define DELTA_PATH "delta.lst"
#define DT_BYTE BIT( 0 ) // A byte
#define DT_SHORT BIT( 1 ) // 2 byte field
#define DT_FLOAT BIT( 2 ) // A floating point field
#define DT_INTEGER BIT( 3 ) // 4 byte integer
#define DT_ANGLE BIT( 4 ) // A floating point angle ( will get masked correctly )
#define DT_TIMEWINDOW_8 BIT( 5 ) // A floating point timestamp, relative to sv.time
#define DT_TIMEWINDOW_BIG BIT( 6 ) // and re-encoded on the client relative to the client's clock
#define DT_STRING BIT( 7 ) // A null terminated string, sent as 8 byte chars
#define DT_SIGNED BIT( 8 ) // sign modificator
#define NUM_FIELDS( x ) ((sizeof( x ) / sizeof( x[0] )) - 1)
// helper macroses
#define ENTS_DEF( x ) #x, offsetof( entity_state_t, x ), sizeof( ((entity_state_t *)0)->x )
#define UCMD_DEF( x ) #x, offsetof( usercmd_t, x ), sizeof( ((usercmd_t *)0)->x )
#define EVNT_DEF( x ) #x, offsetof( event_args_t, x ), sizeof( ((event_args_t *)0)->x )
#define PHYS_DEF( x ) #x, offsetof( movevars_t, x ), sizeof( ((movevars_t *)0)->x )
#define CLDT_DEF( x ) #x, offsetof( clientdata_t, x ), sizeof( ((clientdata_t *)0)->x )
#define WPDT_DEF( x ) #x, offsetof( weapon_data_t, x ), sizeof( ((weapon_data_t *)0)->x )
static qboolean delta_init = false; static qboolean delta_init = false;
// list of all the struct names // list of all the struct names
@ -308,7 +328,7 @@ static delta_info_t dt_info[] =
{ NULL }, { NULL },
}; };
delta_info_t *Delta_FindStruct( const char *name ) static delta_info_t *Delta_FindStruct( const char *name )
{ {
int i; int i;
@ -340,7 +360,7 @@ delta_info_t *Delta_FindStructByIndex( int index )
return &dt_info[index]; return &dt_info[index];
} }
delta_info_t *Delta_FindStructByEncoder( const char *encoderName ) static delta_info_t *Delta_FindStructByEncoder( const char *encoderName )
{ {
int i; int i;
@ -356,7 +376,7 @@ delta_info_t *Delta_FindStructByEncoder( const char *encoderName )
return NULL; return NULL;
} }
delta_info_t *Delta_FindStructByDelta( const delta_t *pFields ) static delta_info_t *Delta_FindStructByDelta( const delta_t *pFields )
{ {
int i; int i;
@ -371,7 +391,7 @@ delta_info_t *Delta_FindStructByDelta( const delta_t *pFields )
return NULL; return NULL;
} }
void Delta_CustomEncode( delta_info_t *dt, const void *from, const void *to ) static void Delta_CustomEncode( delta_info_t *dt, const void *from, const void *to )
{ {
int i; int i;
@ -387,7 +407,7 @@ void Delta_CustomEncode( delta_info_t *dt, const void *from, const void *to )
} }
} }
delta_field_t *Delta_FindFieldInfo( const delta_field_t *pInfo, const char *fieldName ) static delta_field_t *Delta_FindFieldInfo( const delta_field_t *pInfo, const char *fieldName )
{ {
if( !fieldName || !*fieldName ) if( !fieldName || !*fieldName )
return NULL; return NULL;
@ -400,7 +420,7 @@ delta_field_t *Delta_FindFieldInfo( const delta_field_t *pInfo, const char *fiel
return NULL; return NULL;
} }
int Delta_IndexForFieldInfo( const delta_field_t *pInfo, const char *fieldName ) static int Delta_IndexForFieldInfo( const delta_field_t *pInfo, const char *fieldName )
{ {
int i; int i;
@ -415,7 +435,7 @@ int Delta_IndexForFieldInfo( const delta_field_t *pInfo, const char *fieldName )
return -1; return -1;
} }
qboolean Delta_AddField( const char *pStructName, const char *pName, int flags, int bits, float mul, float post_mul ) static qboolean Delta_AddField( const char *pStructName, const char *pName, int flags, int bits, float mul, float post_mul )
{ {
delta_info_t *dt; delta_info_t *dt;
delta_field_t *pFieldInfo; delta_field_t *pFieldInfo;
@ -494,14 +514,14 @@ void Delta_WriteTableField( sizebuf_t *msg, int tableIndex, const delta_t *pFiel
MSG_WriteUBitLong( msg, pField->bits - 1, 5 ); // max received value is 32 (32 bit) MSG_WriteUBitLong( msg, pField->bits - 1, 5 ); // max received value is 32 (32 bit)
// multipliers is null-compressed // multipliers is null-compressed
if( !Q_equal(pField->multiplier, 1.0f) ) if( !Q_equal( pField->multiplier, 1.0f ))
{ {
MSG_WriteOneBit( msg, 1 ); MSG_WriteOneBit( msg, 1 );
MSG_WriteFloat( msg, pField->multiplier ); MSG_WriteFloat( msg, pField->multiplier );
} }
else MSG_WriteOneBit( msg, 0 ); else MSG_WriteOneBit( msg, 0 );
if( !Q_equal(pField->post_multiplier, 1.0f) ) if( !Q_equal( pField->post_multiplier, 1.0f ))
{ {
MSG_WriteOneBit( msg, 1 ); MSG_WriteOneBit( msg, 1 );
MSG_WriteFloat( msg, pField->post_multiplier ); MSG_WriteFloat( msg, pField->post_multiplier );
@ -555,7 +575,7 @@ void Delta_ParseTableField( sizebuf_t *msg )
Delta_AddField( dt->pName, pName, flags, bits, mul, post_mul ); Delta_AddField( dt->pName, pName, flags, bits, mul, post_mul );
} }
qboolean Delta_ParseField( char **delta_script, const delta_field_t *pInfo, delta_t *pField, qboolean bPost ) static qboolean Delta_ParseField( char **delta_script, const delta_field_t *pInfo, delta_t *pField, qboolean bPost )
{ {
string token; string token;
delta_field_t *pFieldInfo; delta_field_t *pFieldInfo;
@ -633,7 +653,7 @@ 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, sizeof( token ))) == NULL ) if(( *delta_script = COM_ParseFile( *delta_script, token, sizeof( token ))) == NULL )
{ {
Con_DPrintf( S_ERROR "Delta_ReadField: %s field bits argument is missing\n", pField->name ); Con_DPrintf( S_ERROR "Delta_ParseField: %s field bits argument is missing\n", pField->name );
return false; return false;
} }
@ -642,14 +662,14 @@ qboolean Delta_ParseField( char **delta_script, const delta_field_t *pInfo, delt
*delta_script = COM_ParseFile( *delta_script, token, sizeof( token )); *delta_script = COM_ParseFile( *delta_script, token, sizeof( token ));
if( Q_strcmp( token, "," )) if( Q_strcmp( token, "," ))
{ {
Con_DPrintf( S_ERROR "Delta_ReadField: expected ',', found '%s' instead\n", token ); Con_DPrintf( S_ERROR "Delta_ParseField: expected ',', found '%s' instead\n", token );
return false; return false;
} }
// read delta-multiplier // read delta-multiplier
if(( *delta_script = COM_ParseFile( *delta_script, token, sizeof( token ))) == NULL ) if(( *delta_script = COM_ParseFile( *delta_script, token, sizeof( token ))) == NULL )
{ {
Con_DPrintf( S_ERROR "Delta_ReadField: %s missing 'multiplier' argument\n", pField->name ); Con_DPrintf( S_ERROR "Delta_ParseField: %s missing 'multiplier' argument\n", pField->name );
return false; return false;
} }
@ -660,14 +680,14 @@ qboolean Delta_ParseField( char **delta_script, const delta_field_t *pInfo, delt
*delta_script = COM_ParseFile( *delta_script, token, sizeof( token )); *delta_script = COM_ParseFile( *delta_script, token, sizeof( token ));
if( Q_strcmp( token, "," )) if( Q_strcmp( token, "," ))
{ {
Con_DPrintf( S_ERROR "Delta_ReadField: expected ',', found '%s' instead\n", token ); Con_DPrintf( S_ERROR "Delta_ParseField: expected ',', found '%s' instead\n", token );
return false; return false;
} }
// read delta-postmultiplier // read delta-postmultiplier
if(( *delta_script = COM_ParseFile( *delta_script, token, sizeof( token ))) == NULL ) if(( *delta_script = COM_ParseFile( *delta_script, token, sizeof( token ))) == NULL )
{ {
Con_DPrintf( S_ERROR "Delta_ReadField: %s missing 'post_multiply' argument\n", pField->name ); Con_DPrintf( S_ERROR "Delta_ParseField: %s missing 'post_multiply' argument\n", pField->name );
return false; return false;
} }
@ -695,7 +715,7 @@ qboolean Delta_ParseField( char **delta_script, const delta_field_t *pInfo, delt
return true; return true;
} }
void Delta_ParseTable( char **delta_script, delta_info_t *dt, const char *encodeDll, const char *encodeFunc ) static void Delta_ParseTable( char **delta_script, delta_info_t *dt, const char *encodeDll, const char *encodeFunc )
{ {
string token; string token;
delta_t *pField; delta_t *pField;
@ -749,7 +769,7 @@ void Delta_ParseTable( char **delta_script, delta_info_t *dt, const char *encode
dt->bInitialized = true; // table is ok dt->bInitialized = true; // table is ok
} }
void Delta_InitFields( void ) static void Delta_InitFields( void )
{ {
byte *afile; byte *afile;
char *pfile; char *pfile;
@ -894,7 +914,7 @@ Delta_ClampIntegerField
prevent data to out of range prevent data to out of range
===================== =====================
*/ */
int Delta_ClampIntegerField( delta_t *pField, int iValue, qboolean bSigned, int numbits ) static int Delta_ClampIntegerField( delta_t *pField, int iValue, qboolean bSigned, int numbits )
{ {
#ifdef _DEBUG #ifdef _DEBUG
if( numbits < 32 && abs( iValue ) >= (uint)BIT( numbits )) if( numbits < 32 && abs( iValue ) >= (uint)BIT( numbits ))
@ -902,7 +922,7 @@ int Delta_ClampIntegerField( delta_t *pField, int iValue, qboolean bSigned, int
#endif #endif
if( numbits < 32 ) if( numbits < 32 )
{ {
int signbits = bSigned ? (numbits - 1) : numbits; int signbits = bSigned ? ( numbits - 1 ) : numbits;
int maxnum = BIT( signbits ) - 1; int maxnum = BIT( signbits ) - 1;
int minnum = bSigned ? ( -maxnum - 1 ) : 0; int minnum = bSigned ? ( -maxnum - 1 ) : 0;
iValue = bound( minnum, iValue, maxnum ); iValue = bound( minnum, iValue, maxnum );
@ -919,7 +939,7 @@ compare fields by offsets
assume from and to is valid assume from and to is valid
===================== =====================
*/ */
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; qboolean bSigned = ( pField->flags & DT_SIGNED ) ? true : false;
float val_a, val_b; float val_a, val_b;
@ -1111,7 +1131,7 @@ write fields by offsets
assume from and to is valid assume from and to is valid
===================== =====================
*/ */
qboolean Delta_WriteField( sizebuf_t *msg, delta_t *pField, void *from, void *to, double timebase ) static qboolean Delta_WriteField( sizebuf_t *msg, delta_t *pField, void *from, void *to, double timebase )
{ {
qboolean bSigned = ( pField->flags & DT_SIGNED ) ? true : false; qboolean bSigned = ( pField->flags & DT_SIGNED ) ? true : false;
float flValue, flAngle; float flValue, flAngle;
@ -1259,7 +1279,7 @@ read fields by offsets
assume 'from' and 'to' is valid assume 'from' and 'to' is valid
===================== =====================
*/ */
qboolean Delta_ReadField( sizebuf_t *msg, delta_t *pField, void *from, void *to, double timebase ) static qboolean Delta_ReadField( sizebuf_t *msg, delta_t *pField, void *from, void *to, double timebase )
{ {
qboolean bSigned = ( pField->flags & DT_SIGNED ) ? true : false; qboolean bSigned = ( pField->flags & DT_SIGNED ) ? true : false;
float flValue, flAngle, flTime; float flValue, flAngle, flTime;

21
engine/common/net_encode.h

@ -18,26 +18,6 @@ GNU General Public License for more details.
#include "eiface.h" #include "eiface.h"
#define DT_BYTE BIT( 0 ) // A byte
#define DT_SHORT BIT( 1 ) // 2 byte field
#define DT_FLOAT BIT( 2 ) // A floating point field
#define DT_INTEGER BIT( 3 ) // 4 byte integer
#define DT_ANGLE BIT( 4 ) // A floating point angle ( will get masked correctly )
#define DT_TIMEWINDOW_8 BIT( 5 ) // A floating point timestamp, relative to sv.time
#define DT_TIMEWINDOW_BIG BIT( 6 ) // and re-encoded on the client relative to the client's clock
#define DT_STRING BIT( 7 ) // A null terminated string, sent as 8 byte chars
#define DT_SIGNED BIT( 8 ) // sign modificator
#define NUM_FIELDS( x ) ((sizeof( x ) / sizeof( x[0] )) - 1)
// helper macroses
#define ENTS_DEF( x ) #x, offsetof( entity_state_t, x ), sizeof( ((entity_state_t *)0)->x )
#define UCMD_DEF( x ) #x, offsetof( usercmd_t, x ), sizeof( ((usercmd_t *)0)->x )
#define EVNT_DEF( x ) #x, offsetof( event_args_t, x ), sizeof( ((event_args_t *)0)->x )
#define PHYS_DEF( x ) #x, offsetof( movevars_t, x ), sizeof( ((movevars_t *)0)->x )
#define CLDT_DEF( x ) #x, offsetof( clientdata_t, x ), sizeof( ((clientdata_t *)0)->x )
#define WPDT_DEF( x ) #x, offsetof( weapon_data_t, x ), sizeof( ((weapon_data_t *)0)->x )
enum enum
{ {
CUSTOM_NONE = 0, CUSTOM_NONE = 0,
@ -97,7 +77,6 @@ typedef struct
void Delta_Init( void ); void Delta_Init( void );
void Delta_InitClient( void ); void Delta_InitClient( void );
void Delta_Shutdown( void ); void Delta_Shutdown( void );
void Delta_InitFields( void );
int Delta_NumTables( void ); int Delta_NumTables( void );
delta_info_t *Delta_FindStructByIndex( int index ); delta_info_t *Delta_FindStructByIndex( int index );
void Delta_AddEncoder( char *name, pfnDeltaEncode encodeFunc ); void Delta_AddEncoder( char *name, pfnDeltaEncode encodeFunc );

Loading…
Cancel
Save