Argentum Online - Cliente
resource_manager.h
1 #ifndef __RESOURCE_MANAGER_H
2 #define __RESOURCE_MANAGER_H
3 #include <unordered_map>
4 
5 #include "SDL/sdl_animated_sprite.h"
6 #include "SDL/sdl_music.h"
7 #include "SDL/sdl_sfx.h"
8 #include "SDL/sdl_texture.h"
9 #include "SDL/sdl_texture_loader.h"
10 #include "SDL/sdl_bitmap_font.h"
11 #include "SDL2/SDL_ttf.h"
12 #include "animation_pack.h"
13 
14 /* ----- Tipos y forward declarations ----- */
15 typedef std::unordered_map<std::string, std::unordered_map<int, SDLTexture>>
16  TextureMap;
17 
18 typedef std::unordered_map<std::string, std::unordered_map<int, AnimationPack>>
19  AnimationPackMap;
20 
21 typedef std::unordered_map<std::string, std::unordered_map<int, SDLSprite>>
22  SpriteMap;
23 
24 typedef std::unordered_map<int, TTF_Font*> FontMap;
25 
26 typedef std::unordered_map<int, SDLMusic> MusicMap;
27 
28 typedef std::unordered_map<int, SDLSoundFx> SoundFxMap;
29 
30 typedef std::unordered_map<int, SDLBitmapFont> BitmapFontMap;
36  private:
37  TextureMap texture_map;
38  AnimationPackMap animation_pack_map;
39  SpriteMap sprite_map;
40  FontMap font_map;
41  BitmapFontMap bitmap_font_map;
42  MusicMap music_map;
43  SoundFxMap sound_fx_map;
45 
53  void _load_textures(SDLTextureLoader& loader,
54  const std::string& texture_index_file);
55 
62  void _load_animations(const std::string& sprite_index_file);
63 
70  void _load_fonts(const std::string& font_index_file);
71 
78  void _load_audio(const std::string& audio_index_file);
79 
80  public:
81  ~ResourceManager();
82 
88  static ResourceManager& get_instance();
89  ResourceManager(const ResourceManager& other) = delete;
90  ResourceManager& operator=(const ResourceManager& other) = delete;
91 
99  SDLTexture& get_texture(const std::string& type, int id);
100 
108  AnimationPack& get_animation_pack(const std::string& type, int id);
109 
117  SDLSprite& get_sprite(const std::string& type, int id);
118 
125  TTF_Font* get_font(int id);
126 
127  SDLBitmapFont& get_bitmap_font(int id);
128 
135  SDLMusic& get_music(int id);
136 
143  SDLSoundFx& get_sound_fx(int id);
144 
149  void free_resources();
150 
157  void init(SDLTextureLoader& loader);
158 
159 
160 };
161 
162 #endif
ResourceManager::get_animation_pack
AnimationPack & get_animation_pack(const std::string &type, int id)
Devuelve un pack de animacion.
Definition: resource_manager.cpp:193
SDLBitmapFont
Fuente bitmap.
Definition: sdl_bitmap_font.h:9
ResourceManager::free_resources
void free_resources()
Libera recursos alocados por el manager.
Definition: resource_manager.cpp:232
AnimationPack
Wrapper de sprites de un mismo conjunto.
Definition: animation_pack.h:17
SDLSoundFx
Objeto de efecto de sonido de SDL.
Definition: sdl_sfx.h:13
ResourceManager::init
void init(SDLTextureLoader &loader)
Realiza la carga a memoria de todos los assets. Solo debe ser llamado una vez.
Definition: resource_manager.cpp:169
SDLMusic
Objeto musical de SDL.
Definition: sdl_music.h:13
ResourceManager
Singleton para el manager de texturas.
Definition: resource_manager.h:35
ResourceManager::get_music
SDLMusic & get_music(int id)
Devuelve un objeto SDLMusic.
Definition: resource_manager.cpp:238
SDLTexture
Objeto de textura de SDL.
Definition: sdl_texture.h:13
ResourceManager::get_sound_fx
SDLSoundFx & get_sound_fx(int id)
Devuelve un objeto SDLSoundFx.
Definition: resource_manager.cpp:245
ResourceManager::get_instance
static ResourceManager & get_instance()
Devuelve la instancia del resource manager.
Definition: resource_manager.cpp:176
ResourceManager::get_texture
SDLTexture & get_texture(const std::string &type, int id)
Obtiene una textura.
Definition: resource_manager.cpp:181
SDLSprite
Sprite animada de SDL.
Definition: sdl_animated_sprite.h:14
ResourceManager::get_sprite
SDLSprite & get_sprite(const std::string &type, int id)
Devuelve un sprite.
Definition: resource_manager.cpp:206
ResourceManager::get_font
TTF_Font * get_font(int id)
Devuelve una fuente de SDL.
Definition: resource_manager.cpp:218
SDLTextureLoader
Cargador de texturas de SDL.
Definition: sdl_texture_loader.h:11