9#ifndef ASW_ASSET_MANAGER_H
10#define ASW_ASSET_MANAGER_H
13#include <unordered_map>
63 std::string key = path +
":" + std::to_string(size);
64 auto it =
fonts.find(key);
65 if (it !=
fonts.end()) {
79 bool hasFont(
const std::string& path,
float size)
const {
80 std::string key = path +
":" + std::to_string(size);
118 auto it =
music.find(path);
119 if (it !=
music.end()) {
150 fonts.erase(path +
":" + std::to_string(size));
208 std::unordered_map<std::string, Font>
fonts;
209 std::unordered_map<std::string, Sample>
samples;
210 std::unordered_map<std::string, Music>
music;
Asset routines for the ASW library.
Centralized asset manager with caching.
void unloadFont(const std::string &path, float size)
Unload a font from the cache.
void unloadMusic(const std::string &path)
Unload music from the cache.
size_t getMusicCount() const
Get the number of cached music tracks.
std::unordered_map< std::string, Sample > samples
size_t getFontCount() const
Get the number of cached fonts.
void unloadSample(const std::string &path)
Unload a sample from the cache.
bool hasMusic(const std::string &path) const
Check if music is cached.
Texture getTexture(const std::string &path)
Get a texture by path (loads and caches on first access).
std::unordered_map< std::string, Texture > textures
Music getMusic(const std::string &path)
Get music by path (loads and caches on first access).
Font getFont(const std::string &path, float size)
Get a font by path and size (loads and caches on first access).
bool hasSample(const std::string &path) const
Check if a sample is cached.
std::unordered_map< std::string, Font > fonts
size_t getSampleCount() const
Get the number of cached samples.
Sample getSample(const std::string &path)
Get a sample by path (loads and caches on first access).
bool hasTexture(const std::string &path) const
Check if a texture is cached.
void clear()
Clear all cached assets.
bool hasFont(const std::string &path, float size) const
Check if a font is cached.
std::unordered_map< std::string, Music > music
size_t getTotalCount() const
Get the total number of cached assets.
void unloadTexture(const std::string &path)
Unload a texture from the cache.
size_t getTextureCount() const
Get the number of cached textures.
asw::Sample loadSample(const std::string &filename)
Loads a sample from a file. Formats supported are WAV, AIFF, RIFF, OGG and VOC. This will abort if th...
asw::Font loadFont(const std::string &filename, float size)
Loads a TTF font from a file. This will abort if the file is not found.
asw::Music loadMusic(const std::string &filename)
Loads a music file from a file. Formats supported are WAV, AIFF, RIFF, OGG and VOC....
asw::Texture loadTexture(const std::string &filename)
Loads a texture from a file. Formats supported are PNG, ICO, CUR, BMP, GIF, JPG, LBM,...
std::shared_ptr< Mix_Chunk > Sample
Alias for a shared pointer to an Mix_Chunk.
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
std::shared_ptr< Mix_Music > Music
Alias for a shared pointer to an Mix_Music.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Types used throughout the ASW library.