From 826ead0896ab8d47ec032627e39874c859260736 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 21 Feb 2012 23:58:54 +0300 Subject: Add vsync option. --- src/client.cpp | 14 ++++++++++++++ src/client.h | 2 ++ src/gui/setup_visual.cpp | 9 +++++++++ src/gui/setup_visual.h | 2 ++ 4 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index b853f1908..242bb2f21 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -564,6 +564,7 @@ void Client::gameInit() applyGrabMode(); applyGamma(); + applyVSync(); // Initialize for drawing mainGraphics->_beginDraw(); @@ -668,6 +669,7 @@ void Client::gameInit() config.addListener("guialpha", this); config.addListener("gamma", this); config.addListener("particleEmitterSkip", this); + config.addListener("vsync", this); setGuiAlpha(config.getFloatValue("guialpha")); optionChanged("fpslimit"); @@ -709,6 +711,7 @@ void Client::gameClear() config.removeListener("guialpha", this); config.removeListener("gamma", this); config.removeListener("particleEmitterSkip", this); + config.removeListener("vsync", this); SDL_RemoveTimer(mLogicCounterId); SDL_RemoveTimer(mSecondsCounterId); @@ -1507,6 +1510,10 @@ void Client::optionChanged(const std::string &name) { Particle::emitterSkip = config.getIntValue("particleEmitterSkip") + 1; } + else if (name == "vsync") + { + applyVSync(); + } } void Client::action(const gcn::ActionEvent &event) @@ -2457,3 +2464,10 @@ void Client::applyGamma() float val = config.getFloatValue("gamma"); SDL_SetGamma(val, val, val); } + +void Client::applyVSync() +{ + int val = config.getIntValue("vsync"); + if (val > 0 && val < 2) + SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, val); +} diff --git a/src/client.h b/src/client.h index 922b24caf..54de27824 100644 --- a/src/client.h +++ b/src/client.h @@ -277,6 +277,8 @@ public: void applyGamma(); + void applyVSync(); + void optionChanged(const std::string &name); void action(const gcn::ActionEvent &event); diff --git a/src/gui/setup_visual.cpp b/src/gui/setup_visual.cpp index 22df1ffa7..454a2c3f6 100644 --- a/src/gui/setup_visual.cpp +++ b/src/gui/setup_visual.cpp @@ -94,6 +94,13 @@ Setup_Visual::Setup_Visual() new SetupItemSlider(_("Gamma"), "", "gamma", this, "gammeEvent", 1, 20, 350, true); + mVSyncList = new SetupItemNames(); + mVSyncList->push_back(_("default")); + mVSyncList->push_back(_("off")); + mVSyncList->push_back(_("on")); + new SetupItemSlider2(_("Vsync"), "", "vsync", this, + "vsyncEvent", 0, 2, mVSyncList); + setDimension(gcn::Rectangle(0, 0, 550, 350)); } @@ -105,6 +112,8 @@ Setup_Visual::~Setup_Visual() mAmbientFxList = nullptr; delete mParticleList; mParticleList = nullptr; + delete mVSyncList; + mVSyncList = nullptr; } void Setup_Visual::apply() diff --git a/src/gui/setup_visual.h b/src/gui/setup_visual.h index 30ae18645..3c4c8a6d2 100644 --- a/src/gui/setup_visual.h +++ b/src/gui/setup_visual.h @@ -45,6 +45,8 @@ class Setup_Visual : public SetupTabScroll SetupItemNames *mAmbientFxList; SetupItemNames *mParticleList; + + SetupItemNames *mVSyncList; }; #endif -- cgit v1.2.3-70-g09d2