1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Use API identical to std classes where possible

This commit is contained in:
Ivan Savenko
2023-08-20 23:45:41 +03:00
parent 87957e74c1
commit 44d16b32fe
32 changed files with 72 additions and 87 deletions

View File

@ -1607,7 +1607,7 @@ void AIStatus::waitTillFree()
{ {
boost::unique_lock<boost::mutex> lock(mx); boost::unique_lock<boost::mutex> lock(mx);
while(battle != NO_BATTLE || !remainingQueries.empty() || !objectsBeingVisited.empty() || ongoingHeroMovement) while(battle != NO_BATTLE || !remainingQueries.empty() || !objectsBeingVisited.empty() || ongoingHeroMovement)
cv.timed_wait(lock, boost::posix_time::milliseconds(10)); cv.wait_for(lock, boost::chrono::milliseconds(10));
} }
bool AIStatus::haveTurn() bool AIStatus::haveTurn()

View File

@ -108,7 +108,7 @@ void CStupidAI::yourTacticPhase(int distance)
void CStupidAI::activeStack( const CStack * stack ) void CStupidAI::activeStack( const CStack * stack )
{ {
//boost::this_thread::sleep(boost::posix_time::seconds(2)); //boost::this_thread::sleep_for(boost::chrono::seconds(2));
print("activeStack called for " + stack->nodeName()); print("activeStack called for " + stack->nodeName());
ReachabilityInfo dists = cb->getReachability(stack); ReachabilityInfo dists = cb->getReachability(stack);
std::vector<EnemyInfo> enemiesShootable, enemiesReachable, enemiesUnreachable; std::vector<EnemyInfo> enemiesShootable, enemiesReachable, enemiesUnreachable;

View File

@ -2677,7 +2677,7 @@ void AIStatus::waitTillFree()
{ {
boost::unique_lock<boost::mutex> lock(mx); boost::unique_lock<boost::mutex> lock(mx);
while(battle != NO_BATTLE || !remainingQueries.empty() || !objectsBeingVisited.empty() || ongoingHeroMovement) while(battle != NO_BATTLE || !remainingQueries.empty() || !objectsBeingVisited.empty() || ongoingHeroMovement)
cv.timed_wait(lock, boost::posix_time::milliseconds(100)); cv.wait_for(lock, boost::chrono::milliseconds(100));
} }
bool AIStatus::haveTurn() bool AIStatus::haveTurn()

View File

@ -149,8 +149,8 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/crc.hpp> #include <boost/crc.hpp>
#include <boost/current_function.hpp> #include <boost/current_function.hpp>
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp> #include <boost/date_time/posix_time/time_formatters.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
@ -165,7 +165,10 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#include <boost/range/adaptor/filtered.hpp> #include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/reversed.hpp> #include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm.hpp> #include <boost/range/algorithm.hpp>
#include <boost/thread.hpp> #include <boost/thread/thread_only.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/once.hpp>
#ifndef M_PI #ifndef M_PI
# define M_PI 3.14159265358979323846 # define M_PI 3.14159265358979323846

View File

@ -54,8 +54,6 @@
namespace po = boost::program_options; namespace po = boost::program_options;
namespace po_style = boost::program_options::command_line_style; namespace po_style = boost::program_options::command_line_style;
extern boost::thread_specific_ptr<bool> inGuiThread;
static po::variables_map vm; static po::variables_map vm;
#ifndef VCMI_IOS #ifndef VCMI_IOS
@ -416,7 +414,7 @@ int main(int argc, char * argv[])
else else
{ {
while(true) while(true)
boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
} }
return 0; return 0;
@ -435,7 +433,6 @@ void playIntro()
static void mainLoop() static void mainLoop()
{ {
setThreadName("MainGUI"); setThreadName("MainGUI");
inGuiThread.reset(new bool(true));
while(1) //main SDL events loop while(1) //main SDL events loop
{ {
@ -476,7 +473,7 @@ static void quitApplication()
vstd::clear_pointer(console);// should be removed after everything else since used by logging vstd::clear_pointer(console);// should be removed after everything else since used by logging
boost::this_thread::sleep(boost::posix_time::milliseconds(750));//??? boost::this_thread::sleep_for(boost::chrono::milliseconds(750));//???
if(!settings["session"]["headless"].Bool()) if(!settings["session"]["headless"].Bool())
GH.screenHandler().close(); GH.screenHandler().close();

View File

@ -1448,7 +1448,7 @@ void CPlayerInterface::centerView (int3 pos, int focusTime)
{ {
auto unlockPim = vstd::makeUnlockGuard(*pim); auto unlockPim = vstd::makeUnlockGuard(*pim);
IgnoreEvents ignore(*this); IgnoreEvents ignore(*this);
boost::this_thread::sleep(boost::posix_time::milliseconds(focusTime)); boost::this_thread::sleep_for(boost::chrono::milliseconds(focusTime));
} }
} }
CCS->curh->show(); CCS->curh->show();
@ -1875,7 +1875,7 @@ void CPlayerInterface::waitForAllDialogs(bool unlockPim)
while(!dialogs.empty()) while(!dialogs.empty())
{ {
auto unlock = vstd::makeUnlockGuardIf(*pim, unlockPim); auto unlock = vstd::makeUnlockGuardIf(*pim, unlockPim);
boost::this_thread::sleep(boost::posix_time::milliseconds(5)); boost::this_thread::sleep_for(boost::chrono::milliseconds(5));
} }
waitWhileDialog(unlockPim); waitWhileDialog(unlockPim);
} }

View File

@ -231,7 +231,7 @@ void CServerHandler::startLocalServerAndConnect()
while(!androidTestServerReadyFlag.load()) while(!androidTestServerReadyFlag.load())
{ {
logNetwork->info("still waiting..."); logNetwork->info("still waiting...");
boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
} }
logNetwork->info("waiting for server finished..."); logNetwork->info("waiting for server finished...");
androidTestServerReadyFlag = false; androidTestServerReadyFlag = false;
@ -261,7 +261,7 @@ void CServerHandler::justConnectToServer(const std::string & addr, const ui16 po
catch(std::runtime_error & error) catch(std::runtime_error & error)
{ {
logNetwork->warn("\nCannot establish connection. %s Retrying in 1 second", error.what()); logNetwork->warn("\nCannot establish connection. %s Retrying in 1 second", error.what());
boost::this_thread::sleep(boost::posix_time::seconds(1)); boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
} }
} }
@ -307,7 +307,7 @@ void CServerHandler::stopServerConnection()
{ {
if(c->handler) if(c->handler)
{ {
while(!c->handler->timed_join(boost::posix_time::milliseconds(50))) while(!c->handler->timed_join(boost::chrono::milliseconds(50)))
applyPacksOnLobbyScreen(); applyPacksOnLobbyScreen();
c->handler->join(); c->handler->join();
} }
@ -761,20 +761,20 @@ void CServerHandler::debugStartTest(std::string filename, bool save)
else else
startLocalServerAndConnect(); startLocalServerAndConnect();
boost::this_thread::sleep(boost::posix_time::milliseconds(100)); boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
while(!settings["session"]["headless"].Bool() && !GH.windows().topWindow<CLobbyScreen>()) while(!settings["session"]["headless"].Bool() && !GH.windows().topWindow<CLobbyScreen>())
boost::this_thread::sleep(boost::posix_time::milliseconds(50)); boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
while(!mi || mapInfo->fileURI != CSH->mi->fileURI) while(!mi || mapInfo->fileURI != CSH->mi->fileURI)
{ {
setMapInfo(mapInfo); setMapInfo(mapInfo);
boost::this_thread::sleep(boost::posix_time::milliseconds(50)); boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
} }
// "Click" on color to remove us from it // "Click" on color to remove us from it
setPlayer(myFirstColor()); setPlayer(myFirstColor());
while(myFirstColor() != PlayerColor::CANNOT_DETERMINE) while(myFirstColor() != PlayerColor::CANNOT_DETERMINE)
boost::this_thread::sleep(boost::posix_time::milliseconds(50)); boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
while(true) while(true)
{ {
@ -787,7 +787,7 @@ void CServerHandler::debugStartTest(std::string filename, bool save)
{ {
} }
boost::this_thread::sleep(boost::posix_time::milliseconds(50)); boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
} }
} }
@ -826,7 +826,7 @@ void CServerHandler::threadHandleConnection()
while(c->connected) while(c->connected)
{ {
while(state == EClientState::STARTING) while(state == EClientState::STARTING)
boost::this_thread::sleep(boost::posix_time::milliseconds(10)); boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
CPack * pack = c->retrievePack(); CPack * pack = c->retrievePack();
if(state == EClientState::DISCONNECTING) if(state == EClientState::DISCONNECTING)

View File

@ -461,7 +461,7 @@ bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey)
double frameDurationSec = packet_duration * av_q2d(format->streams[stream]->time_base); double frameDurationSec = packet_duration * av_q2d(format->streams[stream]->time_base);
uint32_t timeToSleepMillisec = 1000 * (frameDurationSec); uint32_t timeToSleepMillisec = 1000 * (frameDurationSec);
boost::this_thread::sleep(boost::posix_time::millisec(timeToSleepMillisec)); boost::this_thread::sleep_for(boost::chrono::milliseconds(timeToSleepMillisec));
} }
return true; return true;

View File

@ -407,7 +407,7 @@ void BattleWindow::bFleef()
auto txt = boost::format(CGI->generaltexth->allTexts[340]) % heroName; //The Shackles of War are present. %s can not retreat! auto txt = boost::format(CGI->generaltexth->allTexts[340]) % heroName; //The Shackles of War are present. %s can not retreat!
//printing message //printing message
owner.curInt->showInfoDialog(boost::to_string(txt), comps); owner.curInt->showInfoDialog(boost::str(txt), comps);
} }
} }

View File

@ -36,7 +36,7 @@
CGuiHandler GH; CGuiHandler GH;
boost::thread_specific_ptr<bool> inGuiThread; static thread_local bool inGuiThread = false;
SObjectConstruction::SObjectConstruction(CIntObject *obj) SObjectConstruction::SObjectConstruction(CIntObject *obj)
:myObj(obj) :myObj(obj)
@ -69,6 +69,8 @@ SSetCaptureState::~SSetCaptureState()
void CGuiHandler::init() void CGuiHandler::init()
{ {
inGuiThread = true;
inputHandlerInstance = std::make_unique<InputHandler>(); inputHandlerInstance = std::make_unique<InputHandler>();
eventDispatcherInstance = std::make_unique<EventDispatcher>(); eventDispatcherInstance = std::make_unique<EventDispatcher>();
windowHandlerInstance = std::make_unique<WindowHandler>(); windowHandlerInstance = std::make_unique<WindowHandler>();
@ -117,7 +119,7 @@ void CGuiHandler::renderFrame()
bool acquiredTheLockOnPim = false; //for tracking whether pim mutex locking succeeded bool acquiredTheLockOnPim = false; //for tracking whether pim mutex locking succeeded
while(!terminate_cond->get() && !(acquiredTheLockOnPim = CPlayerInterface::pim->try_lock())) //try acquiring long until it succeeds or we are told to terminate while(!terminate_cond->get() && !(acquiredTheLockOnPim = CPlayerInterface::pim->try_lock())) //try acquiring long until it succeeds or we are told to terminate
boost::this_thread::sleep(boost::posix_time::milliseconds(1)); boost::this_thread::sleep_for(boost::chrono::milliseconds(1));
if(acquiredTheLockOnPim) if(acquiredTheLockOnPim)
{ {
@ -207,7 +209,7 @@ void CGuiHandler::drawFPSCounter()
bool CGuiHandler::amIGuiThread() bool CGuiHandler::amIGuiThread()
{ {
return inGuiThread.get() && *inGuiThread; return inGuiThread;
} }
void CGuiHandler::dispatchMainThread(const std::function<void()> & functor) void CGuiHandler::dispatchMainThread(const std::function<void()> & functor)

View File

@ -38,7 +38,7 @@ void CMapHandler::waitForOngoingAnimations()
while(CGI->mh->hasOngoingAnimations()) while(CGI->mh->hasOngoingAnimations())
{ {
auto unlockPim = vstd::makeUnlockGuard(*CPlayerInterface::pim); auto unlockPim = vstd::makeUnlockGuard(*CPlayerInterface::pim);
boost::this_thread::sleep(boost::posix_time::milliseconds(1)); boost::this_thread::sleep_for(boost::chrono::milliseconds(1));
} }
} }

View File

@ -562,7 +562,7 @@ void CSpellWindow::SpellArea::hover(bool on)
if(mySpell) if(mySpell)
{ {
if(on) if(on)
owner->statusBar->write(boost::to_string(boost::format("%s (%s)") % mySpell->getNameTranslated() % CGI->generaltexth->allTexts[171+mySpell->level])); owner->statusBar->write(boost::str(boost::format("%s (%s)") % mySpell->getNameTranslated() % CGI->generaltexth->allTexts[171+mySpell->level]));
else else
owner->statusBar->clear(); owner->statusBar->clear();
} }

View File

@ -233,7 +233,7 @@ int CConsoleHandler::run() const
(*cb)(buffer, false); (*cb)(buffer, false);
} }
else else
boost::this_thread::sleep(boost::posix_time::millisec(100)); boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
#else #else

View File

@ -13,8 +13,6 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
boost::thread_specific_ptr<CRandomGenerator> CRandomGenerator::defaultRand;
CRandomGenerator::CRandomGenerator() CRandomGenerator::CRandomGenerator()
{ {
resetSeed(); resetSeed();
@ -84,11 +82,8 @@ double CRandomGenerator::nextDouble()
CRandomGenerator & CRandomGenerator::getDefault() CRandomGenerator & CRandomGenerator::getDefault()
{ {
if(!defaultRand.get()) static thread_local CRandomGenerator defaultRand;
{ return defaultRand;
defaultRand.reset(new CRandomGenerator());
}
return *defaultRand;
} }
TGenerator & CRandomGenerator::getStdGenerator() TGenerator & CRandomGenerator::getStdGenerator()

View File

@ -80,7 +80,6 @@ public:
private: private:
TGenerator rand; TGenerator rand;
static boost::thread_specific_ptr<CRandomGenerator> defaultRand;
public: public:
template <typename Handler> template <typename Handler>

View File

@ -29,10 +29,12 @@ CThreadHelper::CThreadHelper(std::vector<std::function<void()>> * Tasks, int Thr
} }
void CThreadHelper::run() void CThreadHelper::run()
{ {
boost::thread_group grupa; std::vector<boost::thread> group;
for(int i=0;i<threads;i++) for(int i=0;i<threads;i++)
grupa.create_thread(std::bind(&CThreadHelper::processTasks,this)); group.emplace_back(std::bind(&CThreadHelper::processTasks,this));
grupa.join_all();
for (auto & thread : group)
thread.join();
//thread group deletes threads, do not free manually //thread group deletes threads, do not free manually
} }

View File

@ -46,15 +46,15 @@ public:
void run() void run()
{ {
boost::thread_group grupa; std::vector<boost::thread> group;
for(size_t i=0; i<threads; i++) for(size_t i=0; i<threads; i++)
{ {
std::shared_ptr<Payload> payload = context.at(i); std::shared_ptr<Payload> payload = context.at(i);
group.emplace_back(std::bind(&ThreadPool::processTasks, this, payload));
grupa.create_thread(std::bind(&ThreadPool::processTasks, this, payload));
} }
grupa.join_all(); for (auto & thread : group)
thread.join();
//thread group deletes threads, do not free manually //thread group deletes threads, do not free manually
} }

View File

@ -288,7 +288,7 @@ std::string CLogFormatter::format(const LogRecord & record) const
boost::algorithm::replace_first(message, "%m", record.message); boost::algorithm::replace_first(message, "%m", record.message);
boost::algorithm::replace_first(message, "%c", boost::posix_time::to_simple_string(record.timeStamp)); boost::algorithm::replace_first(message, "%c", boost::posix_time::to_simple_string(record.timeStamp));
//return boost::to_string (boost::format("%d %d %d[%d] - %d") % dateStream.str() % level % record.domain.getName() % record.threadId % record.message); //return boost::str (boost::format("%d %d %d[%d] - %d") % dateStream.str() % level % record.domain.getName() % record.threadId % record.message);
return message; return message;
} }

View File

@ -69,7 +69,7 @@ std::string CGCreature::getHoverText(const CGHeroInstance * hero) const
ms.appendLocalString(EMetaText::GENERAL_TXT,243); ms.appendLocalString(EMetaText::GENERAL_TXT,243);
break; break;
default: //decision = cost in gold default: //decision = cost in gold
ms.appendRawString(boost::to_string(boost::format(VLC->generaltexth->allTexts[244]) % decision)); ms.appendRawString(boost::str(boost::format(VLC->generaltexth->allTexts[244]) % decision));
break; break;
} }

View File

@ -1463,7 +1463,7 @@ bool CGHeroInstance::hasVisions(const CGObjectInstance * target, const int subty
const int distance = static_cast<int>(target->pos.dist2d(visitablePos())); const int distance = static_cast<int>(target->pos.dist2d(visitablePos()));
//logGlobal->debug(boost::to_string(boost::format("Visions: dist %d, mult %d, range %d") % distance % visionsMultiplier % visionsRange)); //logGlobal->debug(boost::str(boost::format("Visions: dist %d, mult %d, range %d") % distance % visionsMultiplier % visionsRange));
return (distance < visionsRange) && (target->pos.z == pos.z); return (distance < visionsRange) && (target->pos.z == pos.z);
} }

View File

@ -421,7 +421,7 @@ int CMapGenerator::getNextMonlithIndex()
while (true) while (true)
{ {
if (monolithIndex >= VLC->objtypeh->knownSubObjects(Obj::MONOLITH_TWO_WAY).size()) if (monolithIndex >= VLC->objtypeh->knownSubObjects(Obj::MONOLITH_TWO_WAY).size())
throw rmgException(boost::to_string(boost::format("There is no Monolith Two Way with index %d available!") % monolithIndex)); throw rmgException(boost::str(boost::format("There is no Monolith Two Way with index %d available!") % monolithIndex));
else else
{ {
//Skip modded Monoliths which can't beplaced on every terrain //Skip modded Monoliths which can't beplaced on every terrain

View File

@ -156,7 +156,7 @@ TRmgTemplateZoneId ZoneOptions::getId() const
void ZoneOptions::setId(TRmgTemplateZoneId value) void ZoneOptions::setId(TRmgTemplateZoneId value)
{ {
if(value <= 0) if(value <= 0)
throw std::runtime_error(boost::to_string(boost::format("Zone %d id should be greater than 0.") % id)); throw std::runtime_error(boost::str(boost::format("Zone %d id should be greater than 0.") % id));
id = value; id = value;
} }
@ -650,7 +650,7 @@ std::string CRmgTemplate::CPlayerCountRange::toString() const
} }
else else
{ {
ret += boost::to_string(boost::format("%d-%d") % p.first % p.second); ret += boost::str(boost::format("%d-%d") % p.first % p.second);
} }
} }

View File

@ -219,7 +219,7 @@ const CMapGenOptions& RmgMap::getMapGenOptions() const
void RmgMap::assertOnMap(const int3& tile) const void RmgMap::assertOnMap(const int3& tile) const
{ {
if (!mapInstance->isInTheMap(tile)) if (!mapInstance->isInTheMap(tile))
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile.toString())); throw rmgException(boost::str(boost::format("Tile %s is outside the map") % tile.toString()));
} }
RmgMap::Zones & RmgMap::getZones() RmgMap::Zones & RmgMap::getZones()
@ -354,7 +354,7 @@ bool RmgMap::isAllowedSpell(const SpellID & sid) const
void RmgMap::dump(bool zoneId) const void RmgMap::dump(bool zoneId) const
{ {
static int id = 0; static int id = 0;
std::ofstream out(boost::to_string(boost::format("zone_%d.txt") % id++)); std::ofstream out(boost::str(boost::format("zone_%d.txt") % id++));
int levels = mapInstance->levels(); int levels = mapInstance->levels();
int width = mapInstance->width; int width = mapInstance->width;
int height = mapInstance->height; int height = mapInstance->height;

View File

@ -115,7 +115,7 @@ void Object::Instance::setAnyTemplate()
{ {
auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(); auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates();
if(templates.empty()) if(templates.empty())
throw rmgException(boost::to_string(boost::format("Did not find any graphics for object (%d,%d)") % dObject.ID % dObject.subID)); throw rmgException(boost::str(boost::format("Did not find any graphics for object (%d,%d)") % dObject.ID % dObject.subID));
dObject.appearance = templates.front(); dObject.appearance = templates.front();
dAccessibleAreaCache.clear(); dAccessibleAreaCache.clear();
@ -128,7 +128,7 @@ void Object::Instance::setTemplate(TerrainId terrain)
if (templates.empty()) if (templates.empty())
{ {
auto terrainName = VLC->terrainTypeHandler->getById(terrain)->getNameTranslated(); auto terrainName = VLC->terrainTypeHandler->getById(terrain)->getNameTranslated();
throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s") % dObject.ID % dObject.subID % terrainName)); throw rmgException(boost::str(boost::format("Did not find graphics for object (%d,%d) at %s") % dObject.ID % dObject.subID % terrainName));
} }
dObject.appearance = templates.front(); dObject.appearance = templates.front();
dAccessibleAreaCache.clear(); dAccessibleAreaCache.clear();
@ -328,7 +328,7 @@ void rmg::Object::setGuardedIfMonster(const Instance& object)
void Object::Instance::finalize(RmgMap & map) void Object::Instance::finalize(RmgMap & map)
{ {
if(!map.isOnMap(getPosition(true))) if(!map.isOnMap(getPosition(true)))
throw rmgException(boost::to_string(boost::format("Position of object %d at %s is outside the map") % dObject.id % getPosition(true).toString())); throw rmgException(boost::str(boost::format("Position of object %d at %s is outside the map") % dObject.id % getPosition(true).toString()));
//If no specific template was defined for this object, select any matching //If no specific template was defined for this object, select any matching
if (!dObject.appearance) if (!dObject.appearance)
@ -337,7 +337,7 @@ void Object::Instance::finalize(RmgMap & map)
auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrainType->getId()); auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrainType->getId());
if (templates.empty()) if (templates.empty())
{ {
throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s (terrain %d)") % dObject.ID % dObject.subID % getPosition(true).toString() % terrainType)); throw rmgException(boost::str(boost::format("Did not find graphics for object (%d,%d) at %s (terrain %d)") % dObject.ID % dObject.subID % getPosition(true).toString() % terrainType));
} }
else else
{ {
@ -346,12 +346,12 @@ void Object::Instance::finalize(RmgMap & map)
} }
if (dObject.isVisitable() && !map.isOnMap(dObject.visitablePos())) if (dObject.isVisitable() && !map.isOnMap(dObject.visitablePos()))
throw rmgException(boost::to_string(boost::format("Visitable tile %s of object %d at %s is outside the map") % dObject.visitablePos().toString() % dObject.id % dObject.pos.toString())); throw rmgException(boost::str(boost::format("Visitable tile %s of object %d at %s is outside the map") % dObject.visitablePos().toString() % dObject.id % dObject.pos.toString()));
for(const auto & tile : dObject.getBlockedPos()) for(const auto & tile : dObject.getBlockedPos())
{ {
if(!map.isOnMap(tile)) if(!map.isOnMap(tile))
throw rmgException(boost::to_string(boost::format("Tile %s of object %d at %s is outside the map") % tile.toString() % dObject.id % dObject.pos.toString())); throw rmgException(boost::str(boost::format("Tile %s of object %d at %s is outside the map") % tile.toString() % dObject.id % dObject.pos.toString()));
} }
for(const auto & tile : getBlockedArea().getTilesVector()) for(const auto & tile : getBlockedArea().getTilesVector())

View File

@ -119,7 +119,7 @@ void Modificator::postfunction(Modificator * modificator)
void Modificator::dump() void Modificator::dump()
{ {
std::ofstream out(boost::to_string(boost::format("seed_%d_modzone_%d_%s.txt") % generator.getRandomSeed() % zone.getId() % getName())); std::ofstream out(boost::str(boost::format("seed_%d_modzone_%d_%s.txt") % generator.getRandomSeed() % zone.getId() % getName()));
int levels = map.levels(); int levels = map.levels();
int width = map.width(); int width = map.width();
int height = map.height(); int height = map.height();

View File

@ -387,7 +387,7 @@ void RiverPlacer::connectRiver(const int3 & tile)
if(tmplates.size() > 3) if(tmplates.size() > 3)
{ {
if(tmplates.size() % 4 != 0) if(tmplates.size() % 4 != 0)
throw rmgException(boost::to_string(boost::format("River templates for (%d,%d) at terrain %s, river %s are incorrect") % throw rmgException(boost::str(boost::format("River templates for (%d,%d) at terrain %s, river %s are incorrect") %
RIVER_DELTA_ID % RIVER_DELTA_SUBTYPE % zone.getTerrainType() % river->shortIdentifier)); RIVER_DELTA_ID % RIVER_DELTA_SUBTYPE % zone.getTerrainType() % river->shortIdentifier));
std::string targetTemplateName = river->deltaName + std::to_string(deltaOrientations[pos]) + ".def"; std::string targetTemplateName = river->deltaName + std::to_string(deltaOrientations[pos]) + ".def";

View File

@ -169,7 +169,7 @@ inline void ThreadPool::cancel()
auto ThreadPool::async(std::function<void()>&& f) const -> boost::future<void> auto ThreadPool::async(std::function<void()>&& f) const -> boost::future<void>
{ {
using TaskT = boost::packaged_task<void>; using TaskT = boost::packaged_task<void>;
{ {
Lock lock(mx); Lock lock(mx);
@ -189,4 +189,4 @@ auto ThreadPool::async(std::function<void()>&& f) const -> boost::future<void>
return fut; return fut;
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -66,10 +66,6 @@
#include <vcmi/events/GenericEvents.h> #include <vcmi/events/GenericEvents.h>
#include <vcmi/events/AdventureEvents.h> #include <vcmi/events/AdventureEvents.h>
#ifndef _MSC_VER
#include <boost/thread/xtime.hpp>
#endif
#define COMPLAIN_RET_IF(cond, txt) do {if (cond){complain(txt); return;}} while(0) #define COMPLAIN_RET_IF(cond, txt) do {if (cond){complain(txt); return;}} while(0)
#define COMPLAIN_RET_FALSE_IF(cond, txt) do {if (cond){complain(txt); return false;}} while(0) #define COMPLAIN_RET_FALSE_IF(cond, txt) do {if (cond){complain(txt); return false;}} while(0)
#define COMPLAIN_RET(txt) {complain(txt); return false;} #define COMPLAIN_RET(txt) {complain(txt); return false;}
@ -973,7 +969,6 @@ void CGameHandler::run(bool resume)
{ {
LOG_TRACE_PARAMS(logGlobal, "resume=%d", resume); LOG_TRACE_PARAMS(logGlobal, "resume=%d", resume);
using namespace boost::posix_time;
for (auto cc : lobby->connections) for (auto cc : lobby->connections)
{ {
auto players = lobby->getAllClientPlayers(cc->connectionID); auto players = lobby->getAllClientPlayers(cc->connectionID);
@ -1068,8 +1063,7 @@ void CGameHandler::run(bool resume)
if(gs->curB) if(gs->curB)
turnTimerHandler.onBattleLoop(waitTime); turnTimerHandler.onBattleLoop(waitTime);
static time_duration p = milliseconds(waitTime); states.cv.wait_for(lock, boost::chrono::milliseconds(waitTime));
states.cv.timed_wait(lock, p);
} }
} }
} }
@ -2575,7 +2569,7 @@ bool CGameHandler::upgradeCreature(ObjectInstanceID objid, SlotID pos, CreatureI
const CArmedInstance * obj = static_cast<const CArmedInstance *>(getObjInstance(objid)); const CArmedInstance * obj = static_cast<const CArmedInstance *>(getObjInstance(objid));
if (!obj->hasStackAtSlot(pos)) if (!obj->hasStackAtSlot(pos))
{ {
COMPLAIN_RET("Cannot upgrade, no stack at slot " + boost::to_string(pos)); COMPLAIN_RET("Cannot upgrade, no stack at slot " + std::to_string(pos));
} }
UpgradeInfo ui; UpgradeInfo ui;
fillUpgradeInfo(obj, pos, ui); fillUpgradeInfo(obj, pos, ui);

View File

@ -179,7 +179,7 @@ void CVCMIServer::run()
} }
while(state == EServerState::LOBBY || state == EServerState::GAMEPLAY_STARTING) while(state == EServerState::LOBBY || state == EServerState::GAMEPLAY_STARTING)
boost::this_thread::sleep(boost::posix_time::milliseconds(50)); boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
logNetwork->info("Thread handling connections ended"); logNetwork->info("Thread handling connections ended");
@ -188,14 +188,14 @@ void CVCMIServer::run()
gh->run(si->mode == StartInfo::LOAD_GAME); gh->run(si->mode == StartInfo::LOAD_GAME);
} }
while(state == EServerState::GAMEPLAY_ENDED) while(state == EServerState::GAMEPLAY_ENDED)
boost::this_thread::sleep(boost::posix_time::milliseconds(50)); boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
} }
void CVCMIServer::establishRemoteConnections() void CVCMIServer::establishRemoteConnections()
{ {
//wait for host connection //wait for host connection
while(connections.empty()) while(connections.empty())
boost::this_thread::sleep(boost::posix_time::milliseconds(50)); boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
uuid = cmdLineOptions["lobby-uuid"].as<std::string>(); uuid = cmdLineOptions["lobby-uuid"].as<std::string>();
int numOfConnections = cmdLineOptions["connections"].as<ui16>(); int numOfConnections = cmdLineOptions["connections"].as<ui16>();
@ -246,7 +246,7 @@ void CVCMIServer::threadAnnounceLobby()
} }
} }
boost::this_thread::sleep(boost::posix_time::milliseconds(50)); boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
} }
} }
@ -265,7 +265,7 @@ void CVCMIServer::prepareToRestart()
campaignBonus = si->campState->getBonusID(campaignMap).value_or(-1); campaignBonus = si->campState->getBonusID(campaignMap).value_or(-1);
} }
// FIXME: dirry hack to make sure old CGameHandler::run is finished // FIXME: dirry hack to make sure old CGameHandler::run is finished
boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
} }
for(auto c : connections) for(auto c : connections)

View File

@ -11,11 +11,4 @@
#include "../Global.h" #include "../Global.h"
#include <boost/crc.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp> //no i/o just types
#include <boost/random/linear_congruential.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/system/system_error.hpp>
VCMI_LIB_USING_NAMESPACE VCMI_LIB_USING_NAMESPACE

View File

@ -116,7 +116,7 @@ void JsonComparer::checkEqualJson(const JsonVector & actual, const JsonVector &
for(size_t idx = 0; idx < sz; idx ++) for(size_t idx = 0; idx < sz; idx ++)
{ {
auto guard = pushName(boost::to_string(idx)); auto guard = pushName(std::to_string(idx));
checkEqualJson(actual.at(idx), expected.at(idx)); checkEqualJson(actual.at(idx), expected.at(idx));
} }

View File

@ -56,7 +56,7 @@ void checkEqual(const std::set<Element> & actual, const std::set<Element> & expe
for(auto elem : expected) for(auto elem : expected)
{ {
if(!vstd::contains(actual, elem)) if(!vstd::contains(actual, elem))
FAIL() << "Required element not found "+boost::to_string(elem); FAIL() << "Required element not found "+std::to_string(elem);
} }
} }
@ -202,8 +202,8 @@ void MapComparer::compareObject(const CGObjectInstance * actual, const CGObjectI
EXPECT_EQ(actual->instanceName, expected->instanceName); EXPECT_EQ(actual->instanceName, expected->instanceName);
EXPECT_EQ(typeid(actual).name(), typeid(expected).name());//todo: remove and use just comparison EXPECT_EQ(typeid(actual).name(), typeid(expected).name());//todo: remove and use just comparison
std::string actualFullID = boost::to_string(boost::format("%s(%d)|%s(%d) %d") % actual->typeName % actual->ID % actual->subTypeName % actual->subID % actual->tempOwner); std::string actualFullID = boost::str(boost::format("%s(%d)|%s(%d) %d") % actual->typeName % actual->ID % actual->subTypeName % actual->subID % actual->tempOwner);
std::string expectedFullID = boost::to_string(boost::format("%s(%d)|%s(%d) %d") % expected->typeName % expected->ID % expected->subTypeName % expected->subID % expected->tempOwner); std::string expectedFullID = boost::str(boost::format("%s(%d)|%s(%d) %d") % expected->typeName % expected->ID % expected->subTypeName % expected->subID % expected->tempOwner);
EXPECT_EQ(actualFullID, expectedFullID); EXPECT_EQ(actualFullID, expectedFullID);