From 93c58533567477de7a4a7185713cc517d1af3c9c Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 18 Dec 2024 06:57:07 +0300 Subject: [PATCH] engine: server: merge SV_FindBestBaseline for normal entities and static entities into single function --- engine/server/server.h | 2 +- engine/server/sv_frame.c | 53 +++++++++++----------------------------- engine/server/sv_game.c | 2 +- 3 files changed, 16 insertions(+), 41 deletions(-) diff --git a/engine/server/server.h b/engine/server/server.h index d0d864d98e..2f145fc60f 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -593,7 +593,7 @@ qboolean SV_CheckID( const char *id ); // sv_frame.c // void SV_InactivateClients( void ); -int SV_FindBestBaselineForStatic( int index, entity_state_t **baseline, entity_state_t *to ); +int SV_FindBestBaseline( int index, entity_state_t **baseline, entity_state_t *to, client_frame_t *frame, qboolean player ); void SV_SkipUpdates( void ); // diff --git a/engine/server/sv_frame.c b/engine/server/sv_frame.c index 07641fa054..5d94d9f12c 100644 --- a/engine/server/sv_frame.c +++ b/engine/server/sv_frame.c @@ -178,9 +178,10 @@ Encode a client frame onto the network channel SV_FindBestBaseline trying to deltas with previous entities +set frame to NULL to check for static entities ============= */ -static int SV_FindBestBaseline( sv_client_t *cl, int index, entity_state_t **baseline, entity_state_t *to, client_frame_t *frame, qboolean player ) +int SV_FindBestBaseline( int index, entity_state_t **baseline, entity_state_t *to, client_frame_t *frame, qboolean player ) { int bestBitCount; int i, bitCount; @@ -193,7 +194,13 @@ static int SV_FindBestBaseline( sv_client_t *cl, int index, entity_state_t **bas for( i = index - 1; bestBitCount > 0 && i >= 0 && ( index - i ) < ( MAX_CUSTOM_BASELINES - 1 ); i-- ) { // don't worry about underflow in circular buffer - entity_state_t *test = &svs.packet_entities[(frame->first_entity+i) % svs.num_client_entities]; + entity_state_t *test; + + // if set, then it's normal entity + if( frame != NULL ) + test = &svs.packet_entities[(frame->first_entity+i) % svs.num_client_entities]; + else + test = &svs.static_entities[i]; if( to->entityType == test->entityType ) { @@ -209,44 +216,12 @@ static int SV_FindBestBaseline( sv_client_t *cl, int index, entity_state_t **bas // using delta from previous entity as baseline for current if( index != bestfound ) - *baseline = &svs.packet_entities[(frame->first_entity+bestfound) % svs.num_client_entities]; - return index - bestfound; -} - -/* -============= -SV_FindBestBaselineForStatic - -trying to deltas with previous static entities -============= -*/ -int SV_FindBestBaselineForStatic( int index, entity_state_t **baseline, entity_state_t *to ) -{ - int bestBitCount; - int i, bitCount; - int bestfound, j; - - bestBitCount = j = Delta_TestBaseline( *baseline, to, false, sv.time ); - bestfound = index; - - // lookup backward for previous 64 states and try to interpret current delta as baseline - for( i = index - 1; bestBitCount > 0 && i >= 0 && ( index - i ) < ( MAX_CUSTOM_BASELINES - 1 ); i-- ) { - // don't worry about underflow in circular buffer - entity_state_t *test = &svs.static_entities[i]; - - bitCount = Delta_TestBaseline( test, to, false, sv.time ); - - if( bitCount < bestBitCount ) - { - bestBitCount = bitCount; - bestfound = i; - } + if( frame != NULL ) + *baseline = &svs.packet_entities[(frame->first_entity+bestfound) % svs.num_client_entities]; + else + *baseline = &svs.static_entities[bestfound]; } - - // using delta from previous entity as baseline for current - if( index != bestfound ) - *baseline = &svs.static_entities[bestfound]; return index - bestfound; } @@ -347,7 +322,7 @@ static void SV_EmitPacketEntities( sv_client_t *cl, client_frame_t *to, sizebuf_ // trying to reduce message by select optimal baseline if( !sv_instancedbaseline.value || !sv.num_instanced || sv.last_valid_baseline > newnum ) { - offset = SV_FindBestBaseline( cl, newindex, &baseline, newent, to, player ); + offset = SV_FindBestBaseline( newindex, &baseline, newent, to, player ); } else { diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index 664794f143..0eae8650b7 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -578,7 +578,7 @@ qboolean SV_CreateStaticEntity( sizebuf_t *msg, int index ) state->number = 0; // trying to compress with previous delta's - offset = SV_FindBestBaselineForStatic( index, &baseline, state ); + offset = SV_FindBestBaseline( index, &baseline, state, NULL, false ); MSG_BeginServerCmd( msg, svc_spawnstatic ); MSG_WriteDeltaEntity( baseline, state, msg, true, DELTA_STATIC, sv.time, offset );