From abbf55fd21d2f26a0adc4526aae2e3f50324632e Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Mon, 29 Jun 2020 14:46:40 +0200 Subject: [PATCH] Merged smooth lighting config options. --- config/client.example.lua | 3 +-- source/client/core/Config.cpp | 9 +++------ source/client/core/Config.hpp | 3 +-- source/client/states/SettingsMenuState.cpp | 14 +++++++++++--- source/client/states/SettingsMenuState.hpp | 2 ++ source/client/world/ChunkBuilder.cpp | 4 ++-- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/config/client.example.lua b/config/client.example.lua index cce6deeb..9b3d2b53 100644 --- a/config/client.example.lua +++ b/config/client.example.lua @@ -14,8 +14,7 @@ isCrosshairVisible = true -- Graphics renderDistance = 8 -isTorchSmoothLightingEnabled = true -isSunSmoothLightingEnabled = true +isSmoothLightingEnabled = true isAmbientOcclusionEnabled = false isWireframeModeEnabled = false isFullscreenModeEnabled = false diff --git a/source/client/core/Config.cpp b/source/client/core/Config.cpp index 0bbb842a..4465fb38 100644 --- a/source/client/core/Config.cpp +++ b/source/client/core/Config.cpp @@ -45,8 +45,7 @@ bool Config::isCrosshairVisible = true; // Graphics u16 Config::renderDistance = 8; -bool Config::isTorchSmoothLightingEnabled = true; -bool Config::isSunSmoothLightingEnabled = true; +bool Config::isSmoothLightingEnabled = true; bool Config::isAmbientOcclusionEnabled = false; bool Config::isWireframeModeEnabled = false; bool Config::isFullscreenModeEnabled = false; @@ -81,8 +80,7 @@ void Config::loadConfigFromFile(const char *filename) { isCrosshairVisible = lua["isCrosshairVisible"].get_or(isCrosshairVisible); renderDistance = lua["renderDistance"].get_or(renderDistance); - isTorchSmoothLightingEnabled = lua["isTorchSmoothLightingEnabled"].get_or(isTorchSmoothLightingEnabled); - isSunSmoothLightingEnabled = lua["isSunSmoothLightingEnabled"].get_or(isSunSmoothLightingEnabled); + isSmoothLightingEnabled = lua["isSmoothLightingEnabled"].get_or(isSmoothLightingEnabled); isAmbientOcclusionEnabled = lua["isAmbientOcclusionEnabled"].get_or(isAmbientOcclusionEnabled); isWireframeModeEnabled = lua["isWireframeModeEnabled"].get_or(isWireframeModeEnabled); isFullscreenModeEnabled = lua["isFullscreenModeEnabled"].get_or(isFullscreenModeEnabled); @@ -118,8 +116,7 @@ void Config::saveConfigToFile(const char *filename) { file << "isCrosshairVisible = " << (isCrosshairVisible ? "true" : "false") << std::endl; file << std::endl; file << "renderDistance = " << renderDistance << std::endl; - file << "isTorchSmoothLightingEnabled = " << (isTorchSmoothLightingEnabled ? "true" : "false") << std::endl; - file << "isSunSmoothLightingEnabled = " << (isSunSmoothLightingEnabled ? "true" : "false") << std::endl; + file << "isSmoothLightingEnabled = " << (isSmoothLightingEnabled ? "true" : "false") << std::endl; file << "isAmbientOcclusionEnabled = " << (isAmbientOcclusionEnabled ? "true" : "false") << std::endl; file << "isWireframeModeEnabled = " << (isWireframeModeEnabled ? "true" : "false") << std::endl; file << "isFullscreenModeEnabled = " << (isFullscreenModeEnabled ? "true" : "false") << std::endl; diff --git a/source/client/core/Config.hpp b/source/client/core/Config.hpp index 7d6909a7..4d660c27 100644 --- a/source/client/core/Config.hpp +++ b/source/client/core/Config.hpp @@ -44,8 +44,7 @@ namespace Config { // Graphics extern u16 renderDistance; - extern bool isTorchSmoothLightingEnabled; - extern bool isSunSmoothLightingEnabled; + extern bool isSmoothLightingEnabled; extern bool isAmbientOcclusionEnabled; extern bool isWireframeModeEnabled; extern bool isFullscreenModeEnabled; diff --git a/source/client/states/SettingsMenuState.cpp b/source/client/states/SettingsMenuState.cpp index c7d1b788..8f0cc6f6 100644 --- a/source/client/states/SettingsMenuState.cpp +++ b/source/client/states/SettingsMenuState.cpp @@ -201,9 +201,17 @@ void SettingsMenuState::addGraphicsButtons() { addToggleButton("Wireframe Mode", Config::isWireframeModeEnabled, false); - addToggleButton("Torch Smooth Lighting", Config::isTorchSmoothLightingEnabled, true); - addToggleButton("Sun Smooth Lighting", Config::isSunSmoothLightingEnabled, true); - addToggleButton("Ambient Occlusion", Config::isAmbientOcclusionEnabled, true); + m_menuWidget.addButton(std::string("Smooth Lighting: ") + (Config::isSmoothLightingEnabled ? "ON" : "OFF"), [&] (TextButton &button) { + Config::isSmoothLightingEnabled = !Config::isSmoothLightingEnabled; + button.setText(std::string("Smooth Lighting: ") + (Config::isSmoothLightingEnabled ? "ON" : "OFF")); + + m_aoButton->setEnabled(!Config::isSmoothLightingEnabled); + + World::isReloadRequested = true; + }); + + m_aoButton = &addToggleButton("Ambient Occlusion", Config::isAmbientOcclusionEnabled, true); + m_aoButton->setEnabled(!Config::isSmoothLightingEnabled); m_menuWidget.addButton("GUI Scale: " + std::to_string(Config::guiScale), [this] (TextButton &button) { Config::guiScale = 1 + (Config::guiScale + 1) % 3; diff --git a/source/client/states/SettingsMenuState.hpp b/source/client/states/SettingsMenuState.hpp index 40472c15..ff78b6f7 100644 --- a/source/client/states/SettingsMenuState.hpp +++ b/source/client/states/SettingsMenuState.hpp @@ -82,6 +82,8 @@ class SettingsMenuState : public InterfaceState { }; MenuState m_state = MenuState::Main; + + TextButton *m_aoButton = nullptr; }; #endif // SETTINGSMENUSTATE_HPP_ diff --git a/source/client/world/ChunkBuilder.cpp b/source/client/world/ChunkBuilder.cpp index f48a26e1..45d069f7 100644 --- a/source/client/world/ChunkBuilder.cpp +++ b/source/client/world/ChunkBuilder.cpp @@ -238,13 +238,13 @@ inline void ChunkBuilder::addFace(s8f x, s8f y, s8f z, s8f f, const ClientChunk vertices[v].texCoord[0] = gk::qlerp(blockTexCoords.x, blockTexCoords.x + blockTexCoords.sizeX, U); vertices[v].texCoord[1] = gk::qlerp(blockTexCoords.y, blockTexCoords.y + blockTexCoords.sizeY, V); - if (Config::isSunSmoothLightingEnabled && block.drawType() != BlockDrawType::Liquid) + if (Config::isSmoothLightingEnabled && block.drawType() != BlockDrawType::Liquid) vertices[v].lightValue[0] = getLightForVertex(Light::Sun, x, y, z, *neighbourOfs[v], normal, chunk); else vertices[v].lightValue[0] = chunk.lightmap().getSunlight(x + normal.x, y + normal.y, z + normal.z); int torchlight = chunk.lightmap().getTorchlight(x, y, z); - if (Config::isTorchSmoothLightingEnabled && torchlight == 0 && block.drawType() != BlockDrawType::Liquid) + if (Config::isSmoothLightingEnabled && torchlight == 0 && block.drawType() != BlockDrawType::Liquid) vertices[v].lightValue[1] = getLightForVertex(Light::Torch, x, y, z, *neighbourOfs[v], normal, chunk); else vertices[v].lightValue[1] = chunk.lightmap().getTorchlight(x + normal.x, y + normal.y, z + normal.z);