farmlands/src/resources/ResourceManager.h

89 lines
1.5 KiB
C++

/*
* ResourceManager.h
*
* Created on: Nov 7, 2016
* Author: tibi
*/
#ifndef STORAGE_RESOURCEMANAGER_H_
#define STORAGE_RESOURCEMANAGER_H_
#include <components/basic/Sprite.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;
};
};
typedef uint32_t ResourceId;
class ResourceManager
{
public:
static ResourceManager& instance();
~ResourceManager();
// Loading routines
void initialize();
void loadMainMenu();
void loadGame();
// Getters
/**
* Obtains the path of the resource in native format.
*/
std::string getPath(ResourceId resourceId);
/**
* Obtains the id of a resource based on its path.
* Returns: the resource id, or -1 if resource not found.
*/
ResourceId getId(std::string resourcePath);
// Resource getters
TTF_Font* font(ResourceId id, int pointSize);
SDL_Texture* texture(ResourceId id);
private:
ResourceManager();
typedef int FontId;
// Instance
static ResourceManager s_instance;
// Loaded resources
LoadedResource* m_loadedResources;
std::map<FontId, TTF_Font*> m_fontCache;
};
} /* namespace resources */
} /* namespace farmlands */
#endif /* STORAGE_RESOURCEMANAGER_H_ */