Skip to content

Commit

Permalink
refactor: move cap_fps to amiberry.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Jan 16, 2025
1 parent 81771d7 commit 1bad27f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
13 changes: 13 additions & 0 deletions src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(end - start) / static_cast<float>(SDL_GetPerformanceFrequency()) * 1000.0f;

const int refresh_rate = std::clamp(sdl_mode.refresh_rate, 50, 60);
const float frame_time = 1000.0f / static_cast<float>(refresh_rate);
const float delay_time = frame_time - elapsed_ms;

if (delay_time > 0.0f)
SDL_Delay(static_cast<Uint32>(delay_time));
}

std::string get_version_string()
{
const auto pre_release_string = std::string(AMIBERRY_VERSION_PRE_RELEASE);
Expand Down
13 changes: 0 additions & 13 deletions src/osdep/gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(end - start) / static_cast<float>(SDL_GetPerformanceFrequency()) * 1000.0f;

const int refresh_rate = std::clamp(sdl_mode.refresh_rate, 50, 60);
const float frame_time = 1000.0f / static_cast<float>(refresh_rate);
const float delay_time = frame_time - elapsed_ms;

if (delay_time > 0.0f)
SDL_Delay(static_cast<Uint32>(delay_time));
}

void update_gui_screen()
{
const AmigaMonitor* mon = &AMonitors[0];
Expand Down

0 comments on commit 1bad27f

Please sign in to comment.