Asset Manager
Centralized asset store with automatic caching and deduplication.
Header: #include <asw/modules/asset_manager.h>Namespace: asw
Overview
The AssetManager class 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 as needed.
asw::AssetManager assets;Textures
getTexture
Texture getTexture(const std::string& path);Get a texture by path. Loads and caches on first access.
hasTexture
bool hasTexture(const std::string& path) const;Check if a texture is already cached.
unloadTexture
void unloadTexture(const std::string& path);Remove a texture from the cache.
Fonts
getFont
Font getFont(const std::string& path, float size);Get a font by path and size. Loads and caches on first access. Fonts are keyed by path:size, so the same font file at different sizes is cached separately.
hasFont
bool hasFont(const std::string& path, float size) const;Check if a font is already cached.
unloadFont
void unloadFont(const std::string& path, float size);Remove a font from the cache.
Samples
getSample
Sample getSample(const std::string& path);Get a sound sample by path. Loads and caches on first access.
hasSample
bool hasSample(const std::string& path) const;Check if a sample is already cached.
unloadSample
void unloadSample(const std::string& path);Remove a sample from the cache.
Music
getMusic
Music getMusic(const std::string& path);Get music by path. Loads and caches on first access.
hasMusic
bool hasMusic(const std::string& path) const;Check if music is already cached.
unloadMusic
void unloadMusic(const std::string& path);Remove music from the cache.
Management
clear
void clear();Clear all cached assets.
Cache Counts
size_t getTextureCount() const;
size_t getFontCount() const;
size_t getSampleCount() const;
size_t getMusicCount() const;
size_t getTotalCount() const;Get the number of cached assets by type or total.
Example
asw::AssetManager assets;
// First call loads from disk, subsequent calls return cached
auto player = assets.getTexture("sprites/player.png");
auto playerAgain = assets.getTexture("sprites/player.png"); // cached
auto font = assets.getFont("fonts/main.ttf", 16.0f);
auto fontLarge = assets.getFont("fonts/main.ttf", 32.0f); // separate cache entry
// Unload when no longer needed
assets.unloadTexture("sprites/player.png");
// Or clear everything
assets.clear();