Skip to content

Commit

Permalink
more fixes to auto-LT
Browse files Browse the repository at this point in the history
the biggest problem was that it would use the local player's latencyTolerance
setting as the max value instead of what the server sent over.  This
could result in weird stuff happening when the LT started changing.
Also, a value of 0 or less is ignored in case somebody unknowingly
tries to force it to go faster than it can.
  • Loading branch information
tra committed Feb 20, 2025
1 parent fb75f26 commit 16a239a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/game/CNetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,16 +815,18 @@ void CNetManager::AutoLatencyControl(FrameNumber frameNumber, Boolean didWait) {

// Usually maxFrameLatency is determined primarily by maxRoundTripLatency...
// but addOneLatency helps account for deficiencies in the calculation by measuring how often clients had to wait too long for packets to arrive
short maxFrameLatency = addOneLatency + itsGame->RoundTripToFrameLatency(maxRoundTripLatency);
short newFrameLatency = addOneLatency + itsGame->RoundTripToFrameLatency(maxRoundTripLatency);

// treat kLatencyToleranceTag as upper limit when in AutoLT mode
maxFrameLatency = std::min<short>(maxFrameLatency, gApplication->Get<double>(kLatencyToleranceTag)/itsGame->fpsScale);
// limit LT unless it's set to zero
if (maxAutoLatency > 0) {
newFrameLatency = std::min<short>(newFrameLatency, maxAutoLatency);
}

DBG_Log("lt", " fn=%d RTT=%d, Classic LT=%.2lf, add=%lf --> FL=%d\n",
frameNumber, maxRoundTripLatency,
(maxRoundTripLatency) / (2.0*CLASSICFRAMETIME), addOneLatency*itsGame->fpsScale, maxFrameLatency);
(maxRoundTripLatency) / (2.0*CLASSICFRAMETIME), addOneLatency*itsGame->fpsScale, newFrameLatency);

itsGame->SetFrameLatency(maxFrameLatency, 2, maxPlayer);
itsGame->SetFrameLatency(newFrameLatency, 2, maxPlayer);
}

ResetLatencyVote();
Expand Down Expand Up @@ -1298,8 +1300,17 @@ void CNetManager::DoConfig(short senderSlot) {
if (PermissionQuery(kAllowLatencyBit, 0) || !(activePlayersDistribution & kdServerOnly) || senderSlot == 0) {
// transmitting latencyTolerance in terms of frameLatency to keep it as a short value on transmission
itsGame->SetFrameTime(theConfig->frameTime);
itsGame->SetFrameLatency(theConfig->frameLatency, -1);
SDL_Log("DoConfig LT = %lf\n", itsGame->latencyTolerance);
maxAutoLatency = theConfig->frameLatency;
short initFrameLatency = theConfig->frameLatency;
if (IsAutoLatencyEnabled()) {
// try setting initial FL from max local RTT value, maybe need the server to send this? we'll see
initFrameLatency = itsGame->RoundTripToFrameLatency(itsCommManager->GetMaxRoundTrip(AlivePlayersDistribution()));
if (maxAutoLatency > 0) {
initFrameLatency = std::min<short>(initFrameLatency, maxAutoLatency);
}
}
itsGame->SetFrameLatency(initFrameLatency, -1);
SDL_Log("DoConfig LT = %lf, FL = %d\n", itsGame->latencyTolerance, maxAutoLatency);
itsGame->SetSpawnOrder((SpawnOrder)theConfig->spawnOrder);
latencyVoteFrame = itsGame->NextFrameForPeriod(AUTOLATENCYPERIOD);
}
Expand All @@ -1310,9 +1321,6 @@ void CNetManager::UpdateLocalConfig() {

config.frameLatency = gApplication
? gApplication->Get<float>(kLatencyToleranceTag) / itsGame->fpsScale : 0;
if (IsAutoLatencyEnabled()) {
config.frameLatency = std::min<short>(config.frameLatency, itsGame->initialFrameLatency);
}
config.frameTime = itsGame->frameTime;
config.spawnOrder = gApplication ? gApplication->Get<short>(kSpawnOrder) : ksHybrid;
config.hullType = gApplication ? gApplication->Number(kHullTypeTag) : 0;
Expand Down
1 change: 1 addition & 0 deletions src/game/CNetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CNetManager : public CDirectObject {

short serverOptions;
short loaderSlot;
short maxAutoLatency; // max frame latency for auto-LT

PlayerConfigRecord config {};

Expand Down
2 changes: 1 addition & 1 deletion src/gui/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static json defaultPrefs = {
// {kJoystickModeTag, false},
{kInvertYAxisTag, false},
{kMouseSensitivityTag, 0},
{kLatencyToleranceTag, 1.0},
{kLatencyToleranceTag, 2.5}, // 2.5 = max for auto latency
{kHullTypeTag, 0}, // 0 = light, 1 = medium, 2 = heavy
{kServerOptionsTag, 129}, // 1 = allow load, 128 = auto latency
{kDefaultUDPPort, 19567},
Expand Down

0 comments on commit 16a239a

Please sign in to comment.