mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
cleanup
This commit is contained in:
parent
895a496f6e
commit
2475a7e8f5
20 changed files with 88 additions and 79 deletions
|
|
@ -52,8 +52,6 @@ std::vector<std::string>& ContentControl::getBasePacks() {
|
|||
}
|
||||
|
||||
void ContentControl::resetContent(const std::vector<std::string>& nonReset) {
|
||||
paths.setCurrentWorldFolder("");
|
||||
|
||||
scripting::cleanup(nonReset);
|
||||
std::vector<PathsRoot> resRoots;
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "ServerMainloop.hpp"
|
||||
|
||||
#include "Engine.hpp"
|
||||
#include "EnginePaths.hpp"
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "logic/LevelController.hpp"
|
||||
#include "interfaces/Process.hpp"
|
||||
|
|
@ -80,11 +79,10 @@ void ServerMainloop::run() {
|
|||
void ServerMainloop::setLevel(std::unique_ptr<Level> level) {
|
||||
if (level == nullptr) {
|
||||
controller->onWorldQuit();
|
||||
engine.getPaths().setCurrentWorldFolder("");
|
||||
controller = nullptr;
|
||||
} else {
|
||||
controller = std::make_unique<LevelController>(
|
||||
&engine, std::move(level), nullptr
|
||||
engine, std::move(level), nullptr
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
UiDocument::UiDocument(
|
||||
std::string id,
|
||||
uidocscript script,
|
||||
UiDocScript script,
|
||||
const std::shared_ptr<gui::UINode>& root,
|
||||
scriptenv env
|
||||
) : id(std::move(id)), script(script), root(root), env(std::move(env)) {
|
||||
|
|
@ -48,7 +48,7 @@ std::shared_ptr<gui::UINode> UiDocument::get(const std::string& id) const {
|
|||
return found->second.lock();
|
||||
}
|
||||
|
||||
const uidocscript& UiDocument::getScript() const {
|
||||
const UiDocScript& UiDocument::getScript() const {
|
||||
return script;
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ std::unique_ptr<UiDocument> UiDocument::read(
|
|||
gui::UiXmlReader reader(gui, scriptenv(env));
|
||||
auto view = reader.readXML(file.string(), *xmldoc->getRoot());
|
||||
view->setId("root");
|
||||
uidocscript script {};
|
||||
UiDocScript script {};
|
||||
auto scriptFile = io::path(file.string()+".lua");
|
||||
if (io::is_regular_file(scriptFile)) {
|
||||
scripting::load_layout_script(
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace gui {
|
|||
class UINode;
|
||||
}
|
||||
|
||||
struct uidocscript {
|
||||
struct UiDocScript {
|
||||
bool onopen : 1;
|
||||
bool onprogress : 1;
|
||||
bool onclose : 1;
|
||||
|
|
@ -23,14 +23,14 @@ using UINodesMap = std::unordered_map<std::string, std::weak_ptr<gui::UINode>>;
|
|||
|
||||
class UiDocument {
|
||||
std::string id;
|
||||
uidocscript script;
|
||||
UiDocScript script;
|
||||
UINodesMap map;
|
||||
std::shared_ptr<gui::UINode> root;
|
||||
scriptenv env;
|
||||
public:
|
||||
UiDocument(
|
||||
std::string id,
|
||||
uidocscript script,
|
||||
UiDocScript script,
|
||||
const std::shared_ptr<gui::UINode> &root,
|
||||
scriptenv env
|
||||
);
|
||||
|
|
@ -42,7 +42,7 @@ public:
|
|||
const UINodesMap& getMap() const;
|
||||
std::shared_ptr<gui::UINode> getRoot() const;
|
||||
std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
||||
const uidocscript& getScript() const;
|
||||
const UiDocScript& getScript() const;
|
||||
scriptenv getEnvironment() const;
|
||||
|
||||
static std::unique_ptr<UiDocument> read(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
#include <bitset>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "audio/audio.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "content/Content.hpp"
|
||||
|
|
@ -37,6 +31,12 @@
|
|||
#include "world/Level.hpp"
|
||||
#include "world/World.hpp"
|
||||
|
||||
#include <bitset>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
static std::shared_ptr<Label> create_label(GUI& gui, wstringsupplier supplier) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
#include <glm/glm.hpp>
|
||||
|
||||
class Camera;
|
||||
class Block;
|
||||
class Assets;
|
||||
class Player;
|
||||
class Engine;
|
||||
|
|
@ -25,7 +24,6 @@ namespace gui {
|
|||
class GUI;
|
||||
class Menu;
|
||||
class UINode;
|
||||
class Panel;
|
||||
class Container;
|
||||
class InventoryView;
|
||||
class SlotView;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ LevelScreen::LevelScreen(
|
|||
assert(player != nullptr);
|
||||
|
||||
controller =
|
||||
std::make_unique<LevelController>(&engine, std::move(levelPtr), player);
|
||||
std::make_unique<LevelController>(engine, std::move(levelPtr), player);
|
||||
playerController = std::make_unique<PlayerController>(
|
||||
settings, *level, *player, *controller->getBlocksController()
|
||||
);
|
||||
|
|
@ -112,11 +112,10 @@ LevelScreen::~LevelScreen() {
|
|||
saveDecorations();
|
||||
}
|
||||
scripting::on_frontend_close();
|
||||
// unblock all bindings
|
||||
input.getBindings().enableAll();
|
||||
playerController->getPlayer()->chunks->saveAndClear();
|
||||
controller->onWorldQuit();
|
||||
engine.getPaths().setCurrentWorldFolder("");
|
||||
|
||||
}
|
||||
|
||||
void LevelScreen::onOpen() {
|
||||
|
|
|
|||
|
|
@ -96,40 +96,54 @@ void Shadows::setQuality(int quality) {
|
|||
}
|
||||
|
||||
void Shadows::setup(Shader& shader, const Weather& weather) {
|
||||
if (shadows) {
|
||||
const auto& worldInfo = level.getWorld()->getInfo();
|
||||
float cloudsIntensity = glm::max(worldInfo.fog, weather.clouds());
|
||||
float shadowsOpacity = 1.0f - cloudsIntensity;
|
||||
shadowsOpacity *= glm::sqrt(glm::abs(
|
||||
glm::mod((worldInfo.daytime + 0.5f) * 2.0f, 1.0f) * 2.0f - 1.0f
|
||||
));
|
||||
shader.uniform1i("u_screen", 0);
|
||||
shader.uniformMatrix("u_shadowsMatrix[0]", shadowCamera.getProjView());
|
||||
shader.uniformMatrix("u_shadowsMatrix[1]", wideShadowCamera.getProjView());
|
||||
shader.uniform3f("u_sunDir", shadowCamera.front);
|
||||
shader.uniform1i("u_shadowsRes", shadowMap->getResolution());
|
||||
shader.uniform1f("u_shadowsOpacity", shadowsOpacity); // TODO: make it configurable
|
||||
shader.uniform1f("u_shadowsSoftness", 1.0f + cloudsIntensity * 4); // TODO: make it configurable
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_SHADOWS0);
|
||||
shader.uniform1i("u_shadows[0]", TARGET_SHADOWS0);
|
||||
glBindTexture(GL_TEXTURE_2D, shadowMap->getDepthMap());
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_SHADOWS1);
|
||||
shader.uniform1i("u_shadows[1]", TARGET_SHADOWS1);
|
||||
glBindTexture(GL_TEXTURE_2D, wideShadowMap->getDepthMap());
|
||||
|
||||
glActiveTexture(TEXTURE_MAIN);
|
||||
if (!shadows) {
|
||||
return;
|
||||
}
|
||||
const auto& worldInfo = level.getWorld()->getInfo();
|
||||
float cloudsIntensity = glm::max(worldInfo.fog, weather.clouds());
|
||||
float shadowsOpacity = 1.0f - cloudsIntensity;
|
||||
shadowsOpacity *= glm::sqrt(glm::abs(
|
||||
glm::mod((worldInfo.daytime + 0.5f) * 2.0f, 1.0f) * 2.0f - 1.0f
|
||||
));
|
||||
shader.uniform1i("u_screen", 0);
|
||||
shader.uniformMatrix("u_shadowsMatrix[0]", shadowCamera.getProjView());
|
||||
shader.uniformMatrix("u_shadowsMatrix[1]", wideShadowCamera.getProjView());
|
||||
shader.uniform3f("u_sunDir", shadowCamera.front);
|
||||
shader.uniform1i("u_shadowsRes", shadowMap->getResolution());
|
||||
shader.uniform1f("u_shadowsOpacity", shadowsOpacity); // TODO: make it configurable
|
||||
shader.uniform1f("u_shadowsSoftness", 1.0f + cloudsIntensity * 4); // TODO: make it configurable
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_SHADOWS0);
|
||||
shader.uniform1i("u_shadows[0]", TARGET_SHADOWS0);
|
||||
glBindTexture(GL_TEXTURE_2D, shadowMap->getDepthMap());
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_SHADOWS1);
|
||||
shader.uniform1i("u_shadows[1]", TARGET_SHADOWS1);
|
||||
glBindTexture(GL_TEXTURE_2D, wideShadowMap->getDepthMap());
|
||||
|
||||
glActiveTexture(TEXTURE_MAIN);
|
||||
}
|
||||
|
||||
void Shadows::refresh(const Camera& camera, const DrawContext& pctx, std::function<void(Camera&)> renderShadowPass) {
|
||||
void Shadows::refresh(
|
||||
const Camera& camera,
|
||||
const DrawContext& pctx,
|
||||
const std::function<void(Camera&)>& renderShadowPass
|
||||
) {
|
||||
static int frameid = 0;
|
||||
if (shadows) {
|
||||
if (frameid % 2 == 0) {
|
||||
generateShadowsMap(camera, pctx, *shadowMap, shadowCamera, 1.0f, renderShadowPass);
|
||||
generateShadowsMap(
|
||||
camera, pctx, *shadowMap, shadowCamera, 1.0f, renderShadowPass
|
||||
);
|
||||
} else {
|
||||
generateShadowsMap(camera, pctx, *wideShadowMap, wideShadowCamera, 3.0f, renderShadowPass);
|
||||
generateShadowsMap(
|
||||
camera,
|
||||
pctx,
|
||||
*wideShadowMap,
|
||||
wideShadowCamera,
|
||||
3.0f,
|
||||
renderShadowPass
|
||||
);
|
||||
}
|
||||
}
|
||||
frameid++;
|
||||
|
|
@ -141,7 +155,7 @@ void Shadows::generateShadowsMap(
|
|||
ShadowMap& shadowMap,
|
||||
Camera& shadowCamera,
|
||||
float scale,
|
||||
std::function<void(Camera&)> renderShadowPass
|
||||
const std::function<void(Camera&)>& renderShadowPass
|
||||
) {
|
||||
auto world = level.getWorld();
|
||||
const auto& worldInfo = world->getInfo();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class DrawContext;
|
|||
struct EngineSettings;
|
||||
class ShadowMap;
|
||||
|
||||
class Shadows {
|
||||
class Shadows final {
|
||||
public:
|
||||
Shadows(const Level& level);
|
||||
~Shadows();
|
||||
|
|
@ -24,7 +24,7 @@ public:
|
|||
void refresh(
|
||||
const Camera& camera,
|
||||
const DrawContext& pctx,
|
||||
std::function<void(Camera&)> renderShadowPass
|
||||
const std::function<void(Camera&)>& renderShadowPass
|
||||
);
|
||||
private:
|
||||
const Level& level;
|
||||
|
|
@ -41,6 +41,6 @@ private:
|
|||
ShadowMap& shadowMap,
|
||||
Camera& shadowCamera,
|
||||
float scale,
|
||||
std::function<void(Camera&)> renderShadowPass
|
||||
const std::function<void(Camera&)>& renderShadowPass
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ void ChunksRenderer::drawShadowsPass(
|
|||
continue;
|
||||
}
|
||||
glm::ivec2 pos {chunk->x, chunk->z};
|
||||
const auto& found = meshes.find({chunk->x, chunk->z});
|
||||
const auto& found = meshes.find(pos);
|
||||
if (found == meshes.end()) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -250,11 +250,11 @@ void ChunksRenderer::drawShadowsPass(
|
|||
pos.x * CHUNK_W + 0.5f, 0.5f, pos.y * CHUNK_D + 0.5f
|
||||
);
|
||||
|
||||
glm::vec3 min(chunk->x * CHUNK_W, chunk->bottom, chunk->z * CHUNK_D);
|
||||
glm::vec3 min(pos.x * CHUNK_W, chunk->bottom, pos.y * CHUNK_D);
|
||||
glm::vec3 max(
|
||||
chunk->x * CHUNK_W + CHUNK_W,
|
||||
pos.x * CHUNK_W + CHUNK_W,
|
||||
chunk->top,
|
||||
chunk->z * CHUNK_D + CHUNK_D
|
||||
pos.y * CHUNK_D + CHUNK_D
|
||||
);
|
||||
|
||||
if (!frustum.isBoxVisible(min, max)) {
|
||||
|
|
|
|||
|
|
@ -86,16 +86,16 @@ WorldRenderer::WorldRenderer(
|
|||
frontend.getContentGfxCache(),
|
||||
engine.getSettings()
|
||||
)),
|
||||
precipitation(std::make_unique<PrecipitationRenderer>(
|
||||
assets, level, *player.chunks, &engine.getSettings().graphics
|
||||
)),
|
||||
particles(std::make_unique<ParticlesRenderer>(
|
||||
assets, level, *player.chunks, engine.getSettings().graphics
|
||||
)),
|
||||
texts(std::make_unique<TextsRenderer>(*batch3d, assets, *frustumCulling)),
|
||||
blockWraps(
|
||||
std::make_unique<BlockWrapsRenderer>(assets, level, *player.chunks)
|
||||
),
|
||||
precipitation(std::make_unique<PrecipitationRenderer>(
|
||||
assets, level, *player.chunks, &engine.getSettings().graphics
|
||||
)) {
|
||||
) {
|
||||
auto& settings = engine.getSettings();
|
||||
level.events->listen(
|
||||
LevelEventType::CHUNK_HIDDEN,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "commons.hpp"
|
||||
|
||||
#include "typedefs.hpp"
|
||||
|
||||
#include "presets/WeatherPreset.hpp"
|
||||
|
|
@ -16,7 +15,6 @@
|
|||
class Assets;
|
||||
class Batch3D;
|
||||
class BlockWrapsRenderer;
|
||||
class Camera;
|
||||
class ChunksRenderer;
|
||||
class DebugLinesRenderer;
|
||||
class DrawContext;
|
||||
|
|
@ -58,6 +56,7 @@ class WorldRenderer {
|
|||
std::unique_ptr<Skybox> skybox;
|
||||
std::unique_ptr<Shadows> shadowMapping;
|
||||
std::unique_ptr<DebugLinesRenderer> debugLines;
|
||||
std::unique_ptr<PrecipitationRenderer> precipitation;
|
||||
Weather weather {};
|
||||
|
||||
float timer = 0.0f;
|
||||
|
|
@ -102,7 +101,6 @@ public:
|
|||
std::unique_ptr<ParticlesRenderer> particles;
|
||||
std::unique_ptr<TextsRenderer> texts;
|
||||
std::unique_ptr<BlockWrapsRenderer> blockWraps;
|
||||
std::unique_ptr<PrecipitationRenderer> precipitation;
|
||||
std::unique_ptr<NamedSkeletons> skeletons;
|
||||
|
||||
static bool showChunkBorders;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ GUI::GUI(Engine& engine)
|
|||
|
||||
rootDocument = std::make_unique<UiDocument>(
|
||||
"core:root",
|
||||
uidocscript {},
|
||||
UiDocScript {},
|
||||
std::dynamic_pointer_cast<gui::UINode>(container),
|
||||
nullptr
|
||||
);
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ void BlocksController::onBlockInteraction(
|
|||
}
|
||||
|
||||
void BlocksController::listenBlockInteraction(
|
||||
const on_block_interaction& callback
|
||||
const OnBlockInteraction& callback
|
||||
) {
|
||||
blockInteractionCallbacks.push_back(callback);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class ContentIndices;
|
|||
enum class BlockInteraction { step, destruction, placing };
|
||||
|
||||
/// @brief Player argument is nullable
|
||||
using on_block_interaction = std::function<
|
||||
using OnBlockInteraction = std::function<
|
||||
void(Player*, const glm::ivec3&, const Block&, BlockInteraction)>;
|
||||
|
||||
/// BlocksController manages block updates and data (inventories, metadata)
|
||||
|
|
@ -32,7 +32,7 @@ class BlocksController {
|
|||
util::Clock blocksTickClock;
|
||||
util::Clock worldTickClock;
|
||||
FastRandom random {};
|
||||
std::vector<on_block_interaction> blockInteractionCallbacks;
|
||||
std::vector<OnBlockInteraction> blockInteractionCallbacks;
|
||||
uint64_t randomTickId = 0;
|
||||
public:
|
||||
BlocksController(const Level& level, Lighting* lighting);
|
||||
|
|
@ -61,5 +61,5 @@ public:
|
|||
);
|
||||
|
||||
/// @brief Add block interaction callback
|
||||
void listenBlockInteraction(const on_block_interaction& callback);
|
||||
void listenBlockInteraction(const OnBlockInteraction& callback);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -133,9 +133,8 @@ static void check_world(const EnginePaths& paths, const io::path& folder) {
|
|||
}
|
||||
|
||||
static const Content* load_world_content(Engine& engine, const io::path& folder) {
|
||||
auto& paths = engine.getPaths();
|
||||
const auto& paths = engine.getPaths();
|
||||
auto& contentControl = engine.getContentControl();
|
||||
paths.setCurrentWorldFolder(folder);
|
||||
|
||||
check_world(paths, folder);
|
||||
call(engine, [&contentControl]() {
|
||||
|
|
@ -221,9 +220,10 @@ static void confirm(
|
|||
}
|
||||
|
||||
void EngineController::openWorld(const std::string& name, bool confirmConvert) {
|
||||
const auto& paths = engine.getPaths();
|
||||
auto& paths = engine.getPaths();
|
||||
auto& debugSettings = engine.getSettings().debug;
|
||||
auto folder = paths.getWorldsFolder() / name;
|
||||
paths.setCurrentWorldFolder(folder);
|
||||
|
||||
auto content = load_world_content(engine, folder);
|
||||
auto worldFiles = std::make_shared<WorldFiles>(folder, debugSettings);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "debug/Logger.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "engine/EnginePaths.hpp"
|
||||
#include "world/files/WorldFiles.hpp"
|
||||
#include "maths/voxmaths.hpp"
|
||||
#include "objects/Entities.hpp"
|
||||
|
|
@ -22,9 +23,10 @@
|
|||
static debug::Logger logger("level-control");
|
||||
|
||||
LevelController::LevelController(
|
||||
Engine* engine, std::unique_ptr<Level> levelPtr, Player* clientPlayer
|
||||
Engine& engine, std::unique_ptr<Level> levelPtr, Player* clientPlayer
|
||||
)
|
||||
: settings(engine->getSettings()),
|
||||
: engine(engine),
|
||||
settings(engine.getSettings()),
|
||||
level(std::move(levelPtr)),
|
||||
chunks(std::make_unique<ChunksController>(*level)),
|
||||
playerTickClock(20, 3) {
|
||||
|
|
@ -147,6 +149,7 @@ void LevelController::saveWorld() {
|
|||
|
||||
void LevelController::onWorldQuit() {
|
||||
scripting::on_world_quit();
|
||||
engine.getPaths().setCurrentWorldFolder("");
|
||||
}
|
||||
|
||||
Level* LevelController::getLevel() {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ struct EngineSettings;
|
|||
|
||||
/// @brief LevelController manages other controllers
|
||||
class LevelController {
|
||||
Engine& engine;
|
||||
EngineSettings& settings;
|
||||
std::unique_ptr<Level> level;
|
||||
// Sub-controllers
|
||||
|
|
@ -24,7 +25,7 @@ class LevelController {
|
|||
public:
|
||||
CallbacksSet<> preQuitCallbacks;
|
||||
|
||||
LevelController(Engine* engine, std::unique_ptr<Level> level, Player* clientPlayer);
|
||||
LevelController(Engine& engine, std::unique_ptr<Level> level, Player* clientPlayer);
|
||||
|
||||
/// @param delta time elapsed since the last update
|
||||
/// @param pause is world and player simulation paused
|
||||
|
|
|
|||
|
|
@ -768,7 +768,7 @@ void scripting::load_layout_script(
|
|||
const std::string& prefix,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
uidocscript& script
|
||||
UiDocScript& script
|
||||
) {
|
||||
int env = *senv;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ struct ItemFuncsSet;
|
|||
struct ItemFuncNamesCache;
|
||||
struct WorldFuncsSet;
|
||||
struct UserComponent;
|
||||
struct uidocscript;
|
||||
struct UiDocScript;
|
||||
class BlocksController;
|
||||
class LevelController;
|
||||
class Entity;
|
||||
|
|
@ -231,7 +231,7 @@ namespace scripting {
|
|||
const std::string& prefix,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
uidocscript& script
|
||||
UiDocScript& script
|
||||
);
|
||||
|
||||
/// @brief Finalize lua state. Using scripting after will lead to Lua panic
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue