The Table Engine
ResourceManager Class Reference

Singleton class for managing game resources like textures and fonts. More...

#include <resourcemanager.h>

+ Collaboration diagram for ResourceManager:

Public Member Functions

void setRenderer (SDL_Renderer *renderer)
 Sets the renderer for resource management. More...
 
SDL_Renderer * getRenderer ()
 Gets the current renderer. More...
 
SDL_Texture * loadTexture (std::string path)
 Loads a texture from a specified file path. More...
 
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. More...
 

Static Public Member Functions

static ResourceManagergetInstance ()
 Retrieves the singleton instance of ResourceManager. More...
 

Private Member Functions

 ResourceManager ()
 Private constructor for singleton pattern. More...
 
 ResourceManager (const ResourceManager &)=delete
 Deleted copy constructor to prevent multiple instances. More...
 
void operator= (const ResourceManager &)=delete
 Deleted assignment operator to prevent multiple instances. More...
 

Private Attributes

SDL_Renderer * m_renderer
 Renderer used to render game objects. More...
 
std::unordered_map< std::string, SDL_Texture * > m_imageResourceMap
 Cache of texture resources. More...
 
std::unordered_map< std::string, TTF_Font * > m_fontMap
 Cache of font resources. More...
 

Detailed Description

Singleton class for managing game resources like textures and fonts.

This class is responsible for loading, caching, and providing access to various game resources, including textures and fonts, to reduce I/O overhead during gameplay.

Definition at line 26 of file resourcemanager.h.

Constructor & Destructor Documentation

◆ ResourceManager() [1/2]

ResourceManager::ResourceManager ( )
private

Private constructor for singleton pattern.

Definition at line 36 of file resourcemanager.h.

◆ ResourceManager() [2/2]

ResourceManager::ResourceManager ( const ResourceManager )
privatedelete

Deleted copy constructor to prevent multiple instances.

Member Function Documentation

◆ getInstance()

static ResourceManager& ResourceManager::getInstance ( )
static

Retrieves the singleton instance of ResourceManager.

Returns
Reference to the singleton ResourceManager instance.

Definition at line 53 of file resourcemanager.h.

◆ getRenderer()

SDL_Renderer * ResourceManager::getRenderer ( )

Gets the current renderer.

Returns
Pointer to the SDL_Renderer used for resource management.

Definition at line 9 of file resourcemanager.cpp.

◆ loadText()

SDL_Texture * ResourceManager::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.

Parameters
font_pathPath to the font file.
textText string to render.
colorSDL_Color for the text.
font_sizeSize of the font to be used (default is 20).
Returns
Pointer to the SDL_Texture containing the rendered text.

Definition at line 42 of file resourcemanager.cpp.

◆ loadTexture()

SDL_Texture * ResourceManager::loadTexture ( std::string  path)

Loads a texture from a specified file path.

Parameters
pathPath to the image file.
Returns
Pointer to the loaded SDL_Texture.

Definition at line 20 of file resourcemanager.cpp.

◆ operator=()

void ResourceManager::operator= ( const ResourceManager )
privatedelete

Deleted assignment operator to prevent multiple instances.

◆ setRenderer()

void ResourceManager::setRenderer ( SDL_Renderer *  renderer)

Sets the renderer for resource management.

Parameters
rendererPointer to the SDL_Renderer to be used for rendering.

Definition at line 14 of file resourcemanager.cpp.

Member Data Documentation

◆ m_fontMap

std::unordered_map<std::string, TTF_Font*> ResourceManager::m_fontMap
private

Cache of font resources.

Definition at line 31 of file resourcemanager.h.

◆ m_imageResourceMap

std::unordered_map<std::string, SDL_Texture*> ResourceManager::m_imageResourceMap
private

Cache of texture resources.

Definition at line 30 of file resourcemanager.h.

◆ m_renderer

SDL_Renderer* ResourceManager::m_renderer
private

Renderer used to render game objects.

Definition at line 29 of file resourcemanager.h.


The documentation for this class was generated from the following files: