mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2024-11-22 02:32:39 +01:00
Merge from classic: better frame time tool, negative sleep remainder.
This commit is contained in:
parent
200a7dbf79
commit
545af17b3b
@ -237,7 +237,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
if (DispGRhistory)
|
if (DispGRhistory)
|
||||||
{
|
{
|
||||||
auto width = 300;
|
auto width = 300;
|
||||||
auto height = 64;
|
auto height = 64, halfHeight = height / 2;
|
||||||
if (!gfr_display)
|
if (!gfr_display)
|
||||||
{
|
{
|
||||||
gfr_display = new gdrv_bitmap8(width, height, false);
|
gfr_display = new gdrv_bitmap8(width, height, false);
|
||||||
@ -245,18 +245,14 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gdrv::ScrollBitmapHorizontal(gfr_display, -1);
|
gdrv::ScrollBitmapHorizontal(gfr_display, -1);
|
||||||
|
gdrv::fill_bitmap(gfr_display, 1, halfHeight, width - 1, 0, ColorRgba::Black()); // Background
|
||||||
|
gdrv::fill_bitmap(gfr_display, 1, halfHeight, width - 1, halfHeight, ColorRgba::White()); // Target
|
||||||
|
|
||||||
auto target = static_cast<float>(TargetFrameTime.count());
|
auto target = static_cast<float>(TargetFrameTime.count());
|
||||||
auto scale = height / target / 2;
|
auto scale = halfHeight / target;
|
||||||
gdrv::fill_bitmap(gfr_display, 1, height, width - 1, 0, ColorRgba::Black()); // Background
|
auto diffHeight = std::min(static_cast<int>(std::round(std::abs(target - dt) * scale)), halfHeight);
|
||||||
|
auto yOffset = dt < target ? halfHeight : halfHeight - diffHeight;
|
||||||
auto targetVal = dt < target ? dt : target;
|
gdrv::fill_bitmap(gfr_display, 1, diffHeight, width - 1, yOffset, ColorRgba::Red()); // Target diff
|
||||||
auto targetHeight = std::min(static_cast<int>(std::round(targetVal * scale)), height);
|
|
||||||
gdrv::fill_bitmap(gfr_display, 1, targetHeight, width - 1, height - targetHeight, ColorRgba::White()); // Target
|
|
||||||
|
|
||||||
auto diffVal = dt < target ? target - dt : dt - target;
|
|
||||||
auto diffHeight = std::min(static_cast<int>(std::round(diffVal * scale)), height);
|
|
||||||
gdrv::fill_bitmap(gfr_display, 1, diffHeight, width - 1, height - targetHeight - diffHeight, ColorRgba::Red()); // Target diff
|
|
||||||
}
|
}
|
||||||
updateCounter++;
|
updateCounter++;
|
||||||
}
|
}
|
||||||
@ -294,15 +290,14 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||||||
{
|
{
|
||||||
std::this_thread::sleep_for(targetTimeDelta);
|
std::this_thread::sleep_for(targetTimeDelta);
|
||||||
frameEnd = Clock::now();
|
frameEnd = Clock::now();
|
||||||
sleepRemainder = DurationMs(frameEnd - updateEnd) - targetTimeDelta;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
frameEnd = updateEnd;
|
frameEnd = updateEnd;
|
||||||
sleepRemainder = DurationMs(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit duration to 2 * target time
|
// Limit duration to 2 * target time
|
||||||
|
sleepRemainder = std::max(std::min(DurationMs(frameEnd - updateEnd) - targetTimeDelta, TargetFrameTime), -TargetFrameTime);
|
||||||
frameDuration = std::min<DurationMs>(DurationMs(frameEnd - frameStart), 2 * TargetFrameTime);
|
frameDuration = std::min<DurationMs>(DurationMs(frameEnd - frameStart), 2 * TargetFrameTime);
|
||||||
frameStart = frameEnd;
|
frameStart = frameEnd;
|
||||||
UpdateToFrameCounter++;
|
UpdateToFrameCounter++;
|
||||||
|
Loading…
Reference in New Issue
Block a user