aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/ResourceManager.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-28 18:18:13 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-28 18:18:13 +0100
commit0e45d4835f65ff9127a16adcbe9a9f0a20370cfc (patch)
treedc67a18640c8b65c575e97d161059944f0b1757a /src/crepe/ResourceManager.cpp
parenta685e5f743786cc6499e7ce8973bb78a83d101f7 (diff)
implement resource manager
Diffstat (limited to 'src/crepe/ResourceManager.cpp')
-rw-r--r--src/crepe/ResourceManager.cpp37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/crepe/ResourceManager.cpp b/src/crepe/ResourceManager.cpp
index 111b9e0..8b1fbf5 100644
--- a/src/crepe/ResourceManager.cpp
+++ b/src/crepe/ResourceManager.cpp
@@ -1,5 +1,3 @@
-#include <stdexcept>
-
#include "util/Log.h"
#include "ResourceManager.h"
@@ -11,26 +9,23 @@ ResourceManager::~ResourceManager() { dbg_trace(); }
ResourceManager::ResourceManager() { dbg_trace(); }
void ResourceManager::clear() {
+ std::erase_if(this->resources, [](const pair<const Asset, CacheEntry> & pair) {
+ const CacheEntry & entry = pair.second;
+ return entry.persistent == false;
+ });
+}
+
+void ResourceManager::clear_all() {
this->resources.clear();
}
-// template <typename T>
-// T & ResourceManager::cache(const Asset & asset) {
-// dbg_trace();
-// static_assert(is_base_of<Resource, T>::value, "cache must recieve a derivative class of Resource");
-//
-// if (!this->resources.contains(asset))
-// this->resources[asset] = make_unique<T>(asset);
-//
-// Resource * resource = this->resources.at(asset).get();
-// T * concrete_resource = dynamic_cast<T *>(resource);
-//
-// if (concrete_resource == nullptr)
-// throw runtime_error(format("ResourceManager: mismatch between requested type and actual type of resource ({})", asset.get_path()));
-//
-// return *concrete_resource;
-// }
-//
-// #include "facade/Sound.h"
-// template Sound & ResourceManager::cache(const Asset &);
+void ResourceManager::set_persistent(const Asset & asset, bool persistent) {
+ this->get_entry(asset).persistent = persistent;
+}
+
+ResourceManager::CacheEntry & ResourceManager::get_entry(const Asset & asset) {
+ if (!this->resources.contains(asset))
+ this->resources[asset] = {};
+ return this->resources.at(asset);
+}