From 9452ea88d9d5bdea9426ee057855d783afa8015f Mon Sep 17 00:00:00 2001 From: theyareonit Date: Mon, 16 Sep 2024 02:51:35 +0200 Subject: [PATCH] more refactor --- src/main.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0e5dff2..20cc676 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -96,19 +96,20 @@ void updateInputQueueAndTime(int stepCount) { double lastDFactor = 0.0; while (true) { InputEvent front; - if (!inputQueueCopy.empty()) { - front = inputQueueCopy.front(); - if (front.time.QuadPart - lastFrameTime.QuadPart < stepDelta.QuadPart * (i + 1)) { - double dFactor = static_cast((front.time.QuadPart - lastFrameTime.QuadPart) % stepDelta.QuadPart) / stepDelta.QuadPart; - stepQueue.emplace(Step{ front, std::clamp(dFactor - lastDFactor, SMALLEST_FLOAT, 1.0), false }); - lastDFactor = dFactor; - inputQueueCopy.pop(); - continue; - } + bool empty = inputQueueCopy.empty(); + if (!empty) front = inputQueueCopy.front(); + + if (!empty && front.time.QuadPart - lastFrameTime.QuadPart < stepDelta.QuadPart * (i + 1)) { + double dFactor = static_cast((front.time.QuadPart - lastFrameTime.QuadPart) % stepDelta.QuadPart) / stepDelta.QuadPart; + stepQueue.emplace(Step{ front, std::clamp(dFactor - lastDFactor, SMALLEST_FLOAT, 1.0), false }); + inputQueueCopy.pop(); + lastDFactor = dFactor; + continue; + } + else { + stepQueue.emplace(Step{ EMPTY_INPUT, std::max(SMALLEST_FLOAT, 1.0 - lastDFactor), true }); + break; } - front = nextInput; - stepQueue.emplace(Step{ front, std::max(SMALLEST_FLOAT, 1.0 - lastDFactor), true }); - break; } } }