refactor Engine
This commit is contained in:
parent
331734792d
commit
e442402e43
@ -24,9 +24,13 @@ static void load_configs(Input& input, const io::path& root) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentControl::ContentControl(std::function<void()> postContent)
|
ContentControl::ContentControl(
|
||||||
: postContent(std::move(postContent)) {
|
EnginePaths& paths, Input& input, std::function<void()> postContent
|
||||||
basePacks = io::read_list("res:config/builtins.list");
|
)
|
||||||
|
: paths(paths),
|
||||||
|
input(input),
|
||||||
|
postContent(std::move(postContent)),
|
||||||
|
basePacks(io::read_list("res:config/builtins.list")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentControl::~ContentControl() = default;
|
ContentControl::~ContentControl() = default;
|
||||||
@ -35,13 +39,15 @@ Content* ContentControl::get() {
|
|||||||
return content.get();
|
return content.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Content* ContentControl::get() const {
|
||||||
|
return content.get();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string>& ContentControl::getBasePacks() {
|
std::vector<std::string>& ContentControl::getBasePacks() {
|
||||||
return basePacks;
|
return basePacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentControl::resetContent(
|
void ContentControl::resetContent() {
|
||||||
EnginePaths& paths, Input& input, std::vector<ContentPack>& contentPacks
|
|
||||||
) {
|
|
||||||
scripting::cleanup();
|
scripting::cleanup();
|
||||||
std::vector<PathsRoot> resRoots;
|
std::vector<PathsRoot> resRoots;
|
||||||
{
|
{
|
||||||
@ -67,24 +73,15 @@ void ContentControl::resetContent(
|
|||||||
postContent();
|
postContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentControl::loadContent(
|
void ContentControl::loadContent(const std::vector<std::string>& names) {
|
||||||
EnginePaths& paths,
|
|
||||||
Input& input,
|
|
||||||
std::vector<ContentPack>& packs,
|
|
||||||
const std::vector<std::string>& names
|
|
||||||
) {
|
|
||||||
PacksManager manager;
|
PacksManager manager;
|
||||||
manager.setSources(getDefaultSources());
|
manager.setSources(getDefaultSources());
|
||||||
manager.scan();
|
manager.scan();
|
||||||
packs = manager.getAll(manager.assemble(names));
|
contentPacks = manager.getAll(manager.assemble(names));
|
||||||
loadContent(paths, input, packs);
|
loadContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentControl::loadContent(
|
void ContentControl::loadContent() {
|
||||||
EnginePaths& paths,
|
|
||||||
Input& input,
|
|
||||||
std::vector<ContentPack>& contentPacks
|
|
||||||
) {
|
|
||||||
scripting::cleanup();
|
scripting::cleanup();
|
||||||
|
|
||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
@ -138,3 +135,13 @@ std::vector<io::path> ContentControl::getDefaultSources() {
|
|||||||
"res:content",
|
"res:content",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<ContentPack>& ContentControl::getContentPacks() {
|
||||||
|
return contentPacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ContentPack> ContentControl::getAllContentPacks() {
|
||||||
|
auto packs = contentPacks;
|
||||||
|
packs.insert(packs.begin(), ContentPack::createCore(paths));
|
||||||
|
return packs;
|
||||||
|
}
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#include "ContentPack.hpp"
|
||||||
|
|
||||||
class Content;
|
class Content;
|
||||||
struct ContentPack;
|
struct ContentPack;
|
||||||
class EnginePaths;
|
class EnginePaths;
|
||||||
@ -16,33 +18,31 @@ namespace io {
|
|||||||
|
|
||||||
class ContentControl {
|
class ContentControl {
|
||||||
public:
|
public:
|
||||||
ContentControl(std::function<void()> postContent);
|
ContentControl(
|
||||||
|
EnginePaths& paths, Input& input, std::function<void()> postContent
|
||||||
|
);
|
||||||
~ContentControl();
|
~ContentControl();
|
||||||
|
|
||||||
Content* get();
|
Content* get();
|
||||||
|
|
||||||
|
const Content* get() const;
|
||||||
|
|
||||||
std::vector<std::string>& getBasePacks();
|
std::vector<std::string>& getBasePacks();
|
||||||
|
|
||||||
void resetContent(
|
void resetContent();
|
||||||
EnginePaths& paths, Input& input, std::vector<ContentPack>& packs
|
|
||||||
);
|
|
||||||
|
|
||||||
void loadContent(
|
void loadContent(const std::vector<std::string>& names);
|
||||||
EnginePaths& paths,
|
|
||||||
Input& input,
|
|
||||||
std::vector<ContentPack>& packs,
|
|
||||||
const std::vector<std::string>& names
|
|
||||||
);
|
|
||||||
|
|
||||||
void loadContent(
|
void loadContent();
|
||||||
EnginePaths& paths,
|
|
||||||
Input& input,
|
|
||||||
std::vector<ContentPack>& packs
|
|
||||||
);
|
|
||||||
|
|
||||||
std::vector<io::path> getDefaultSources();
|
std::vector<io::path> getDefaultSources();
|
||||||
|
std::vector<ContentPack>& getContentPacks();
|
||||||
|
std::vector<ContentPack> getAllContentPacks();
|
||||||
private:
|
private:
|
||||||
|
EnginePaths& paths;
|
||||||
|
Input& input;
|
||||||
std::unique_ptr<Content> content;
|
std::unique_ptr<Content> content;
|
||||||
std::vector<std::string> basePacks;
|
|
||||||
std::function<void()> postContent;
|
std::function<void()> postContent;
|
||||||
|
std::vector<std::string> basePacks;
|
||||||
|
std::vector<ContentPack> contentPacks;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -139,6 +139,13 @@ void Engine::initialize(CoreParameters coreParameters) {
|
|||||||
"res:"
|
"res:"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
content = std::make_unique<ContentControl>(paths, *input, [this]() {
|
||||||
|
langs::setup("res:", langs::get_current(), paths.resPaths.collectRoots());
|
||||||
|
if (!isHeadless()) {
|
||||||
|
loadAssets();
|
||||||
|
onAssetsLoaded();
|
||||||
|
}
|
||||||
|
});
|
||||||
scripting::initialize(this);
|
scripting::initialize(this);
|
||||||
if (!isHeadless()) {
|
if (!isHeadless()) {
|
||||||
gui->setPageLoader(scripting::create_page_loader());
|
gui->setPageLoader(scripting::create_page_loader());
|
||||||
@ -146,14 +153,6 @@ void Engine::initialize(CoreParameters coreParameters) {
|
|||||||
keepAlive(settings.ui.language.observe([this](auto lang) {
|
keepAlive(settings.ui.language.observe([this](auto lang) {
|
||||||
setLanguage(lang);
|
setLanguage(lang);
|
||||||
}, true));
|
}, true));
|
||||||
|
|
||||||
content = std::make_unique<ContentControl>([this]() {
|
|
||||||
langs::setup("res:", langs::get_current(), paths.resPaths.collectRoots());
|
|
||||||
if (!isHeadless()) {
|
|
||||||
loadAssets();
|
|
||||||
onAssetsLoaded();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::loadSettings() {
|
void Engine::loadSettings() {
|
||||||
@ -318,47 +317,23 @@ void Engine::loadAssets() {
|
|||||||
}
|
}
|
||||||
assets = std::move(new_assets);
|
assets = std::move(new_assets);
|
||||||
|
|
||||||
if (content == nullptr) {
|
if (content) {
|
||||||
return;
|
ModelsGenerator::prepare(*content, *assets);
|
||||||
}
|
|
||||||
for (auto& [name, def] : content->blocks.getDefs()) {
|
|
||||||
if (def->model == BlockModel::custom && def->modelName.empty()) {
|
|
||||||
assets->store(
|
|
||||||
std::make_unique<model::Model>(
|
|
||||||
ModelsGenerator::loadCustomBlockModel(
|
|
||||||
def->customModelRaw, *assets, !def->shadeless
|
|
||||||
)
|
|
||||||
),
|
|
||||||
name + ".model"
|
|
||||||
);
|
|
||||||
def->modelName = def->name + ".model";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (auto& [name, def] : content->items.getDefs()) {
|
|
||||||
assets->store(
|
|
||||||
std::make_unique<model::Model>(
|
|
||||||
ModelsGenerator::generate(*def, *content, *assets)
|
|
||||||
),
|
|
||||||
name + ".model"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::loadContent() {
|
void Engine::loadContent() {
|
||||||
content->loadContent(paths, *input, contentPacks);
|
content->loadContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::resetContent() {
|
void Engine::resetContent() {
|
||||||
paths.setCurrentWorldFolder("");
|
paths.setCurrentWorldFolder("");
|
||||||
content->resetContent(paths, *input, contentPacks);
|
content->resetContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::loadWorldContent(const io::path& folder) {
|
void Engine::loadWorldContent(const io::path& folder) {
|
||||||
contentPacks.clear();
|
|
||||||
paths.setCurrentWorldFolder(folder);
|
paths.setCurrentWorldFolder(folder);
|
||||||
content->loadContent(
|
content->loadContent(ContentPack::worldPacksList("world:"));
|
||||||
paths, *input, contentPacks, ContentPack::worldPacksList("world:")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::setScreen(std::shared_ptr<Screen> screen) {
|
void Engine::setScreen(std::shared_ptr<Screen> screen) {
|
||||||
@ -401,24 +376,6 @@ Assets* Engine::getAssets() {
|
|||||||
return assets.get();
|
return assets.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Content* Engine::getContent() const {
|
|
||||||
return content->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
Content* Engine::getWriteableContent() {
|
|
||||||
return content->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ContentPack> Engine::getAllContentPacks() {
|
|
||||||
auto packs = getContentPacks();
|
|
||||||
packs.insert(packs.begin(), ContentPack::createCore(paths));
|
|
||||||
return packs;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ContentPack>& Engine::getContentPacks() {
|
|
||||||
return contentPacks;
|
|
||||||
}
|
|
||||||
|
|
||||||
EnginePaths& Engine::getPaths() {
|
EnginePaths& Engine::getPaths() {
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,7 +64,6 @@ class Engine : public util::ObjectsKeeper {
|
|||||||
std::unique_ptr<SettingsHandler> settingsHandler;
|
std::unique_ptr<SettingsHandler> settingsHandler;
|
||||||
std::unique_ptr<Assets> assets;
|
std::unique_ptr<Assets> assets;
|
||||||
std::shared_ptr<Screen> screen;
|
std::shared_ptr<Screen> screen;
|
||||||
std::vector<ContentPack> contentPacks;
|
|
||||||
std::unique_ptr<ContentControl> content;
|
std::unique_ptr<ContentControl> content;
|
||||||
std::unique_ptr<EngineController> controller;
|
std::unique_ptr<EngineController> controller;
|
||||||
std::unique_ptr<cmd::CommandsInterpreter> cmd;
|
std::unique_ptr<cmd::CommandsInterpreter> cmd;
|
||||||
@ -145,16 +144,6 @@ public:
|
|||||||
|
|
||||||
bool isQuitSignal() const;
|
bool isQuitSignal() const;
|
||||||
|
|
||||||
/// @brief Get current Content instance
|
|
||||||
const Content* getContent() const;
|
|
||||||
|
|
||||||
Content* getWriteableContent();
|
|
||||||
|
|
||||||
/// @brief Get selected content packs
|
|
||||||
std::vector<ContentPack>& getContentPacks();
|
|
||||||
|
|
||||||
std::vector<ContentPack> getAllContentPacks();
|
|
||||||
|
|
||||||
/// @brief Get current screen
|
/// @brief Get current screen
|
||||||
std::shared_ptr<Screen> getScreen();
|
std::shared_ptr<Screen> getScreen();
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,30 @@ static inline UVRegion get_region_for(
|
|||||||
return texreg.region;
|
return texreg.region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelsGenerator::prepare(Content& content, Assets& assets) {
|
||||||
|
for (auto& [name, def] : content.blocks.getDefs()) {
|
||||||
|
if (def->model == BlockModel::custom && def->modelName.empty()) {
|
||||||
|
assets.store(
|
||||||
|
std::make_unique<model::Model>(
|
||||||
|
loadCustomBlockModel(
|
||||||
|
def->customModelRaw, assets, !def->shadeless
|
||||||
|
)
|
||||||
|
),
|
||||||
|
name + ".model"
|
||||||
|
);
|
||||||
|
def->modelName = def->name + ".model";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto& [name, def] : content.items.getDefs()) {
|
||||||
|
assets.store(
|
||||||
|
std::make_unique<model::Model>(
|
||||||
|
generate(*def, content, assets)
|
||||||
|
),
|
||||||
|
name + ".model"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
model::Model ModelsGenerator::fromCustom(
|
model::Model ModelsGenerator::fromCustom(
|
||||||
const Assets& assets,
|
const Assets& assets,
|
||||||
const std::vector<BoxModel>& modelBoxes,
|
const std::vector<BoxModel>& modelBoxes,
|
||||||
|
|||||||
@ -11,6 +11,8 @@ class Block;
|
|||||||
|
|
||||||
class ModelsGenerator {
|
class ModelsGenerator {
|
||||||
public:
|
public:
|
||||||
|
static void prepare(Content& content, Assets& assets);
|
||||||
|
|
||||||
static model::Model generate(
|
static model::Model generate(
|
||||||
const ItemDef& def, const Content& content, const Assets& assets
|
const ItemDef& def, const Content& content, const Assets& assets
|
||||||
);
|
);
|
||||||
|
|||||||
@ -146,8 +146,9 @@ static void load_world(
|
|||||||
int64_t localPlayer
|
int64_t localPlayer
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
auto content = engine.getContent();
|
auto& contentControl = engine.getContentControl();
|
||||||
auto& packs = engine.getContentPacks();
|
auto content = contentControl.get();
|
||||||
|
auto& packs = contentControl.getContentPacks();
|
||||||
auto& settings = engine.getSettings();
|
auto& settings = engine.getSettings();
|
||||||
|
|
||||||
auto level = World::load(worldFiles, settings, *content, packs);
|
auto level = World::load(worldFiles, settings, *content, packs);
|
||||||
@ -203,7 +204,8 @@ void EngineController::openWorld(const std::string& name, bool confirmConvert) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Content* content = engine.getContent();
|
const auto& contentControl = engine.getContentControl();
|
||||||
|
const Content* content = contentControl.get();
|
||||||
auto worldFiles = std::make_shared<WorldFiles>(
|
auto worldFiles = std::make_shared<WorldFiles>(
|
||||||
folder, engine.getSettings().debug);
|
folder, engine.getSettings().debug);
|
||||||
if (auto report = World::checkIndices(worldFiles, content)) {
|
if (auto report = World::checkIndices(worldFiles, content)) {
|
||||||
@ -269,14 +271,15 @@ void EngineController::createWorld(
|
|||||||
})) {
|
})) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto& contentControl = engine.getContentControl();
|
||||||
auto level = World::create(
|
auto level = World::create(
|
||||||
name,
|
name,
|
||||||
generatorID,
|
generatorID,
|
||||||
folder,
|
folder,
|
||||||
seed,
|
seed,
|
||||||
engine.getSettings(),
|
engine.getSettings(),
|
||||||
*engine.getContent(),
|
*contentControl.get(),
|
||||||
engine.getContentPacks()
|
contentControl.getContentPacks()
|
||||||
);
|
);
|
||||||
if (!engine.isHeadless()) {
|
if (!engine.isHeadless()) {
|
||||||
level->players->create(localPlayer);
|
level->players->create(localPlayer);
|
||||||
@ -299,7 +302,8 @@ void EngineController::reconfigPacks(
|
|||||||
const std::vector<std::string>& packsToAdd,
|
const std::vector<std::string>& packsToAdd,
|
||||||
const std::vector<std::string>& packsToRemove
|
const std::vector<std::string>& packsToRemove
|
||||||
) {
|
) {
|
||||||
auto content = engine.getContent();
|
auto& contentControl = engine.getContentControl();
|
||||||
|
auto content = contentControl.get();
|
||||||
bool hasIndices = false;
|
bool hasIndices = false;
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@ -322,7 +326,9 @@ void EngineController::reconfigPacks(
|
|||||||
PacksManager manager;
|
PacksManager manager;
|
||||||
manager.setSources(engine.getContentControl().getDefaultSources());
|
manager.setSources(engine.getContentControl().getDefaultSources());
|
||||||
manager.scan();
|
manager.scan();
|
||||||
auto names = PacksManager::getNames(engine.getContentPacks());
|
auto names = PacksManager::getNames(
|
||||||
|
engine.getContentControl().getContentPacks()
|
||||||
|
);
|
||||||
for (const auto& id : packsToAdd) {
|
for (const auto& id : packsToAdd) {
|
||||||
names.push_back(id);
|
names.push_back(id);
|
||||||
}
|
}
|
||||||
@ -331,7 +337,7 @@ void EngineController::reconfigPacks(
|
|||||||
names.erase(std::find(names.begin(), names.end(), id));
|
names.erase(std::find(names.begin(), names.end(), id));
|
||||||
}
|
}
|
||||||
names = manager.assemble(names);
|
names = manager.assemble(names);
|
||||||
engine.getContentPacks() = manager.getAll(names);
|
engine.getContentControl().getContentPacks() = manager.getAll(names);
|
||||||
} catch (const contentpack_error& err) {
|
} catch (const contentpack_error& err) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
std::string(err.what()) + " [" + err.getPackId() + "]"
|
std::string(err.what()) + " [" + err.getPackId() + "]"
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "content/ContentLoader.hpp"
|
#include "content/ContentLoader.hpp"
|
||||||
|
#include "content/ContentControl.hpp"
|
||||||
#include "lighting/Lighting.hpp"
|
#include "lighting/Lighting.hpp"
|
||||||
#include "logic/BlocksController.hpp"
|
#include "logic/BlocksController.hpp"
|
||||||
#include "logic/LevelController.hpp"
|
#include "logic/LevelController.hpp"
|
||||||
@ -625,7 +626,7 @@ static int l_reload_script(lua::State* L) {
|
|||||||
if (content == nullptr) {
|
if (content == nullptr) {
|
||||||
throw std::runtime_error("content is not initialized");
|
throw std::runtime_error("content is not initialized");
|
||||||
}
|
}
|
||||||
auto& writeableContent = *engine->getWriteableContent();
|
auto& writeableContent = *content_control->get();
|
||||||
auto& def = writeableContent.blocks.require(name);
|
auto& def = writeableContent.blocks.require(name);
|
||||||
ContentLoader::reloadScript(writeableContent, def);
|
ContentLoader::reloadScript(writeableContent, def);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#include "world/generator/VoxelFragment.hpp"
|
#include "world/generator/VoxelFragment.hpp"
|
||||||
#include "content/ContentLoader.hpp"
|
#include "content/ContentLoader.hpp"
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
|
#include "content/ContentControl.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "../lua_custom_types.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
|
/// @brief Get a list of all world generators
|
||||||
/// @return A table with the IDs of all world generators
|
/// @return A table with the IDs of all world generators
|
||||||
static int l_get_generators(lua::State* L) {
|
static int l_get_generators(lua::State* L) {
|
||||||
auto packs = engine->getAllContentPacks();
|
auto packs = content_control->getAllContentPacks();
|
||||||
|
|
||||||
lua::createtable(L, 0, 0);
|
lua::createtable(L, 0, 0);
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "frontend/UiDocument.hpp"
|
#include "frontend/UiDocument.hpp"
|
||||||
#include "frontend/hud.hpp"
|
#include "frontend/hud.hpp"
|
||||||
|
#include "content/ContentControl.hpp"
|
||||||
#include "graphics/ui/elements/InventoryView.hpp"
|
#include "graphics/ui/elements/InventoryView.hpp"
|
||||||
#include "items/Inventories.hpp"
|
#include "items/Inventories.hpp"
|
||||||
#include "logic/BlocksController.hpp"
|
#include "logic/BlocksController.hpp"
|
||||||
@ -176,7 +177,7 @@ static int l_reload_script(lua::State* L) {
|
|||||||
if (content == nullptr) {
|
if (content == nullptr) {
|
||||||
throw std::runtime_error("content is not initialized");
|
throw std::runtime_error("content is not initialized");
|
||||||
}
|
}
|
||||||
auto& writeableContent = *engine->getWriteableContent();
|
auto& writeableContent = *content_control->get();
|
||||||
auto pack = writeableContent.getPackRuntime(packid);
|
auto pack = writeableContent.getPackRuntime(packid);
|
||||||
const auto& info = pack->getInfo();
|
const auto& info = pack->getInfo();
|
||||||
scripting::load_hud_script(
|
scripting::load_hud_script(
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
|
#include "content/ContentControl.hpp"
|
||||||
#include "frontend/hud.hpp"
|
#include "frontend/hud.hpp"
|
||||||
#include "frontend/screens/Screen.hpp"
|
#include "frontend/screens/Screen.hpp"
|
||||||
#include "graphics/ui/GUI.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*) {
|
static int l_reset_bindings(lua::State*) {
|
||||||
reset_pack_bindings("res:");
|
reset_pack_bindings("res:");
|
||||||
for (auto& pack : engine->getContentPacks()) {
|
for (const auto& pack : content_control->getContentPacks()) {
|
||||||
reset_pack_bindings(pack.folder);
|
reset_pack_bindings(pack.folder);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "content/ContentLoader.hpp"
|
#include "content/ContentLoader.hpp"
|
||||||
|
#include "content/ContentControl.hpp"
|
||||||
#include "items/ItemDef.hpp"
|
#include "items/ItemDef.hpp"
|
||||||
#include "api_lua.hpp"
|
#include "api_lua.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
@ -94,7 +95,7 @@ static int l_reload_script(lua::State* L) {
|
|||||||
if (content == nullptr) {
|
if (content == nullptr) {
|
||||||
throw std::runtime_error("content is not initialized");
|
throw std::runtime_error("content is not initialized");
|
||||||
}
|
}
|
||||||
auto& writeableContent = *engine->getWriteableContent();
|
auto& writeableContent = *content_control->get();
|
||||||
auto& def = writeableContent.items.require(name);
|
auto& def = writeableContent.items.require(name);
|
||||||
ContentLoader::reloadScript(writeableContent, def);
|
ContentLoader::reloadScript(writeableContent, def);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -21,7 +21,7 @@ using namespace scripting;
|
|||||||
|
|
||||||
static int l_pack_get_folder(lua::State* L) {
|
static int l_pack_get_folder(lua::State* L) {
|
||||||
std::string packName = lua::tostring(L, 1);
|
std::string packName = lua::tostring(L, 1);
|
||||||
auto packs = engine->getAllContentPacks();
|
auto packs = content_control->getAllContentPacks();
|
||||||
|
|
||||||
for (auto& pack : packs) {
|
for (auto& pack : packs) {
|
||||||
if (pack.id == packName) {
|
if (pack.id == packName) {
|
||||||
@ -33,7 +33,7 @@ static int l_pack_get_folder(lua::State* L) {
|
|||||||
|
|
||||||
/// @brief pack.get_installed() -> array<string>
|
/// @brief pack.get_installed() -> array<string>
|
||||||
static int l_pack_get_installed(lua::State* L) {
|
static int l_pack_get_installed(lua::State* L) {
|
||||||
auto& packs = engine->getContentPacks();
|
auto& packs = content_control->getContentPacks();
|
||||||
lua::createtable(L, packs.size(), 0);
|
lua::createtable(L, packs.size(), 0);
|
||||||
for (size_t i = 0; i < packs.size(); i++) {
|
for (size_t i = 0; i < packs.size(); i++) {
|
||||||
lua::pushstring(L, packs[i].id);
|
lua::pushstring(L, packs[i].id);
|
||||||
@ -49,10 +49,10 @@ static int l_pack_get_available(lua::State* L) {
|
|||||||
worldFolder = level->getWorld()->wfile->getFolder();
|
worldFolder = level->getWorld()->wfile->getFolder();
|
||||||
}
|
}
|
||||||
PacksManager manager;
|
PacksManager manager;
|
||||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
manager.setSources(content_control->getDefaultSources());
|
||||||
manager.scan();
|
manager.scan();
|
||||||
|
|
||||||
const auto& installed = engine->getContentPacks();
|
const auto& installed = content_control->getContentPacks();
|
||||||
for (auto& pack : installed) {
|
for (auto& pack : installed) {
|
||||||
manager.exclude(pack.id);
|
manager.exclude(pack.id);
|
||||||
}
|
}
|
||||||
@ -142,8 +142,7 @@ static int pack_get_infos(lua::State* L) {
|
|||||||
lua::pop(L, 1);
|
lua::pop(L, 1);
|
||||||
}
|
}
|
||||||
std::unordered_map<std::string, ContentPack> packs;
|
std::unordered_map<std::string, ContentPack> packs;
|
||||||
auto content = engine->getContent();
|
const auto& loadedPacks = content_control->getContentPacks();
|
||||||
const auto& loadedPacks = engine->getContentPacks();
|
|
||||||
for (const auto& pack : loadedPacks) {
|
for (const auto& pack : loadedPacks) {
|
||||||
if (ids.find(pack.id) != ids.end()) {
|
if (ids.find(pack.id) != ids.end()) {
|
||||||
packs[pack.id] = pack;
|
packs[pack.id] = pack;
|
||||||
@ -156,7 +155,7 @@ static int pack_get_infos(lua::State* L) {
|
|||||||
worldFolder = level->getWorld()->wfile->getFolder();
|
worldFolder = level->getWorld()->wfile->getFolder();
|
||||||
}
|
}
|
||||||
PacksManager manager;
|
PacksManager manager;
|
||||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
manager.setSources(content_control->getDefaultSources());
|
||||||
manager.scan();
|
manager.scan();
|
||||||
auto vec =
|
auto vec =
|
||||||
manager.getAll(std::vector<std::string>(ids.begin(), ids.end()));
|
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 packid = lua::tostring(L, 1);
|
||||||
|
|
||||||
auto content = engine->getContent();
|
auto& packs = content_control->getContentPacks();
|
||||||
auto& packs = engine->getContentPacks();
|
|
||||||
auto found =
|
auto found =
|
||||||
std::find_if(packs.begin(), packs.end(), [packid](const auto& pack) {
|
std::find_if(packs.begin(), packs.end(), [packid](const auto& pack) {
|
||||||
return pack.id == packid;
|
return pack.id == packid;
|
||||||
@ -199,7 +197,7 @@ static int l_pack_get_info(lua::State* L) {
|
|||||||
worldFolder = level->getWorld()->wfile->getFolder();
|
worldFolder = level->getWorld()->wfile->getFolder();
|
||||||
}
|
}
|
||||||
PacksManager manager;
|
PacksManager manager;
|
||||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
manager.setSources(content_control->getDefaultSources());
|
||||||
manager.scan();
|
manager.scan();
|
||||||
auto vec = manager.getAll({packid});
|
auto vec = manager.getAll({packid});
|
||||||
if (!vec.empty()) {
|
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) {
|
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);
|
lua::createtable(L, packs.size(), 0);
|
||||||
for (size_t i = 0; i < packs.size(); i++) {
|
for (size_t i = 0; i < packs.size(); i++) {
|
||||||
lua::pushstring(L, packs[i]);
|
lua::pushstring(L, packs[i]);
|
||||||
@ -237,7 +235,7 @@ static int l_pack_assemble(lua::State* L) {
|
|||||||
worldFolder = level->getWorld()->wfile->getFolder();
|
worldFolder = level->getWorld()->wfile->getFolder();
|
||||||
}
|
}
|
||||||
PacksManager manager;
|
PacksManager manager;
|
||||||
manager.setSources(engine->getContentControl().getDefaultSources());
|
manager.setSources(content_control->getDefaultSources());
|
||||||
manager.scan();
|
manager.scan();
|
||||||
try {
|
try {
|
||||||
ids = manager.assemble(ids);
|
ids = manager.assemble(ids);
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#include "coders/json.hpp"
|
#include "coders/json.hpp"
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "content/ContentLoader.hpp"
|
#include "content/ContentLoader.hpp"
|
||||||
|
#include "content/ContentControl.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "world/files/WorldFiles.hpp"
|
#include "world/files/WorldFiles.hpp"
|
||||||
#include "io/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
@ -217,7 +218,7 @@ static int l_reload_script(lua::State* L) {
|
|||||||
if (content == nullptr) {
|
if (content == nullptr) {
|
||||||
throw std::runtime_error("content is not initialized");
|
throw std::runtime_error("content is not initialized");
|
||||||
}
|
}
|
||||||
auto& writeableContent = *engine->getWriteableContent();
|
auto& writeableContent = *content_control->get();
|
||||||
auto pack = writeableContent.getPackRuntime(packid);
|
auto pack = writeableContent.getPackRuntime(packid);
|
||||||
ContentLoader::loadWorldScript(*pack);
|
ContentLoader::loadWorldScript(*pack);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include "scripting_commons.hpp"
|
#include "scripting_commons.hpp"
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "content/ContentPack.hpp"
|
#include "content/ContentPack.hpp"
|
||||||
|
#include "content/ContentControl.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "io/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
@ -40,6 +41,7 @@ Engine* scripting::engine = nullptr;
|
|||||||
Level* scripting::level = nullptr;
|
Level* scripting::level = nullptr;
|
||||||
const Content* scripting::content = nullptr;
|
const Content* scripting::content = nullptr;
|
||||||
const ContentIndices* scripting::indices = nullptr;
|
const ContentIndices* scripting::indices = nullptr;
|
||||||
|
ContentControl* scripting::content_control = nullptr;
|
||||||
BlocksController* scripting::blocks = nullptr;
|
BlocksController* scripting::blocks = nullptr;
|
||||||
LevelController* scripting::controller = nullptr;
|
LevelController* scripting::controller = nullptr;
|
||||||
|
|
||||||
@ -68,6 +70,7 @@ int scripting::load_script(
|
|||||||
|
|
||||||
void scripting::initialize(Engine* engine) {
|
void scripting::initialize(Engine* engine) {
|
||||||
scripting::engine = engine;
|
scripting::engine = engine;
|
||||||
|
scripting::content_control = &engine->getContentControl();
|
||||||
lua::initialize(engine->getPaths(), engine->getCoreParameters());
|
lua::initialize(engine->getPaths(), engine->getCoreParameters());
|
||||||
|
|
||||||
load_script(io::path("stdlib.lua"), true);
|
load_script(io::path("stdlib.lua"), true);
|
||||||
@ -268,21 +271,21 @@ void scripting::on_world_load(LevelController* controller) {
|
|||||||
lua::call_nothrow(L, 0, 0);
|
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");
|
lua::emit_event(L, pack.id + ":.worldopen");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::on_world_tick() {
|
void scripting::on_world_tick() {
|
||||||
auto L = lua::get_main_state();
|
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");
|
lua::emit_event(L, pack.id + ":.worldtick");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::on_world_save() {
|
void scripting::on_world_save() {
|
||||||
auto L = lua::get_main_state();
|
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");
|
lua::emit_event(L, pack.id + ":.worldsave");
|
||||||
}
|
}
|
||||||
if (lua::getglobal(L, "__vc_on_world_save")) {
|
if (lua::getglobal(L, "__vc_on_world_save")) {
|
||||||
@ -292,7 +295,7 @@ void scripting::on_world_save() {
|
|||||||
|
|
||||||
void scripting::on_world_quit() {
|
void scripting::on_world_quit() {
|
||||||
auto L = lua::get_main_state();
|
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");
|
lua::emit_event(L, pack.id + ":.worldquit");
|
||||||
}
|
}
|
||||||
if (lua::getglobal(L, "__vc_on_world_quit")) {
|
if (lua::getglobal(L, "__vc_on_world_quit")) {
|
||||||
@ -308,7 +311,7 @@ void scripting::on_world_quit() {
|
|||||||
void scripting::cleanup() {
|
void scripting::cleanup() {
|
||||||
auto L = lua::get_main_state();
|
auto L = lua::get_main_state();
|
||||||
lua::requireglobal(L, "pack");
|
lua::requireglobal(L, "pack");
|
||||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
for (auto& pack : content_control->getAllContentPacks()) {
|
||||||
lua::requirefield(L, "unload");
|
lua::requirefield(L, "unload");
|
||||||
lua::pushstring(L, pack.id);
|
lua::pushstring(L, pack.id);
|
||||||
lua::call_nothrow(L, 1);
|
lua::call_nothrow(L, 1);
|
||||||
|
|||||||
@ -14,6 +14,7 @@ class Engine;
|
|||||||
class Content;
|
class Content;
|
||||||
struct ContentPack;
|
struct ContentPack;
|
||||||
class ContentIndices;
|
class ContentIndices;
|
||||||
|
class ContentControl;
|
||||||
class Level;
|
class Level;
|
||||||
class Block;
|
class Block;
|
||||||
class Chunk;
|
class Chunk;
|
||||||
@ -38,6 +39,7 @@ namespace scripting {
|
|||||||
extern Engine* engine;
|
extern Engine* engine;
|
||||||
extern const Content* content;
|
extern const Content* content;
|
||||||
extern const ContentIndices* indices;
|
extern const ContentIndices* indices;
|
||||||
|
extern ContentControl* content_control;
|
||||||
extern Level* level;
|
extern Level* level;
|
||||||
extern BlocksController* blocks;
|
extern BlocksController* blocks;
|
||||||
extern LevelController* controller;
|
extern LevelController* controller;
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "io/io.hpp"
|
#include "io/io.hpp"
|
||||||
#include "assets/Assets.hpp"
|
#include "assets/Assets.hpp"
|
||||||
|
#include "content/ContentControl.hpp"
|
||||||
#include "frontend/hud.hpp"
|
#include "frontend/hud.hpp"
|
||||||
#include "frontend/UiDocument.hpp"
|
#include "frontend/UiDocument.hpp"
|
||||||
#include "graphics/render/WorldRenderer.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);
|
lua::call_nothrow(L, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
for (auto& pack : content_control->getAllContentPacks()) {
|
||||||
lua::emit_event(
|
lua::emit_event(
|
||||||
lua::get_main_state(),
|
lua::get_main_state(),
|
||||||
pack.id + ":.hudopen",
|
pack.id + ":.hudopen",
|
||||||
@ -57,7 +58,7 @@ void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void scripting::on_frontend_render() {
|
void scripting::on_frontend_render() {
|
||||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
for (auto& pack : content_control->getAllContentPacks()) {
|
||||||
lua::emit_event(
|
lua::emit_event(
|
||||||
lua::get_main_state(),
|
lua::get_main_state(),
|
||||||
pack.id + ":.hudrender",
|
pack.id + ":.hudrender",
|
||||||
@ -68,7 +69,7 @@ void scripting::on_frontend_render() {
|
|||||||
|
|
||||||
void scripting::on_frontend_close() {
|
void scripting::on_frontend_close() {
|
||||||
auto L = lua::get_main_state();
|
auto L = lua::get_main_state();
|
||||||
for (auto& pack : Engine::getInstance().getAllContentPacks()) {
|
for (auto& pack : content_control->getAllContentPacks()) {
|
||||||
lua::emit_event(
|
lua::emit_event(
|
||||||
L,
|
L,
|
||||||
pack.id + ":.hudclose",
|
pack.id + ":.hudclose",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user