refactor: move Weather instance to WorldInfo

This commit is contained in:
MihailRis
2025-02-28 18:49:44 +03:00
parent 0ea842580c
commit 9c4db8fa10
9 changed files with 116 additions and 61 deletions
+4 -2
View File
@@ -111,6 +111,7 @@ void WorldRenderer::setupWorldShader(
const EngineSettings& settings,
float fogFactor
) {
const auto& weather = level.getWorld()->getInfo().weather;
shader.use();
shader.uniformMatrix("u_model", glm::mat4(1.0f));
shader.uniformMatrix("u_proj", camera.getProjection());
@@ -152,7 +153,7 @@ void WorldRenderer::renderLevel(
bool pause,
bool hudVisible
) {
weather.update(delta);
const auto& weather = level.getWorld()->getInfo().weather;
texts->render(ctx, camera, settings, hudVisible, false);
@@ -200,7 +201,7 @@ void WorldRenderer::renderLevel(
setupWorldShader(entityShader, camera, settings, fogFactor);
std::array<WeatherPreset*, 2> weatherInstances {&weather.a, &weather.b};
std::array<const WeatherPreset*, 2> weatherInstances {&weather.a, &weather.b};
for (const auto& weather : weatherInstances) {
float zero = weather->fall.minOpacity;
float one = weather->fall.maxOpacity;
@@ -335,6 +336,7 @@ void WorldRenderer::draw(
) {
timer += delta * !pause;
auto world = level.getWorld();
const auto& weather = world->getInfo().weather;
const Viewport& vp = pctx.getViewport();
camera.aspect = vp.getWidth() / static_cast<float>(vp.getHeight());
+1 -39
View File
@@ -11,6 +11,7 @@
#include "typedefs.hpp"
#include "presets/WeatherPreset.hpp"
#include "world/Weather.hpp"
class Level;
class Player;
@@ -34,44 +35,6 @@ class ModelBatch;
class Assets;
struct EngineSettings;
struct Weather {
WeatherPreset a {};
WeatherPreset b {};
std::string nameA;
std::string nameB;
float t = 1.0f;
float speed = 0.0f;
void update(float delta) {
t += delta * speed;
t = std::min(t, 1.0f);
b.intensity = t;
a.intensity = 1.0f - t;
}
void change(WeatherPreset preset, float time, std::string name="") {
std::swap(a, b);
std::swap(nameA, nameB);
b = std::move(preset);
t = 0.0f;
speed = 1.0f / glm::max(time, 1.e-5f);
nameB = std::move(name);
update(0.0f);
}
float fogOpacity() const {
return b.fogOpacity * t + a.fogOpacity * (1.0f - t);
}
float fogDencity() const {
return b.fogDencity * t + a.fogDencity * (1.0f - t);
}
float fogCurve() const {
return b.fogCurve * t + a.fogCurve * (1.0f - t);
}
};
class WorldRenderer {
Engine& engine;
const Level& level;
@@ -113,7 +76,6 @@ public:
std::unique_ptr<ParticlesRenderer> particles;
std::unique_ptr<BlockWrapsRenderer> blockWraps;
std::unique_ptr<PrecipitationRenderer> precipitation;
Weather weather {};
static bool showChunkBorders;
static bool showEntitiesDebug;