Pyrogenesis  trunk
Replay.h
Go to the documentation of this file.
1 /* Copyright (C) 2016 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 
22 
23 struct SimulationCommand;
24 class ScriptInterface;
25 
26 /**
27  * Replay log recorder interface.
28  * Call its methods at appropriate times during the game.
29  */
31 {
32 public:
34  virtual ~IReplayLogger() { }
35 
36  /**
37  * Started the game with the given game attributes.
38  */
39  virtual void StartGame(JS::MutableHandleValue attribs) = 0;
40 
41  /**
42  * Run the given turn with the given collection of player commands.
43  */
44  virtual void Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>& commands) = 0;
45 
46  /**
47  * Optional hash of simulation state (for sync checking).
48  */
49  virtual void Hash(const std::string& hash, bool quick) = 0;
50 
51  /**
52  * Remember the directory containing the commands.txt file, so that we can save additional files to it.
53  */
54  virtual OsPath GetDirectory() const = 0;
55 };
56 
57 /**
58  * Implementation of IReplayLogger that simply throws away all data.
59  */
61 {
62 public:
63  virtual void StartGame(JS::MutableHandleValue UNUSED(attribs)) { }
64  virtual void Turn(u32 UNUSED(n), u32 UNUSED(turnLength), std::vector<SimulationCommand>& UNUSED(commands)) { }
65  virtual void Hash(const std::string& UNUSED(hash), bool UNUSED(quick)) { }
66  virtual OsPath GetDirectory() const { return OsPath(); }
67 };
68 
69 /**
70  * Implementation of IReplayLogger that saves data to a file in the logs directory.
71  */
73 {
75 public:
76  CReplayLogger(ScriptInterface& scriptInterface);
77  ~CReplayLogger();
78 
79  virtual void StartGame(JS::MutableHandleValue attribs);
80  virtual void Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>& commands);
81  virtual void Hash(const std::string& hash, bool quick);
82  virtual OsPath GetDirectory() const;
83 
84 private:
86  std::ostream* m_Stream;
88 };
89 
90 /**
91  * Replay log replayer. Runs the log with no graphics and dumps some info to stdout.
92  */
94 {
95 public:
96  CReplayPlayer();
97  ~CReplayPlayer();
98 
99  void Load(const std::string& path);
100  void Replay(bool serializationtest, int rejointestturn, bool ooslog);
101 
102 private:
103  std::istream* m_Stream;
104 };
105 
106 #endif // INCLUDED_REPLAY
#define NONCOPYABLE(className)
Indicates that a class is noncopyable (usually due to const or reference members, or because the clas...
Definition: code_annotation.h:217
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Definition: code_annotation.h:38
virtual ~IReplayLogger()
Definition: Replay.h:34
virtual OsPath GetDirectory() const
Remember the directory containing the commands.txt file, so that we can save additional files to it...
Definition: Replay.h:66
std::ostream * m_Stream
Definition: Replay.h:86
virtual void Turn(u32 n, u32 turnLength, std::vector< SimulationCommand > &commands)=0
Run the given turn with the given collection of player commands.
Replay log recorder interface.
Definition: Replay.h:30
uint32_t u32
Definition: types.h:39
Definition: path.h:77
virtual void StartGame(JS::MutableHandleValue attribs)=0
Started the game with the given game attributes.
Replay log replayer.
Definition: Replay.h:93
Path OsPath
Definition: os_path.h:31
Simulation command, typically received over the network in multiplayer games.
Definition: SimulationCommand.h:27
virtual void Hash(const std::string &hash, bool quick)=0
Optional hash of simulation state (for sync checking).
static Status Load(const OsPath &pathname, void *buf, size_t size, const Parameters &p=Parameters(), const CompletedHook &completedHook=CompletedHook(), const IssueHook &issueHook=IssueHook())
Definition: io.h:337
OsPath m_Directory
Definition: Replay.h:87
virtual void Turn(u32 n, u32 turnLength, std::vector< SimulationCommand > &commands)
Run the given turn with the given collection of player commands.
Definition: Replay.h:64
IReplayLogger()
Definition: Replay.h:33
std::istream * m_Stream
Definition: Replay.h:103
ScriptInterface & m_ScriptInterface
Definition: Replay.h:85
virtual void Hash(const std::string &hash, bool quick)
Optional hash of simulation state (for sync checking).
Definition: Replay.h:65
virtual OsPath GetDirectory() const =0
Remember the directory containing the commands.txt file, so that we can save additional files to it...
Abstraction around a SpiderMonkey JSContext.
Definition: ScriptInterface.h:71
Implementation of IReplayLogger that saves data to a file in the logs directory.
Definition: Replay.h:72
Implementation of IReplayLogger that simply throws away all data.
Definition: Replay.h:60
virtual void StartGame(JS::MutableHandleValue attribs)
Started the game with the given game attributes.
Definition: Replay.h:63