Changeset View
Changeset View
Standalone View
Standalone View
source/ps/Replay.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
elexis: ^ | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 16 Lines | |||||
#include "lib/tex/tex.h" | #include "lib/tex/tex.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Loader.h" | #include "ps/Loader.h" | ||||
#include "ps/Mod.h" | #include "ps/Mod.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/ProfileViewer.h" | #include "ps/ProfileViewer.h" | ||||
#include "ps/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "ps/Mod.h" | |||||
#include "ps/Util.h" | #include "ps/Util.h" | ||||
#include "ps/VisualReplay.h" | #include "ps/VisualReplay.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/ScriptStats.h" | #include "scriptinterface/ScriptStats.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/helpers/SimulationCommand.h" | #include "simulation2/helpers/SimulationCommand.h" | ||||
#include <ctime> | #include <ctime> | ||||
#include <fstream> | #include <fstream> | ||||
CReplayLogger::CReplayLogger(const ScriptInterface& scriptInterface) : | CReplayLogger::CReplayLogger(const ScriptInterface& scriptInterface) : | ||||
m_ScriptInterface(scriptInterface), m_Stream(NULL) | m_ScriptInterface(scriptInterface), m_Stream(NULL) | ||||
{ | { | ||||
} | } | ||||
CReplayLogger::~CReplayLogger() | CReplayLogger::~CReplayLogger() | ||||
{ | { | ||||
delete m_Stream; | delete m_Stream; | ||||
} | } | ||||
void CReplayLogger::StartGame(JS::MutableHandleValue attribs) | void CReplayLogger::StartGame(JS::MutableHandleValue attribs) | ||||
{ | { | ||||
JSContext* cx = m_ScriptInterface.GetContext(); | |||||
JSAutoRequest rq(cx); | |||||
elexisUnsubmitted Done Inline ActionsAutoRequest probably not needed, but should be kept for consistency and good practice. elexis: AutoRequest probably not needed, but should be kept for consistency and good practice. | |||||
ImarokAuthorUnsubmitted Not Done Inline ActionsI think it is needed for L65 Imarok: I think it is needed for L65 | |||||
// Add timestamp, since the file-modification-date can change | // Add timestamp, since the file-modification-date can change | ||||
m_ScriptInterface.SetProperty(attribs, "timestamp", (double)std::time(nullptr)); | m_ScriptInterface.SetProperty(attribs, "timestamp", (double)std::time(nullptr)); | ||||
// Add engine version and currently loaded mods for sanity checks when replaying | // Add engine version and currently loaded mods for sanity checks when replaying | ||||
m_ScriptInterface.SetProperty(attribs, "engine_version", CStr(engine_version)); | m_ScriptInterface.SetProperty(attribs, "engine_version", CStr(engine_version)); | ||||
m_ScriptInterface.SetProperty(attribs, "mods", g_modsLoaded); | m_ScriptInterface.SetProperty(attribs, "mods", JS::RootedValue(cx, Mod::GetLoadedModsWithVersions(m_ScriptInterface))); | ||||
elexisUnsubmitted Not Done Inline ActionsCalling a function seems nicer than a global indeed. If something needs that very frequently, it can cache that on it's own, or we should have a getter for the cache. elexis: Calling a function seems nicer than a global indeed. If something needs that very frequently… | |||||
m_Directory = createDateIndexSubdirectory(VisualReplay::GetDirectoryName()); | m_Directory = createDateIndexSubdirectory(VisualReplay::GetDirectoryName()); | ||||
debug_printf("Writing replay to %s\n", m_Directory.string8().c_str()); | debug_printf("Writing replay to %s\n", m_Directory.string8().c_str()); | ||||
m_Stream = new std::ofstream(OsString(m_Directory / L"commands.txt").c_str(), std::ofstream::out | std::ofstream::trunc); | m_Stream = new std::ofstream(OsString(m_Directory / L"commands.txt").c_str(), std::ofstream::out | std::ofstream::trunc); | ||||
*m_Stream << "start " << m_ScriptInterface.StringifyJSON(attribs, false) << "\n"; | *m_Stream << "start " << m_ScriptInterface.StringifyJSON(attribs, false) << "\n"; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
^