Fixed issue with endless waiting for next tic

https://forum.zdoom.org/viewtopic.php?t=58426&p=1028622#p1028547
This commit is contained in:
alexey.lysiuk 2017-11-25 11:03:37 +02:00
parent 0f5ff5a5de
commit 074a8e4895

View file

@ -130,11 +130,22 @@ int I_WaitForTic(int prevtic)
int time;
while ((time = I_GetTime()) <= prevtic)
{
// Windows-specific note:
// The minimum amount of time a thread can sleep is controlled by timeBeginPeriod.
// We set this to 1 ms in DoMain.
uint64_t sleepTime = NSToMS(FirstFrameStartTime + TicToNS(prevtic + 1) - I_nsTime());
if (sleepTime > 2)
std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime - 2));
const uint64_t next = FirstFrameStartTime + TicToNS(prevtic + 1);
const uint64_t now = I_nsTime();
if (next > now)
{
const uint64_t sleepTime = NSToMS(next - now);
if (sleepTime > 2)
{
std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime - 2));
}
}
I_SetFrameTime();
}