1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Client threading tweak

This commit is contained in:
AlexVinS
2017-11-16 14:15:43 +03:00
parent d7366f04a9
commit 805b5215de
4 changed files with 49 additions and 3 deletions

View File

@@ -816,6 +816,7 @@ void CClient::battleStarted(const BattleInfo * info)
void CClient::battleFinished()
{
stopAllBattleActions();
for(auto & side : gs->curB->sides)
if(battleCallbacks.count(side.color))
battleCallbacks[side.color]->setBattle(nullptr);
@@ -982,6 +983,38 @@ std::string CClient::aiNameForPlayer(bool battleAI)
return goodAI;
}
void CClient::startPlayerBattleAction(PlayerColor color)
{
stopPlayerBattleAction(color);
if(vstd::contains(battleints, color))
{
auto thread = std::make_shared<boost::thread>(std::bind(&CClient::waitForMoveAndSend, this, color));
playerActionThreads[color] = thread;
}
}
void CClient::stopPlayerBattleAction(PlayerColor color)
{
if(vstd::contains(playerActionThreads, color))
{
auto thread = playerActionThreads.at(color);
if(thread->joinable())
{
thread->interrupt();
thread->join();
}
playerActionThreads.erase(color);
}
}
void CClient::stopAllBattleActions()
{
while(!playerActionThreads.empty())
stopPlayerBattleAction(playerActionThreads.begin()->first);
}
void CServerHandler::startServer()
{
if(settings["session"]["donotstartserver"].Bool())