diff --git a/src/GlobalConfig.cpp b/src/GlobalConfig.cpp index 9f20512..279c71d 100644 --- a/src/GlobalConfig.cpp +++ b/src/GlobalConfig.cpp @@ -48,6 +48,7 @@ nlohmann::json GlobalConfig::get_config_json(const InputManager& input) const { toRet["keybinds"] = jKeybinds; toRet["guiScale"] = guiScale; toRet["jumpTransitionTime"] = jumpTransitionTime; + toRet["mainCallbackRate"] = mainCallbackRate; toRet["disableGraphicsDriverWorkarounds"] = disableGraphicsDriverWorkarounds; toRet["viewWebVersionWelcome"] = viewWebVersionWelcome; toRet["dragZoomSpeed"] = dragZoomSpeed; @@ -120,7 +121,9 @@ void GlobalConfig::set_config_json(InputManager& input, const nlohmann::json& j, try{j.at("displayName").get_to(displayName);} catch(...) {} try{j.at("dragZoomSpeed").get_to(dragZoomSpeed);} catch(...) {} try{j.at("scrollZoomSpeed").get_to(scrollZoomSpeed);} catch(...) {} - try{j.at("vsync").get_to(vsyncValue);} catch(...) {} + try{j.at("mainCallbackRate").get_to(mainCallbackRate);} catch(...) {} + if(version >= VersionNumber(0, 6, 0)) + try{j.at("vsync").get_to(vsyncValue);} catch(...) {} #ifndef __EMSCRIPTEN__ try{j.at("applyDisplayScale").get_to(applyDisplayScale);} catch(...) {} #endif @@ -211,3 +214,6 @@ void GlobalConfig::load_licenses() { ownLicenseText += read_file_to_string("data/license"); } +void GlobalConfig::update_main_loop_call_rate() { + SDL_SetHint(SDL_HINT_MAIN_CALLBACK_RATE, std::to_string(mainCallbackRate).c_str()); +} diff --git a/src/GlobalConfig.hpp b/src/GlobalConfig.hpp index 1f63b92..9c5af44 100644 --- a/src/GlobalConfig.hpp +++ b/src/GlobalConfig.hpp @@ -73,6 +73,8 @@ class GlobalConfig { bool realTimeEraser = true; + unsigned mainCallbackRate = 144; + struct TabletOptions { bool pressureAffectsBrushWidth = true; uint8_t middleClickButton = 1; @@ -92,6 +94,7 @@ class GlobalConfig { void save_palettes(); void load_palettes(); void load_licenses(); + void update_main_loop_call_rate(); bool checkForUpdates = true; bool useNativeFilePicker = true; @@ -108,7 +111,7 @@ class GlobalConfig { bool flipZoomToolDirection = false; bool disableGraphicsDriverWorkarounds = false; - int vsyncValue = 1; + int vsyncValue = 0; SDL_DateFormat dateFormat = SDL_DATE_FORMAT_DDMMYYYY; SDL_TimeFormat timeFormat = SDL_TIME_FORMAT_12HR; diff --git a/src/MainProgram.hpp b/src/MainProgram.hpp index 8b01a57..c1eabdd 100644 --- a/src/MainProgram.hpp +++ b/src/MainProgram.hpp @@ -203,7 +203,6 @@ class MainProgram { } updateCheckerData; float calculate_gui_scale(); - private: std::unordered_set tabsToClose; void close_set_to_close_tabs(); diff --git a/src/Screens/FileSelectScreen.cpp b/src/Screens/FileSelectScreen.cpp index 94fb450..59b3ee5 100644 --- a/src/Screens/FileSelectScreen.cpp +++ b/src/Screens/FileSelectScreen.cpp @@ -32,6 +32,7 @@ #include "../GUIStuff/ElementHelpers/ColorPickerHelpers.hpp" #include "../GUIStuff/ElementHelpers/CheckBoxHelpers.hpp" #include "../GUIStuff/ElementHelpers/NumberSliderHelpers.hpp" +#include "../GUIStuff/ElementHelpers/RadioButtonHelpers.hpp" #include "../World.hpp" #include "Helpers/StringHelpers.hpp" #include "PhoneDrawingProgramScreen.hpp" @@ -1147,6 +1148,20 @@ void FileSelectScreen::settings_view() { slider_scalar_field(gui, "tablet brush minimum size", "Brush relative minimum size", &main.conf.tabletOptions.brushMinimumSize, 0.0f, 1.0f, {.decimalPrecision = 3}); slider_scalar_field(gui, "tablet brush pressure smoothing factor", "Brush pressure smoothing factor", &main.conf.tabletOptions.brushPressureSmoothingFactor, 0.0f, 1.0f, {.decimalPrecision = 3}); checkbox_boolean_field(gui, "pen pressure width", "Pen pressure affects brush size", &main.conf.tabletOptions.pressureAffectsBrushWidth); + text_label(gui, "VSync:"); + radio_button_selector(gui, "VSync selector", &main.conf.vsyncValue, { + {"On", 1}, + {"Off", 0}, + {"Adaptive", -1} + }, [&] { + main.set_vsync_value(main.conf.vsyncValue); + }); + input_scalar_field(gui, "FPS cap", "FPS Cap", &main.conf.mainCallbackRate, 10, 100000, { + .onEdit = [&] { + main.conf.update_main_loop_call_rate(); + } + }); + checkbox_boolean_field(gui, "real time eraser", "Eraser works in real time", &main.conf.realTimeEraser); #ifndef __ANDROID__ checkbox_boolean_field(gui, "use mobile UI", "Use mobile UI (requires restart)", &main.conf.mobileUI); #endif diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index e0dc0eb..e129d0c 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -1546,6 +1546,11 @@ void Toolbar::general_settings_inner_gui() { }, [&] { main.set_vsync_value(main.conf.vsyncValue); }); + input_scalar_field(gui, "FPS cap", "FPS Cap", &main.conf.mainCallbackRate, 10, 100000, { + .onEdit = [&] { + main.conf.update_main_loop_call_rate(); + } + }); checkbox_boolean_field(gui, "real time eraser", "Eraser works in real time", &main.conf.realTimeEraser); checkbox_boolean_field(gui, "force extension on path", "Force extension on path when saving files", &main.conf.forceExtensionOnPath); diff --git a/src/main.cpp b/src/main.cpp index f9aa298..fbd21f0 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -363,6 +363,7 @@ void initialize_sdl(MainStruct& mS) { // Take maximize and fullscreen into account SDL_GetWindowSize(mS.window, &mS.m->window.size.x(), &mS.m->window.size.y()); mS.m->input.update_safe_area(); + mS.m->conf.update_main_loop_call_rate(); } void sdl_terminate(MainStruct& mS) {