Resource: treballant en la visualització de la càrrega de recursos
This commit is contained in:
@@ -1,77 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "animated_sprite.h" // Para AnimationsFileBuffer
|
||||
#include "text.h" // Para TextFile, Text
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para DemoData
|
||||
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
|
||||
// --- Estructuras para recursos individuales ---
|
||||
|
||||
// Sonido
|
||||
struct ResourceSound
|
||||
{
|
||||
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) {}
|
||||
};
|
||||
|
||||
// Música
|
||||
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) {}
|
||||
};
|
||||
|
||||
// Textura
|
||||
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) {}
|
||||
};
|
||||
|
||||
// Fichero de texto (fuente)
|
||||
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) {}
|
||||
};
|
||||
|
||||
// Objeto de texto
|
||||
struct ResourceText
|
||||
{
|
||||
std::string name; // Nombre del objeto
|
||||
std::shared_ptr<Text> text; // Objeto
|
||||
|
||||
ResourceText(const std::string &name, std::shared_ptr<Text> text)
|
||||
: name(name), text(text) {}
|
||||
};
|
||||
|
||||
// Animación
|
||||
struct ResourceAnimation
|
||||
{
|
||||
std::string name; // Nombre del fichero
|
||||
AnimationsFileBuffer animation; // Objeto con las animaciones
|
||||
|
||||
ResourceAnimation(const std::string &name, const AnimationsFileBuffer &animation)
|
||||
: name(name), animation(animation) {}
|
||||
};
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "animated_sprite.h"
|
||||
#include "text.h"
|
||||
#include "texture.h"
|
||||
#include "utils.h"
|
||||
#include "jail_audio.h"
|
||||
|
||||
// --- Clase Resource: gestiona todos los recursos del juego (singleton) ---
|
||||
class Resource
|
||||
@@ -91,13 +27,84 @@ public:
|
||||
AnimationsFileBuffer &getAnimation(const std::string &name); // Obtiene la animación por nombre
|
||||
DemoData &getDemoData(int index); // Obtiene los datos de demo por índice
|
||||
|
||||
// --- Recarga de recursos ---
|
||||
// --- Métodos de recarga de recursos ---
|
||||
void reload(); // Recarga todos los recursos
|
||||
void reloadTextures(); // Recarga solo las texturas
|
||||
|
||||
private:
|
||||
// --- Singleton ---
|
||||
static Resource *instance_;
|
||||
// --- Estructuras para recursos individuales ---
|
||||
struct ResourceSound
|
||||
{
|
||||
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) {}
|
||||
};
|
||||
|
||||
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) {}
|
||||
};
|
||||
|
||||
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) {}
|
||||
};
|
||||
|
||||
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) {}
|
||||
};
|
||||
|
||||
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) {}
|
||||
};
|
||||
|
||||
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) {}
|
||||
};
|
||||
|
||||
// --- Estructura para el progreso de carga ---
|
||||
struct ResourceCount
|
||||
{
|
||||
int total; // Número total de recursos
|
||||
int loaded; // Número de recursos cargados
|
||||
|
||||
ResourceCount() : total(0), loaded(0) {}
|
||||
ResourceCount(int total, int loaded) : total(total), loaded(loaded) {}
|
||||
|
||||
void add(int amount) { loaded += amount; }
|
||||
float getPercentage() const
|
||||
{
|
||||
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
|
||||
@@ -108,6 +115,9 @@ private:
|
||||
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
||||
std::vector<DemoData> demos_; // Vector con los ficheros de datos para el modo demostración
|
||||
|
||||
// --- Progreso de carga ---
|
||||
ResourceCount count_; // Contador de recursos cargados
|
||||
|
||||
// --- Métodos internos de carga y gestión ---
|
||||
void loadSounds(); // Carga los sonidos
|
||||
void loadMusics(); // Carga las músicas
|
||||
@@ -123,6 +133,12 @@ private:
|
||||
void clearSounds(); // Vacía el vector de sonidos
|
||||
void clearMusics(); // Vacía el vector de músicas
|
||||
|
||||
// --- Métodos internos para gestionar el progreso ---
|
||||
void calculateTotal(); // Calcula el número de recursos para cargar
|
||||
void renderProgress(); // Muestra el progreso de carga
|
||||
void checkEvents(); // Comprueba los eventos durante la carga
|
||||
void updateLoadingProgress(int steps = 1); // Actualiza el progreso de carga
|
||||
|
||||
// --- Constructores y destructor privados (singleton) ---
|
||||
Resource(); // Constructor privado
|
||||
~Resource() = default; // Destructor privado
|
||||
|
||||
Reference in New Issue
Block a user