Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
ReplayTurnManager.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_REPLAYTURNMANAGER
19#define INCLUDED_REPLAYTURNMANAGER
20
21#include "ps/CStr.h"
24
25#include <js/ValueArray.h>
26#include <map>
27#include <string>
28#include <utility>
29#include <vector>
30
31class CSimulation2;
32class IReplayLogger;
33
34/**
35 * Implementation of CLocalTurnManager for replay games.
36 */
38{
39public:
40 CReplayTurnManager(CSimulation2& simulation, IReplayLogger& replay);
41
42 void StoreReplayCommand(turn_id_t turn, int player, const std::string& command);
43
44 void StoreReplayTurnLength(turn_id_t turn, std::uint32_t turnLength);
45
46 void StoreReplayHash(turn_id_t turn, const std::string& hash, bool quick);
47
49
50private:
51 void NotifyFinishedUpdate(turn_id_t turn, const UpdateCallback& sendEventToAll) override;
52
53 void DoTurn(turn_id_t turn, const UpdateCallback& sendEventToAll);
54
55 static const CStr EventNameReplayFinished;
56 static const CStr EventNameReplayOutOfSync;
57
58 bool m_HasSyncError = false;
59
60 // Contains the commands of every player on each turn
61 std::map<turn_id_t, std::vector<std::pair<player_id_t, std::string>>> m_ReplayCommands;
62
63 // Contains the length of every turn
64 std::map<turn_id_t, std::uint32_t> m_ReplayTurnLengths;
65
66 // Contains all replay hash values and weather or not the quick hash method was used
67 std::map<turn_id_t, std::pair<std::string, bool>> m_ReplayHash;
68};
69
70#endif // INCLUDED_REPLAYTURNMANAGER
std::int32_t turn_id_t
At 1000 turns/second, a 32-bit counter would overflow in ~49 days.
Definition: SimulationCommand.h:31
Implementation of CTurnManager for offline games.
Definition: LocalTurnManager.h:33
Implementation of CLocalTurnManager for replay games.
Definition: ReplayTurnManager.h:38
void NotifyFinishedUpdate(turn_id_t turn, const UpdateCallback &sendEventToAll) override
Called when this client has finished a simulation update.
Definition: ReplayTurnManager.cpp:75
std::map< turn_id_t, std::pair< std::string, bool > > m_ReplayHash
Definition: ReplayTurnManager.h:67
void StoreReplayHash(turn_id_t turn, const std::string &hash, bool quick)
Definition: ReplayTurnManager.cpp:56
static const CStr EventNameReplayFinished
Definition: ReplayTurnManager.h:55
void StoreReplayCommand(turn_id_t turn, int player, const std::string &command)
Definition: ReplayTurnManager.cpp:50
std::map< turn_id_t, std::vector< std::pair< player_id_t, std::string > > > m_ReplayCommands
Definition: ReplayTurnManager.h:61
CReplayTurnManager(CSimulation2 &simulation, IReplayLogger &replay)
Definition: ReplayTurnManager.cpp:45
bool m_HasSyncError
Definition: ReplayTurnManager.h:58
void StoreReplayTurnLength(turn_id_t turn, std::uint32_t turnLength)
Definition: ReplayTurnManager.cpp:61
void StoreFinalReplayTurn(turn_id_t turn)
Definition: ReplayTurnManager.cpp:70
std::map< turn_id_t, std::uint32_t > m_ReplayTurnLengths
Definition: ReplayTurnManager.h:64
static const CStr EventNameReplayOutOfSync
Definition: ReplayTurnManager.h:56
void DoTurn(turn_id_t turn, const UpdateCallback &sendEventToAll)
Definition: ReplayTurnManager.cpp:122
Public API for simulation system.
Definition: Simulation2.h:57
std::function< void(const std::string &, const std::optional< JS::HandleValueArray >)> UpdateCallback
Definition: TurnManager.h:92
Replay log recorder interface.
Definition: Replay.h:40