1
0
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:
nordsoft
2023-08-28 03:14:58 +04:00
parent 7dc1717ec6
commit 2c61d1b23f
2 changed files with 11 additions and 6 deletions

View File

@@ -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));
}
}