aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager/ResourceManager.cpp
blob: a141a46afc535cb899dff7fda047d4230e044291 (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/Log.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);
}