18 #include "precompiled.h"
42 #define getpid _getpid // use the non-deprecated function name
45 static std::string
Hexify(
const std::string& s)
47 std::stringstream str;
49 for (
size_t i = 0; i < s.size(); ++i)
50 str << std::setfill(
'0') << std::setw(2) << (int)(
unsigned char)s[i];
55 m_ScriptInterface(scriptInterface)
61 std::wstringstream name;
68 OsPath path =
psLogDir() / L
"sim_log" / name.str() / L
"commands.txt";
85 *
m_Stream <<
"turn " << n <<
" " << turnLength <<
"\n";
86 for (
size_t i = 0; i < commands.size(); ++i)
118 m_Stream =
new std::ifstream(path.c_str());
143 std::vector<SimulationCommand> commands;
166 else if (type ==
"turn")
171 else if (type ==
"cmd")
181 commands.push_back(cmd);
183 else if (type ==
"hash" || type ==
"hash-quick")
185 std::string replayHash;
188 bool quick = (type ==
"hash-quick");
197 std::string hexHash =
Hexify(hash);
198 if (hexHash == replayHash)
201 debug_printf(L
"HASH MISMATCH (%hs != %hs)", hexHash.c_str(), replayHash.c_str());
204 else if (type ==
"end")
233 debug_printf(L
"Unrecognised replay token %hs\n", type.c_str());
The container that holds the rules, resources and attributes of the game.
virtual void StartGame(const CScriptValRooted &attribs)
Started the game with the given game attributes.
CScriptStatsTable * g_ScriptStatsTable
const OsPath & psLogDir()
Status LDR_NonprogressiveLoad()
const PSRETURN PSRETURN_OK
void RecordFrameStart()
Call in main thread at the start of a frame.
static void out(const wchar_t *fmt,...)
Class CProfileViewer: Manage and display profiling tables.
virtual void Hash(const std::string &hash, bool quick)
Optional hash of simulation state (for sync checking).
std::string StringifyJSON(jsval obj, bool indent=true)
Stringify to a JSON string, UTF-8 encoded.
CScriptValRooted ParseJSON(const std::string &string_utf8)
Parse a UTF-8-encoded JSON string.
CReplayLogger(ScriptInterface &scriptInterface)
void Update(int turnLength)
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
void Load(const std::string &path)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
#define PROFILE2(region)
Starts timing from now until the end of the current scope.
void IncrementFrameNumber()
void SaveToFile()
Call in any thread to save a JSONP representation of the buffers for all threads, to a file named pro...
Simulation command, typically received over the network in multiplayer games.
void StartGame(const CScriptValRooted &attribs, const std::string &savedState)
ScriptInterface & GetScriptInterface() const
CGame * g_Game
Globally accessible pointer to the CGame object.
bool ComputeStateHash(std::string &outHash, bool quick)
virtual void Turn(u32 n, u32 turnLength, const std::vector< SimulationCommand > &commands)
Run the given turn with the given collection of player commands.
CSimulation2 * GetSimulation2()
Get the pointer to the simulation2 object.
#define PROFILE2_ATTR
Associates a string (with printf-style formatting) with the current region or event.
ScriptInterface & m_ScriptInterface
jsval get() const
Returns the current value (or JSVAL_VOID if uninitialised).
Abstraction around a SpiderMonkey JSContext.
void tex_codec_register_all()
Manually register codecs.
PSRETURN ReallyStartGame()
Game initialization has been completed.
Status CreateDirectories(const OsPath &path, mode_t mode)
void tex_codec_unregister_all()
remove all codecs that have been registered.
static std::string Hexify(const std::string &s)
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
static std::string OsString(const OsPath &path)
void timer_DisplayClientTotals()
display all clients' totals; does not reset them.