From 78c767b69352c8103738adac7159914bad666d31 Mon Sep 17 00:00:00 2001 From: Madhav Kanbur Date: Wed, 21 Nov 2018 11:11:02 +0530 Subject: [PATCH] Add option to limit framerate from UI Signed-off-by: Madhav Kanbur --- src/Config.cpp | 4 ++++ src/Config.h | 2 ++ src/libui_sdl/main.cpp | 13 +++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index fea92e9a..9b8f148b 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -47,6 +47,8 @@ int ScreenLayout; int ScreenSizing; int ScreenFilter; +int LimitFPS; + int DirectBoot; int Threaded3D; @@ -103,6 +105,8 @@ ConfigEntry ConfigFile[] = {"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0}, {"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0}, + {"LimitFPS", 0, &LimitFPS, 1, NULL, 0}, + {"DirectBoot", 0, &DirectBoot, 1, NULL, 0}, {"Threaded3D", 0, &Threaded3D, 1, NULL, 0}, diff --git a/src/Config.h b/src/Config.h index d7b0858c..cea051f7 100644 --- a/src/Config.h +++ b/src/Config.h @@ -40,6 +40,8 @@ extern int ScreenLayout; extern int ScreenSizing; extern int ScreenFilter; +extern int LimitFPS; + extern int DirectBoot; extern int Threaded3D; diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 9ca829ec..880ffa38 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -216,7 +216,6 @@ int EmuThreadFunc(void* burp) u32 lasttick = starttick; u32 lastmeasuretick = lasttick; u32 fpslimitcount = 0; - bool limitfps = true; char melontitle[100]; while (EmuRunning != 0) @@ -306,7 +305,7 @@ int EmuThreadFunc(void* burp) lasttick = curtick; u32 wantedtick = starttick + (u32)((float)fpslimitcount * framerate); - if (curtick < wantedtick && limitfps) + if (curtick < wantedtick && Config::LimitFPS) { SDL_Delay(wantedtick - curtick); } @@ -1299,6 +1298,12 @@ void OnSetScreenFiltering(uiMenuItem* item, uiWindow* window, void* blarg) else Config::ScreenFilter = 0; } +void OnSetLimitFPS(uiMenuItem* item, uiWindow* window, void* blarg) +{ + int chk = uiMenuItemChecked(item); + if (chk != 0) Config::LimitFPS = true; + else Config::LimitFPS = false; +} void ApplyNewSettings() { @@ -1509,6 +1514,10 @@ int main(int argc, char** argv) uiMenuItemOnClicked(menuitem, OnSetScreenFiltering, NULL); uiMenuItemSetChecked(menuitem, Config::ScreenFilter==1); + menuitem = uiMenuAppendCheckItem(menu, "Limit framerate"); + uiMenuItemOnClicked(menuitem, OnSetLimitFPS, NULL); + uiMenuItemSetChecked(menuitem, Config::LimitFPS==1); + int w = Config::WindowWidth; int h = Config::WindowHeight;