[PR] Speed Up Slow Instances for Lockstep #300
Merged
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.
A very important part of rollback netcode is to ensure both players are playing on roughly the same frame at the same time. This can be somewhat challenging because the games may not start at the exact same time and two computers may not run the game at exactly the same speed. If we don't make sure players are playing on roughly the same frame, you end up with situations of really bad one-sided rollbacks.
We use ACKs to estimate delay time/ping in order to estimate what frame our opponent is on. This has always been the case in Slippi.
What this PR does is it changes how we react to being offset from our opponent.
Previously the player that was ahead would stall on maximum one frame every 30 frames in order to slow down and let the opponent catch up. This was problematic because it only really let us slow down to 58 fps which means if someone was running slower than that for a bit, they would never catch up, causing longer stalls for the person ahead and extremely bad one sided rollbacks. This method would also punish the person with the computer that was fast enough to run the game, stalls can cause a missed input if the timing is really bad. Generally one frame is mostly not noticeable but it's still not ideal.
The new method instead tries to speed up the person running the game slower by doubling frames. It can do this a maximum of 10 times per 60 frames, allowing for the person running slow to catch up faster than previously. Worth noting that doubled frames can mess up timings and cause doubled inputs but at least now we're punishing the person who can't run the game full speed.
Potential future optimizations:
We could try live-tweaking emulation speed in order to sync up the run speed for both players. This could possibly make it so we can time-sync more accurately so both players are running on exactly the same frame and also prevent doubled frames in order to re-sync periodically. One example: on a good connection, I was forced to re-sync once every 47 seconds because my computer was running the game slightly slower than my opponent. In other words, my computer would drift by about one frame every 47 seconds.