From 1bad27ffd64b7482cd9854359ed29630ebe9efcd Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 16 Jan 2025 15:36:09 +0100 Subject: [PATCH] refactor: move cap_fps to amiberry.cpp --- src/osdep/amiberry.cpp | 13 +++++++++++++ src/osdep/gui/main_window.cpp | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/osdep/amiberry.cpp b/src/osdep/amiberry.cpp index e5ba96678..fd08c48ee 100644 --- a/src/osdep/amiberry.cpp +++ b/src/osdep/amiberry.cpp @@ -138,6 +138,19 @@ bool lctrl_pressed, rctrl_pressed, lalt_pressed, ralt_pressed, lshift_pressed, r bool hotkey_pressed = false; bool mouse_grabbed = false; +void cap_fps(Uint64 start) +{ + const auto end = SDL_GetPerformanceCounter(); + const auto elapsed_ms = static_cast(end - start) / static_cast(SDL_GetPerformanceFrequency()) * 1000.0f; + + const int refresh_rate = std::clamp(sdl_mode.refresh_rate, 50, 60); + const float frame_time = 1000.0f / static_cast(refresh_rate); + const float delay_time = frame_time - elapsed_ms; + + if (delay_time > 0.0f) + SDL_Delay(static_cast(delay_time)); +} + std::string get_version_string() { const auto pre_release_string = std::string(AMIBERRY_VERSION_PRE_RELEASE); diff --git a/src/osdep/gui/main_window.cpp b/src/osdep/gui/main_window.cpp index 5b01ee136..1343116f5 100644 --- a/src/osdep/gui/main_window.cpp +++ b/src/osdep/gui/main_window.cpp @@ -242,19 +242,6 @@ static void show_help_requested() } } -void cap_fps(Uint64 start) -{ - const auto end = SDL_GetPerformanceCounter(); - const auto elapsed_ms = static_cast(end - start) / static_cast(SDL_GetPerformanceFrequency()) * 1000.0f; - - const int refresh_rate = std::clamp(sdl_mode.refresh_rate, 50, 60); - const float frame_time = 1000.0f / static_cast(refresh_rate); - const float delay_time = frame_time - elapsed_ms; - - if (delay_time > 0.0f) - SDL_Delay(static_cast(delay_time)); -} - void update_gui_screen() { const AmigaMonitor* mon = &AMonitors[0];