Skip to content

Commit

Permalink
Add a 60 FPS max limit (fix #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
adepierre committed Oct 9, 2024
1 parent e420409 commit f0a98cc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ficsit-companion/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#include <chrono>
#if !defined(__EMSCRIPTEN__)
#include <thread>
#endif

#include <imgui.h>
#include <backends/imgui_impl_sdl2.h>
#include <backends/imgui_impl_opengl3.h>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f0a98cc

Please sign in to comment.