From 49c691d00a06c20cf81854ee30683369334e424f Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Thu, 30 May 2019 07:10:46 +0300 Subject: [PATCH 1/4] Make settings manager locale-independent again --- components/settings/settings.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 59e75dc76d..b3701f7644 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -7,6 +7,7 @@ #include #include +#include namespace Settings { @@ -354,12 +355,14 @@ float Manager::getFloat (const std::string& setting, const std::string& category const std::string value = getString(setting, category); try { - return std::stof(value); + // We have to rely on Boost because std::stof from C++11 + // uses the current locale for separators which we don't want and often silently ignores parsing errors. + return boost::lexical_cast(value); } - catch(const std::exception& e) + catch (boost::bad_lexical_cast&) { Log(Debug::Warning) << "Cannot parse setting '" << setting << "' (invalid setting value: " << value << ")."; - return 0; + return 0.f; } } @@ -401,12 +404,16 @@ void Manager::setString(const std::string &setting, const std::string &category, void Manager::setInt (const std::string& setting, const std::string& category, const int value) { - setString(setting, category, std::to_string(value)); + std::ostringstream stream; + stream << value; + setString(setting, category, stream.str()); } void Manager::setFloat (const std::string &setting, const std::string &category, const float value) { - setString(setting, category, std::to_string(value)); + std::ostringstream stream; + stream << value; + setString(setting, category, stream.str()); } void Manager::setBool(const std::string &setting, const std::string &category, const bool value) From b87b29eeb00ec5e4a6fdbae67a51e65f3256d855 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Thu, 30 May 2019 07:11:13 +0300 Subject: [PATCH 2/4] Make framerate limit configurable in the launcher --- apps/launcher/graphicspage.cpp | 28 ++++++++++++++++++++++++++++ apps/launcher/graphicspage.hpp | 1 + files/ui/graphicspage.ui | 29 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 56cd086807..f9d8e1e1d8 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -44,6 +44,7 @@ Launcher::GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, Settings: connect(fullScreenCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotFullScreenChanged(int))); connect(standardRadioButton, SIGNAL(toggled(bool)), this, SLOT(slotStandardToggled(bool))); connect(screenComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(screenChanged(int))); + connect(framerateLimitCheckBox, SIGNAL(toggled(bool)), this, SLOT(slotFramerateLimitToggled(bool))); } @@ -121,6 +122,17 @@ bool Launcher::GraphicsPage::loadSettings() customHeightSpinBox->setValue(height); } + float fpsLimit = mEngineSettings.getFloat("framerate limit", "Video"); + if (fpsLimit != 0) + { + framerateLimitCheckBox->setCheckState(Qt::Checked); + framerateLimitSpinBox->setValue(fpsLimit); + } + else + { + framerateLimitSpinBox->setEnabled(false); + } + return true; } @@ -166,6 +178,17 @@ void Launcher::GraphicsPage::saveSettings() int cScreen = screenComboBox->currentIndex(); if (cScreen != mEngineSettings.getInt("screen", "Video")) mEngineSettings.setInt("screen", "Video", cScreen); + + if (framerateLimitCheckBox->checkState()) + { + float cFpsLimit = framerateLimitSpinBox->value(); + if (cFpsLimit != mEngineSettings.getFloat("framerate limit", "Video")) + mEngineSettings.setFloat("framerate limit", "Video", cFpsLimit); + } + else if (mEngineSettings.getFloat("framerate limit", "Video") != 0) + { + mEngineSettings.setFloat("framerate limit", "Video", 0); + } } QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen) @@ -266,3 +289,8 @@ void Launcher::GraphicsPage::slotStandardToggled(bool checked) customHeightSpinBox->setEnabled(true); } } + +void Launcher::GraphicsPage::slotFramerateLimitToggled(bool checked) +{ + framerateLimitSpinBox->setEnabled(checked); +} diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index 9d943d5e29..05915e6805 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -31,6 +31,7 @@ namespace Launcher private slots: void slotFullScreenChanged(int state); void slotStandardToggled(bool checked); + void slotFramerateLimitToggled(bool checked); private: Files::ConfigurationManager &mCfgMgr; diff --git a/files/ui/graphicspage.ui b/files/ui/graphicspage.ui index 0afda6ac7a..1f91fb19d1 100644 --- a/files/ui/graphicspage.ui +++ b/files/ui/graphicspage.ui @@ -62,6 +62,13 @@ + + + + Framerate limit + + + @@ -143,6 +150,28 @@ + + + + FPS + + + 1 + + + 1 + + + 999 + + + 15 + + + 300 + + + From 9502e9f3f7a049ceb1aa879d6138fb47588909ca Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Thu, 30 May 2019 08:48:39 +0300 Subject: [PATCH 3/4] Disable FPS limit spinbox by default and set the maximum to 1000 Make window border and framerate limit labels consistent with other labels --- apps/launcher/graphicspage.cpp | 4 ---- files/ui/graphicspage.ui | 9 ++++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index f9d8e1e1d8..c991e79f4d 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -128,10 +128,6 @@ bool Launcher::GraphicsPage::loadSettings() framerateLimitCheckBox->setCheckState(Qt::Checked); framerateLimitSpinBox->setValue(fpsLimit); } - else - { - framerateLimitSpinBox->setEnabled(false); - } return true; } diff --git a/files/ui/graphicspage.ui b/files/ui/graphicspage.ui index 1f91fb19d1..eba913b919 100644 --- a/files/ui/graphicspage.ui +++ b/files/ui/graphicspage.ui @@ -34,7 +34,7 @@ - Window border + Window Border @@ -65,7 +65,7 @@ - Framerate limit + Framerate Limit: @@ -152,6 +152,9 @@ + + false + FPS @@ -162,7 +165,7 @@ 1 - 999 + 1000 15 From dfb852cbb01266b7d22beb3563a4487bf98d3271 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Mon, 3 Jun 2019 12:15:01 +0300 Subject: [PATCH 4/4] Improve Boost apologia --- components/fallback/fallback.cpp | 4 ++-- components/settings/settings.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/fallback/fallback.cpp b/components/fallback/fallback.cpp index e2060935e6..d5c6c4e974 100644 --- a/components/fallback/fallback.cpp +++ b/components/fallback/fallback.cpp @@ -30,8 +30,8 @@ namespace Fallback { try { - // We have to rely on Boost because std::stof from C++11 - // uses the current locale for separators which we don't want and often silently ignores parsing errors. + // We have to rely on Boost because std::stof from C++11 uses the current locale + // for separators (which is undesired) and it often silently ignores parsing errors. return boost::lexical_cast(fallback); } catch (boost::bad_lexical_cast&) diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index b3701f7644..42f65fc557 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -355,8 +355,8 @@ float Manager::getFloat (const std::string& setting, const std::string& category const std::string value = getString(setting, category); try { - // We have to rely on Boost because std::stof from C++11 - // uses the current locale for separators which we don't want and often silently ignores parsing errors. + // We have to rely on Boost because std::stof from C++11 uses the current locale + // for separators (which is undesired) and it often silently ignores parsing errors. return boost::lexical_cast(value); } catch (boost::bad_lexical_cast&)