Send empty snapshots to clients downloading using legacy protocol

Save bandwidth by excluding entity and player state changes from
snapshots sent to clients downloading using the legacy protocol. The
snapshots are mainly needed to update the reliableAcknowledge.

The idea is from Noah "Chomenor" Metzger's ioef-cmod project. Though I
implemented the dummy snapshot code closer to the real snapshot code.
This commit is contained in:
Zack Middleton 2018-05-18 09:40:53 -05:00
parent 457b7944b9
commit 58f257e868
3 changed files with 64 additions and 11 deletions

View file

@ -401,7 +401,7 @@ void SV_SendMessageToClient( msg_t *msg, client_t *client );
void SV_SendClientMessages( void );
void SV_SendClientSnapshot( client_t *client );
#ifdef ELITEFORCE
void SV_WriteSnapshotToClient( client_t *client, msg_t *msg );
void SV_WriteDummySnapshotToClient( client_t *client, msg_t *msg );
#endif
//

View file

@ -1242,6 +1242,7 @@ int SV_SendDownloadMessages(void)
{
MSG_InitOOB(&msg, msgBuffer, sizeof(msgBuffer));
msg.compat = qtrue;
SV_WriteDummySnapshotToClient(cl, &msg);
}
else
#endif
@ -1255,12 +1256,7 @@ int SV_SendDownloadMessages(void)
if(retval)
{
#ifdef ELITEFORCE
if(msg.compat)
{
// compat clients need svc_snapshot to update reliableAcknowledge
SV_WriteSnapshotToClient(cl, &msg);
}
else
if(!msg.compat)
#endif
MSG_WriteByte(&msg, svc_EOF);
SV_Netchan_Transmit(cl, &msg);

View file

@ -119,10 +119,7 @@ static void SV_EmitPacketEntities( clientSnapshot_t *from, clientSnapshot_t *to,
SV_WriteSnapshotToClient
==================
*/
#ifndef ELITEFORCE
static
#endif
void SV_WriteSnapshotToClient( client_t *client, msg_t *msg ) {
static void SV_WriteSnapshotToClient( client_t *client, msg_t *msg ) {
clientSnapshot_t *frame, *oldframe;
int lastframe;
int i;
@ -216,6 +213,66 @@ void SV_WriteSnapshotToClient( client_t *client, msg_t *msg ) {
}
#ifdef ELITEFORCE
/*
==================
SV_WriteDummySnapshotToClient
While a client downloads a pk3 using the legacy protocol they need
a snapshot to update the reliableAcknowledge. This dummy snapshot
does not include areabits, entities, or player state updates.
==================
*/
void SV_WriteDummySnapshotToClient( client_t *client, msg_t *msg ) {
int snapFlags;
playerState_t ps;
MSG_WriteByte (msg, svc_snapshot);
// NOTE, MRE: now sent at the start of every message from server to client
// let the client know which reliable clientCommands we have received
#ifdef ELITEFORCE
if(msg->compat)
MSG_WriteLong( msg, client->lastClientCommand );
#else
//MSG_WriteLong( msg, client->lastClientCommand );
#endif
// send over the current server time so the client can drift
// its view of time to try to match
if( client->oldServerTime ) {
MSG_WriteLong (msg, sv.time + client->oldServerTime);
} else {
MSG_WriteLong (msg, sv.time);
}
// what we are delta'ing from
MSG_WriteByte (msg, 0);
snapFlags = svs.snapFlagServerBit;
if ( client->rateDelayed ) {
snapFlags |= SNAPFLAG_RATE_DELAYED;
}
if ( client->state != CS_ACTIVE ) {
snapFlags |= SNAPFLAG_NOT_ACTIVE;
}
MSG_WriteByte (msg, snapFlags);
// send over the areabits
MSG_WriteByte (msg, 0);
MSG_WriteData (msg, NULL, 0);
// delta encode the playerstate
Com_Memset (&ps, 0, sizeof(ps));
MSG_WriteDeltaPlayerstate( msg, &ps, &ps );
// delta encode the entities
MSG_WriteBits( msg, (MAX_GENTITIES-1), GENTITYNUM_BITS );
}
#endif
/*
==================
SV_UpdateServerCommandsToClient