From 7e38907854a8644640d1adcfbef456a9641f7c67 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Mon, 24 Feb 2020 23:16:51 +0900 Subject: [PATCH] [SettingsMenuState] It's now possible to disable VSync. --- client/include/core/Config.hpp | 1 + client/source/core/ClientApplication.cpp | 5 ++++- client/source/core/Config.cpp | 2 ++ client/source/states/SettingsMenuState.cpp | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/include/core/Config.hpp b/client/include/core/Config.hpp index 595986fdc..cc027b443 100644 --- a/client/include/core/Config.hpp +++ b/client/include/core/Config.hpp @@ -40,6 +40,7 @@ namespace Config { extern bool isAmbientOcclusionEnabled; extern bool isWireframeModeEnabled; extern bool isFullscreenModeEnabled; + extern bool isVerticalSyncEnabled; extern float cameraFOV; extern u16 screenWidth; extern u16 screenHeight; diff --git a/client/source/core/ClientApplication.cpp b/client/source/core/ClientApplication.cpp index 3dacbd55b..a85ca1714 100644 --- a/client/source/core/ClientApplication.cpp +++ b/client/source/core/ClientApplication.cpp @@ -56,7 +56,7 @@ void ClientApplication::init() { gk::GamePad::init(m_keyboardHandler); createWindow(Config::screenWidth, Config::screenHeight, APP_NAME); - m_window.setVerticalSyncEnabled(true); + m_window.setVerticalSyncEnabled(Config::isVerticalSyncEnabled); m_window.disableView(); initOpenGL(); @@ -86,6 +86,9 @@ void ClientApplication::handleEvents() { if (Config::screenWidth != m_window.getSize().x || Config::screenHeight != m_window.getSize().y) { m_window.resize(Config::screenWidth, Config::screenHeight); } + + if (Config::isVerticalSyncEnabled != m_window.isVerticalSyncEnabled()) + m_window.setVerticalSyncEnabled(Config::isVerticalSyncEnabled); } void ClientApplication::onEvent(const SDL_Event &event) { diff --git a/client/source/core/Config.cpp b/client/source/core/Config.cpp index d90087c5c..abd74c40e 100644 --- a/client/source/core/Config.cpp +++ b/client/source/core/Config.cpp @@ -36,6 +36,7 @@ bool Config::isSunSmoothLightingEnabled = true; bool Config::isAmbientOcclusionEnabled = false; bool Config::isWireframeModeEnabled = false; bool Config::isFullscreenModeEnabled = false; +bool Config::isVerticalSyncEnabled = true; float Config::cameraFOV = 70.0f; u16 Config::screenWidth = 1600; u16 Config::screenHeight = 1050; @@ -68,6 +69,7 @@ void Config::loadConfigFromFile(const char *file) { isAmbientOcclusionEnabled = lua["isAmbientOcclusionEnabled"].get_or(isAmbientOcclusionEnabled); isWireframeModeEnabled = lua["isWireframeModeEnabled"].get_or(isWireframeModeEnabled); isFullscreenModeEnabled = lua["isFullscreenModeEnabled"].get_or(isFullscreenModeEnabled); + isVerticalSyncEnabled = lua["isVerticalSyncEnabled"].get_or(isVerticalSyncEnabled); cameraFOV = lua["cameraFOV"].get_or(cameraFOV); screenWidth = lua["screenWidth"].get_or(screenWidth); screenHeight = lua["screenHeight"].get_or(screenHeight); diff --git a/client/source/states/SettingsMenuState.cpp b/client/source/states/SettingsMenuState.cpp index ff78f2e97..388f85f13 100644 --- a/client/source/states/SettingsMenuState.cpp +++ b/client/source/states/SettingsMenuState.cpp @@ -164,7 +164,7 @@ void SettingsMenuState::addGraphicsButtons() { button.setText("Resolution: " + std::to_string(Config::screenWidth) + "x" + std::to_string(Config::screenHeight)); }); - m_menuWidget.addButton("Use VSync: ON", [] (TextButton &) {}).setEnabled(false); + addToggleButton("Use VSync", Config::isVerticalSyncEnabled, false); } void SettingsMenuState::addInputButtons() {