farmlands/src/resources/ResourceManager.h

99 lines
1.7 KiB
C++

/*
* ResourceManager.h
*
* Created on: Nov 7, 2016
* Author: tibi
*/
#ifndef STORAGE_RESOURCEMANAGER_H_
#define STORAGE_RESOURCEMANAGER_H_
#include <model/Level.h>
#include <vector>
#include <map>
#include <memory>
#include <string>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
namespace farmlands {
// Forward declaration
struct GameState;
namespace resources {
struct LoadedResource
{
bool loaded;
union
{
struct
{
SDL_Surface* surface;
SDL_Texture* texture;
} texture;
model::Level* level;
};
};
class ResourceManager
{
public:
ResourceManager();
virtual ~ResourceManager();
void initialize(GameState* gameState);
// Loading routines
void loadMainMenu();
void loadGameAssets();
void loadLevel(int levelId);
TTF_Font* font(int id, int pointSize);
SDL_Texture* texture(int id);
model::Level* level(int id);
private:
/**
* Obtains the path of the resource in native format.
*/
std::string getPath(int resourceId);
/**
* Obtains the id of a resource based on its path.
* Returns: the resource id, or -1 if resource not found.
*/
int getId(std::string resourcePath);
/**
* Loads the cell data for a level tile layer.
*/
void loadLevelLayer(model::Level* level, size_t layerNumber, int resourceId);
/**
* Loads a texture into memory.
*/
void loadTexture(int textureId);
void loadFont(int fontId, int pointSize);
// State
GameState* m_gameState;
// Loaded resources
LoadedResource* m_loadedResources;
typedef int FontId;
std::map<FontId, TTF_Font*> m_fontCache;
};
} /* namespace resources */
} /* namespace farmlands */
#endif /* STORAGE_RESOURCEMANAGER_H_ */