Afegint smart pointers

Actualitzat Resources
Actualitzades les classes Sprite i derivades
Afegida nova tipografia
Actualitzat Asset
Actualitzat Text
This commit is contained in:
2025-02-24 14:09:29 +01:00
parent 48971cd5d1
commit e6f101ece6
42 changed files with 2669 additions and 3158 deletions

View File

@@ -1,141 +1,197 @@
#pragma once
#include <SDL2/SDL_render.h> // Para SDL_Renderer
#include <string> // Para string, basic_string
#include <vector> // Para vector
class Asset;
class Texture;
struct animatedSprite_t;
struct Options;
struct room_t;
struct textFile_t;
#include <memory> // Para shared_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "animated_sprite.h" // Para AnimationsFileBuffer
#include "text.h" // Para TextFile
#include "texture.h" // Para Texture
#include "utils.h" // Para DemoData
#include "room.h"
struct JA_Music_t;
struct JA_Sound_t;
struct res_texture_t
// Estructura para almacenar ficheros de sonido y su nombre
struct ResourceSound
{
std::string name; // Nombre de la textura
Texture *texture; // La textura
std::string name; // Nombre del sonido
JA_Sound_t *sound; // Objeto con el sonido
// Constructor
ResourceSound(const std::string &name, JA_Sound_t *sound)
: name(name), sound(sound) {}
};
struct res_animation_t
// Estructura para almacenar ficheros musicales y su nombre
struct ResourceMusic
{
std::string name; // Nombre de la textura
animatedSprite_t *animation; // La animación
std::string name; // Nombre de la musica
JA_Music_t *music; // Objeto con la música
// Constructor
ResourceMusic(const std::string &name, JA_Music_t *music)
: name(name), music(music) {}
};
struct res_textOffset_t
// Estructura para almacenar objetos Texture y su nombre
struct ResourceTexture
{
std::string name; // Nombre del offset
textFile_t *textFile; // Los offsets de la fuente
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) {}
};
struct res_tileMap_t
// Estructura para almacenar ficheros TextFile y su nombre
struct ResourceTextFile
{
std::string name; // Nombre del mapa de tiles
std::vector<int> *tileMap; // Vector con los indices del mapa de tiles
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) {}
};
struct res_room_t
// Estructura para almacenar objetos Text y su nombre
struct ResourceText
{
std::string name; // Nombre de la habitación
room_t *room; // Vector con las habitaciones
std::string name; // Nombre del objeto
std::shared_ptr<Text> text; // Objeto
// Constructor
ResourceText(const std::string &name, std::shared_ptr<Text> text)
: name(name), text(text) {}
};
// Estructura para almacenar ficheros animaciones y su nombre
struct ResourceAnimation
{
std::string name; // Nombre del fichero
AnimationsFileBuffer animation; // Objeto con las animaciones
// Constructor
ResourceAnimation(const std::string &name, const AnimationsFileBuffer &animation)
: name(name), animation(animation) {}
};
// Estructura para almacenar ficheros con el mapa de tiles de una habitación y su nombre
struct ResourceTileMap
{
std::string name; // Nombre del mapa de tiles
std::vector<int> tileMap; // Vector con los indices del mapa de tiles
// Constructor
ResourceTileMap(const std::string &name, const std::vector<int> &tileMap)
: name(name), tileMap(tileMap) {}
};
// Estructura para almacenar habitaciones y su nombre
struct ResourceRoom
{
std::string name; // Nombre de la habitación
std::shared_ptr<room_t> room; // Habitación
// Constructor
ResourceRoom(const std::string &name, std::shared_ptr<room_t> room)
: name(name), room(room) {}
};
// Clase Resource. Almacena recursos de disco en memoria
class Resource
{
private:
// [SINGLETON] Objeto privado
static Resource *resource_;
// [SINGLETON] Objeto resource privado para Don Melitón
static Resource *resource_;
// Variables
std::vector<res_texture_t> textures_;
std::vector<res_animation_t> animations_;
std::vector<res_textOffset_t> offsets_;
std::vector<res_tileMap_t> tile_maps_;
std::vector<res_room_t> rooms_;
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<ResourceText> texts_; // Vector con los objetos de texto
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
std::vector<ResourceTileMap> tile_maps_; // Vector con los mapas de tiles
std::vector<ResourceRoom> rooms_; // Vector con las habitaciones
// Constructor
Resource() = default;
// Carga los sonidos
void loadSounds();
// Destructor
~Resource() = default;
// Carga las musicas
void loadMusics();
// Carga las texturas
void loadTextures();
// Carga los ficheros de texto
void loadTextFiles();
// Carga las animaciones
void loadAnimations();
// Carga los mapas de tiles
void loadTileMaps();
// Carga las habitaciones
void loadRooms();
// Crea los objetos de texto
void createText();
// Vacia todos los vectores de recursos
void clear();
// Carga todos los recursos
void load();
// Vacía el vector de sonidos
void clearSounds();
// Vacía el vector de musicas
void clearMusics();
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
// Constructor
Resource();
// Destructor
~Resource() = default;
public:
// [SINGLETON] Crearemos el objeto con esta función estática
static void init();
// [SINGLETON] Crearemos el objeto resource con esta función estática
static void init();
// [SINGLETON] Destruiremos el objeto con esta función estática
static void destroy();
// [SINGLETON] Destruiremos el objeto resource con esta función estática
static void destroy();
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
static Resource *get();
// [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él
static Resource *get();
// Carga las texturas de una lista
void loadTextures(std::vector<std::string> list);
// Obtiene el sonido a partir de un nombre
JA_Sound_t *getSound(const std::string &name);
// Vuelve a cargar las texturas
void reLoadTextures();
// Obtiene la música a partir de un nombre
JA_Music_t *getMusic(const std::string &name);
// Carga las animaciones desde una lista
void loadAnimations(std::vector<std::string> list);
// Obtiene la textura a partir de un nombre
std::shared_ptr<Texture> getTexture(const std::string &name);
// Vuelve a cargar las animaciones
void reLoadAnimations();
// Obtiene el fichero de texto a partir de un nombre
std::shared_ptr<TextFile> getTextFile(const std::string &name);
// Carga los offsets desde una lista
void loadOffsets(std::vector<std::string> list);
// Obtiene el objeto de texto a partir de un nombre
std::shared_ptr<Text> getText(const std::string &name);
// Vuelve a cargar los offsets
void reLoadOffsets();
// Obtiene la animación a partir de un nombre
AnimationsFileBuffer &getAnimation(const std::string &name);
// Carga los mapas de tiles desde una lista
void loadTileMaps(std::vector<std::string> list);
// Obtiene el mapa de tiles a partir de un nombre
std::vector<int> &getTileMap(const std::string &name);
// Vuelve a cargar los mapas de tiles
void reLoadTileMaps();
// Obtiene la habitación a partir de un nombre
std::shared_ptr<room_t> getRoom(const std::string &name);
// Carga las habitaciones desde una lista
void loadRooms(std::vector<std::string> list);
// Vuelve a cargar las habitaciones
void reLoadRooms();
// Vuelve a cargar todos los recursos
void reLoad();
// Libera las texturas
void freeTextures();
// Libera las animaciones
void freeAnimations();
// Libera los offsets
void freeOffsets();
// Libera los mapas de tiles
void freeTileMaps();
// Libera las habitaciones
void freeRooms();
// Libera todos los recursos
void free();
// Obtiene una textura
Texture *getTexture(std::string name);
// Obtiene una animación
animatedSprite_t *getAnimation(std::string name);
// Obtiene un offset
textFile_t *getOffset(std::string name);
// Obtiene un mapa de tiles
std::vector<int> *getTileMap(std::string name);
// Obtiene una habitacion
room_t *getRoom(std::string name);
// Obtiene todas las habitaciones
std::vector<res_room_t> *getAllRooms();
// Recarga todos los recursos
void reload();
};