From 0e45d4835f65ff9127a16adcbe9a9f0a20370cfc Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 28 Nov 2024 18:18:13 +0100 Subject: implement resource manager --- src/crepe/ResourceManager.h | 51 ++++++++++----------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) (limited to 'src/crepe/ResourceManager.h') diff --git a/src/crepe/ResourceManager.h b/src/crepe/ResourceManager.h index 26a86a8..fc50b65 100644 --- a/src/crepe/ResourceManager.h +++ b/src/crepe/ResourceManager.h @@ -5,12 +5,10 @@ #include "api/Asset.h" -#include "Component.h" #include "Resource.h" namespace crepe { - /** * \brief The ResourceManager is responsible for storing and managing assets over * multiple scenes. @@ -26,51 +24,24 @@ public: virtual ~ResourceManager(); // dbg_trace private: - template - Resource & get_internal(const Component & component, const Asset & asset); - - template - const Asset & get_source(const Component & component) const; - + struct CacheEntry { + std::unique_ptr resource = nullptr; + bool persistent = false; + }; //! A cache that holds all the assets, accessible by their file path, over multiple scenes. - std::unordered_map> resources; + std::unordered_map resources; + CacheEntry & get_entry(const Asset & asset); public: - /** - * \brief Caches an asset by loading it from the given file path. - * - * \param file_path The path to the asset file to load. - * \param reload If true, the asset will be reloaded from the file, even if - * it is already cached. - * \tparam T The type of asset to cache (e.g., texture, sound, etc.). - * - * \return A reference to the resource - * - * This template function caches the asset at the given file path. If the - * asset is already cached, the existing instance will be returned. - * Otherwise, the concrete resource will be instantiated and added to the - * cache. - */ - template - void cache(const Asset & asset, bool persistent = false); - - template - void cache(const Component & component, bool persistent = false); - - // void resman.cache(Asset, Lifetime); - // void resman.cache(Component, Asset, Lifetime); + void set_persistent(const Asset & asset, bool persistent); - template - Resource & get(const Component & component); + template + Resource & get(const Asset & asset); - //! Clear the resource cache void clear(); + void clear_all(); }; -class Sound; -class AudioSource; -template <> -Sound & ResourceManager::get(const AudioSource & component); - } // namespace crepe +#include "ResourceManager.hpp" -- cgit v1.2.3