Ticket #3339: t3339_command_line_option_ooslog_unique_v1.1.patch

File t3339_command_line_option_ooslog_unique_v1.1.patch, 3.1 KB (added by elexis, 9 years ago)

Changed the name of the option to "oosdump-unique", some beautifying.

  • binaries/system/readme.txt

     
    4848                      PATH is system path to commands.txt containing simulation log
    4949-replay-visual=PATH visual replay of a previous game, used for analysis purposes
    5050                      PATH is system path to commands.txt containing simulation log
    5151-writableRoot       store runtime game data in root data directory
    5252                      (only use if you have write permissions on that directory)
     53-oosdump-unique     adds unix timestamp and process id to the filename of the out of sync log
     54                     to prevent the file from being overwritten by another process.
    5355-ooslog             dumps simulation state in binary and ASCII representations each turn,
    5456                      files created in sim_log within the game's log folder. NOTE: game will
    55                       run much slower with this option!
     57                      run much slower with this option and can use hundreds of megabytes of disk space!
    5658-serializationtest  checks simulation state each turn for serialization errors; on test
    5759                      failure, error is displayed and logs created in oos_log within the
    5860                      game's log folder. NOTE: game will run much slower with this option!
    5961
    6062Windows-specific:
  • source/network/NetTurnManager.cpp

     
    2424#include "network/NetMessage.h"
    2525
    2626#include "gui/GUIManager.h"
    2727#include "maths/MathUtil.h"
    2828#include "ps/CLogger.h"
     29#include "ps/GameSetup/CmdLineArgs.h"
    2930#include "ps/Profile.h"
    3031#include "ps/Pyrogenesis.h"
    3132#include "ps/Replay.h"
    3233#include "ps/SavedGame.h"
    3334#include "scriptinterface/ScriptInterface.h"
    3435#include "simulation2/Simulation2.h"
    3536
     37#include <ctime>
    3638#include <sstream>
    3739#include <fstream>
     40#include <iostream>
    3841#include <iomanip>
    3942
     43#if MSC_VERSION
     44#include <process.h>
     45#define getpid _getpid // use the non-deprecated function name
     46#endif
     47
    4048static const int DEFAULT_TURN_LENGTH_MP = 500;
    4149static const int DEFAULT_TURN_LENGTH_SP = 200;
    4250
    4351static const int COMMAND_DELAY = 2;
    4452
     
    228236
    229237    bool quick = !TurnNeedsFullHash(turn);
    230238    std::string hash;
    231239    ENSURE(m_Simulation2.ComputeStateHash(hash, quick));
    232240
    233     OsPath path = psLogDir()/"oos_dump.txt";
     241    std::wstringstream name;
     242    name << L"oos_dump";
     243    if (g_args.Has("oosdump-unique"))
     244        name << L"_" << std::time(0) << L"_" << getpid();
     245    name << L".txt";
     246
     247    OsPath path = psLogDir()/name.str();
    234248    std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc);
    235249    m_Simulation2.DumpDebugState(file);
    236250    file.close();
    237251
    238252    hash = Hexify(hash);
  • source/network/NetTurnManager.h

     
    2323
    2424#include <list>
    2525#include <map>
    2626#include <vector>
    2727
     28extern CmdLineArgs g_args;
     29
    2830class CNetServerWorker;
    2931class CNetClient;
    3032class CSimulationMessage;
    3133class CSimulation2;
    3234class IReplayLogger;