refactor: moved funcs to assetload
This commit is contained in:
@@ -17,19 +17,19 @@ class Assets;
|
|||||||
namespace assetload {
|
namespace assetload {
|
||||||
/// @brief final work to do in the main thread
|
/// @brief final work to do in the main thread
|
||||||
using postfunc = std::function<void(Assets*)>;
|
using postfunc = std::function<void(Assets*)>;
|
||||||
|
|
||||||
|
using setupfunc = std::function<void(const Assets*)>;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void assets_setup(const Assets*);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void assets_setup(const Assets*);
|
|
||||||
|
|
||||||
using assetssetupfunc = std::function<void(const Assets*)>;
|
|
||||||
|
|
||||||
class Assets {
|
class Assets {
|
||||||
std::vector<TextureAnimation> animations;
|
std::vector<TextureAnimation> animations;
|
||||||
|
|
||||||
using assets_map = std::unordered_map<std::string, std::shared_ptr<void>>;
|
using assets_map = std::unordered_map<std::string, std::shared_ptr<void>>;
|
||||||
std::unordered_map<std::type_index, assets_map> assets;
|
std::unordered_map<std::type_index, assets_map> assets;
|
||||||
std::vector<assetssetupfunc> setupFuncs;
|
std::vector<assetload::setupfunc> setupFuncs;
|
||||||
public:
|
public:
|
||||||
Assets() {}
|
Assets() {}
|
||||||
Assets(const Assets&) = delete;
|
Assets(const Assets&) = delete;
|
||||||
@@ -72,13 +72,13 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addSetupFunc(assetssetupfunc setupfunc) {
|
void addSetupFunc(assetload::setupfunc setupfunc) {
|
||||||
setupFuncs.push_back(setupfunc);
|
setupFuncs.push_back(setupfunc);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void assets_setup(const Assets* assets) {
|
void assetload::assets_setup(const Assets* assets) {
|
||||||
if (auto mapPtr = assets->getMap<T>()) {
|
if (auto mapPtr = assets->getMap<T>()) {
|
||||||
for (const auto& entry : **mapPtr) {
|
for (const auto& entry : **mapPtr) {
|
||||||
static_cast<T*>(entry.second.get())->setup(assets);
|
static_cast<T*>(entry.second.get())->setup(assets);
|
||||||
|
|||||||
+1
-1
@@ -245,7 +245,7 @@ void Engine::loadAssets() {
|
|||||||
Shader::preprocessor->setPaths(resPaths.get());
|
Shader::preprocessor->setPaths(resPaths.get());
|
||||||
|
|
||||||
auto new_assets = std::make_unique<Assets>();
|
auto new_assets = std::make_unique<Assets>();
|
||||||
new_assets->addSetupFunc(assets_setup<rigging::RigConfig>);
|
new_assets->addSetupFunc(assetload::assets_setup<rigging::RigConfig>);
|
||||||
AssetsLoader loader(new_assets.get(), resPaths.get());
|
AssetsLoader loader(new_assets.get(), resPaths.get());
|
||||||
AssetsLoader::addDefaults(loader, content.get());
|
AssetsLoader::addDefaults(loader, content.get());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user