diff --git a/engine/client/cl_parse_gs.c b/engine/client/cl_parse_gs.c index 080613e8..68a7441c 100644 --- a/engine/client/cl_parse_gs.c +++ b/engine/client/cl_parse_gs.c @@ -596,7 +596,6 @@ void CL_ParseGoldSrcServerMessage( sizebuf_t *msg ) case svc_goldsrc_serverinfo: Cbuf_Execute(); // make sure any stuffed commands are done CL_ParseServerData( msg, PROTO_GOLDSRC ); - Delta_InitMeta(); break; case svc_lightstyle: CL_ParseLightStyle( msg, PROTO_GOLDSRC ); diff --git a/engine/common/net_encode.c b/engine/common/net_encode.c index 65c020fa..a2535b62 100644 --- a/engine/common/net_encode.c +++ b/engine/common/net_encode.c @@ -376,13 +376,74 @@ static delta_info_t dt_info[] = [DT_ENTITY_STATE_T] = { "entity_state_t", ent_fields, NUM_FIELDS( ent_fields ) }, [DT_ENTITY_STATE_PLAYER_T] = { "entity_state_player_t", ent_fields, NUM_FIELDS( ent_fields ) }, [DT_CUSTOM_ENTITY_STATE_T] = { "custom_entity_state_t", ent_fields, NUM_FIELDS( ent_fields ) }, -[DT_GOLDSRC_DELTA_T] = { "goldsrc_delta_t", meta_fields, NUM_FIELDS( meta_fields ) }, #if XASH_ENGINE_TESTS [DT_DELTA_TEST_STRUCT_T] = { "delta_test_struct_t", test_fields, NUM_FIELDS( test_fields ) }, #endif [DT_STRUCT_COUNT] = { NULL }, }; +// meta description is special, it cannot be overriden +static const delta_info_t dt_goldsrc_meta = +{ + .pName = "goldsrc_delta_t", + .pInfo = meta_fields, + .maxFields = NUM_FIELDS( meta_fields ), + .numFields = NUM_FIELDS( meta_fields ), + .pFields = (delta_t[NUM_FIELDS( meta_fields )]) + { + { + DESC_DEF( fieldType ), + .flags = DT_INTEGER, + .multiplier = 1.0f, + .post_multiplier = 1.0f, + .bits = 32, + }, + { + DESC_DEF( fieldName ), + .flags = DT_STRING, + .multiplier = 1.0f, + .post_multiplier = 1.0f, + .bits = 1, + }, + { + DESC_DEF( fieldOffset ), + .flags = DT_INTEGER, + .multiplier = 1.0f, + .post_multiplier = 1.0f, + .bits = 16, + }, + { + DESC_DEF( fieldSize ), + .flags = DT_INTEGER, + .multiplier = 1.0f, + .post_multiplier = 1.0f, + .bits = 8, + }, + { + DESC_DEF( significant_bits ), + .flags = DT_INTEGER, + .multiplier = 1.0f, + .post_multiplier = 1.0f, + .bits = 8, + }, + { + DESC_DEF( premultiply ), + .flags = DT_FLOAT, + .multiplier = 4000.0f, + .post_multiplier = 1.0f, + .bits = 32, + }, + { + DESC_DEF( postmultiply ), + .flags = DT_FLOAT, + .multiplier = 4000.0f, + .post_multiplier = 1.0f, + .bits = 32, + }, + }, + .bInitialized = true +}; + static delta_info_t *Delta_FindStruct( const char *name ) { int i; @@ -620,66 +681,6 @@ void Delta_ParseTableField( sizebuf_t *msg ) Delta_AddField( dt, pName, flags, bits, mul, post_mul ); } -void Delta_InitMeta( void ) -{ - delta_info_t *dt = Delta_FindStructByIndex( DT_GOLDSRC_DELTA_T ); - - if( dt->bInitialized ) - return; - - Delta_AddField( dt, "fieldType", DT_INTEGER, 32, 1.0f, 1.0f ); - Delta_AddField( dt, "fieldName", DT_STRING, 1, 1.0f, 1.0f ); - Delta_AddField( dt, "fieldOffset", DT_INTEGER, 16, 1.0f, 1.0f ); - Delta_AddField( dt, "fieldSize", DT_INTEGER, 8, 1.0f, 1.0f ); - Delta_AddField( dt, "significant_bits", DT_INTEGER, 8, 1.0f, 1.0f ); - Delta_AddField( dt, "premultiply", DT_FLOAT, 32, 4000.0f, 1.0f ); - Delta_AddField( dt, "postmultiply", DT_FLOAT, 32, 4000.0f, 1.0f ); - dt->numFields = dt->maxFields; - dt->bInitialized = true; -} - -void Delta_ParseTableField_GS( sizebuf_t *msg ) -{ - const char *s = MSG_ReadString( msg ); - delta_info_t *dt = Delta_FindStruct( s ); - goldsrc_delta_t null = { 0 }; - int i, num_fields; - - - // delta encoders it's already initialized on this machine (local game) - if( delta_init ) - { - Delta_Shutdown(); - Delta_InitMeta(); - } - - if( !dt ) - Host_Error( "%s: not initialized", __func__ ); - - num_fields = MSG_ReadShort( msg ); - if( num_fields > dt->maxFields ) - Host_Error( "%s: numFields > maxFields", __func__ ); - - MSG_StartBitWriting( msg ); - - for( i = 0; i < num_fields; i++ ) - { - goldsrc_delta_t to; - - Delta_ReadGSFields( msg, DT_GOLDSRC_DELTA_T, &null, &to, 0.0f ); - - // patch our DT_SIGNED flag - if( FBitSet( to.fieldType, DT_SIGNED_GS )) - { - ClearBits( to.fieldType, DT_SIGNED_GS ); - SetBits( to.fieldType, DT_SIGNED ); - } - Delta_AddField( dt, to.fieldName, to.fieldType, to.significant_bits, to.premultiply, to.postmultiply ); - } - - MSG_EndBitWriting( msg ); -} - static qboolean Delta_ParseField( char **delta_script, const delta_field_t *pInfo, delta_t *pField, qboolean bPost ) { string token; @@ -1483,9 +1484,8 @@ static qboolean Delta_ReadField( sizebuf_t *msg, delta_t *pField, const void *fr return true; } -void Delta_ReadGSFields( sizebuf_t *msg, int index, const void *from, void *to, double timebase ) +static void Delta_ParseGSFields( sizebuf_t *msg, const delta_info_t *dt, const void *from, void *to, double timebase ) { - delta_info_t *dt = Delta_FindStructByIndex( index ); uint8_t bits[8] = { 0 }; delta_t *pField; byte c; @@ -1507,6 +1507,12 @@ void Delta_ReadGSFields( sizebuf_t *msg, int index, const void *from, void *to, } } +void Delta_ReadGSFields( sizebuf_t *msg, int index, const void *from, void *to, double timebase ) +{ + const delta_info_t *dt = Delta_FindStructByIndex( index ); + Delta_ParseGSFields( msg, dt, from, to, timebase ); +} + void Delta_WriteGSFields( sizebuf_t *msg, int index, const void *from, const void *to, double timebase ) { delta_info_t *dt = Delta_FindStructByIndex( index ); @@ -2105,6 +2111,44 @@ qboolean MSG_ReadDeltaEntity( sizebuf_t *msg, const entity_state_t *from, entity return true; } +void Delta_ParseTableField_GS( sizebuf_t *msg ) +{ + const char *s = MSG_ReadString( msg ); + delta_info_t *dt = Delta_FindStruct( s ); + goldsrc_delta_t null = { 0 }; + int i, num_fields; + + // delta encoders it's already initialized on this machine (local game) + if( delta_init ) + Delta_Shutdown(); + + if( !dt ) + Host_Error( "%s: not initialized", __func__ ); + + num_fields = MSG_ReadShort( msg ); + if( num_fields > dt->maxFields ) + Host_Error( "%s: numFields > maxFields", __func__ ); + + MSG_StartBitWriting( msg ); + + for( i = 0; i < num_fields; i++ ) + { + goldsrc_delta_t to; + + Delta_ParseGSFields( msg, &dt_goldsrc_meta, &null, &to, 0.0f ); + + // patch our DT_SIGNED flag + if( FBitSet( to.fieldType, DT_SIGNED_GS )) + { + ClearBits( to.fieldType, DT_SIGNED_GS ); + SetBits( to.fieldType, DT_SIGNED ); + } + Delta_AddField( dt, to.fieldName, to.fieldType, to.significant_bits, to.premultiply, to.postmultiply ); + } + + MSG_EndBitWriting( msg ); +} + /* ================== Delta_WriteDescriptionToClient diff --git a/engine/common/net_encode.h b/engine/common/net_encode.h index 48332929..a73045ef 100644 --- a/engine/common/net_encode.h +++ b/engine/common/net_encode.h @@ -43,7 +43,6 @@ enum DT_ENTITY_STATE_T, DT_ENTITY_STATE_PLAYER_T, DT_CUSTOM_ENTITY_STATE_T, - DT_GOLDSRC_DELTA_T, #if XASH_ENGINE_TESTS DT_DELTA_TEST_STRUCT_T, #endif @@ -104,7 +103,6 @@ typedef struct // void Delta_Init( void ); void Delta_InitClient( void ); -void Delta_InitMeta( void ); void Delta_Shutdown( void ); void Delta_AddEncoder( char *name, pfnDeltaEncode encodeFunc ); int Delta_FindField( delta_t *pFields, const char *fieldname );