Precàrrega de tots els recursos al inici del joc
8.000.000 de cherrypickings que he anat fent pel codi
This commit is contained in:
@@ -2,21 +2,66 @@
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "jail_audio.h"
|
||||
#include "texture.h"
|
||||
#include "text.h"
|
||||
#include "animated_sprite.h"
|
||||
|
||||
// Estructura para almacenar ficheros de sonido y su nombre
|
||||
struct ResourceSound
|
||||
{
|
||||
std::string name; // Nombre del sonido
|
||||
JA_Sound_t *sound; // Fichero con el sonido
|
||||
JA_Sound_t *sound; // Objeto con el sonido
|
||||
|
||||
// Constructor
|
||||
ResourceSound(const std::string &name, JA_Sound_t *sound)
|
||||
: name(name), sound(sound) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros musicales y su nombre
|
||||
struct ResourceMusic
|
||||
{
|
||||
std::string name; // Nombre de la musica
|
||||
JA_Music_t *music; // Fichero con la música
|
||||
JA_Music_t *music; // Objeto con la música
|
||||
|
||||
// Constructor
|
||||
ResourceMusic(const std::string &name, JA_Music_t *music)
|
||||
: name(name), music(music) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar objetos Texture y su nombre
|
||||
struct ResourceTexture
|
||||
{
|
||||
std::string name; // Nombre de la textura
|
||||
std::shared_ptr<Texture> texture; // Objeto con la textura
|
||||
|
||||
// Constructor
|
||||
ResourceTexture(const std::string &name, std::shared_ptr<Texture> texture)
|
||||
: name(name), texture(texture) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros TextFile y su nombre
|
||||
struct ResourceTextFile
|
||||
{
|
||||
std::string name; // Nombre del fichero
|
||||
std::shared_ptr<TextFile> text_file; // Objeto con los descriptores de la fuente de texto
|
||||
|
||||
// Constructor
|
||||
ResourceTextFile(const std::string &name, std::shared_ptr<TextFile> text_file)
|
||||
: name(name), text_file(text_file) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros animaciones y su nombre
|
||||
struct ResourceAnimation
|
||||
{
|
||||
std::string name; // Nombre del fichero
|
||||
Animations animation; // Objeto con las animaciones
|
||||
|
||||
// Constructor
|
||||
ResourceAnimation(const std::string &name, Animations animation)
|
||||
: name(name), animation(animation) {}
|
||||
};
|
||||
|
||||
class Resource
|
||||
@@ -25,15 +70,27 @@ private:
|
||||
// [SINGLETON] Objeto resource privado para Don Melitón
|
||||
static Resource *resource_;
|
||||
|
||||
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
||||
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
||||
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
||||
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
||||
std::vector<ResourceTexture> textures_; // Vector con las musicas
|
||||
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
||||
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
||||
|
||||
// Carga los sonidos del juego
|
||||
// Carga los sonidos
|
||||
void loadSounds();
|
||||
|
||||
// Carga las musicas del juego
|
||||
// Carga las musicas
|
||||
void loadMusics();
|
||||
|
||||
// Carga las texturas
|
||||
void loadTextures();
|
||||
|
||||
// Carga los ficheros de texto
|
||||
void loadTextFiles();
|
||||
|
||||
// Carga las animaciones
|
||||
void loadAnimations();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||
|
||||
// Constructor
|
||||
@@ -52,9 +109,18 @@ public:
|
||||
// [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él
|
||||
static Resource *get();
|
||||
|
||||
// Obtiene el fichero de sonido a partir de un nombre
|
||||
// Obtiene el sonido a partir de un nombre
|
||||
JA_Sound_t *getSound(const std::string &name);
|
||||
|
||||
// Obtiene el fichero de música a partir de un nombre
|
||||
// Obtiene la música a partir de un nombre
|
||||
JA_Music_t *getMusic(const std::string &name);
|
||||
|
||||
// Obtiene la textura a partir de un nombre
|
||||
std::shared_ptr<Texture> getTexture(const std::string &name);
|
||||
|
||||
// Obtiene el fichero de texto a partir de un nombre
|
||||
std::shared_ptr<TextFile> getTextFile(const std::string &name);
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
Animations &getAnimation(const std::string &name);
|
||||
};
|
||||
Reference in New Issue
Block a user