ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::AssetManager Class Reference

Centralized asset manager with caching. More...

#include <asset_manager.h>

Public Member Functions

Texture getTexture (const std::string &path)
 Get a texture by path (loads and caches on first access).
 
bool hasTexture (const std::string &path) const
 Check if a texture is cached.
 
Font getFont (const std::string &path, float size)
 Get a font by path and size (loads and caches on first access).
 
bool hasFont (const std::string &path, float size) const
 Check if a font is cached.
 
Sample getSample (const std::string &path)
 Get a sample by path (loads and caches on first access).
 
bool hasSample (const std::string &path) const
 Check if a sample is cached.
 
Music getMusic (const std::string &path)
 Get music by path (loads and caches on first access).
 
bool hasMusic (const std::string &path) const
 Check if music is cached.
 
void unloadTexture (const std::string &path)
 Unload a texture from the cache.
 
void unloadFont (const std::string &path, float size)
 Unload a font from the cache.
 
void unloadSample (const std::string &path)
 Unload a sample from the cache.
 
void unloadMusic (const std::string &path)
 Unload music from the cache.
 
void clear ()
 Clear all cached assets.
 
size_t getTextureCount () const
 Get the number of cached textures.
 
size_t getFontCount () const
 Get the number of cached fonts.
 
size_t getSampleCount () const
 Get the number of cached samples.
 
size_t getMusicCount () const
 Get the number of cached music tracks.
 
size_t getTotalCount () const
 Get the total number of cached assets.
 

Private Attributes

std::unordered_map< std::string, Texturetextures
 
std::unordered_map< std::string, Fontfonts
 
std::unordered_map< std::string, Samplesamples
 
std::unordered_map< std::string, Musicmusic
 

Detailed Description

Centralized asset manager with caching.

Wraps the asw::assets loading functions with a cache layer. Loading the same asset path twice returns the same shared_ptr without hitting disk. Not a singleton — create one per scene or share globally.

Definition at line 26 of file asset_manager.h.

Member Function Documentation

◆ clear()

void asw::AssetManager::clear ( )
inline

Clear all cached assets.

Definition at line 167 of file asset_manager.h.

◆ getFont()

Font asw::AssetManager::getFont ( const std::string & path,
float size )
inline

Get a font by path and size (loads and caches on first access).

Parameters
pathThe path to the font file.
sizeThe font size.
Returns
The loaded font.

Definition at line 62 of file asset_manager.h.

◆ getFontCount()

size_t asw::AssetManager::getFontCount ( ) const
inline

Get the number of cached fonts.

Returns
The number of cached fonts.

Definition at line 184 of file asset_manager.h.

◆ getMusic()

Music asw::AssetManager::getMusic ( const std::string & path)
inline

Get music by path (loads and caches on first access).

Parameters
pathThe path to the music file.
Returns
The loaded music.

Definition at line 117 of file asset_manager.h.

◆ getMusicCount()

size_t asw::AssetManager::getMusicCount ( ) const
inline

Get the number of cached music tracks.

Returns
The number of cached music tracks.

Definition at line 196 of file asset_manager.h.

◆ getSample()

Sample asw::AssetManager::getSample ( const std::string & path)
inline

Get a sample by path (loads and caches on first access).

Parameters
pathThe path to the sample file.
Returns
The loaded sample.

Definition at line 91 of file asset_manager.h.

◆ getSampleCount()

size_t asw::AssetManager::getSampleCount ( ) const
inline

Get the number of cached samples.

Returns
The number of cached samples.

Definition at line 190 of file asset_manager.h.

◆ getTexture()

Texture asw::AssetManager::getTexture ( const std::string & path)
inline

Get a texture by path (loads and caches on first access).

Parameters
pathThe path to the texture file.
Returns
The loaded texture.

Definition at line 35 of file asset_manager.h.

◆ getTextureCount()

size_t asw::AssetManager::getTextureCount ( ) const
inline

Get the number of cached textures.

Returns
The number of cached textures.

Definition at line 178 of file asset_manager.h.

◆ getTotalCount()

size_t asw::AssetManager::getTotalCount ( ) const
inline

Get the total number of cached assets.

Returns
The total number of cached assets.

Definition at line 202 of file asset_manager.h.

◆ hasFont()

bool asw::AssetManager::hasFont ( const std::string & path,
float size ) const
inline

Check if a font is cached.

Parameters
pathThe path to the font file.
sizeThe font size.
Returns
True if the font is in the cache.

Definition at line 79 of file asset_manager.h.

◆ hasMusic()

bool asw::AssetManager::hasMusic ( const std::string & path) const
inline

Check if music is cached.

Parameters
pathThe path to the music file.
Returns
True if the music is in the cache.

Definition at line 132 of file asset_manager.h.

◆ hasSample()

bool asw::AssetManager::hasSample ( const std::string & path) const
inline

Check if a sample is cached.

Parameters
pathThe path to the sample file.
Returns
True if the sample is in the cache.

Definition at line 106 of file asset_manager.h.

◆ hasTexture()

bool asw::AssetManager::hasTexture ( const std::string & path) const
inline

Check if a texture is cached.

Parameters
pathThe path to the texture file.
Returns
True if the texture is in the cache.

Definition at line 50 of file asset_manager.h.

◆ unloadFont()

void asw::AssetManager::unloadFont ( const std::string & path,
float size )
inline

Unload a font from the cache.

Parameters
pathThe path to the font file.
sizeThe font size.

Definition at line 149 of file asset_manager.h.

◆ unloadMusic()

void asw::AssetManager::unloadMusic ( const std::string & path)
inline

Unload music from the cache.

Parameters
pathThe path to the music file.

Definition at line 163 of file asset_manager.h.

◆ unloadSample()

void asw::AssetManager::unloadSample ( const std::string & path)
inline

Unload a sample from the cache.

Parameters
pathThe path to the sample file.

Definition at line 157 of file asset_manager.h.

◆ unloadTexture()

void asw::AssetManager::unloadTexture ( const std::string & path)
inline

Unload a texture from the cache.

Parameters
pathThe path to the texture file.

Definition at line 142 of file asset_manager.h.

Member Data Documentation

◆ fonts

std::unordered_map<std::string, Font> asw::AssetManager::fonts
private

Definition at line 208 of file asset_manager.h.

◆ music

std::unordered_map<std::string, Music> asw::AssetManager::music
private

Definition at line 210 of file asset_manager.h.

◆ samples

std::unordered_map<std::string, Sample> asw::AssetManager::samples
private

Definition at line 209 of file asset_manager.h.

◆ textures

std::unordered_map<std::string, Texture> asw::AssetManager::textures
private

Definition at line 207 of file asset_manager.h.


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