Platformer
Platformer
ResourceManager.hpp
1 #ifndef RESOURCE_MANAGER_HPP
2 #define RESOURCE_MANAGER_HPP
3 
4 #include <memory>
5 #include <string>
6 #include <unordered_map>
7 
8 #include "SDLFontWrapper.hpp"
9 #include "SDLSoundWrapper.hpp"
10 #include "SDLTextureWrapper.hpp"
11 
17  public:
19  static ResourceManager& instance();
20 
23  void shutdown();
24 
30  std::shared_ptr<SDLTextureWrapper> LoadImage(
31  const std::string& path);
32 
38  std::shared_ptr<SDLFontWrapper> LoadFont(
39  const std::string& path,
41  int textSize);
42 
48  static std::shared_ptr<SDLSoundWrapper> LoadSound(
49  const std::string& path);
50 
52  ResourceManager(const ResourceManager& m) = delete;
53 
55  void operator=(const ResourceManager& m) = delete;
56 
57  private:
60 
63 
65  std::unordered_map<std::string, std::shared_ptr<SDLTextureWrapper>>
67 
69  std::unordered_map<std::string, std::shared_ptr<SDLFontWrapper>> loadedFonts;
70 
72  std::unordered_map<std::string, std::shared_ptr<SDLSoundWrapper>>
74 };
75 
76 #endif
static ResourceManager & instance()
The singleton instance of the ResourceManager.
Definition: ResourceManager.cpp:9
std::unordered_map< std::string, std::shared_ptr< SDLTextureWrapper > > loadedImages
Map of all currently loaded images.
Definition: ResourceManager.hpp:66
void operator=(const ResourceManager &m)=delete
Stop the compiler from generating methods to copy the object.
static std::shared_ptr< SDLSoundWrapper > LoadSound(const std::string &path)
Loads a sound from the given path Uses the stored sound if already loaded.
Definition: ResourceManager.cpp:67
~ResourceManager()
Constructs a ResourceManager.
Definition: ResourceManager.cpp:7
ResourceManager()
Constructs a ResourceManager.
Definition: ResourceManager.cpp:5
This class manages the resources of our game as a singleton.
Definition: ResourceManager.hpp:16
std::shared_ptr< SDLTextureWrapper > LoadImage(const std::string &path)
Loads an image from the given path Uses the stored image if already loaded.
Definition: ResourceManager.cpp:26
std::shared_ptr< SDLFontWrapper > LoadFont(const std::string &path, int textSize)
Loads a font from the given path in the given textSize Uses the stored font if already loaded...
Definition: ResourceManager.cpp:49
std::unordered_map< std::string, std::shared_ptr< SDLFontWrapper > > loadedFonts
Map of all currently loaded fonts.
Definition: ResourceManager.hpp:69
std::unordered_map< std::string, std::shared_ptr< SDLSoundWrapper > > loadedSounds
Map of all currently loaded sounds.
Definition: ResourceManager.hpp:73
void shutdown()
Shuts down the ResourceManager, removing all its references to loaded resources.
Definition: ResourceManager.cpp:14