1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +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()
{
DWORD lastBlankFinish = GetTickCount();
Array<int> waitTimes;
while (!mClosing)
{
bool didWait = false;
@ -1315,13 +1319,29 @@ void WinBFApp::VSyncThreadProc()
if (output != NULL)
{
DWORD start = GetTickCount();
DWORD startTick = GetTickCount();
bool success = output->WaitForVBlank() == 0;
int elapsed = (int)(GetTickCount() - start);
if (elapsed >= 20)
DWORD endTick = GetTickCount();
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)
{