refactor: add GUI instance reference to UI nodes

This commit is contained in:
MihailRis
2025-04-02 14:55:53 +03:00
parent 74a94f869c
commit 4c48afbb90
70 changed files with 1133 additions and 832 deletions
+10 -5
View File
@@ -19,13 +19,14 @@
#include "items/ItemDef.hpp"
#include "Assets.hpp"
#include "assetload_funcs.hpp"
#include "engine/Engine.hpp"
namespace fs = std::filesystem;
static debug::Logger logger("assets-loader");
AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
: assets(assets), paths(paths) {
AssetsLoader::AssetsLoader(Engine& engine, Assets& assets, const ResPaths* paths)
: engine(engine), assets(assets), paths(paths) {
addLoader(AssetType::SHADER, assetload::shader);
addLoader(AssetType::TEXTURE, assetload::texture);
addLoader(AssetType::FONT, assetload::font);
@@ -73,7 +74,7 @@ void AssetsLoader::loadNext() {
aloader_func loader = getLoader(entry.tag);
auto postfunc =
loader(this, paths, entry.filename, entry.alias, entry.config);
postfunc(assets);
postfunc(&assets);
entries.pop();
} catch (std::runtime_error& err) {
logger.error() << err.what();
@@ -101,7 +102,7 @@ static void add_layouts(
AssetType::LAYOUT,
file.string(),
name,
std::make_shared<LayoutCfg>(env)
std::make_shared<LayoutCfg>(&loader.getEngine().getGUI(), env)
);
}
}
@@ -296,6 +297,10 @@ bool AssetsLoader::loadExternalTexture(
return false;
}
Engine& AssetsLoader::getEngine() {
return engine;
}
const ResPaths* AssetsLoader::getPaths() const {
return paths;
}
@@ -324,7 +329,7 @@ std::shared_ptr<Task> AssetsLoader::startTask(runnable onDone) {
std::make_shared<util::ThreadPool<aloader_entry, assetload::postfunc>>(
"assets-loader-pool",
[=]() { return std::make_shared<LoaderWorker>(this); },
[=](const assetload::postfunc& func) { func(assets); }
[this](const assetload::postfunc& func) { func(&assets); }
);
pool->setOnComplete(std::move(onDone));
while (!entries.empty()) {