mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Use precision clocks for timer
This commit is contained in:
@@ -999,18 +999,23 @@ void CGameHandler::run(bool resume)
|
||||
turnOrder->onGameStarted();
|
||||
|
||||
//wait till game is done
|
||||
auto clockLast = std::chrono::high_resolution_clock::now();
|
||||
while(lobby->getState() == EServerState::GAMEPLAY)
|
||||
{
|
||||
const auto clockDuration = std::chrono::high_resolution_clock::now() - clockLast;
|
||||
const int timePassed = std::chrono::duration_cast<std::chrono::milliseconds>(clockDuration).count();
|
||||
clockLast += clockDuration;
|
||||
|
||||
const int waitTime = 100; //ms
|
||||
|
||||
for(PlayerColor player(0); player < PlayerColor::PLAYER_LIMIT; ++player)
|
||||
if(gs->isPlayerMakingTurn(player))
|
||||
turnTimerHandler.onPlayerMakingTurn(player, waitTime);
|
||||
turnTimerHandler.onPlayerMakingTurn(player, timePassed);
|
||||
|
||||
if(gs->curB)
|
||||
turnTimerHandler.onBattleLoop(waitTime);
|
||||
turnTimerHandler.onBattleLoop(timePassed);
|
||||
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(waitTime));
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user