jugant amb clang-tidy

This commit is contained in:
2025-07-19 22:25:46 +02:00
parent e06503a8fc
commit 1d3fd79a9e
30 changed files with 779 additions and 606 deletions

View File

@@ -5,6 +5,7 @@
#include <memory> // Para shared_ptr
#include <string> // Para basic_string, string
#include <utility>
#include <vector> // Para vector
#include "animated_sprite.h" // Para AnimationsFileBuffer
@@ -21,16 +22,16 @@ class Resource {
// --- Métodos de singleton ---
static void init(); // Inicializa el objeto Resource
static void destroy(); // Libera el objeto Resource
static Resource *get(); // Obtiene el puntero al objeto Resource
static auto get() -> Resource *; // Obtiene el puntero al objeto Resource
// --- Métodos de acceso a recursos ---
JA_Sound_t *getSound(const std::string &name); // Obtiene el sonido por nombre
JA_Music_t *getMusic(const std::string &name); // Obtiene la música por nombre
std::shared_ptr<Texture> getTexture(const std::string &name); // Obtiene la textura por nombre
std::shared_ptr<TextFile> getTextFile(const std::string &name); // Obtiene el fichero de texto por nombre
std::shared_ptr<Text> getText(const std::string &name); // Obtiene el objeto de texto por nombre
AnimationsFileBuffer &getAnimation(const std::string &name); // Obtiene la animación por nombre
DemoData &getDemoData(int index); // Obtiene los datos de demo por índice
auto getSound(const std::string &name) -> JA_Sound_t *; // Obtiene el sonido por nombre
auto getMusic(const std::string &name) -> JA_Music_t *; // Obtiene la música por nombre
auto getTexture(const std::string &name) -> std::shared_ptr<Texture>; // Obtiene la textura por nombre
auto getTextFile(const std::string &name) -> std::shared_ptr<TextFile>; // Obtiene el fichero de texto por nombre
auto getText(const std::string &name) -> std::shared_ptr<Text>; // Obtiene el objeto de texto por nombre
auto getAnimation(const std::string &name) -> AnimationsFileBuffer &; // Obtiene la animación por nombre
auto getDemoData(int index) -> DemoData &; // Obtiene los datos de demo por índice
// --- Métodos de recarga de recursos ---
void reload(); // Recarga todos los recursos
@@ -42,48 +43,48 @@ class Resource {
std::string name; // Nombre del sonido
JA_Sound_t *sound; // Objeto con el sonido
ResourceSound(const std::string &name, JA_Sound_t *sound)
: name(name), sound(sound) {}
ResourceSound(std::string name, JA_Sound_t *sound)
: name(std::move(name)), sound(sound) {}
};
struct ResourceMusic {
std::string name; // Nombre de la música
JA_Music_t *music; // Objeto con la música
ResourceMusic(const std::string &name, JA_Music_t *music)
: name(name), music(music) {}
ResourceMusic(std::string name, JA_Music_t *music)
: name(std::move(name)), music(music) {}
};
struct ResourceTexture {
std::string name; // Nombre de la textura
std::shared_ptr<Texture> texture; // Objeto con la textura
ResourceTexture(const std::string &name, std::shared_ptr<Texture> texture)
: name(name), texture(texture) {}
ResourceTexture(std::string name, std::shared_ptr<Texture> texture)
: name(std::move(name)), texture(std::move(texture)) {}
};
struct ResourceTextFile {
std::string name; // Nombre del fichero
std::shared_ptr<TextFile> text_file; // Objeto con los descriptores de la fuente de texto
ResourceTextFile(const std::string &name, std::shared_ptr<TextFile> text_file)
: name(name), text_file(text_file) {}
ResourceTextFile(std::string name, std::shared_ptr<TextFile> text_file)
: name(std::move(name)), text_file(std::move(text_file)) {}
};
struct ResourceText {
std::string name; // Nombre del objeto
std::shared_ptr<Text> text; // Objeto de texto
ResourceText(const std::string &name, std::shared_ptr<Text> text)
: name(name), text(text) {}
ResourceText(std::string name, std::shared_ptr<Text> text)
: name(std::move(name)), text(std::move(text)) {}
};
struct ResourceAnimation {
std::string name; // Nombre de la animación
AnimationsFileBuffer animation; // Objeto con las animaciones
ResourceAnimation(const std::string &name, const AnimationsFileBuffer &animation)
: name(name), animation(animation) {}
ResourceAnimation(std::string name, AnimationsFileBuffer animation)
: name(std::move(name)), animation(std::move(animation)) {}
};
// --- Estructura para el progreso de carga ---
@@ -96,14 +97,11 @@ class Resource {
void add(size_t amount) { loaded += amount; }
void increase() { loaded++; }
float getPercentage() const {
return total > 0 ? static_cast<float>(loaded) / static_cast<float>(total) : 0.0f;
[[nodiscard]] auto getPercentage() const -> float {
return total > 0 ? static_cast<float>(loaded) / static_cast<float>(total) : 0.0F;
}
};
// --- Instancia singleton ---
static Resource *instance_; // Instancia única de Resource
// --- Vectores de recursos ---
std::vector<ResourceSound> sounds_; // Vector con los sonidos
std::vector<ResourceMusic> musics_; // Vector con las músicas
@@ -146,4 +144,7 @@ class Resource {
// --- Constructores y destructor privados (singleton) ---
Resource(); // Constructor privado
~Resource(); // Destructor privado
// --- Instancia singleton ---
static Resource *instance_; // Instancia única de Resource
};