4#include <SDL3_image/SDL_image.h>
5#include <SDL3_mixer/SDL_mixer.h>
6#include <SDL3_ttf/SDL_ttf.h>
8#include <unordered_map>
16std::unordered_map<std::string, asw::Texture>
textures;
17std::unordered_map<std::string, asw::Font>
fonts;
18std::unordered_map<std::string, asw::Sample>
samples;
19std::unordered_map<std::string, asw::Music>
music;
28 const char* base_path = SDL_GetBasePath();
29 if (base_path ==
nullptr) {
32 return std::string(base_path) + filename;
39 const auto full_path =
get_path(filename);
42 if (temp ==
nullptr) {
46 SDL_SetTextureScaleMode(temp, SDL_SCALEMODE_NEAREST);
47 SDL_SetTextureBlendMode(temp, SDL_BLENDMODE_BLEND);
52 return { temp, [](SDL_Texture* t) {
54 SDL_DestroyTexture(t);
92 = SDL_CreateTexture(r, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, w, h);
94 SDL_SetTextureScaleMode(txr, SDL_SCALEMODE_NEAREST);
95 SDL_SetTextureBlendMode(txr, SDL_BLENDMODE_BLEND);
97 return { txr, [](SDL_Texture* t) {
99 SDL_DestroyTexture(t);
108 const auto full_path =
get_path(filename);
109 TTF_Font* temp = TTF_OpenFont(full_path.c_str(), size);
111 if (temp ==
nullptr) {
117 return { temp, [](TTF_Font* f) {
126 if (
auto it =
fonts.find(key); it !=
fonts.end()) {
131 fonts.try_emplace(key, font);
137 auto it =
fonts.find(key);
138 if (it ==
fonts.end()) {
153 const auto full_path =
get_path(filename);
156 if (temp ==
nullptr) {
160 return { temp, [](MIX_Audio* a) {
174 samples.try_emplace(key, sample);
196 const auto full_path =
get_path(filename);
199 if (temp ==
nullptr) {
203 return { temp, [](MIX_Audio* a) {
212 if (
auto it =
music.find(key); it !=
music.end()) {
217 music.try_emplace(key, mus);
223 auto it =
music.find(key);
224 if (it ==
music.end()) {
Asset routines for the ASW library.
Display and window routines for the ASW library.
std::unordered_map< std::string, asw::Music > music
std::unordered_map< std::string, asw::Sample > samples
std::unordered_map< std::string, asw::Texture > textures
std::unordered_map< std::string, asw::Font > fonts
asw::Sample get_sample(const std::string &key)
Get a cached sample.
asw::Texture create_texture(int w, int h)
Create a Texture given the specified dimensions.
void unload_music(const std::string &key)
Remove a cached music.
std::string get_path(const std::string &filename)
Get the full path to an asset given its filename. This assumes that all assets are located in an "ass...
asw::Texture get_texture(const std::string &key)
Get a cached texture.
void unload_sample(const std::string &key)
Remove a cached sample.
void unload_font(const std::string &key)
Remove a cached font.
asw::Music load_music(const std::string &filename)
Loads a music file from a file. Formats supported are WAV, AIFF, RIFF, OGG and VOC....
void clear_all()
Clear all cached assets. This will remove all cached textures, fonts, samples, and music.
void unload_texture(const std::string &key)
Remove a cached texture.
asw::Music get_music(const std::string &key)
Get a cached music.
asw::Font load_font(const std::string &filename, float size)
Loads a TTF font from a file. This will abort if the file is not found.
asw::Sample load_sample(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 get_font(const std::string &key)
Get a cached font.
asw::Texture load_texture(const std::string &filename)
Loads a texture from a file. Formats supported are PNG, ICO, CUR, BMP, GIF, JPG, LBM,...
asw::Renderer * get_renderer()
Get the SDL renderer.
MIX_Mixer * get_mixer()
Get the SDL mixer device.
void abort_on_error(const std::string &message)
Abort program and display error message.
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
std::shared_ptr< MIX_Audio > Sample
Alias for a shared pointer to an MIX_Audio.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
std::shared_ptr< MIX_Audio > Music
Alias for a shared pointer to an MIX_Audio.
Sound module for the ASW library.
Types used throughout the ASW library.
General utility functions.