The Table Engine
resourcemanager.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <unordered_map>
5 
6 #include <SDL2/SDL.h>
7 #include <SDL2/SDL_ttf.h>
8 
9 // #include "sound.h"
10 
27 {
28  private:
29  SDL_Renderer* m_renderer;
30  std::unordered_map<std::string, SDL_Texture*> m_imageResourceMap;
31  std::unordered_map<std::string, TTF_Font*> m_fontMap;
32 
37 
41  ResourceManager(const ResourceManager&) = delete;
42 
46  void operator=(const ResourceManager&) = delete;
47 
48  public:
54  static ResourceManager instance;
55  return instance;
56  }
57 
62  void setRenderer(SDL_Renderer* renderer);
63 
68  SDL_Renderer* getRenderer();
69 
75  SDL_Texture* loadTexture(std::string path);
76 
85  SDL_Texture* loadText(std::string font_path, std::string text, SDL_Color color, int font_size = 20);
86 
87  // Sound management methods can be added here in future.
88  // Example:
89  // /**
90  // * @brief Loads a sound file.
91  // * @param path Path to the sound file.
92  // * @return Pointer to the loaded Sound object.
93  // */
94  // Sound* loadSound(std::string path);
95 };
Singleton class for managing game resources like textures and fonts.
void setRenderer(SDL_Renderer *renderer)
Sets the renderer for resource management.
SDL_Renderer * m_renderer
Renderer used to render game objects.
SDL_Texture * loadText(std::string font_path, std::string text, SDL_Color color, int font_size=20)
Loads a text as a texture using a specified TTF font.
SDL_Renderer * getRenderer()
Gets the current renderer.
ResourceManager()
Private constructor for singleton pattern.
std::unordered_map< std::string, SDL_Texture * > m_imageResourceMap
Cache of texture resources.
SDL_Texture * loadTexture(std::string path)
Loads a texture from a specified file path.
void operator=(const ResourceManager &)=delete
Deleted assignment operator to prevent multiple instances.
static ResourceManager & getInstance()
Retrieves the singleton instance of ResourceManager.
ResourceManager(const ResourceManager &)=delete
Deleted copy constructor to prevent multiple instances.
std::unordered_map< std::string, TTF_Font * > m_fontMap
Cache of font resources.