aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-12 15:11:27 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-12 15:11:27 +0100
commit3c9b331668189e9c1a35d3d6ac6ded601f725e78 (patch)
treeadffea3a1d9424b22f45a722c0faf619f0ba7857
parent59c7588c6162a0be7dac13610e0b854f70b6d8b9 (diff)
assetmanager
-rw-r--r--src/crepe/api/AssetManager.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/crepe/api/AssetManager.h b/src/crepe/api/AssetManager.h
index fefbed9..68235c3 100644
--- a/src/crepe/api/AssetManager.h
+++ b/src/crepe/api/AssetManager.h
@@ -7,24 +7,69 @@
namespace crepe {
+
+/**
+ * \brief The AssetManager is responsible for storing and managing assets over multiple scenes.
+ *
+ * The AssetManager ensures that assets are loaded once and can be accessed across different scenes.
+ * It caches assets to avoid reloading them every time a scene is loaded. Assets are retained in memory
+ * until the AssetManager is destroyed, at which point the cached assets are cleared.
+ */
class AssetManager {
private:
+ //! A cache that holds all the assets, accessible by their file path, over multiple scenes.
std::unordered_map<std::string, std::any> asset_cache;
private:
+ /**
+ * \brief Private constructor for the AssetManager.
+ *
+ */
AssetManager();
+
+ /**
+ * \brief Private destructor for the AssetManager.
+ *
+ */
virtual ~AssetManager();
public:
+
+ //! Deleted copy constructor to prevent copying of the AssetManager instance.
AssetManager(const AssetManager &) = delete;
+
+ //! Deleted move constructor to prevent moving of the AssetManager instance.
AssetManager(AssetManager &&) = delete;
+
+ //! Deleted copy assignment operator to prevent copying the AssetManager instance.
AssetManager & operator=(const AssetManager &) = delete;
+
+ //! Deleted move assignment operator to prevent moving the AssetManager instance.
AssetManager & operator=(AssetManager &&) = delete;
+ /**
+ * \brief Retrieves the singleton instance of the AssetManager.
+ *
+ * \return A reference to the single instance of the AssetManager.
+ *
+ */
static AssetManager & get_instance();
public:
+ /**
+ * \brief Caches an asset by loading it from the given file path.
+ *
+ * \param[in] file_path The path to the asset file to load.
+ * \param[in] reload If true, the asset will be reloaded from the file, even if it is already cached.
+ * \tparam asset The type of asset to cache (e.g., texture, sound, etc.).
+ *
+ * \return A shared pointer to the cached asset.
+ *
+ * This template function caches the asset at the given file path. If the asset is already cached
+ * and `reload` is false, the existing cached version will be returned. Otherwise, the asset will
+ * be reloaded and added to the cache.
+ */
template <typename asset>
std::shared_ptr<asset> cache(const std::string & file_path,
bool reload = false);