diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 16 | ||||
-rw-r--r-- | src/gui/setup.cpp | 2 | ||||
-rw-r--r-- | src/gui/setup_video.cpp | 76 | ||||
-rw-r--r-- | src/gui/setup_video.h | 11 | ||||
-rw-r--r-- | src/main.cpp | 2 |
5 files changed, 97 insertions, 10 deletions
diff --git a/src/game.cpp b/src/game.cpp index a03989fe..0ccc7542 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -344,11 +344,7 @@ void Game::logic() int gameTime = tick_time; int drawTime = tick_time * 10; int delta = 0; - int fpsLimit = (int)config.getValue("fpslimit", 0); - if (fpsLimit) - { - delta = 1000 / fpsLimit; - } + int fpsLimit = 0; while (!done) { @@ -361,6 +357,16 @@ void Game::logic() } gameTime = tick_time; + + fpsLimit = (int)config.getValue("fpslimit", 50); + if (fpsLimit) + { + delta = 1000 / fpsLimit; + } + else + { + delta = 0; + } // Update the screen when application is active, delay otherwise if (SDL_GetAppState() & SDL_APPACTIVE) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 91bd5ce7..e0e0e81b 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -58,7 +58,7 @@ Setup::Setup(): } TabbedContainer *panel = new TabbedContainer(); - panel->setDimension(gcn::Rectangle(5, 5, 220, 130)); + panel->setDimension(gcn::Rectangle(5, 5, 220, 150)); panel->setOpaque(false); SetupTab *tab; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index a009d2d5..cf50b98c 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -27,6 +27,7 @@ #include <vector> #include <SDL.h> +#include <guichan/key.hpp> #include <guichan/listmodel.hpp> #include <guichan/widgets/label.hpp> @@ -36,6 +37,7 @@ #include "ok_dialog.h" #include "scrollarea.h" #include "slider.h" +#include "textfield.h" #include "../configuration.h" #include "../graphics.h" @@ -103,12 +105,16 @@ Setup_Video::Setup_Video(): mOpenGLEnabled(config.getValue("opengl", 0)), mCustomCursorEnabled(config.getValue("customcursor", 1)), mOpacity(config.getValue("guialpha", 0.8)), + mFps((int)config.getValue("fpslimit", 50)), mModeListModel(new ModeListModel()), mModeList(new ListBox(mModeListModel)), mFsCheckBox(new CheckBox("Full screen", mFullScreenEnabled)), mOpenGLCheckBox(new CheckBox("OpenGL", mOpenGLEnabled)), mCustomCursorCheckBox(new CheckBox("Custom cursor", mCustomCursorEnabled)), - mAlphaSlider(new Slider(0.2, 1.0)) + mAlphaSlider(new Slider(0.2, 1.0)), + mFpsCheckBox(new CheckBox("FPS Limit: ")), + mFpsSlider(new Slider(10, 200)), + mFpsField(new TextField()) { setOpaque(false); @@ -126,16 +132,32 @@ Setup_Video::Setup_Video(): mOpenGLCheckBox->setPosition(110, 30); mCustomCursorCheckBox->setPosition(110, 50); mAlphaSlider->setDimension(gcn::Rectangle(10, 80, 100, 10)); - alphaLabel->setPosition(20 + mAlphaSlider->getWidth(), mAlphaSlider->getY()); + alphaLabel->setPosition(20 + mAlphaSlider->getWidth(), + mAlphaSlider->getY()); + mFpsCheckBox->setPosition(90, 100); + mFpsSlider->setDimension(gcn::Rectangle(10, 100, 75, 10)); + mFpsField->setPosition(100 + mFpsCheckBox->getWidth(), 100); + mFpsField->setWidth(30); mModeList->setSelected(-1); mAlphaSlider->setValue(mOpacity); + + mFpsField->setText(toString(mFps)); + mFpsField->setEnabled(mFps > 0); + mFpsSlider->setValue(mFps); + mFpsSlider->setEnabled(mFps > 0); + mFpsCheckBox->setMarked(mFps > 0); mCustomCursorCheckBox->setEventId("customcursor"); mAlphaSlider->setEventId("guialpha"); + mFpsCheckBox->setEventId("fpslimitcheckbox"); + mFpsSlider->setEventId("fpslimitslider"); mCustomCursorCheckBox->addActionListener(this); mAlphaSlider->addActionListener(this); + mFpsCheckBox->addActionListener(this); + mFpsSlider->addActionListener(this); + mFpsField->addKeyListener(this); add(scrollArea); add(mFsCheckBox); @@ -143,6 +165,9 @@ Setup_Video::Setup_Video(): add(mCustomCursorCheckBox); add(mAlphaSlider); add(alphaLabel); + add(mFpsCheckBox); + add(mFpsSlider); + add(mFpsField); } Setup_Video::~Setup_Video() @@ -188,6 +213,9 @@ void Setup_Video::apply() new OkDialog("Changing OpenGL", "Applying change to OpenGL requires restart."); } + + // FPS change + config.setValue("fpslimit", mFps); // We sync old and new values at apply time mFullScreenEnabled = config.getValue("screen", 0); @@ -220,4 +248,48 @@ void Setup_Video::action(const std::string &event) config.setValue("customcursor", mCustomCursorCheckBox->isMarked() ? 1 : 0); } + else if (event == "fpslimitslider") + { + mFps = mFpsSlider->getValue(); + mFpsField->setText(toString(mFps)); + } + else if (event == "fpslimitcheckbox") + { + if (mFpsCheckBox->isMarked()) + { + mFps = mFpsSlider->getValue(); + } + else + { + mFps = 0; + } + mFpsField->setEnabled(mFps > 0); + mFpsField->setText(toString(mFps)); + mFpsSlider->setValue(mFps); + mFpsSlider->setEnabled(mFps > 0); + } +} + +void Setup_Video::keyPress(const gcn::Key &key) +{ + std::stringstream tempFps(mFpsField->getText()); + + if (tempFps >> mFps) + { + if (mFps < 10) + { + mFps = 10; + } + else if (mFps > 200) + { + mFps = 200; + } + mFpsField->setText(toString(mFps)); + mFpsSlider->setValue(mFps); + } + else + { + mFpsField->setText(""); + mFps = 0; + } } diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index d7129950..d8ee1914 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -27,10 +27,12 @@ #include "setuptab.h" #include <guichan/actionlistener.hpp> +#include <guichan/keylistener.hpp> #include "../guichanfwd.h" -class Setup_Video : public SetupTab, public gcn::ActionListener +class Setup_Video : public SetupTab, public gcn::ActionListener, + public gcn::KeyListener { public: Setup_Video(); @@ -40,12 +42,16 @@ class Setup_Video : public SetupTab, public gcn::ActionListener void cancel(); void action(const std::string&); + + /** Called when key is pressed */ + void keyPress(const gcn::Key& key); private: bool mFullScreenEnabled; bool mOpenGLEnabled; bool mCustomCursorEnabled; double mOpacity; + int mFps; class ModeListModel *mModeListModel; @@ -54,6 +60,9 @@ class Setup_Video : public SetupTab, public gcn::ActionListener gcn::CheckBox *mOpenGLCheckBox; gcn::CheckBox *mCustomCursorCheckBox; gcn::Slider *mAlphaSlider; + gcn::CheckBox *mFpsCheckBox; + gcn::Slider *mFpsSlider; + gcn::TextField *mFpsField; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 985a2ba4..9202654a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -182,7 +182,7 @@ void init_engine() config.setValue("remember", 1); config.setValue("sfxVolume", 100); config.setValue("musicVolume", 60); - config.setValue("fpslimit", 0); + config.setValue("fpslimit", 50); config.setValue("updatehost", "http://themanaworld.org/files"); config.setValue("customcursor", 1); config.setValue("homeDir", homeDir); |