Skip to content

Commit

Permalink
engine: server: merge SV_FindBestBaseline for normal entities and sta…
Browse files Browse the repository at this point in the history
…tic entities into single function
  • Loading branch information
a1batross committed Dec 18, 2024
1 parent 98e5872 commit 93c5853
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 41 deletions.
2 changes: 1 addition & 1 deletion engine/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

//
Expand Down
53 changes: 14 additions & 39 deletions engine/server/sv_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 )
{
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion engine/server/sv_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 93c5853

Please sign in to comment.