/* * ResourceManager.cpp * * Created on: Nov 7, 2016 * Author: tibi */ #include #include #include #define FONTID(id,size) (id * 1000 + size) #define FONTID_SIZE(fontid) (fontid % 1000) #define FONTID_ID(fontid) (fontid / 1000) namespace farmlands { namespace resources { ResourceManager::ResourceManager() : m_renderer(nullptr), m_loadedLevel(nullptr), m_loadedResources(new LoadedResource[sizeof(RInfo) / sizeof(RInfo[0])]) { } ResourceManager::~ResourceManager() { delete[] m_loadedResources; } void ResourceManager::initialize(SDL_Renderer* renderer) { m_renderer = renderer; } void ResourceManager::loadMainMenu() { } TTF_Font* ResourceManager::font(int id, int pointSize) { // Open from cache auto it = m_fontCache.find(FONTID(id, pointSize)); if (it != m_fontCache.end()) return it->second; // Open font TTF_Font* font = TTF_OpenFont(RInfo[id].path, pointSize); m_fontCache.emplace(FONTID(id, pointSize), font); return font; } std::string ResourceManager::getPath(int resourceId) { boost::filesystem::path resPath(ASSETS_DIR); resPath.append(RInfo[resourceId].path); return resPath.native(); } int ResourceManager::getId(std::string resPathStr) { boost::filesystem::path resPath(resPathStr); for(size_t i = 0; i < sizeof(RInfo) / sizeof(RInfo[0]); i++) { boost::filesystem::path iPath (RInfo[i].path); if (resPath == iPath) return (int)i; } return -1; } } /* namespace storage */ } /* namespace farmlands */