1 #include "nta/ResourceManager.h"
2 #include "nta/Logger.h"
6 std::map<std::pair<std::string, int>, TTF_Font*> ResourceManager::m_fontMap;
17 std::pair<std::string, int> key = std::make_pair(fontPath, fontSize);
18 if (m_fontMap.find(key) == m_fontMap.end()) {
20 auto font = TTF_OpenFont(fontPath.c_str(), fontSize);
22 auto err_str =
"SDL_TTF failed to load font \"" + fontPath +
23 "\" with error: " + TTF_GetError();
28 m_fontMap[key] = font;
32 void ResourceManager::destroy() {
37 delete[] pair.second.data;
40 for (
auto& pair : m_fontMap) {
42 TTF_CloseFont(pair.second);
static std::map< std::string, RawTexture > m_textureMap
a map for associating a texture with the name of its file
static Result< GLTexture > readImage(crstring filePath, GLint minFilt, GLint magFilt, crvec2 dimensions)
loads in any image file
static void writeToLog(crstring entry)
writes an entry in the log
static Result< RawTexture > getTexture(crstring imagePath, crvec2 dimensions)
returns the resource with the given path, loading it if need be
static void unindent(size_t tab_size=TAB_SIZE)
unindents entries
bool is_ok() const
Is this normal data.
static Result new_err(const Error &err)
static Result new_ok(const T &data)
T get_data() const
Get the data (only use if is_ok() returns true)
static Error writeErrorToLog(crstring error, ErrorType type=OTHER)
writes entry in log and then notifies ErrorManager
static void indent(size_t tab_size=TAB_SIZE)
indents entries