I'm working on a game that's going to use GGPO for rollback netcode. I understand the need for a deterministic engine whose state can be saved, restored, advanced from user inputs, etc. I understand that I may need to do this several times in a frame, and that therefore, from a performance point of view, updating the game engine needs to be fast enough to be called more than once in a frame.

My question is.... how many updates in a frame do I realistically need to budget for? If I can identify a realistic worst case, I'll simply run my game engine that many times a frame while I'm developing it.

  • \$\begingroup\$ How many times in a frame do you query for new inputs from the network? \$\endgroup\$
    – DMGregory
    May 5 at 13:13
  • \$\begingroup\$ Well, I don't - GGPO is handling things at that level. \$\endgroup\$
    – Tom Davies
    May 5 at 13:41
  • 1
    \$\begingroup\$ re. your recently deleted question, I was writing answer to - look into "Hungarian Algorithm". Given two sets of coordinates it will calculate best pairs (with minimal net length). \$\endgroup\$
    – Kromster
    May 12 at 11:05
  • \$\begingroup\$ Aha! Thanks. Yes, my search took me there as well, eventually. I decided to delete the question as it's more of a CS/Maths issue, and framing it in its context of controlling AI agents was confusing the fundamental issue. I found this too: cs.stackexchange.com/questions/2082/… It's a great example of a problem that seems intuitively easy to a human but is actually quite tricky (and expensive) to solve \$\endgroup\$
    – Tom Davies
    May 12 at 11:37

I haven't used GGPO but reading through the documentation, it looks like you would just use the amount of updates that your engine needs. I think that's 1 per frame. Looking at the diagram:


It looks like the prediction serves as the remote update for the most part. You would track player input locally, update with predictions, validate with real remote data, rollback when appropriate.

From the docs:

GGPO checks the quality of its prediction for previous frames every time it receives a remote input. As mentioned earlier, GGPO doesn't receive the inputs for player 2's first frame until player 1's fourth. At frame 4, GGPO notices that the inputs received from the network do not match the predicted inputs sent earlier. To resynchronize the two games, GGPO needs to undo the damage caused by running the game with incorrect inputs for 3 frames. It does this by asking the game engine to go back in time to a frame before the erroneously speculated inputs were sent (i.e. to "rollback" to a previous state). Once the previous state has been restored, GGPO asks the engine to move forward one frame at a time with the corrected input stream. These frames are shown in light blue. Your game engine should advance through these frames as quickly as possible with no visible effect to the user. For example, your video renderer should not draw these frames to the screen. Your audio renderer should ideally continue to generate audio, but it should not be rendered until after the rollback, at which point samples should start playing n frames in, where n is the current frame minus the frame where the sample was generated. Once your engine reaches the frame it was on before GGPO discovered the error, GGPO drops out of rollback mode and allows the game to proceed as normal. Frames 5 and 6 in the diagram show what happens when GGPO predicts correctly. Since the game state is correct, there's no reason to rollback.

I would see no reason to update more than once per frame, every frame.

  • \$\begingroup\$ In the situation described above, GGPO tells your game to rollback to its state 3 frames ago, then sequentially apply the corrected 3 frames' worth of input. So in that case, you need to be able to complete a rollback, and 3 engine updates within one frame. \$\endgroup\$
    – Tom Davies
    May 5 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.