mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add background assets loader
This commit is contained in:
parent
245e040a1c
commit
0cf7d9b1ed
9 changed files with 104 additions and 46 deletions
|
|
@ -1,13 +1,12 @@
|
|||
#include "AssetsManagement.hpp"
|
||||
|
||||
#include "assets/Assets.hpp"
|
||||
#include "assets/AssetsLoader.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "graphics/core/Shader.hpp"
|
||||
#include "EnginePaths.hpp"
|
||||
#include "coders/GLSLExtension.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "EnginePaths.hpp"
|
||||
#include "graphics/core/Shader.hpp"
|
||||
#include "graphics/render/ModelsGenerator.hpp"
|
||||
#include "graphics/ui/GUI.hpp"
|
||||
|
||||
|
|
@ -15,6 +14,10 @@ static debug::Logger logger("assets-management");
|
|||
|
||||
AssetsManagement::AssetsManagement(Engine& engine) : engine(engine) {}
|
||||
|
||||
AssetsManagement::~AssetsManagement() {
|
||||
finishBackgroundLoader();
|
||||
}
|
||||
|
||||
const Assets* AssetsManagement::getStorage() const {
|
||||
return assets.get();
|
||||
}
|
||||
|
|
@ -23,7 +26,23 @@ Assets* AssetsManagement::getStorage() {
|
|||
return assets.get();
|
||||
}
|
||||
|
||||
AssetsLoader& AssetsManagement::acquireBackgroundLoader() {
|
||||
if (backgroundLoader) {
|
||||
return *backgroundLoader;
|
||||
}
|
||||
if (assets == nullptr) {
|
||||
throw std::runtime_error("no assets storage available");
|
||||
}
|
||||
backgroundLoader = std::make_unique<AssetsLoader>(
|
||||
engine, *assets, engine.getResPaths()
|
||||
);
|
||||
backgroundLoaderTask = backgroundLoader->startTask(nullptr);
|
||||
return *backgroundLoader;
|
||||
}
|
||||
|
||||
void AssetsManagement::loadAssets(Content* content) {
|
||||
finishBackgroundLoader();
|
||||
|
||||
const auto& paths = engine.getPaths();
|
||||
logger.info() << "loading assets";
|
||||
Shader::preprocessor->setPaths(&paths.resPaths);
|
||||
|
|
@ -34,7 +53,7 @@ void AssetsManagement::loadAssets(Content* content) {
|
|||
|
||||
// no need
|
||||
// correct log messages order is more useful
|
||||
// todo: before setting to true, check if GLSLExtension thread safe
|
||||
// todo: before setting to true, check if GLSLExtension thread safe
|
||||
bool threading = false; // look at three upper lines
|
||||
if (threading) {
|
||||
auto task = loader.startTask([=](){});
|
||||
|
|
@ -51,3 +70,17 @@ void AssetsManagement::loadAssets(Content* content) {
|
|||
assets->setup();
|
||||
engine.getGUI().onAssetsLoad(assets.get());
|
||||
}
|
||||
|
||||
void AssetsManagement::update() {
|
||||
if (backgroundLoaderTask) {
|
||||
backgroundLoaderTask->update();
|
||||
}
|
||||
}
|
||||
|
||||
void AssetsManagement::finishBackgroundLoader() {
|
||||
if (backgroundLoaderTask == nullptr) {
|
||||
return;
|
||||
}
|
||||
backgroundLoaderTask.reset();
|
||||
backgroundLoader.reset();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue