1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Replace thread approach with callback based

This commit is contained in:
nordsoft
2023-08-11 20:04:14 +04:00
parent ef7008a753
commit 70d04ad957
4 changed files with 21 additions and 26 deletions

View File

@@ -383,32 +383,8 @@ void CMainMenu::startTutorial()
auto mapInfo = std::make_shared<CMapInfo>();
mapInfo->mapInit(tutorialMap.getName());
CSH->startMapAfterConnection(mapInfo);
CMainMenu::openLobby(ESelectionScreen::newGame, true, nullptr, ELoadMode::NONE);
std::thread waitForConnectionThread([mapInfo](){
boost::this_thread::sleep(boost::posix_time::milliseconds(100)); //delay this thread
//connecting to server
while(CSH->state != EClientState::LOBBY)
{
if(CSH->state == EClientState::CONNECTION_CANCELLED || CSH->state == EClientState::NONE)
return;
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
}
//start game from main thread
GH.dispatchMainThread([mapInfo]()
{
while(!CSH->si || mapInfo->fileURI != CSH->si->mapname)
{
CSH->setMapInfo(mapInfo);
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
}
CSH->sendStartGame();
});
});
waitForConnectionThread.detach();
}
std::shared_ptr<CMainMenu> CMainMenu::create()