From f0a98cc4bd0a4cb23b7841fcaee247c519c911b1 Mon Sep 17 00:00:00 2001 From: adepierre <24371370+adepierre@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:38:37 +0200 Subject: [PATCH] Add a 60 FPS max limit (fix #14) --- ficsit-companion/src/main.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ficsit-companion/src/main.cpp b/ficsit-companion/src/main.cpp index 59f64d3..90637a2 100644 --- a/ficsit-companion/src/main.cpp +++ b/ficsit-companion/src/main.cpp @@ -1,3 +1,8 @@ +#include +#if !defined(__EMSCRIPTEN__) +#include +#endif + #include #include #include @@ -107,6 +112,9 @@ bool Render(SDL_Window* window, App* app) } } + const std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); + const std::chrono::steady_clock::time_point end = start + std::chrono::milliseconds(16); + // Init imgui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplSDL2_NewFrame(); @@ -137,6 +145,15 @@ bool Render(SDL_Window* window, App* app) ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); SDL_GL_SwapWindow(window); +#if !defined(__EMSCRIPTEN__) + std::this_thread::sleep_until(end); +#else + while (std::chrono::steady_clock::now() < end) + { + emscripten_sleep(1); + } +#endif + return true; }