mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add AssetsManagement
This commit is contained in:
parent
89485dc592
commit
d5f8fed633
4 changed files with 82 additions and 30 deletions
53
src/engine/AssetsManagement.cpp
Normal file
53
src/engine/AssetsManagement.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#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 "graphics/render/ModelsGenerator.hpp"
|
||||
#include "graphics/ui/GUI.hpp"
|
||||
|
||||
static debug::Logger logger("assets-management");
|
||||
|
||||
AssetsManagement::AssetsManagement(Engine& engine) : engine(engine) {}
|
||||
|
||||
const Assets* AssetsManagement::getStorage() const {
|
||||
return assets.get();
|
||||
}
|
||||
|
||||
Assets* AssetsManagement::getStorage() {
|
||||
return assets.get();
|
||||
}
|
||||
|
||||
void AssetsManagement::loadAssets(Content* content) {
|
||||
const auto& paths = engine.getPaths();
|
||||
logger.info() << "loading assets";
|
||||
Shader::preprocessor->setPaths(&paths.resPaths);
|
||||
|
||||
auto new_assets = std::make_unique<Assets>();
|
||||
AssetsLoader loader(engine, *new_assets, paths.resPaths);
|
||||
AssetsLoader::addDefaults(loader, content);
|
||||
|
||||
// no need
|
||||
// correct log messages order is more useful
|
||||
// todo: before setting to true, check if GLSLExtension thread safe
|
||||
bool threading = false; // look at three upper lines
|
||||
if (threading) {
|
||||
auto task = loader.startTask([=](){});
|
||||
task->waitForEnd();
|
||||
} else {
|
||||
while (loader.hasNext()) {
|
||||
loader.loadNext();
|
||||
}
|
||||
}
|
||||
assets = std::move(new_assets);
|
||||
if (content) {
|
||||
ModelsGenerator::prepare(*content, *assets);
|
||||
}
|
||||
assets->setup();
|
||||
engine.getGUI().onAssetsLoad(assets.get());
|
||||
}
|
||||
22
src/engine/AssetsManagement.hpp
Normal file
22
src/engine/AssetsManagement.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Assets;
|
||||
class AssetsLoader;
|
||||
class Engine;
|
||||
class Content;
|
||||
|
||||
class AssetsManagement {
|
||||
public:
|
||||
AssetsManagement(Engine& engine);
|
||||
|
||||
void loadAssets(Content* content);
|
||||
|
||||
Assets* getStorage();
|
||||
const Assets* getStorage() const;
|
||||
private:
|
||||
Engine& engine;
|
||||
std::unique_ptr<Assets> assets;
|
||||
std::unique_ptr<AssetsLoader> backgroundLoader;
|
||||
};
|
||||
|
|
@ -34,6 +34,7 @@
|
|||
#include "window/input.hpp"
|
||||
#include "window/Window.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "AssetsManagement.hpp"
|
||||
#include "Mainloop.hpp"
|
||||
#include "ServerMainloop.hpp"
|
||||
#include "WindowControl.hpp"
|
||||
|
|
@ -84,6 +85,7 @@ void Engine::onContentLoad() {
|
|||
}
|
||||
|
||||
void Engine::initializeClient() {
|
||||
assets = std::make_unique<AssetsManagement>(*this);
|
||||
windowControl = std::make_unique<WindowControl>(*this);
|
||||
auto [window, input] = windowControl->initialize();
|
||||
|
||||
|
|
@ -305,7 +307,7 @@ void Engine::renderFrame() {
|
|||
screen->draw(time.getDelta());
|
||||
|
||||
DrawContext ctx(nullptr, *window, nullptr);
|
||||
gui->draw(ctx, *assets);
|
||||
gui->draw(ctx, *assets->getStorage());
|
||||
}
|
||||
|
||||
void Engine::saveSettings() {
|
||||
|
|
@ -363,33 +365,7 @@ void Engine::setLevelConsumer(OnWorldOpen levelConsumer) {
|
|||
}
|
||||
|
||||
void Engine::loadAssets() {
|
||||
logger.info() << "loading assets";
|
||||
Shader::preprocessor->setPaths(&paths->resPaths);
|
||||
|
||||
auto content = this->content->get();
|
||||
|
||||
auto new_assets = std::make_unique<Assets>();
|
||||
AssetsLoader loader(*this, *new_assets, paths->resPaths);
|
||||
AssetsLoader::addDefaults(loader, content);
|
||||
|
||||
// no need
|
||||
// correct log messages order is more useful
|
||||
// todo: before setting to true, check if GLSLExtension thread safe
|
||||
bool threading = false; // look at three upper lines
|
||||
if (threading) {
|
||||
auto task = loader.startTask([=](){});
|
||||
task->waitForEnd();
|
||||
} else {
|
||||
while (loader.hasNext()) {
|
||||
loader.loadNext();
|
||||
}
|
||||
}
|
||||
assets = std::move(new_assets);
|
||||
if (content) {
|
||||
ModelsGenerator::prepare(*content, *assets);
|
||||
}
|
||||
assets->setup();
|
||||
gui->onAssetsLoad(assets.get());
|
||||
assets->loadAssets(content->get());
|
||||
}
|
||||
|
||||
void Engine::loadProject() {
|
||||
|
|
@ -442,7 +418,7 @@ EngineSettings& Engine::getSettings() {
|
|||
}
|
||||
|
||||
Assets* Engine::getAssets() {
|
||||
return assets.get();
|
||||
return assets->getStorage();
|
||||
}
|
||||
|
||||
EnginePaths& Engine::getPaths() {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <string>
|
||||
|
||||
class Assets;
|
||||
class AssetsManagement;
|
||||
class ContentControl;
|
||||
class EngineController;
|
||||
class EnginePaths;
|
||||
|
|
@ -52,7 +53,7 @@ class Engine : public util::ObjectsKeeper {
|
|||
std::unique_ptr<EnginePaths> paths;
|
||||
std::unique_ptr<Project> project;
|
||||
std::unique_ptr<SettingsHandler> settingsHandler;
|
||||
std::unique_ptr<Assets> assets;
|
||||
std::unique_ptr<AssetsManagement> assets;
|
||||
std::shared_ptr<Screen> screen;
|
||||
std::unique_ptr<ContentControl> content;
|
||||
std::unique_ptr<EngineController> controller;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue