1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-05-17 11:11:29 +00:00

Merge pull request #2404 from Capostrophic/framerate

Make framerate limit configurable in the launcher
This commit is contained in:
Chris Djali 2019-07-19 16:16:20 +01:00 committed by GitHub
commit 576285573b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 8 deletions

View file

@ -44,6 +44,7 @@ Launcher::GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, Settings:
connect(fullScreenCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotFullScreenChanged(int))); connect(fullScreenCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotFullScreenChanged(int)));
connect(standardRadioButton, SIGNAL(toggled(bool)), this, SLOT(slotStandardToggled(bool))); connect(standardRadioButton, SIGNAL(toggled(bool)), this, SLOT(slotStandardToggled(bool)));
connect(screenComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(screenChanged(int))); connect(screenComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(screenChanged(int)));
connect(framerateLimitCheckBox, SIGNAL(toggled(bool)), this, SLOT(slotFramerateLimitToggled(bool)));
} }
@ -121,6 +122,13 @@ bool Launcher::GraphicsPage::loadSettings()
customHeightSpinBox->setValue(height); customHeightSpinBox->setValue(height);
} }
float fpsLimit = mEngineSettings.getFloat("framerate limit", "Video");
if (fpsLimit != 0)
{
framerateLimitCheckBox->setCheckState(Qt::Checked);
framerateLimitSpinBox->setValue(fpsLimit);
}
return true; return true;
} }
@ -166,6 +174,17 @@ void Launcher::GraphicsPage::saveSettings()
int cScreen = screenComboBox->currentIndex(); int cScreen = screenComboBox->currentIndex();
if (cScreen != mEngineSettings.getInt("screen", "Video")) if (cScreen != mEngineSettings.getInt("screen", "Video"))
mEngineSettings.setInt("screen", "Video", cScreen); 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) QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen)
@ -266,3 +285,8 @@ void Launcher::GraphicsPage::slotStandardToggled(bool checked)
customHeightSpinBox->setEnabled(true); customHeightSpinBox->setEnabled(true);
} }
} }
void Launcher::GraphicsPage::slotFramerateLimitToggled(bool checked)
{
framerateLimitSpinBox->setEnabled(checked);
}

View file

@ -31,6 +31,7 @@ namespace Launcher
private slots: private slots:
void slotFullScreenChanged(int state); void slotFullScreenChanged(int state);
void slotStandardToggled(bool checked); void slotStandardToggled(bool checked);
void slotFramerateLimitToggled(bool checked);
private: private:
Files::ConfigurationManager &mCfgMgr; Files::ConfigurationManager &mCfgMgr;

View file

@ -30,8 +30,8 @@ namespace Fallback
{ {
try try
{ {
// We have to rely on Boost because std::stof from C++11 // We have to rely on Boost because std::stof from C++11 uses the current locale
// uses the current locale for separators which we don't want and often silently ignores parsing errors. // for separators (which is undesired) and it often silently ignores parsing errors.
return boost::lexical_cast<float>(fallback); return boost::lexical_cast<float>(fallback);
} }
catch (boost::bad_lexical_cast&) catch (boost::bad_lexical_cast&)

View file

@ -7,6 +7,7 @@
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
namespace Settings namespace Settings
{ {
@ -354,12 +355,14 @@ float Manager::getFloat (const std::string& setting, const std::string& category
const std::string value = getString(setting, category); const std::string value = getString(setting, category);
try try
{ {
return std::stof(value); // 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<float>(value);
} }
catch(const std::exception& e) catch (boost::bad_lexical_cast&)
{ {
Log(Debug::Warning) << "Cannot parse setting '" << setting << "' (invalid setting value: " << value << ")."; 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) 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) 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) void Manager::setBool(const std::string &setting, const std::string &category, const bool value)

View file

@ -34,7 +34,7 @@
<item row="2" column="0"> <item row="2" column="0">
<widget class="QCheckBox" name="windowBorderCheckBox"> <widget class="QCheckBox" name="windowBorderCheckBox">
<property name="text"> <property name="text">
<string>Window border</string> <string>Window Border</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -62,6 +62,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0">
<widget class="QCheckBox" name="framerateLimitCheckBox">
<property name="text">
<string>Framerate Limit:</string>
</property>
</widget>
</item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QComboBox" name="antiAliasingComboBox"> <widget class="QComboBox" name="antiAliasingComboBox">
<item> <item>
@ -143,6 +150,31 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="framerateLimitSpinBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string> FPS</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>1</double>
</property>
<property name="maximum">
<double>1000</double>
</property>
<property name="singleStep">
<double>15</double>
</property>
<property name="value">
<double>300</double>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>