1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Fixed incorrect primary update schedule when updates are disabled/enabled

This commit is contained in:
narzoul 2017-07-16 20:35:31 +02:00
parent 6a2255160f
commit d2adc5c811

View File

@ -31,6 +31,7 @@ namespace
HANDLE g_updateThread = nullptr; HANDLE g_updateThread = nullptr;
HANDLE g_updateEvent = nullptr; HANDLE g_updateEvent = nullptr;
std::atomic<int> g_disableUpdateCount = 0; std::atomic<int> g_disableUpdateCount = 0;
bool g_isUpdateSuspended = false;
long long g_qpcFlipModeTimeout = 0; long long g_qpcFlipModeTimeout = 0;
long long g_qpcLastFlip = 0; long long g_qpcLastFlip = 0;
long long g_qpcNextUpdate = 0; long long g_qpcNextUpdate = 0;
@ -42,11 +43,6 @@ namespace
{ {
Compat::LogEnter("RealPrimarySurface::compatBlt", dest); Compat::LogEnter("RealPrimarySurface::compatBlt", dest);
if (g_disableUpdateCount > 0)
{
return false;
}
bool result = false; bool result = false;
auto primary(DDraw::PrimarySurface::getPrimary()); auto primary(DDraw::PrimarySurface::getPrimary());
@ -293,15 +289,19 @@ namespace DDraw
void RealPrimarySurface::disableUpdates() void RealPrimarySurface::disableUpdates()
{ {
++g_disableUpdateCount; if (0 == g_disableUpdateCount++ && isUpdateScheduled())
ResetEvent(g_updateEvent); {
ResetEvent(g_updateEvent);
g_isUpdateSuspended = true;
}
} }
void RealPrimarySurface::enableUpdates() void RealPrimarySurface::enableUpdates()
{ {
if (0 == --g_disableUpdateCount) if (0 == --g_disableUpdateCount && g_isUpdateSuspended)
{ {
update(); SetEvent(g_updateEvent);
g_isUpdateSuspended = false;
} }
} }
@ -313,6 +313,8 @@ namespace DDraw
} }
ResetEvent(g_updateEvent); ResetEvent(g_updateEvent);
g_isUpdateSuspended = false;
g_qpcLastFlip = Time::queryPerformanceCounter(); g_qpcLastFlip = Time::queryPerformanceCounter();
compatBlt(*g_backBuffer); compatBlt(*g_backBuffer);
HRESULT result = g_frontBuffer->Flip(g_frontBuffer, nullptr, flags); HRESULT result = g_frontBuffer->Flip(g_frontBuffer, nullptr, flags);
@ -414,24 +416,34 @@ namespace DDraw
void RealPrimarySurface::update() void RealPrimarySurface::update()
{ {
if (0 == g_disableUpdateCount && (g_isFullScreen || g_clipper)) if (g_isUpdateSuspended || !(g_isFullScreen || g_clipper))
{ {
if (!isUpdateScheduled()) return;
}
if (!isUpdateScheduled())
{
const auto qpcNow = Time::queryPerformanceCounter();
const long long missedIntervals = (qpcNow - g_qpcNextUpdate) / g_qpcUpdateInterval;
g_qpcNextUpdate += g_qpcUpdateInterval * (missedIntervals + 1);
if (Time::qpcToMs(g_qpcNextUpdate - qpcNow) < 2)
{
g_qpcNextUpdate += g_qpcUpdateInterval;
}
if (g_disableUpdateCount <= 0)
{ {
const auto qpcNow = Time::queryPerformanceCounter();
const long long missedIntervals = (qpcNow - g_qpcNextUpdate) / g_qpcUpdateInterval;
g_qpcNextUpdate += g_qpcUpdateInterval * (missedIntervals + 1);
if (Time::qpcToMs(g_qpcNextUpdate - qpcNow) < 2)
{
g_qpcNextUpdate += g_qpcUpdateInterval;
}
SetEvent(g_updateEvent); SetEvent(g_updateEvent);
} }
else if (msUntilNextUpdate() <= 0) else
{ {
updateNow(); g_isUpdateSuspended = true;
} }
} }
else if (msUntilNextUpdate() <= 0)
{
updateNow();
}
} }
void RealPrimarySurface::updatePalette(DWORD startingEntry, DWORD count) void RealPrimarySurface::updatePalette(DWORD startingEntry, DWORD count)