1 #ifndef RESOURCE_MANAGER_HPP
2 #define RESOURCE_MANAGER_HPP
4 #include <SDL2/SDL_ttf.h>
5 #include <SDL2/SDL_image.h>
25 SDL_Log(
"Sprite being freed");
47 SDL_Texture*
get()
const
49 return mTexture.get();
53 std::shared_ptr<SDL_Texture> mTexture;
56 template <
typename Derived,
class T>
89 std::shared_ptr<T>
GetResource(
const std::string &resourceName)
91 auto res = Find(resourceName);
104 std::shared_ptr<T>
Load(
const std::string &path)
106 return static_cast<Derived *
>(
this)->
Load(path);
117 auto res = Find(resourceName);
125 auto filePath =
fileMap.find(resourceName);
129 std::shared_ptr<T> resource =
Load(filePath->second);
134 resourceMap.emplace(resourceName, std::make_pair(resource, 1));
144 for (
auto const &[key, val] :
fileMap)
146 printf(
"loading resource: %s, %s\n", key.c_str(), val.c_str());
155 std::map<std::string, std::pair<std::shared_ptr<T>,
int>>
resourceMap;
163 std::pair<std::shared_ptr<T>,
int> *Find(
const std::string &resourceName)
void operator=(ResourceManager const &)
Allow subclasses to assign to a resource manager, but subclasses must ensure singleton functionality...
bool AddAllResource()
Definition: ResourceManager.hpp:142
bool AddResource(const std::string &resourceName)
Definition: ResourceManager.hpp:115
std::shared_ptr< T > Load(const std::string &path)
Definition: ResourceManager.hpp:104
std::shared_ptr< T > GetResource(const std::string &resourceName)
Definition: ResourceManager.hpp:89
std::map< std::string, std::string > fileMap
stores location of resources
Definition: ResourceManager.hpp:156
std::map< std::string, std::pair< std::shared_ptr< T >, int > > resourceMap
Internal resource mapping inherited by manager implementations.
Definition: ResourceManager.hpp:155
int shutDown()
Definition: ResourceManager.hpp:69
Definition: ResourceManager.hpp:62
SDL_Texture * get() const
Definition: ResourceManager.hpp:47
TextureWrapper(const std::shared_ptr< SDL_Texture > &texture)
Definition: ResourceManager.hpp:39
Definition: ResourceManager.hpp:32
~Sprite()
Definition: ResourceManager.hpp:23
std::shared_ptr< SDL_Texture > texture
the full texture of the sprite bitmap.
Definition: ResourceManager.hpp:18
ResourceManager()
Definition: ResourceManager.hpp:158
std::shared_ptr< SDL_Surface > spriteSheet
the spritesheet to create the texture from.
Definition: ResourceManager.hpp:17
Definition: ResourceManager.hpp:15