From d3e8c9a343eba8cecfc39b1e0e485387ef58056e Mon Sep 17 00:00:00 2001
From: Li
Date: Wed, 15 Mar 2023 20:21:59 +1300
Subject: [PATCH] Limit FPS to 60fps
---
DumpDVD/Gui/MainWindow.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/DumpDVD/Gui/MainWindow.cpp b/DumpDVD/Gui/MainWindow.cpp
index b32905c..55180ef 100644
--- a/DumpDVD/Gui/MainWindow.cpp
+++ b/DumpDVD/Gui/MainWindow.cpp
@@ -23,12 +23,17 @@ namespace Li::Gui {
DumpDVD* dumpDvdMenu = new DumpDVD();
while (!this->sdl->IsExiting()) {
+ uint64_t start = SDL_GetPerformanceCounter();
this->sdl->PollEvent();
this->sdl->NewFrame();
dumpDvdMenu->RenderUI();
this->sdl->Render();
+ uint64_t end = SDL_GetPerformanceCounter();
+ float elapsedMS = (end - start) / (float)SDL_GetPerformanceFrequency() * 1000.0f;
+ // Cap to 60 FPS
+ SDL_Delay(floor(16.666f - elapsedMS));
}
delete dumpDvdMenu;