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