Merge branch 'main' of https://github.com/MihailRis/VoxelEngine-Cpp
This commit is contained in:
@@ -19,7 +19,7 @@ LevelFrontend::LevelFrontend(LevelController* controller, Assets* assets)
|
||||
contentCache(std::make_unique<ContentGfxCache>(level->content, assets))
|
||||
{
|
||||
assets->store(
|
||||
BlocksPreview::build(contentCache.get(), assets, level->content).release(),
|
||||
BlocksPreview::build(contentCache.get(), assets, level->content),
|
||||
"block-previews"
|
||||
);
|
||||
controller->getPlayerController()->listenBlockInteraction(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "../audio/audio.hpp"
|
||||
#include "../delegates.hpp"
|
||||
#include "../engine.hpp"
|
||||
#include "../settings.hpp"
|
||||
#include "../graphics/core/Mesh.hpp"
|
||||
#include "../graphics/ui/elements/CheckBox.hpp"
|
||||
#include "../graphics/ui/elements/TextBox.hpp"
|
||||
@@ -19,6 +20,7 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <bitset>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -71,15 +73,24 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
L" visible: "+std::to_wstring(level->chunks->visible);
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
auto* indices = level->content->getIndices();
|
||||
auto def = indices->getBlockDef(player->selectedVoxel.id);
|
||||
std::wstringstream stream;
|
||||
stream << std::hex << player->selectedVoxel.states;
|
||||
if (def) {
|
||||
stream << L" (" << util::str2wstr_utf8(def->name) << L")";
|
||||
stream << "r:" << player->selectedVoxel.state.rotation << " s:"
|
||||
<< player->selectedVoxel.state.segment << " u:"
|
||||
<< std::bitset<8>(player->selectedVoxel.state.userbits);
|
||||
if (player->selectedVoxel.id == BLOCK_VOID) {
|
||||
return std::wstring {L"block: -"};
|
||||
} else {
|
||||
return L"block: "+std::to_wstring(player->selectedVoxel.id)+
|
||||
L" "+stream.str();
|
||||
}
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
auto* indices = level->content->getIndices();
|
||||
if (auto def = indices->getBlockDef(player->selectedVoxel.id)) {
|
||||
return L"name: " + util::str2wstr_utf8(def->name);
|
||||
} else {
|
||||
return std::wstring {L"name: void"};
|
||||
}
|
||||
return L"block: "+std::to_wstring(player->selectedVoxel.id)+
|
||||
L" "+stream.str();
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
return L"seed: "+std::to_wstring(level->getWorld()->getSeed());
|
||||
@@ -137,8 +148,8 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
}
|
||||
{
|
||||
auto bar = std::make_shared<TrackBar>(0.0f, 1.0f, 0.0f, 0.005f, 8);
|
||||
bar->setSupplier([=]() {return WorldRenderer::fog;});
|
||||
bar->setConsumer([=](double val) {WorldRenderer::fog = val;});
|
||||
bar->setSupplier([=]() {return level->getWorld()->fog;});
|
||||
bar->setConsumer([=](double val) {level->getWorld()->fog = val;});
|
||||
panel->add(bar);
|
||||
}
|
||||
{
|
||||
|
||||
@@ -333,7 +333,7 @@ void Hud::openInventory(
|
||||
if (blockinv == nullptr) {
|
||||
blockinv = level->inventories->createVirtual(blockUI->getSlotsCount());
|
||||
}
|
||||
level->chunks->getChunkByVoxel(block.x, block.y, block.z)->setUnsaved(true);
|
||||
level->chunks->getChunkByVoxel(block.x, block.y, block.z)->flags.unsaved = true;
|
||||
blockUI->bind(blockinv, content);
|
||||
blockPos = block;
|
||||
currentblockid = level->chunks->get(block.x, block.y, block.z)->id;
|
||||
|
||||
+10
-5
@@ -62,9 +62,11 @@ gui::page_loader_func menus::create_page_loader(Engine* engine) {
|
||||
auto file = engine->getResPaths()->find("layouts/pages/"+name+".xml");
|
||||
auto fullname = "core:pages/"+name;
|
||||
|
||||
auto document = UiDocument::read(scripting::get_root_environment(), fullname, file).release();
|
||||
engine->getAssets()->store(document, fullname);
|
||||
|
||||
auto document_ptr = UiDocument::read(
|
||||
scripting::get_root_environment(), fullname, file
|
||||
);
|
||||
auto document = document_ptr.get();
|
||||
engine->getAssets()->store(std::move(document_ptr), fullname);
|
||||
scripting::on_ui_open(document, std::move(args));
|
||||
return document->getRoot();
|
||||
};
|
||||
@@ -75,8 +77,11 @@ UiDocument* menus::show(Engine* engine, const std::string& name, std::vector<dyn
|
||||
auto file = engine->getResPaths()->find("layouts/"+name+".xml");
|
||||
auto fullname = "core:layouts/"+name;
|
||||
|
||||
auto document = UiDocument::read(scripting::get_root_environment(), fullname, file).release();
|
||||
engine->getAssets()->store(document, fullname);
|
||||
auto document_ptr = UiDocument::read(
|
||||
scripting::get_root_environment(), fullname, file
|
||||
);
|
||||
auto document = document_ptr.get();
|
||||
engine->getAssets()->store(std::move(document_ptr), fullname);
|
||||
scripting::on_ui_open(document, std::move(args));
|
||||
menu->addPage(name, document->getRoot());
|
||||
menu->setPage(name);
|
||||
|
||||
@@ -1,27 +1,30 @@
|
||||
#include "LevelScreen.hpp"
|
||||
|
||||
#include "../../core_defs.hpp"
|
||||
#include "../hud.hpp"
|
||||
#include "../LevelFrontend.hpp"
|
||||
#include "../../debug/Logger.hpp"
|
||||
#include "../../audio/audio.hpp"
|
||||
#include "../../coders/imageio.hpp"
|
||||
#include "../../graphics/core/PostProcessing.hpp"
|
||||
#include "../../debug/Logger.hpp"
|
||||
#include "../../engine.hpp"
|
||||
#include "../../files/files.hpp"
|
||||
#include "../../graphics/core/DrawContext.hpp"
|
||||
#include "../../graphics/core/Viewport.hpp"
|
||||
#include "../../graphics/core/ImageData.hpp"
|
||||
#include "../../graphics/ui/GUI.hpp"
|
||||
#include "../../graphics/ui/elements/Menu.hpp"
|
||||
#include "../../graphics/core/PostProcessing.hpp"
|
||||
#include "../../graphics/core/Viewport.hpp"
|
||||
#include "../../graphics/render/WorldRenderer.hpp"
|
||||
#include "../../graphics/ui/elements/Menu.hpp"
|
||||
#include "../../graphics/ui/GUI.hpp"
|
||||
#include "../../logic/LevelController.hpp"
|
||||
#include "../../logic/scripting/scripting_hud.hpp"
|
||||
#include "../../util/stringutil.hpp"
|
||||
#include "../../physics/Hitbox.hpp"
|
||||
#include "../../voxels/Chunks.hpp"
|
||||
#include "../../world/Level.hpp"
|
||||
#include "../../world/World.hpp"
|
||||
#include "../../window/Camera.hpp"
|
||||
#include "../../window/Events.hpp"
|
||||
#include "../../window/Window.hpp"
|
||||
#include "../../engine.hpp"
|
||||
#include "../../world/Level.hpp"
|
||||
#include "../../world/World.hpp"
|
||||
|
||||
static debug::Logger logger("level-screen");
|
||||
|
||||
@@ -45,6 +48,9 @@ LevelScreen::LevelScreen(Engine* engine, std::unique_ptr<Level> level)
|
||||
keepAlive(settings.camera.fov.observe([=](double value) {
|
||||
controller->getPlayer()->camera->setFov(glm::radians(value));
|
||||
}));
|
||||
keepAlive(Events::getBinding(BIND_CHUNKS_RELOAD).onactived.add([=](){
|
||||
controller->getLevel()->chunks->saveAndClear();
|
||||
}));
|
||||
|
||||
animator = std::make_unique<TextureAnimator>();
|
||||
animator->addAnimations(assets->getAnimations());
|
||||
@@ -55,16 +61,19 @@ LevelScreen::LevelScreen(Engine* engine, std::unique_ptr<Level> level)
|
||||
void LevelScreen::initializeContent() {
|
||||
auto content = controller->getLevel()->content;
|
||||
for (auto& entry : content->getPacks()) {
|
||||
auto pack = entry.second.get();
|
||||
const ContentPack& info = pack->getInfo();
|
||||
fs::path scriptFile = info.folder/fs::path("scripts/hud.lua");
|
||||
if (fs::is_regular_file(scriptFile)) {
|
||||
scripting::load_hud_script(pack->getEnvironment(), info.id, scriptFile);
|
||||
}
|
||||
initializePack(entry.second.get());
|
||||
}
|
||||
scripting::on_frontend_init(hud.get());
|
||||
}
|
||||
|
||||
void LevelScreen::initializePack(ContentPackRuntime* pack) {
|
||||
const ContentPack& info = pack->getInfo();
|
||||
fs::path scriptFile = info.folder/fs::path("scripts/hud.lua");
|
||||
if (fs::is_regular_file(scriptFile)) {
|
||||
scripting::load_hud_script(pack->getEnvironment(), info.id, scriptFile);
|
||||
}
|
||||
}
|
||||
|
||||
LevelScreen::~LevelScreen() {
|
||||
saveWorldPreview();
|
||||
scripting::on_frontend_close();
|
||||
@@ -83,8 +92,11 @@ void LevelScreen::saveWorldPreview() {
|
||||
// camera special copy for world preview
|
||||
Camera camera = *player->camera;
|
||||
camera.setFov(glm::radians(70.0f));
|
||||
|
||||
DrawContext pctx(nullptr, {Window::width, Window::height}, batch.get());
|
||||
|
||||
Viewport viewport(previewSize * 1.5, previewSize);
|
||||
DrawContext ctx(nullptr, viewport, batch.get());
|
||||
DrawContext ctx(&pctx, viewport, batch.get());
|
||||
|
||||
worldRenderer->draw(ctx, &camera, false, postProcessing.get());
|
||||
auto image = postProcessing->toImage();
|
||||
@@ -106,9 +118,6 @@ void LevelScreen::updateHotkeys() {
|
||||
if (Events::jpressed(keycode::F3)) {
|
||||
controller->getPlayer()->debug = !controller->getPlayer()->debug;
|
||||
}
|
||||
if (Events::jpressed(keycode::F5)) {
|
||||
controller->getLevel()->chunks->saveAndClear();
|
||||
}
|
||||
}
|
||||
|
||||
void LevelScreen::update(float delta) {
|
||||
@@ -138,7 +147,7 @@ void LevelScreen::update(float delta) {
|
||||
controller->getLevel()->getWorld()->updateTimers(delta);
|
||||
animator->update(delta);
|
||||
}
|
||||
controller->update(delta, !inputLocked, hud->isPause());
|
||||
controller->update(glm::min(delta, 0.2f), !inputLocked, hud->isPause());
|
||||
hud->update(hudVisible);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,21 +12,23 @@ class LevelController;
|
||||
class WorldRenderer;
|
||||
class TextureAnimator;
|
||||
class PostProcessing;
|
||||
class ContentPackRuntime;
|
||||
class Level;
|
||||
|
||||
class LevelScreen : public Screen {
|
||||
std::unique_ptr<LevelFrontend> frontend;
|
||||
std::unique_ptr<Hud> hud;
|
||||
std::unique_ptr<LevelController> controller;
|
||||
std::unique_ptr<WorldRenderer> worldRenderer;
|
||||
std::unique_ptr<TextureAnimator> animator;
|
||||
std::unique_ptr<PostProcessing> postProcessing;
|
||||
std::unique_ptr<Hud> hud;
|
||||
|
||||
void saveWorldPreview();
|
||||
|
||||
bool hudVisible = true;
|
||||
void updateHotkeys();
|
||||
void initializeContent();
|
||||
void initializePack(ContentPackRuntime* pack);
|
||||
public:
|
||||
LevelScreen(Engine* engine, std::unique_ptr<Level> level);
|
||||
~LevelScreen();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../../graphics/core/Batch2D.hpp"
|
||||
#include "../../graphics/core/Shader.hpp"
|
||||
#include "../../graphics/core/Texture.hpp"
|
||||
#include "../../maths/UVRegion.hpp"
|
||||
#include "../../window/Window.hpp"
|
||||
#include "../../window/Camera.hpp"
|
||||
#include "../../engine.hpp"
|
||||
|
||||
Reference in New Issue
Block a user