Ticket #4095: movehexify2.patch

File movehexify2.patch, 4.4 KB (added by echotangoecho, 8 years ago)

Change the previous patch to make the Hexify function use a range-based for loop.

  • source/network/NetTurnManager.cpp

     
    2929#include "ps/CLogger.h"
    3030#include "ps/Profile.h"
    3131#include "ps/Pyrogenesis.h"
    3232#include "ps/Replay.h"
    3333#include "ps/SavedGame.h"
     34#include "ps/Util.h"
    3435#include "scriptinterface/ScriptInterface.h"
    3536#include "simulation2/Simulation2.h"
    3637
    37 #include <sstream>
    3838#include <fstream>
    39 #include <iomanip>
    4039
    4140const u32 DEFAULT_TURN_LENGTH_MP = 500;
    4241const u32 DEFAULT_TURN_LENGTH_SP = 200;
    4342
    4443static const int COMMAND_DELAY = 2;
    static const int COMMAND_DELAY = 2;  
    4746#define NETTURN_LOG(args) debug_printf args
    4847#else
    4948#define NETTURN_LOG(args)
    5049#endif
    5150
    52 static std::string Hexify(const std::string& s)
    53 {
    54     std::stringstream str;
    55     str << std::hex;
    56     for (size_t i = 0; i < s.size(); ++i)
    57         str << std::setfill('0') << std::setw(2) << (int)(unsigned char)s[i];
    58     return str.str();
    59 }
    60 
    6151CNetTurnManager::CNetTurnManager(CSimulation2& simulation, u32 defaultTurnLength, int clientId, IReplayLogger& replay) :
    6252    m_Simulation2(simulation), m_CurrentTurn(0), m_ReadyTurn(1), m_TurnLength(defaultTurnLength), m_DeltaSimTime(0),
    6353    m_PlayerId(-1), m_ClientId(clientId), m_HasSyncError(false), m_Replay(replay),
    6454    m_TimeWarpNumTurns(0), m_FinalTurn(std::numeric_limits<u32>::max())
    6555{
  • source/ps/Replay.cpp

     
    3737#include "scriptinterface/ScriptStats.h"
    3838#include "simulation2/Simulation2.h"
    3939#include "simulation2/helpers/SimulationCommand.h"
    4040
    4141#include <ctime>
    42 #include <sstream>
    4342#include <fstream>
    44 #include <iomanip>
    45 
    46 static std::string Hexify(const std::string& s)
    47 {
    48     std::stringstream str;
    49     str << std::hex;
    50     for (size_t i = 0; i < s.size(); ++i)
    51         str << std::setfill('0') << std::setw(2) << (int)(unsigned char)s[i];
    52     return str.str();
    53 }
    5443
    5544CReplayLogger::CReplayLogger(ScriptInterface& scriptInterface) :
    5645    m_ScriptInterface(scriptInterface), m_Stream(NULL)
    5746{
    5847}
  • source/ps/Util.cpp

    void WriteBigScreenshot(const VfsPath& e  
    420420    else
    421421        LOGERROR("Error writing screenshot to '%s'", filename.string8());
    422422
    423423    free(tile_data);
    424424}
     425
     426std::string Hexify(const std::string& s)
     427{
     428    std::stringstream str;
     429    str << std::hex;
     430    for (char c : s)
     431        str << std::setfill('0') << std::setw(2) << (int)(unsigned char)c;
     432    return str.str();
     433}
  • source/ps/Util.h

     
    2020
    2121#include "lib/file/vfs/vfs_path.h"
    2222
    2323struct Tex;
    2424
    25 extern void WriteSystemInfo();
     25void WriteSystemInfo();
    2626
    27 extern const wchar_t* ErrorString(int err);
     27const wchar_t* ErrorString(int err);
    2828
    29 extern OsPath createDateIndexSubdirectory(const OsPath& parentDir);
     29OsPath createDateIndexSubdirectory(const OsPath& parentDir);
    3030
    31 extern void WriteScreenshot(const VfsPath& extension);
    32 extern void WriteBigScreenshot(const VfsPath& extension, int tiles);
     31void WriteScreenshot(const VfsPath& extension);
     32void WriteBigScreenshot(const VfsPath& extension, int tiles);
    3333
    34 extern Status tex_write(Tex* t, const VfsPath& filename);
     34Status tex_write(Tex* t, const VfsPath& filename);
     35
     36std::string Hexify(const std::string& s);
    3537
    3638#endif // PS_UTIL_H
  • source/simulation2/Simulation2.cpp

     
    4444#include "ps/Util.h"
    4545#include "ps/XML/Xeromyces.h"
    4646
    4747#include <iomanip>
    4848
    49 static std::string Hexify(const std::string& s) // TODO: shouldn't duplicate this function in so many places
    50 {
    51     std::stringstream str;
    52     str << std::hex;
    53     for (size_t i = 0; i < s.size(); ++i)
    54         str << std::setfill('0') << std::setw(2) << (int)(unsigned char)s[i];
    55     return str.str();
    56 }
    57 
    5849class CSimulation2Impl
    5950{
    6051public:
    6152    CSimulation2Impl(CUnitManager* unitManager, shared_ptr<ScriptRuntime> rt, CTerrain* terrain) :
    6253        m_SimContext(), m_ComponentManager(m_SimContext, rt),