Skip to content

Commit d3b62e8

Browse files
authored
bugfix(network): Revert changes to ConnectionManager::getMaximumLatency() to avoid a higher latency runahead than required (TheSuperHackers#2199)
1 parent 1174285 commit d3b62e8

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

Core/GameEngine/Include/GameNetwork/ConnectionManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class ConnectionManager
171171

172172
// void doPerFrameMetrics(UnsignedInt frame);
173173
void getMinimumFps(Int &minFps, Int &minFpsPlayer); ///< Returns the smallest FPS in the m_fpsAverages list.
174-
Real getMaximumLatency(); ///< Returns the highest average latency between players.
174+
Real getMaximumLatency(); ///< Returns the average of the two highest average latencies between players.
175175

176176
void requestFrameDataResend(Int playerID, UnsignedInt frame); ///< request of this player that he send the specified frame's data.
177177

Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,15 +1362,25 @@ void ConnectionManager::updateRunAhead(Int oldRunAhead, Int frameRate, Bool didS
13621362
}
13631363

13641364
Real ConnectionManager::getMaximumLatency() {
1365-
Real maxLatency = 0.0f;
1365+
1366+
Real lat1 = 0.0f;
1367+
Real lat2 = 0.0f;
13661368

13671369
for (Int i = 0; i < MAX_SLOTS; ++i) {
1368-
if (isPlayerConnected(i) && m_latencyAverages[i] > maxLatency) {
1369-
maxLatency = m_latencyAverages[i];
1370+
if (isPlayerConnected(i)) {
1371+
if (m_latencyAverages[i] != 0.0f) {
1372+
if (m_latencyAverages[i] > lat1) {
1373+
lat2 = lat1;
1374+
lat1 = m_latencyAverages[i];
1375+
}
1376+
else if (m_latencyAverages[i] > lat2) {
1377+
lat2 = m_latencyAverages[i];
1378+
}
1379+
}
13701380
}
13711381
}
13721382

1373-
return maxLatency;
1383+
return (lat1 + lat2) / 2.0f;
13741384
}
13751385

13761386
void ConnectionManager::getMinimumFps(Int &minFps, Int &minFpsPlayer) {

0 commit comments

Comments
 (0)