Skip to content
Snippets Groups Projects
Commit d41d220b authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

start of asset management interfaces

parent 2cb7b057
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,7 @@
#include "fggl/scenes/menu.hpp"
#include "fggl/modules/manager.hpp"
#include "fggl/assets/module.hpp"
#include "GameScene.h"
#include "rollball.hpp"
......@@ -74,6 +75,7 @@ int main(int argc, const char* argv[]) {
moduleManager.use<fggl::audio::OpenAL>();
moduleManager.use<fggl::gfx::OpenGL4>();
moduleManager.use<fggl::display::GLFW>();
moduleManager.use<fggl::assets::AssetFolders>();
moduleManager.resolve();
// create the application
......
......@@ -20,6 +20,11 @@
#define FGGL_ASSETS_MANAGER_HPP
#include <string_view>
#include <map>
#include <functional>
#include <memory>
#include "fggl/data/storage.hpp"
#include "fggl/util/safety.hpp"
namespace fggl::assets {
......@@ -27,11 +32,37 @@ namespace fggl::assets {
struct AssetTag{};
using AssetType = util::OpaqueName<std::string_view, AssetTag>;
class Manager {
struct AssetData {
void* data;
std::size_t size;
};
struct AssetCallbacks {
std::function<void(const AssetType&, AssetData)> init;
std::function<void(const AssetType&, AssetData)> destroy;
};
struct Asset{};
class AssetManager {
public:
constexpr const static modules::ModuleService service = modules::make_service("fggl::assets::AssetModule");
using AssetGUID = std::string;
AssetManager(data::Storage* storage) : m_storage(storage) {}
virtual ~AssetManager() = default;
void load(const AssetType&, const AssetGUID& name);
void loadToTemp(const AssetType&, const AssetGUID& name);
void unload(const AssetGUID& name);
private:
data::Storage* m_storage;
std::map<AssetGUID, std::shared_ptr<Asset>> m_registry;
std::map<AssetType, AssetCallbacks> m_callbacks;
};
} // namespace fggl::assets
#endif //FGGL_ASSETS_MANAGER_HPP
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 27/06/22.
//
#ifndef FGGL_ASSETS_MODULE_HPP
#define FGGL_ASSETS_MODULE_HPP
#include "fggl/modules/module.hpp"
#include "fggl/data/module.hpp"
#include "fggl/assets/manager.hpp"
namespace fggl::assets {
struct AssetFolders {
constexpr static const char* name = "fggl::assets::Folders";
constexpr static const std::array<modules::ModuleService, 1> provides = {
AssetManager::service
};
constexpr static const std::array<modules::ModuleService, 1> depends = {
data::Storage::service
};
static const modules::ServiceFactory factory;
};
bool asset_factory(modules::ModuleService service, modules::Services& services) {
if (service == AssetManager::service) {
auto storage = services.get<data::Storage>();
services.create<AssetManager>(storage);
return true;
}
return false;
}
const modules::ServiceFactory AssetFolders::factory = asset_factory;
} // namespace fggl::assets
#endif //FGGL_ASSETS_MODULE_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment