bugfix(network): Fix runahead logic update to better follow the maximum network latency and avoid stutters and slow downs#1482
Merged
xezon merged 2 commits intoTheSuperHackers:mainfrom Sep 9, 2025
Conversation
xezon
reviewed
Sep 4, 2025
GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
Outdated
Show resolved
Hide resolved
cae8af1 to
f95daef
Compare
Author
|
Tweaked and pushed |
f95daef to
d92eb4c
Compare
Author
|
Forgot to copy across to generals, fixed |
xezon
approved these changes
Sep 4, 2025
xezon
left a comment
There was a problem hiding this comment.
Code looks plausible. We trust the Mauller that the Network runs better.
|
Has merge conflicts. |
Author
This code is currently running in GO and it's smooooooth.
Will tweak it when i get home, half day on fridays which is nice. |
…lows the max network latency
d92eb4c to
c5b75d8
Compare
Author
|
Rebased with main |
xezon
reviewed
Sep 6, 2025
Generals/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
Outdated
Show resolved
Hide resolved
fbraz3
pushed a commit
to fbraz3/GeneralsX
that referenced
this pull request
Nov 10, 2025
…um network latency and avoid stutters and slow downs (TheSuperHackers#1482)
fbraz3
pushed a commit
to fbraz3/GeneralsX
that referenced
this pull request
Feb 23, 2026
…um network latency and avoid stutters and slow downs (TheSuperHackers#1482)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses issues with how the runAhead logic calculated the number of logic frames the local client can progress before receiving data in an online or network game.
If the calculated run ahead is not correct for the current network latency, it can introduce stutter and game slow downs.
This is due to the client needing to wait for new commands before progressing the simulation.
The original runahead logic had two fundamental flaws in its calculation that can introduce stutter, even when the network latency is good between clients:
Originally they used the average of the two highest latencies to calculate the maximum latency.
The issue with this is that you are averaging two values which are already averages, this can result in a latency value lower than the actual highest latency in the network.
This can result in a situation where the runahead value is calculated to a lower than required value. which will result in microstutter as clients wait for new commands.
This issue introduces the largest amount of stutter in a game. With the original calculation, when the latency is between two runahead values, it would always truncate to the lowest value. Which would result in the latency following the runahead.
This slowly introduces more stutter as the latency approaches the next runahead threshold.
To correct this, the runahead should have been rounded up to the next integer value, so the number of logic frames always exceeds the latency.
e.g 10 frames being 330ms vs 310ms network latency. This implicitly adds a buffering effect to the network latency on top of the additional network slack.
For the network slack, we now calculate this as a part of the latency value instead of the runahead like in the original code.
This then allows the network slack to work as a buffer between the current latency and the calculated runahead.
So if the slack is a 10% window, when the latency gets within 10% of the current runahead, the runahead will be pushed up to the next runahead level.
There are further optimisations that help with Networked game performance, but these will be handled in future PR's.
Most of these revolve around allowing the runahead to go bellow 10 frames,
increasing the update frequency of the runahead,
decreasing the number of bins the network latency is calculated over and reducing the frame batching time.
In combination, the above optimisations allow the game to be more responsive when the network latency allows, while also letting the game adapt to network conditions faster.