move weather from WorldRenderer to LevelFrontend

This commit is contained in:
MihailRis 2026-06-19 00:01:45 +03:00
parent 22f09d3659
commit ac00c561ee
7 changed files with 26 additions and 10 deletions

View file

@ -147,3 +147,7 @@ const ContentGfxCache& LevelFrontend::getContentGfxCache() const {
LevelController& LevelFrontend::getController() const {
return controller;
}
Weather& LevelFrontend::getWeather() {
return weather;
}

View file

@ -1,5 +1,7 @@
#pragma once
#include "world/Weather.hpp"
#include <memory>
class Assets;
@ -15,6 +17,7 @@ class LevelFrontend {
LevelController& controller;
Assets& assets;
std::unique_ptr<ContentGfxCache> contentCache;
Weather weather {};
public:
LevelFrontend(
Engine& engine,
@ -28,4 +31,5 @@ public:
const ContentGfxCache& getContentGfxCache() const;
ContentGfxCache& getContentGfxCache();
LevelController& getController() const;
Weather& getWeather();
};

View file

@ -81,7 +81,7 @@ LevelScreen::LevelScreen(
auto resetChunks = [=](bool) {
player->chunks->saveAndClear();
renderer->clear();
renderer->resetCache();
};
keepAlive(settings.graphics.backlight.observe(resetChunks));
keepAlive(settings.graphics.softLighting.observe(resetChunks));
@ -94,7 +94,7 @@ LevelScreen::LevelScreen(
}));
keepAlive(input.addCallback(BIND_CHUNKS_RELOAD, [=]() {
player->chunks->saveAndClear();
renderer->clear();
renderer->resetCache();
return false;
}));
controller->preQuitCallbacks.listen([this]() {
@ -153,7 +153,7 @@ void LevelScreen::loadDecorations() {
}
auto data = io::read_object(CLIENT_FILE);
if (data.has("weather")) {
renderer->getWeather().deserialize(data["weather"]);
frontend->getWeather().deserialize(data["weather"]);
}
}
@ -161,7 +161,7 @@ void LevelScreen::saveDecorations() {
io::create_directory("world:client");
auto data = dv::object();
data["weather"] = renderer->getWeather().serialize();
data["weather"] = frontend->getWeather().serialize();
io::write_json(CLIENT_FILE, data, true);
}
@ -257,7 +257,7 @@ void LevelScreen::update(float delta) {
hud->update(hudVisible);
const Weather& weather = renderer->getWeather();
const Weather& weather = frontend->getWeather();
const Player& player = playerController->getPlayer();
const Camera& camera = *player.currentCamera;
decorator->update(paused ? 0.0f : delta, camera, weather);

View file

@ -24,6 +24,7 @@
#include "voxels/Chunks.hpp"
#include "window/Camera.hpp"
#include "world/Level.hpp"
#include "world/Weather.hpp"
#include "WorldRenderer.hpp"
namespace fs = std::filesystem;

View file

@ -51,6 +51,7 @@
#include "window/Window.hpp"
#include "world/Level.hpp"
#include "world/LevelEvents.hpp"
#include "world/Weather.hpp"
#include "world/World.hpp"
#include "debug/Logger.hpp"
@ -84,6 +85,7 @@ WorldRenderer::WorldRenderer(
level(frontend.getLevel()),
player(player),
assets(*engine.getAssets()),
weather(frontend.getWeather()),
frustumCulling(std::make_unique<Frustum>()),
lineBatch(std::make_unique<LineBatch>()),
batch3d(std::make_unique<Batch3D>(BATCH3D_CAPACITY)),
@ -590,7 +592,7 @@ void WorldRenderer::renderBlockOverlay(const DrawContext& wctx) {
batch3d->flush();
}
void WorldRenderer::clear() {
void WorldRenderer::resetCache() {
chunksRenderer->clear();
}

View file

@ -4,7 +4,6 @@
#include "typedefs.hpp"
#include "presets/WeatherPreset.hpp"
#include "world/Weather.hpp"
#include "window/Camera.hpp"
#include "util/ObjectsKeeper.hpp"
@ -36,6 +35,7 @@ class Skybox;
class TextsRenderer;
class CloudsRenderer;
struct EngineSettings;
struct Weather;
class WorldRenderer final : public util::ObjectsKeeper {
public:
@ -54,7 +54,7 @@ public:
PostProcessing& postProcessing
);
void clear();
void resetCache();
void setDebug(bool flag);
@ -66,6 +66,7 @@ private:
const Level& level;
Player& player;
const Assets& assets;
Weather& weather;
std::unique_ptr<Frustum> frustumCulling;
std::unique_ptr<LineBatch> lineBatch;
std::unique_ptr<Batch3D> batch3d;
@ -77,13 +78,11 @@ private:
std::unique_ptr<DebugLinesRenderer> debugLines;
std::unique_ptr<PrecipitationRenderer> precipitation;
std::unique_ptr<CloudsRenderer> cloudsRenderer;
Weather weather {};
float timer = 0.0f;
bool debug = false;
bool lightsDebug = false;
bool gbufferPipeline = false;
bool dirtySettings = false;
/// @brief Render block selection lines

View file

@ -2,6 +2,7 @@
#include "world/Level.hpp"
#include "world/World.hpp"
#include "world/Weather.hpp"
using namespace scripting;
@ -9,6 +10,11 @@ static Weather& require_weather() {
if (level == nullptr) {
throw std::runtime_error("world is not open");
}
if (renderer == nullptr) {
throw std::runtime_error(
"world frontend is not initialized yet (wait for on_hud_open event)"
);
}
return renderer->getWeather();
}