Implemented resource manager which can load textures and levels.

Implemented script to generate Resources.g.h file linking assets to code.
Added assets from old project.
This commit is contained in:
2016-11-12 14:17:00 +02:00
parent 294fd6e2ac
commit 914ae0de0d
74 changed files with 14937 additions and 304 deletions

View File

@ -0,0 +1,78 @@
/*
* ResourceManager.cpp
*
* Created on: Nov 7, 2016
* Author: tibi
*/
#include <resources/ResourceManager.h>
#include <resources/Resources.h>
#include <boost/filesystem.hpp>
#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 */