浏览代码

Unblock UI while tutorial loading

nordsoft 2 年之前
父节点
当前提交
ef7008a753
共有 1 个文件被更改,包括 17 次插入6 次删除
  1. 17 6
      client/mainmenu/CMainMenu.cpp

+ 17 - 6
client/mainmenu/CMainMenu.cpp

@@ -386,18 +386,29 @@ void CMainMenu::startTutorial()
 	
 	CMainMenu::openLobby(ESelectionScreen::newGame, true, nullptr, ELoadMode::NONE);
 	
-	GH.dispatchMainThread([mapInfo](){
-		while(!CSH->c || !CSH->c->handler)
-			boost::this_thread::sleep(boost::posix_time::milliseconds(50));
+	std::thread waitForConnectionThread([mapInfo](){
+		boost::this_thread::sleep(boost::posix_time::milliseconds(100)); //delay this thread
 		
-		while(!CSH->mi || mapInfo->fileURI != CSH->mi->fileURI)
+		//connecting to server
+		while(CSH->state != EClientState::LOBBY)
 		{
-			CSH->setMapInfo(mapInfo);
+			if(CSH->state == EClientState::CONNECTION_CANCELLED || CSH->state == EClientState::NONE)
+				return;
 			boost::this_thread::sleep(boost::posix_time::milliseconds(50));
 		}
 		
-		CSH->sendStartGame();
+		//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()