Merge branch 'smooth-gentleman' into 'master'

Smooth out gentleman delay

See merge request KartKrew/Kart!1256
This commit is contained in:
AJ Martinez 2023-06-01 21:54:56 +00:00
commit 4791789bd7

View file

@ -116,6 +116,9 @@ UINT16 pingmeasurecount = 1;
UINT32 realpingtable[MAXPLAYERS]; //the base table of ping where an average will be sent to everyone.
UINT32 playerpingtable[MAXPLAYERS]; //table of player latency values.
#define GENTLEMANSMOOTHING (TICRATE)
static tic_t reference_lag;
static UINT8 spike_time;
static tic_t lowest_lag;
boolean server_lagless;
static CV_PossibleValue_t mindelay_cons_t[] = {{0, "MIN"}, {30, "MAX"}, {0, NULL}};
@ -5974,6 +5977,30 @@ static void CL_SendClientCmd(void)
{
// Gentlemens' ping.
lagDelay = min(lowest_lag, MAXGENTLEMENDELAY);
// Is our connection worse than our current gentleman point?
// Make sure it stays that way for a bit before increasing delay levels.
if (lagDelay > reference_lag)
{
spike_time++;
if (spike_time >= GENTLEMANSMOOTHING)
{
// Okay, this is genuinely the new baseline delay.
reference_lag = lagDelay;
spike_time = 0;
}
else
{
// Just a temporary fluctuation, ignore it.
lagDelay = reference_lag;
}
}
else
{
reference_lag = lagDelay; // Adjust quickly if the connection improves.
spike_time = 0;
}
if (server) // Clients have to wait for the gamestate to make it back. Servers don't!
lagDelay *= 2; // Simulate the HELLFUCK NIGHTMARE of a complete round trip.
}