1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Zero-time check for WaitForVBlank

This commit is contained in:
Brian Fiete 2022-05-15 08:12:13 -07:00
parent ae5d8313c4
commit 2aaf5a2db4

View file

@ -1297,6 +1297,10 @@ void BFP_CALLTYPE WinBFApp::VSyncThreadProcThunk(void* ptr)
void WinBFApp::VSyncThreadProc() void WinBFApp::VSyncThreadProc()
{ {
DWORD lastBlankFinish = GetTickCount();
Array<int> waitTimes;
while (!mClosing) while (!mClosing)
{ {
bool didWait = false; bool didWait = false;
@ -1315,13 +1319,29 @@ void WinBFApp::VSyncThreadProc()
if (output != NULL) if (output != NULL)
{ {
DWORD start = GetTickCount(); DWORD startTick = GetTickCount();
bool success = output->WaitForVBlank() == 0; bool success = output->WaitForVBlank() == 0;
int elapsed = (int)(GetTickCount() - start); DWORD endTick = GetTickCount();
if (elapsed >= 20)
if (success)
{ {
NOP; int elapsed = (int)(endTick - startTick);
} waitTimes.Add(elapsed);
if (waitTimes.mSize > 8)
waitTimes.RemoveAt(0);
if (elapsed <= 1)
{
bool hadNonZero = false;
for (auto waitTime : waitTimes)
{
if (waitTime > 1)
hadNonZero = true;
}
if (!hadNonZero)
success = false;
}
}
if (success) if (success)
{ {