Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Replay.h
Go to the documentation of this file.
1 /* Copyright (C) 2010 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_REPLAY
19 #define INCLUDED_REPLAY
20 
21 class CScriptValRooted;
22 struct SimulationCommand;
23 class ScriptInterface;
24 
25 /**
26  * Replay log recorder interface.
27  * Call its methods at appropriate times during the game.
28  */
30 {
31 public:
33  virtual ~IReplayLogger() { }
34 
35  /**
36  * Started the game with the given game attributes.
37  */
38  virtual void StartGame(const CScriptValRooted& attribs) = 0;
39 
40  /**
41  * Run the given turn with the given collection of player commands.
42  */
43  virtual void Turn(u32 n, u32 turnLength, const std::vector<SimulationCommand>& commands) = 0;
44 
45  /**
46  * Optional hash of simulation state (for sync checking).
47  */
48  virtual void Hash(const std::string& hash, bool quick) = 0;
49 };
50 
51 /**
52  * Implementation of IReplayLogger that simply throws away all data.
53  */
55 {
56 public:
57  virtual void StartGame(const CScriptValRooted& UNUSED(attribs)) { }
58  virtual void Turn(u32 UNUSED(n), u32 UNUSED(turnLength), const std::vector<SimulationCommand>& UNUSED(commands)) { }
59  virtual void Hash(const std::string& UNUSED(hash), bool UNUSED(quick)) { }
60 };
61 
62 /**
63  * Implementation of IReplayLogger that saves data to a file in the logs directory.
64  */
66 {
68 public:
69  CReplayLogger(ScriptInterface& scriptInterface);
71 
72  virtual void StartGame(const CScriptValRooted& attribs);
73  virtual void Turn(u32 n, u32 turnLength, const std::vector<SimulationCommand>& commands);
74  virtual void Hash(const std::string& hash, bool quick);
75 
76 private:
78  std::ostream* m_Stream;
79 };
80 
81 /**
82  * Replay log replayer. Runs the log with no graphics and dumps some info to stdout.
83  */
85 {
86 public:
87  CReplayPlayer();
89 
90  void Load(const std::string& path);
91  void Replay();
92 
93 private:
94  std::istream* m_Stream;
95 };
96 
97 #endif // INCLUDED_REPLAY
virtual void StartGame(const CScriptValRooted &attribs)
Started the game with the given game attributes.
Definition: Replay.cpp:78
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
virtual ~IReplayLogger()
Definition: Replay.h:33
virtual void Turn(u32 n, u32 turnLength, const std::vector< SimulationCommand > &commands)=0
Run the given turn with the given collection of player commands.
~CReplayLogger()
Definition: Replay.cpp:73
std::ostream * m_Stream
Definition: Replay.h:78
void Replay()
Definition: Replay.cpp:122
virtual void Hash(const std::string &hash, bool quick)
Optional hash of simulation state (for sync checking).
Definition: Replay.cpp:94
Replay log recorder interface.
Definition: Replay.h:29
CReplayLogger(ScriptInterface &scriptInterface)
Definition: Replay.cpp:54
void Load(const std::string &path)
Definition: Replay.cpp:114
Replay log replayer.
Definition: Replay.h:84
Simulation command, typically received over the network in multiplayer games.
virtual void Hash(const std::string &hash, bool quick)=0
Optional hash of simulation state (for sync checking).
virtual void Turn(u32 n, u32 turnLength, const std::vector< SimulationCommand > &commands)
Run the given turn with the given collection of player commands.
Definition: Replay.cpp:83
IReplayLogger()
Definition: Replay.h:32
std::istream * m_Stream
Definition: Replay.h:94
ScriptInterface & m_ScriptInterface
Definition: Replay.h:77
virtual void Hash(const std::string &hash, bool quick)
Optional hash of simulation state (for sync checking).
Definition: Replay.h:59
#define u32
Definition: types.h:41
NONCOPYABLE(CReplayLogger)
virtual void StartGame(const CScriptValRooted &attribs)=0
Started the game with the given game attributes.
Abstraction around a SpiderMonkey JSContext.
virtual void Turn(u32 n, u32 turnLength, const std::vector< SimulationCommand > &commands)
Run the given turn with the given collection of player commands.
Definition: Replay.h:58
Implementation of IReplayLogger that saves data to a file in the logs directory.
Definition: Replay.h:65
Implementation of IReplayLogger that simply throws away all data.
Definition: Replay.h:54
virtual void StartGame(const CScriptValRooted &attribs)
Started the game with the given game attributes.
Definition: Replay.h:57