Netcode: allow observers to lag behind the live game.

Observers no longer lag the game for players. There is still some time
to serialise the game when sending it to a joining observer, and
depending on the chosen 'max lag' the game may stop while observers
sufficiently catch up, but this impact too is reduced.

- Make the NetServerTurnManager ignore players marked as 'observers' for
the purpose of ending a turn, effectively making it possible for
observers to lag without it affecting the players in any way.
- Add a config option (network.observermaxlag) that specifies how many
turns behind the live game observers are allowed to be. Default to 10
turns, or 2 seconds, to keep them 'largely live'.
- The controller is not treated as an observer.
- Implement a simple UI to show this delay & allow the game to speed up
automatically to try and catch up. This can be deactivated via
network.autocatchup.
- Move network options to the renamed 'Network / Lobby' options page.
- Do not debug_warn/crash when receiving commands from the past -
instead warn and carry on, to avoid DOS and "coop play" issues.

Refs #5903, Refs #4210

Differential Revision: https://code.wildfiregames.com/D3737
This was SVN commit r25156.
This commit is contained in:
wraitii
2021-03-29 07:53:06 +00:00
parent e3a254225a
commit 5ebf2020b0
12 changed files with 188 additions and 60 deletions
+12
View File
@@ -98,6 +98,17 @@ void SetSimRate(float rate)
g_Game->SetSimRate(rate);
}
int GetPendingTurns(const ScriptRequest& rq)
{
if (!g_Game || !g_Game->GetTurnManager())
{
ScriptException::Raise(rq, "Game is not started");
return 0;
}
return g_Game->GetTurnManager()->GetPendingTurns();
}
bool IsPaused(const ScriptRequest& rq)
{
if (!g_Game)
@@ -179,6 +190,7 @@ void RegisterScriptFunctions(const ScriptRequest& rq)
ScriptFunction::Register<&SetViewedPlayer>(rq, "SetViewedPlayer");
ScriptFunction::Register<&GetSimRate>(rq, "GetSimRate");
ScriptFunction::Register<&SetSimRate>(rq, "SetSimRate");
ScriptFunction::Register<&GetPendingTurns>(rq, "GetPendingTurns");
ScriptFunction::Register<&IsPaused>(rq, "IsPaused");
ScriptFunction::Register<&SetPaused>(rq, "SetPaused");
ScriptFunction::Register<&IsVisualReplay>(rq, "IsVisualReplay");