mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-30 01:25:51 +00:00
System: Make inter-frame sleep slightly more precise
This commit is contained in:
parent
66caaf6103
commit
b074c0d1ee
|
@ -27,9 +27,13 @@ static HANDLE GetSleepTimer()
|
||||||
return s_sleep_timer;
|
return s_sleep_timer;
|
||||||
|
|
||||||
s_sleep_timer_created = true;
|
s_sleep_timer_created = true;
|
||||||
|
s_sleep_timer = CreateWaitableTimerEx(nullptr, nullptr, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS);
|
||||||
|
if (!s_sleep_timer)
|
||||||
|
{
|
||||||
s_sleep_timer = CreateWaitableTimer(nullptr, TRUE, nullptr);
|
s_sleep_timer = CreateWaitableTimer(nullptr, TRUE, nullptr);
|
||||||
if (!s_sleep_timer)
|
if (!s_sleep_timer)
|
||||||
std::fprintf(stderr, "CreateWaitableTimer() failed, falling back to Sleep()\n");
|
std::fprintf(stderr, "CreateWaitableTimer() failed, falling back to Sleep()\n");
|
||||||
|
}
|
||||||
|
|
||||||
return s_sleep_timer;
|
return s_sleep_timer;
|
||||||
}
|
}
|
||||||
|
@ -89,8 +93,19 @@ void Timer::SleepUntil(Value value, bool exact)
|
||||||
{
|
{
|
||||||
if (exact)
|
if (exact)
|
||||||
{
|
{
|
||||||
while (GetCurrentValue() < value)
|
for (;;)
|
||||||
|
{
|
||||||
|
Value current = GetCurrentValue();
|
||||||
|
if (current >= value)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// spin for the last 1ms
|
||||||
|
if ((value - current) > ConvertMillisecondsToValue(1))
|
||||||
|
{
|
||||||
SleepUntil(value, false);
|
SleepUntil(value, false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue