aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-12 21:21:16 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-12 21:21:16 +0100
commit2eaebb2a79ef71589a0be89cfe419f874fbadd09 (patch)
treecc7645dc927331d7728b4e81e88bf7aae06f0564 /src/crepe
parent24818173c970829553d75787ed6a60e6c95e16c6 (diff)
removed asset manager
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/AssetManager.h62
-rw-r--r--src/crepe/facade/SDLFontContext.cpp18
2 files changed, 9 insertions, 71 deletions
diff --git a/src/crepe/api/AssetManager.h b/src/crepe/api/AssetManager.h
deleted file mode 100644
index 3b1cc4b..0000000
--- a/src/crepe/api/AssetManager.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#pragma once
-
-#include <any>
-#include <memory>
-#include <string>
-#include <unordered_map>
-
-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:
- AssetManager();
- virtual ~AssetManager();
-
-public:
- AssetManager(const AssetManager &) = delete;
- AssetManager(AssetManager &&) = delete;
- AssetManager & operator=(const AssetManager &) = delete;
- 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 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 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 T>
- std::shared_ptr<T> cache(const std::string & file_path, bool reload = false);
-};
-
-} // namespace crepe
-
-#include "AssetManager.hpp"
diff --git a/src/crepe/facade/SDLFontContext.cpp b/src/crepe/facade/SDLFontContext.cpp
index d7a0bff..e7f04cc 100644
--- a/src/crepe/facade/SDLFontContext.cpp
+++ b/src/crepe/facade/SDLFontContext.cpp
@@ -8,26 +8,26 @@ using namespace std;
SDLFontContext::SDLFontContext(){
if (!FcInit()) {
- throw std::runtime_error("Failed to initialize Fontconfig.");
+ throw runtime_error("Failed to initialize Fontconfig.");
}
}
SDLFontContext::~SDLFontContext(){
FcFini();
}
-unique_ptr<Asset> SDLFontContext::get_font_asset(const std::string & font_family) {
+unique_ptr<Asset> SDLFontContext::get_font_asset(const string & font_family) {
// Create a pattern to search for the font family
FcPattern* pattern = FcNameParse(reinterpret_cast<const FcChar8*>(font_family.c_str()));
if (!pattern) {
- throw std::runtime_error("Failed to create font pattern.");
+ throw runtime_error("Failed to create font pattern.");
}
// Default configuration
FcConfig* config = FcConfigGetCurrent();
if (!config) {
FcPatternDestroy(pattern);
- throw std::runtime_error("Failed to get current Fontconfig configuration.");
+ throw runtime_error("Failed to get current Fontconfig configuration.");
}
// Match the font pattern
@@ -36,18 +36,18 @@ unique_ptr<Asset> SDLFontContext::get_font_asset(const std::string & font_family
FcPatternDestroy(pattern);
if (!matched_pattern) {
- throw std::runtime_error("No matching font found.");
+ throw runtime_error("No matching font found.");
}
// Extract the file path
FcChar8* file_path = nullptr;
if (FcPatternGetString(matched_pattern, FC_FILE, 0, &file_path) != FcResultMatch || !file_path) {
FcPatternDestroy(matched_pattern);
- throw std::runtime_error("Failed to get font file path.");
+ throw runtime_error("Failed to get font file path.");
}
- // Convert the file path to a std::string
- std::string font_file_path(reinterpret_cast<const char*>(file_path));
+ // Convert the file path to a string
+ string font_file_path(reinterpret_cast<const char*>(file_path));
FcPatternDestroy(matched_pattern);
- return std::move(make_unique<Asset>(font_file_path));
+ return move(make_unique<Asset>(font_file_path));
}