Ticket #3408: t3408_no_empty_commands_txt_v1.patch
File t3408_no_empty_commands_txt_v1.patch, 1.6 KB (added by , 9 years ago) |
---|
-
source/ps/Replay.cpp
47 47 std::stringstream str; 48 48 str << std::hex; 49 49 for (size_t i = 0; i < s.size(); ++i) 50 50 str << std::setfill('0') << std::setw(2) << (int)(unsigned char)s[i]; 51 51 return str.str(); 52 52 } 53 53 54 54 CReplayLogger::CReplayLogger(ScriptInterface& scriptInterface) : 55 55 m_ScriptInterface(scriptInterface) 56 56 { 57 } 58 59 CReplayLogger::~CReplayLogger() 60 { 61 delete m_Stream; 62 } 63 64 void CReplayLogger::StartGame(JS::MutableHandleValue attribs) 65 { 57 66 // Construct the directory name based on the PID, to be relatively unique. 58 67 // Append "-1", "-2" etc if we run multiple matches in a single session, 59 68 // to avoid accidentally overwriting earlier logs. 60 69 61 70 std::wstringstream name; 62 71 name << getpid(); 63 72 64 73 static int run = -1; 65 74 if (++run) 66 75 name << "-" << run; 67 76 68 77 OsPath path = psLogDir() / L"sim_log" / name.str() / L"commands.txt"; 69 78 CreateDirectories(path.Parent(), 0700); 70 79 m_Stream = new std::ofstream(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); 71 }72 73 CReplayLogger::~CReplayLogger()74 {75 delete m_Stream;76 }77 78 void CReplayLogger::StartGame(JS::MutableHandleValue attribs)79 {80 80 *m_Stream << "start " << m_ScriptInterface.StringifyJSON(attribs, false) << "\n"; 81 81 } 82 82 83 83 void CReplayLogger::Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>& commands) 84 84 { 85 85 JSContext* cx = m_ScriptInterface.GetContext(); 86 86 JSAutoRequest rq(cx); 87 87 88 88 *m_Stream << "turn " << n << " " << turnLength << "\n"; 89 89 for (size_t i = 0; i < commands.size(); ++i)