diff options
Diffstat (limited to 'src/crepe/ResourceManager.cpp')
-rw-r--r-- | src/crepe/ResourceManager.cpp | 37 |
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); +} |