mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-15 22:49:37 +00:00
Spectate catchup (#3012)
## Description: https://github.com/user-attachments/assets/dc118d5f-3b7f-4ccb-8579-5b0d8c73fe8e Catchup mechanic for live games and changes replays to have a backlog for more "max" speed ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: w.o.n
This commit is contained in:
@@ -20,7 +20,13 @@ import {
|
||||
import { getPersistentID } from "./Auth";
|
||||
import { LobbyConfig } from "./ClientGameRunner";
|
||||
import { ReplaySpeedChangeEvent } from "./InputHandler";
|
||||
import { defaultReplaySpeedMultiplier } from "./utilities/ReplaySpeedMultiplier";
|
||||
import {
|
||||
defaultReplaySpeedMultiplier,
|
||||
ReplaySpeedMultiplier,
|
||||
} from "./utilities/ReplaySpeedMultiplier";
|
||||
|
||||
// build a small backlog so MAX can catch up.
|
||||
const MAX_REPLAY_BACKLOG_TURNS = 60;
|
||||
|
||||
export class LocalServer {
|
||||
// All turns from the game record on replay.
|
||||
@@ -64,9 +70,16 @@ export class LocalServer {
|
||||
const turnIntervalMs =
|
||||
this.lobbyConfig.serverConfig.turnIntervalMs() *
|
||||
this.replaySpeedMultiplier;
|
||||
const backlog = Math.max(0, this.turns.length - this.turnsExecuted);
|
||||
const allowReplayBacklog =
|
||||
this.replaySpeedMultiplier === ReplaySpeedMultiplier.fastest &&
|
||||
this.lobbyConfig.gameRecord !== undefined;
|
||||
const maxBacklog = allowReplayBacklog ? MAX_REPLAY_BACKLOG_TURNS : 0;
|
||||
|
||||
const canQueueNextTurn =
|
||||
backlog === 0 || (maxBacklog > 0 && backlog < maxBacklog);
|
||||
if (
|
||||
this.turnsExecuted === this.turns.length &&
|
||||
canQueueNextTurn &&
|
||||
Date.now() > this.turnStartTime + turnIntervalMs
|
||||
) {
|
||||
this.turnStartTime = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user