From d41d220b5fe21dd67922dbfe19f86e0824e96950 Mon Sep 17 00:00:00 2001 From: Joseph Walton-Rivers <joseph@walton-rivers.uk> Date: Mon, 27 Jun 2022 23:44:06 +0100 Subject: [PATCH] start of asset management interfaces --- demo/demo/main.cpp | 2 ++ include/fggl/assets/manager.hpp | 33 ++++++++++++++++++++- include/fggl/assets/module.hpp | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 include/fggl/assets/module.hpp diff --git a/demo/demo/main.cpp b/demo/demo/main.cpp index e1802a3..e7e79b3 100644 --- a/demo/demo/main.cpp +++ b/demo/demo/main.cpp @@ -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 diff --git a/include/fggl/assets/manager.hpp b/include/fggl/assets/manager.hpp index 598e648..40cdf39 100644 --- a/include/fggl/assets/manager.hpp +++ b/include/fggl/assets/manager.hpp @@ -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 diff --git a/include/fggl/assets/module.hpp b/include/fggl/assets/module.hpp new file mode 100644 index 0000000..a4079cb --- /dev/null +++ b/include/fggl/assets/module.hpp @@ -0,0 +1,51 @@ +/* + * 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 -- GitLab