diff --git a/demo/demo/main.cpp b/demo/demo/main.cpp index e1802a3a01be8697f1797e18fe37ee74ccfc93ef..e7e79b380286862470e18d7f71b3fdf74f92c68d 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 598e6489d0f20c5b36eb2e64c628d92b686f634a..40cdf39cabffa672bed972415952e77b9d77d43f 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 0000000000000000000000000000000000000000..a4079cba04eacd6fab0f359dcebc8983fc8f7437 --- /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