From c9378cfaba06e0b299a1bfd4197f62da018693da Mon Sep 17 00:00:00 2001 From: Struma Date: Thu, 6 Jul 2023 23:58:18 -0400 Subject: [PATCH] update `Input.repeat` timing on each Graphics.update Instead of updating the `Input.repeat?` frame timing every time `Graphics.frame_rate=` is called, automatically set it to the current average framerate (or close to it) --- src/display/graphics.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/display/graphics.cpp b/src/display/graphics.cpp index 8989fdf..1e6f1e0 100644 --- a/src/display/graphics.cpp +++ b/src/display/graphics.cpp @@ -1152,6 +1152,15 @@ void Graphics::update(bool checkForShutdown) { p->threadData->rqWindowAdjust.wait(); p->last_update = shState->runTime(); + // update Input.repeat timing, rounding the framerate to the nearest 2 + { + static const double mult = 2.0; + double afr = std::abs(averageFrameRate()); // abs shouldn't be necessary but that's ok + afr += mult / 2; + afr -= std::fmod(afr, mult); + shState->input().recalcRepeat(std::floor(afr)); + } + if (checkForShutdown) p->checkShutDownReset(); @@ -1315,7 +1324,7 @@ void Graphics::setFrameRate(int value) { return; p->fpsLimiter.setDesiredFPS(p->frameRate); - shState->input().recalcRepeat((unsigned int)p->frameRate); + //shState->input().recalcRepeat((unsigned int)p->frameRate); } double Graphics::averageFrameRate() {