aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager/ResourceManager.cpp
blob: 5713183b7b47906a1f17286e3fae9087f67a3e5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "util/dbg.h"

#include "ResourceManager.h"

using namespace crepe;
using namespace std;

ResourceManager::ResourceManager(Mediator & mediator) : Manager(mediator) {
	dbg_trace();
	mediator.resource_manager = *this;
}
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(); }

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);
}