From e4d7d3a803aafa4b222ea386bc08fcaba993697c Mon Sep 17 00:00:00 2001 From: Eugene Date: Tue, 27 Aug 2024 22:58:04 +0300 Subject: [PATCH] server: optimize certain gamestate acknowledge cases --- code/client/cl_curl.c | 6 +++--- code/qcommon/common.c | 2 +- code/qcommon/qcommon.h | 2 +- code/server/sv_client.c | 30 ++++++++++++++++++++++-------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/code/client/cl_curl.c b/code/client/cl_curl.c index c9f2a10ca..586db2488 100644 --- a/code/client/cl_curl.c +++ b/code/client/cl_curl.c @@ -748,8 +748,8 @@ static int Com_DL_CallbackProgress( void *data, double dltotal, double dlnow, do Com_Printf( "%s: aborted\n", dl->Name ); return -1; } - Cvar_Set( "cl_downloadSize", va( "%i", dl->Size ) ); - Cvar_Set( "cl_downloadCount", va( "%i", dl->Count ) ); + Cvar_SetIntegerValue( "cl_downloadSize", dl->Size ); + Cvar_SetIntegerValue( "cl_downloadCount", dl->Count ); } if ( dl->Size ) { @@ -1043,7 +1043,7 @@ qboolean Com_DL_Begin( download_t *dl, const char *localName, const char *remote Cvar_Set( "cl_downloadName", dl->Name ); Cvar_Set( "cl_downloadSize", "0" ); Cvar_Set( "cl_downloadCount", "0" ); - Cvar_Set( "cl_downloadTime", va( "%i", cls.realtime ) ); + Cvar_SetIntegerValue( "cl_downloadTime", cls.realtime ); } return qtrue; diff --git a/code/qcommon/common.c b/code/qcommon/common.c index 6ccd99fda..3186ab37f 100644 --- a/code/qcommon/common.c +++ b/code/qcommon/common.c @@ -304,7 +304,7 @@ void NORETURN FORMAT_PRINTF(2, 3) QDECL Com_Error( errorParm_t code, const char com_errorEntered = qtrue; - Cvar_Set( "com_errorCode", va( "%i", code ) ); + Cvar_SetIntegerValue( "com_errorCode", code ); // when we are running automated scripts, make sure we // know if anything failed diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h index 8fd2b47d4..095cf9455 100644 --- a/code/qcommon/qcommon.h +++ b/code/qcommon/qcommon.h @@ -208,7 +208,7 @@ qboolean NET_IsLocalAddress( const netadr_t *adr ); const char *NET_AdrToString( const netadr_t *a ); const char *NET_AdrToStringwPort( const netadr_t *a ); int NET_StringToAdr( const char *s, netadr_t *a, netadrtype_t family ); -#ifndef DEDICATED +#ifndef DEDICATED qboolean NET_GetLoopPacket( netsrc_t sock, netadr_t *net_from, msg_t *net_message ); #endif #ifdef USE_IPV6 diff --git a/code/server/sv_client.c b/code/server/sv_client.c index b3b0efff9..311172ee1 100644 --- a/code/server/sv_client.c +++ b/code/server/sv_client.c @@ -1021,6 +1021,7 @@ static void SV_SendClientGameState( client_t *client ) { const svEntity_t *svEnt; msg_t msg; byte msgBuffer[ MAX_MSGLEN_BUF ]; + qboolean csUpdated; Com_DPrintf( "SV_SendClientGameState() for %s\n", client->name ); @@ -1028,12 +1029,6 @@ static void SV_SendClientGameState( client_t *client ) { client->state = CS_PRIMED; - if ( client->gamestateAck == GSA_INIT ) { - client->gamestateAck = GSA_SENT_ONCE; - } else { - client->gamestateAck = GSA_SENT_MANY; - } - client->downloading = qfalse; client->pureAuthentic = qfalse; @@ -1068,6 +1063,7 @@ static void SV_SendClientGameState( client_t *client ) { MSG_WriteLong( &msg, client->reliableSequence ); // write the configstrings + csUpdated = qfalse; for ( start = 0 ; start < MAX_CONFIGSTRINGS ; start++ ) { if ( *sv.configstrings[ start ] != '\0' ) { MSG_WriteByte( &msg, svc_configstring ); @@ -1082,7 +1078,22 @@ static void SV_SendClientGameState( client_t *client ) { MSG_WriteBigString( &msg, sv.configstrings[start] ); } } - client->csUpdated[ start ] = qfalse; + if ( client->csUpdated[start] ) { + csUpdated = qtrue; + } + client->csUpdated[start] = qfalse; + } + + if ( client->gamestateAck == GSA_INIT ) { + // inital submission, accept any messageAcknowledge with matching serverId + client->gamestateAck = GSA_SENT_ONCE; + } else { + if ( client->gamestateAck == GSA_SENT_ONCE && !csUpdated ) { + // if no configstrings being updated since last submission then assume that we're (re)sending identical gamestate + } else { + // expect exact messageAcknowledge + client->gamestateAck = GSA_SENT_MANY; + } } // write the baselines @@ -1286,7 +1297,10 @@ static void SV_BeginDownload_f( client_t *cl ) { cl->gentity = NULL; cl->downloading = qtrue; - cl->gamestateAck = GSA_SENT_MANY; // expect exact messageAcknowledge next time + + if ( cl->gamestateAck = GSA_ACKED ) { + cl->gamestateAck = GSA_SENT_ONCE; + } }