From bbbdb2d9d4bfb94acd335f193c597bfcc9d08ed4 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Sat, 13 Nov 2021 15:48:16 +0300 Subject: [PATCH] Fixed off by one in frame time tool. --- SpaceCadetPinball/winmain.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index b71c8ad..661b17b 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -290,25 +290,20 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi if (DispGRhistory) { auto width = render::vscreen.Width / 2; - auto height = 64; + auto height = 64, halfHeight = height / 2; if (!gfr_display.BmpBufPtr1) { gdrv::create_bitmap(&gfr_display, width, height); } gdrv::ScrollBitmapHorizontal(&gfr_display, -1); + gdrv::fill_bitmap(&gfr_display, 1, halfHeight, width - 1, 0, 0); // Background + gdrv::fill_bitmap(&gfr_display, 1, halfHeight, width - 1, halfHeight, -1); // Target - float target = TargetFrameTime; - auto scale = height / target / 2; - gdrv::fill_bitmap(&gfr_display, 1, height, width - 1, 0, 0); // Background - - auto targetVal = dt < target ? dt : target; - auto targetHeight = min(static_cast(std::floor(targetVal * scale)), height); - gdrv::fill_bitmap(&gfr_display, 1, targetHeight, width - 1, height - targetHeight, -1); // Target - - auto diffVal = dt < target ? target - dt : dt - target; - auto diffHeight = min(static_cast(std::floor(diffVal * scale)), height); - gdrv::fill_bitmap(&gfr_display, 1, diffHeight, width - 1, height - targetHeight - diffHeight, 1); // Target diff + auto scale = halfHeight / TargetFrameTime; + auto diffHeight = min(static_cast(std::round(std::abs(TargetFrameTime - dt) * scale)), halfHeight); + auto yOffset = dt < TargetFrameTime ? halfHeight : halfHeight - diffHeight; + gdrv::fill_bitmap(&gfr_display, 1, diffHeight, width - 1, yOffset, 1); // Target diff gdrv::blit(&gfr_display, 0, 0, render::vscreen.Width - width, 0, width, height); }