From a1860ff668867c9abbd43fdc3034328297a383d0 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 10 Mar 2025 14:51:59 +0300 Subject: [PATCH] cleanup --- src/graphics/render/Decorator.cpp | 7 +++---- src/graphics/render/WorldRenderer.cpp | 2 +- src/presets/WeatherPreset.hpp | 17 ++++++++++++++++- src/world/Weather.hpp | 4 ++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/graphics/render/Decorator.cpp b/src/graphics/render/Decorator.cpp index 8196efde..c0c88ebb 100644 --- a/src/graphics/render/Decorator.cpp +++ b/src/graphics/render/Decorator.cpp @@ -116,7 +116,8 @@ void Decorator::updateRandom( } } float intensity = weather.intensity * weather.fall.maxIntensity; - if (dst2 < 128 && random.randFloat() < glm::pow(intensity, 2.0f) && rainSplash.has_value()) { + if (rainSplash.has_value() && dst2 < 128 && + random.randFloat() < glm::pow(intensity, 2.0f)) { auto treg = util::get_texture_region( assets, "particles:rain_splash_0", "" ); @@ -239,13 +240,11 @@ void Decorator::updateTextNotes() { } void Decorator::updateRandomSounds(float delta, const Weather& weather) { - float thunderRate = weather.a.thunderRate * weather.a.intensity + - weather.b.thunderRate * weather.b.intensity; thunderTimer += delta; util::PseudoRandom random(rand()); if (thunderTimer >= 1.0f) { thunderTimer = 0.0f; - if (random.randFloat() < thunderRate) { + if (random.randFloat() < weather.thunderRate()) { audio::play( assets.get("ambient/thunder"), glm::vec3(), diff --git a/src/graphics/render/WorldRenderer.cpp b/src/graphics/render/WorldRenderer.cpp index 531f3267..2903028c 100644 --- a/src/graphics/render/WorldRenderer.cpp +++ b/src/graphics/render/WorldRenderer.cpp @@ -388,7 +388,7 @@ void WorldRenderer::draw( renderBlockOverlay(wctx); } - // Rendering fullscreen quad with + // Rendering fullscreen quad auto screenShader = assets.get("screen"); screenShader->use(); screenShader->uniform1f("u_timer", timer); diff --git a/src/presets/WeatherPreset.hpp b/src/presets/WeatherPreset.hpp index e4e76402..b3fa5db2 100644 --- a/src/presets/WeatherPreset.hpp +++ b/src/presets/WeatherPreset.hpp @@ -10,21 +10,34 @@ struct WeatherPreset : Serializable { struct { /// @brief Precipitation texture std::string texture; + /// @brief Fall sound std::string noise; + /// @brief Vertical speed float vspeed = 1.0f; + /// @brief Max horizontal speed float hspeed = 0.1f; + /// @brief UV scaling float scale = 0.1f; + /// @brief Fall opacity interpreted as zero. - /// @example if 0.8 then opacity range is 0.8-1.0 for 0.0-1.0 intensity + /// @example if 0.8 then opacity range is 0.8-max for 0.0-1.0 intensity float minOpacity = 0.0f; + + /// @brief Fall opacity interpreted as one. + /// @example if 0.8 then opacity range is min-0.8 for 0.0-1.0 intensity float maxOpacity = 1.0f; + + /// @brief Max fall intencity + /// (influences opacity, noise volume and splashes frequency) float maxIntensity = 1.0f; + /// @brief Clip texture by alpha channel bool opaque = false; + /// @brief Fall splash std::optional splash; } fall {}; @@ -38,8 +51,10 @@ struct WeatherPreset : Serializable { /// @brief Weather fog curve float fogCurve = 1.0f; + /// @brief Clouds opacity float clouds = 0.0f; + /// @brief Thunder rate in range 0.0-1.0 (1.0 is 100% - every second) float thunderRate = 0.0f; /// @brief Weather effects intensity diff --git a/src/world/Weather.hpp b/src/world/Weather.hpp index 023995b9..98999126 100644 --- a/src/world/Weather.hpp +++ b/src/world/Weather.hpp @@ -41,6 +41,10 @@ struct Weather : Serializable { return b.fogCurve * t + a.fogCurve * (1.0f - t); } + float thunderRate() const { + return b.thunderRate * t + a.thunderRate * (1.0f - t); + } + dv::value serialize() const override { return dv::object({ {"a", a.serialize()},