refactor Engine
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentLoader.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "lighting/Lighting.hpp"
|
||||
#include "logic/BlocksController.hpp"
|
||||
#include "logic/LevelController.hpp"
|
||||
@@ -625,7 +626,7 @@ static int l_reload_script(lua::State* L) {
|
||||
if (content == nullptr) {
|
||||
throw std::runtime_error("content is not initialized");
|
||||
}
|
||||
auto& writeableContent = *engine->getWriteableContent();
|
||||
auto& writeableContent = *content_control->get();
|
||||
auto& def = writeableContent.blocks.require(name);
|
||||
ContentLoader::reloadScript(writeableContent, def);
|
||||
return 0;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "world/generator/VoxelFragment.hpp"
|
||||
#include "content/ContentLoader.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "../lua_custom_types.hpp"
|
||||
|
||||
@@ -50,7 +51,7 @@ static int l_load_fragment(lua::State* L) {
|
||||
/// @brief Get a list of all world generators
|
||||
/// @return A table with the IDs of all world generators
|
||||
static int l_get_generators(lua::State* L) {
|
||||
auto packs = engine->getAllContentPacks();
|
||||
auto packs = content_control->getAllContentPacks();
|
||||
|
||||
lua::createtable(L, 0, 0);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "content/Content.hpp"
|
||||
#include "frontend/UiDocument.hpp"
|
||||
#include "frontend/hud.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "graphics/ui/elements/InventoryView.hpp"
|
||||
#include "items/Inventories.hpp"
|
||||
#include "logic/BlocksController.hpp"
|
||||
@@ -176,7 +177,7 @@ static int l_reload_script(lua::State* L) {
|
||||
if (content == nullptr) {
|
||||
throw std::runtime_error("content is not initialized");
|
||||
}
|
||||
auto& writeableContent = *engine->getWriteableContent();
|
||||
auto& writeableContent = *content_control->get();
|
||||
auto pack = writeableContent.getPackRuntime(packid);
|
||||
const auto& info = pack->getInfo();
|
||||
scripting::load_hud_script(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "engine/Engine.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "frontend/hud.hpp"
|
||||
#include "frontend/screens/Screen.hpp"
|
||||
#include "graphics/ui/GUI.hpp"
|
||||
@@ -136,7 +137,7 @@ static void reset_pack_bindings(const io::path& packFolder) {
|
||||
|
||||
static int l_reset_bindings(lua::State*) {
|
||||
reset_pack_bindings("res:");
|
||||
for (auto& pack : engine->getContentPacks()) {
|
||||
for (const auto& pack : content_control->getContentPacks()) {
|
||||
reset_pack_bindings(pack.folder);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentLoader.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "items/ItemDef.hpp"
|
||||
#include "api_lua.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
@@ -94,7 +95,7 @@ static int l_reload_script(lua::State* L) {
|
||||
if (content == nullptr) {
|
||||
throw std::runtime_error("content is not initialized");
|
||||
}
|
||||
auto& writeableContent = *engine->getWriteableContent();
|
||||
auto& writeableContent = *content_control->get();
|
||||
auto& def = writeableContent.items.require(name);
|
||||
ContentLoader::reloadScript(writeableContent, def);
|
||||
return 0;
|
||||
|
||||
@@ -21,7 +21,7 @@ using namespace scripting;
|
||||
|
||||
static int l_pack_get_folder(lua::State* L) {
|
||||
std::string packName = lua::tostring(L, 1);
|
||||
auto packs = engine->getAllContentPacks();
|
||||
auto packs = content_control->getAllContentPacks();
|
||||
|
||||
for (auto& pack : packs) {
|
||||
if (pack.id == packName) {
|
||||
@@ -33,7 +33,7 @@ static int l_pack_get_folder(lua::State* L) {
|
||||
|
||||
/// @brief pack.get_installed() -> array<string>
|
||||
static int l_pack_get_installed(lua::State* L) {
|
||||
auto& packs = engine->getContentPacks();
|
||||
auto& packs = content_control->getContentPacks();
|
||||
lua::createtable(L, packs.size(), 0);
|
||||
for (size_t i = 0; i < packs.size(); i++) {
|
||||
lua::pushstring(L, packs[i].id);
|
||||
@@ -49,10 +49,10 @@ static int l_pack_get_available(lua::State* L) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
PacksManager manager;
|
||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
||||
manager.setSources(content_control->getDefaultSources());
|
||||
manager.scan();
|
||||
|
||||
const auto& installed = engine->getContentPacks();
|
||||
const auto& installed = content_control->getContentPacks();
|
||||
for (auto& pack : installed) {
|
||||
manager.exclude(pack.id);
|
||||
}
|
||||
@@ -142,8 +142,7 @@ static int pack_get_infos(lua::State* L) {
|
||||
lua::pop(L, 1);
|
||||
}
|
||||
std::unordered_map<std::string, ContentPack> packs;
|
||||
auto content = engine->getContent();
|
||||
const auto& loadedPacks = engine->getContentPacks();
|
||||
const auto& loadedPacks = content_control->getContentPacks();
|
||||
for (const auto& pack : loadedPacks) {
|
||||
if (ids.find(pack.id) != ids.end()) {
|
||||
packs[pack.id] = pack;
|
||||
@@ -156,7 +155,7 @@ static int pack_get_infos(lua::State* L) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
PacksManager manager;
|
||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
||||
manager.setSources(content_control->getDefaultSources());
|
||||
manager.scan();
|
||||
auto vec =
|
||||
manager.getAll(std::vector<std::string>(ids.begin(), ids.end()));
|
||||
@@ -187,8 +186,7 @@ static int l_pack_get_info(lua::State* L) {
|
||||
}
|
||||
auto packid = lua::tostring(L, 1);
|
||||
|
||||
auto content = engine->getContent();
|
||||
auto& packs = engine->getContentPacks();
|
||||
auto& packs = content_control->getContentPacks();
|
||||
auto found =
|
||||
std::find_if(packs.begin(), packs.end(), [packid](const auto& pack) {
|
||||
return pack.id == packid;
|
||||
@@ -199,7 +197,7 @@ static int l_pack_get_info(lua::State* L) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
PacksManager manager;
|
||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
||||
manager.setSources(content_control->getDefaultSources());
|
||||
manager.scan();
|
||||
auto vec = manager.getAll({packid});
|
||||
if (!vec.empty()) {
|
||||
@@ -212,7 +210,7 @@ static int l_pack_get_info(lua::State* L) {
|
||||
}
|
||||
|
||||
static int l_pack_get_base_packs(lua::State* L) {
|
||||
auto& packs = engine->getContentControl().getBasePacks();
|
||||
auto& packs = content_control->getBasePacks();
|
||||
lua::createtable(L, packs.size(), 0);
|
||||
for (size_t i = 0; i < packs.size(); i++) {
|
||||
lua::pushstring(L, packs[i]);
|
||||
@@ -237,7 +235,7 @@ static int l_pack_assemble(lua::State* L) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
PacksManager manager;
|
||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
||||
manager.setSources(content_control->getDefaultSources());
|
||||
manager.scan();
|
||||
try {
|
||||
ids = manager.assemble(ids);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "coders/json.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentLoader.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "world/files/WorldFiles.hpp"
|
||||
#include "io/engine_paths.hpp"
|
||||
@@ -217,7 +218,7 @@ static int l_reload_script(lua::State* L) {
|
||||
if (content == nullptr) {
|
||||
throw std::runtime_error("content is not initialized");
|
||||
}
|
||||
auto& writeableContent = *engine->getWriteableContent();
|
||||
auto& writeableContent = *content_control->get();
|
||||
auto pack = writeableContent.getPackRuntime(packid);
|
||||
ContentLoader::loadWorldScript(*pack);
|
||||
return 0;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "scripting_commons.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentPack.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "io/engine_paths.hpp"
|
||||
@@ -40,6 +41,7 @@ Engine* scripting::engine = nullptr;
|
||||
Level* scripting::level = nullptr;
|
||||
const Content* scripting::content = nullptr;
|
||||
const ContentIndices* scripting::indices = nullptr;
|
||||
ContentControl* scripting::content_control = nullptr;
|
||||
BlocksController* scripting::blocks = nullptr;
|
||||
LevelController* scripting::controller = nullptr;
|
||||
|
||||
@@ -68,6 +70,7 @@ int scripting::load_script(
|
||||
|
||||
void scripting::initialize(Engine* engine) {
|
||||
scripting::engine = engine;
|
||||
scripting::content_control = &engine->getContentControl();
|
||||
lua::initialize(engine->getPaths(), engine->getCoreParameters());
|
||||
|
||||
load_script(io::path("stdlib.lua"), true);
|
||||
@@ -268,21 +271,21 @@ void scripting::on_world_load(LevelController* controller) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
|
||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(L, pack.id + ":.worldopen");
|
||||
}
|
||||
}
|
||||
|
||||
void scripting::on_world_tick() {
|
||||
auto L = lua::get_main_state();
|
||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(L, pack.id + ":.worldtick");
|
||||
}
|
||||
}
|
||||
|
||||
void scripting::on_world_save() {
|
||||
auto L = lua::get_main_state();
|
||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(L, pack.id + ":.worldsave");
|
||||
}
|
||||
if (lua::getglobal(L, "__vc_on_world_save")) {
|
||||
@@ -292,7 +295,7 @@ void scripting::on_world_save() {
|
||||
|
||||
void scripting::on_world_quit() {
|
||||
auto L = lua::get_main_state();
|
||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(L, pack.id + ":.worldquit");
|
||||
}
|
||||
if (lua::getglobal(L, "__vc_on_world_quit")) {
|
||||
@@ -308,7 +311,7 @@ void scripting::on_world_quit() {
|
||||
void scripting::cleanup() {
|
||||
auto L = lua::get_main_state();
|
||||
lua::requireglobal(L, "pack");
|
||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::requirefield(L, "unload");
|
||||
lua::pushstring(L, pack.id);
|
||||
lua::call_nothrow(L, 1);
|
||||
|
||||
@@ -14,6 +14,7 @@ class Engine;
|
||||
class Content;
|
||||
struct ContentPack;
|
||||
class ContentIndices;
|
||||
class ContentControl;
|
||||
class Level;
|
||||
class Block;
|
||||
class Chunk;
|
||||
@@ -38,6 +39,7 @@ namespace scripting {
|
||||
extern Engine* engine;
|
||||
extern const Content* content;
|
||||
extern const ContentIndices* indices;
|
||||
extern ContentControl* content_control;
|
||||
extern Level* level;
|
||||
extern BlocksController* blocks;
|
||||
extern LevelController* controller;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "engine/Engine.hpp"
|
||||
#include "io/io.hpp"
|
||||
#include "assets/Assets.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "frontend/hud.hpp"
|
||||
#include "frontend/UiDocument.hpp"
|
||||
#include "graphics/render/WorldRenderer.hpp"
|
||||
@@ -45,7 +46,7 @@ void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
|
||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(
|
||||
lua::get_main_state(),
|
||||
pack.id + ":.hudopen",
|
||||
@@ -57,7 +58,7 @@ void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) {
|
||||
}
|
||||
|
||||
void scripting::on_frontend_render() {
|
||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(
|
||||
lua::get_main_state(),
|
||||
pack.id + ":.hudrender",
|
||||
@@ -68,7 +69,7 @@ void scripting::on_frontend_render() {
|
||||
|
||||
void scripting::on_frontend_close() {
|
||||
auto L = lua::get_main_state();
|
||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(
|
||||
L,
|
||||
pack.id + ":.hudclose",
|
||||
|
||||
Reference in New Issue
Block a user