From 4a3487f17bed861f4ced95a6b8b56183100a11e7 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 1 Jul 2024 16:32:54 +0300 Subject: [PATCH] add assetssetupfunc --- src/assets/Assets.hpp | 35 +++++++++++++++++++++++++++++++++++ src/engine.cpp | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/src/assets/Assets.hpp b/src/assets/Assets.hpp index fd39e8fe..f94adbd9 100644 --- a/src/assets/Assets.hpp +++ b/src/assets/Assets.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -18,11 +19,17 @@ namespace assetload { using postfunc = std::function; } +template +void assets_setup(const Assets*); + +using assetssetupfunc = std::function; + class Assets { std::vector animations; using assets_map = std::unordered_map>; std::unordered_map assets; + std::vector setupFuncs; public: Assets() {} Assets(const Assets&) = delete; @@ -49,6 +56,34 @@ public: } return static_cast(found->second.get()); } + + template + std::optional getMap() const { + const auto& mapIter = assets.find(typeid(T)); + if (mapIter == assets.end()) { + return std::nullopt; + } + return &mapIter->second; + } + + void setup() { + for (auto& setupFunc : setupFuncs) { + setupFunc(this); + } + } + + void addSetupFunc(assetssetupfunc setupfunc) { + setupFuncs.push_back(setupfunc); + } }; +template +void assets_setup(const Assets* assets) { + if (auto mapPtr = assets->getMap()) { + for (const auto& entry : **mapPtr) { + static_cast(entry.second.get())->setup(assets); + } + } +} + #endif // ASSETS_ASSETS_HPP_ diff --git a/src/engine.cpp b/src/engine.cpp index e24e66cd..9e5c7235 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -23,6 +23,7 @@ #include "graphics/core/ImageData.hpp" #include "graphics/core/Shader.hpp" #include "graphics/ui/GUI.hpp" +#include "objects/rigging.hpp" #include "logic/EngineController.hpp" #include "logic/CommandsInterpreter.hpp" #include "logic/scripting/scripting.hpp" @@ -121,6 +122,7 @@ void Engine::loadControls() { } void Engine::onAssetsLoaded() { + assets->setup(); gui->onAssetsLoad(assets.get()); } @@ -243,9 +245,12 @@ void Engine::loadAssets() { Shader::preprocessor->setPaths(resPaths.get()); auto new_assets = std::make_unique(); + new_assets->addSetupFunc(assets_setup); AssetsLoader loader(new_assets.get(), resPaths.get()); AssetsLoader::addDefaults(loader, content.get()); + // no need + // correct log messages order is more useful bool threading = false; if (threading) { auto task = loader.startTask([=](){});