Ticket #3408: t3408_no_empty_commands_txt_v1.patch

File t3408_no_empty_commands_txt_v1.patch, 1.6 KB (added by elexis, 9 years ago)
  • source/ps/Replay.cpp

     
    4747    std::stringstream str;
    4848    str << std::hex;
    4949    for (size_t i = 0; i < s.size(); ++i)
    5050        str << std::setfill('0') << std::setw(2) << (int)(unsigned char)s[i];
    5151    return str.str();
    5252}
    5353
    5454CReplayLogger::CReplayLogger(ScriptInterface& scriptInterface) :
    5555    m_ScriptInterface(scriptInterface)
    5656{
     57}
     58
     59CReplayLogger::~CReplayLogger()
     60{
     61    delete m_Stream;
     62}
     63
     64void CReplayLogger::StartGame(JS::MutableHandleValue attribs)
     65{
    5766    // Construct the directory name based on the PID, to be relatively unique.
    5867    // Append "-1", "-2" etc if we run multiple matches in a single session,
    5968    // to avoid accidentally overwriting earlier logs.
    6069
    6170    std::wstringstream name;
    6271    name << getpid();
    6372
    6473    static int run = -1;
    6574    if (++run)
    6675        name << "-" << run;
    6776
    6877    OsPath path = psLogDir() / L"sim_log" / name.str() / L"commands.txt";
    6978    CreateDirectories(path.Parent(), 0700);
    7079    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 {
    8080    *m_Stream << "start " << m_ScriptInterface.StringifyJSON(attribs, false) << "\n";
    8181}
    8282
    8383void CReplayLogger::Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>& commands)
    8484{
    8585    JSContext* cx = m_ScriptInterface.GetContext();
    8686    JSAutoRequest rq(cx);
    8787   
    8888    *m_Stream << "turn " << n << " " << turnLength << "\n";
    8989    for (size_t i = 0; i < commands.size(); ++i)