This commit is contained in:
2025-11-19 20:43:20 +01:00
parent 35ef99cf7c
commit 5337e3b4e5
8 changed files with 112 additions and 47 deletions

View File

@@ -78,7 +78,7 @@ class Audio {
// --- Tipos anidados ---
struct Music {
MusicState state{MusicState::STOPPED}; // Estado actual de la música
std::string name{}; // Última pista de música reproducida
std::string name; // Última pista de música reproducida
bool loop{false}; // Indica si se reproduce en bucle
};

View File

@@ -197,7 +197,7 @@ void Cache::loadSounds() {
sound = JA_LoadSound(l.c_str());
}
sounds_.emplace_back(SoundResource{name, sound});
sounds_.emplace_back(SoundResource{.name = name, .sound = sound});
printWithDots("Sound : ", name, "[ LOADED ]");
updateLoadingProgress();
}
@@ -224,7 +224,7 @@ void Cache::loadMusics() {
music = JA_LoadMusic(l.c_str());
}
musics_.emplace_back(MusicResource{name, music});
musics_.emplace_back(MusicResource{.name = name, .music = music});
printWithDots("Music : ", name, "[ LOADED ]");
updateLoadingProgress(1);
}
@@ -238,7 +238,7 @@ void Cache::loadSurfaces() {
for (const auto& l : list) {
auto name = getFileName(l);
surfaces_.emplace_back(SurfaceResource{name, std::make_shared<Surface>(l)});
surfaces_.emplace_back(SurfaceResource{.name = name, .surface = std::make_shared<Surface>(l)});
surfaces_.back().surface->setTransparentColor(0);
updateLoadingProgress();
}
@@ -261,7 +261,7 @@ void Cache::loadPalettes() {
for (const auto& l : list) {
auto name = getFileName(l);
palettes_.emplace_back(ResourcePalette{name, readPalFile(l)});
palettes_.emplace_back(ResourcePalette{.name = name, .palette = readPalFile(l)});
updateLoadingProgress();
}
}
@@ -274,7 +274,7 @@ void Cache::loadTextFiles() {
for (const auto& l : list) {
auto name = getFileName(l);
text_files_.emplace_back(TextFileResource{name, Text::loadTextFile(l)});
text_files_.emplace_back(TextFileResource{.name = name, .text_file = Text::loadTextFile(l)});
updateLoadingProgress();
}
}
@@ -291,7 +291,7 @@ void Cache::loadAnimations() {
// Cargar bytes del archivo YAML sin parsear (carga lazy)
auto yaml_bytes = Helper::loadFile(l);
animations_.emplace_back(AnimationResource{name, yaml_bytes});
animations_.emplace_back(AnimationResource{.name = name, .yaml_data = yaml_bytes});
printWithDots("Animation : ", name, "[ LOADED ]");
updateLoadingProgress();
}
@@ -305,7 +305,7 @@ void Cache::loadRooms() {
for (const auto& l : list) {
auto name = getFileName(l);
rooms_.emplace_back(RoomResource{name, std::make_shared<Room::Data>(Room::loadYAML(l))});
rooms_.emplace_back(RoomResource{.name = name, .room = std::make_shared<Room::Data>(Room::loadYAML(l))});
printWithDots("Room : ", name, "[ LOADED ]");
updateLoadingProgress();
}
@@ -313,22 +313,22 @@ void Cache::loadRooms() {
void Cache::createText() {
struct ResourceInfo {
std::string key{}; // Identificador del recurso
std::string texture_file{}; // Nombre del archivo de textura
std::string text_file{}; // Nombre del archivo de texto
std::string key; // Identificador del recurso
std::string texture_file; // Nombre del archivo de textura
std::string text_file; // Nombre del archivo de texto
};
std::cout << "\n>> CREATING TEXT_OBJECTS" << '\n';
std::vector<ResourceInfo> resources = {
{"aseprite", "aseprite.gif", "aseprite.txt"},
{"gauntlet", "gauntlet.gif", "gauntlet.txt"},
{"smb2", "smb2.gif", "smb2.txt"},
{"subatomic", "subatomic.gif", "subatomic.txt"},
{"8bithud", "8bithud.gif", "8bithud.txt"}};
{.key = "aseprite", .texture_file = "aseprite.gif", .text_file = "aseprite.txt"},
{.key = "gauntlet", .texture_file = "gauntlet.gif", .text_file = "gauntlet.txt"},
{.key = "smb2", .texture_file = "smb2.gif", .text_file = "smb2.txt"},
{.key = "subatomic", .texture_file = "subatomic.gif", .text_file = "subatomic.txt"},
{.key = "8bithud", .texture_file = "8bithud.gif", .text_file = "8bithud.txt"}};
for (const auto& res_info : resources) {
texts_.emplace_back(TextResource{res_info.key, std::make_shared<Text>(getSurface(res_info.texture_file), getTextFile(res_info.text_file))});
texts_.emplace_back(TextResource{.name = res_info.key, .text = std::make_shared<Text>(getSurface(res_info.texture_file), getTextFile(res_info.text_file))});
printWithDots("Text : ", res_info.key, "[ DONE ]");
}
}
@@ -374,7 +374,7 @@ void Cache::calculateTotal() {
total += list.size();
}
count_ = ResourceCount{total, 0};
count_ = ResourceCount{.total = total, .loaded = 0};
}
// Muestra el progreso de carga

View File

@@ -74,17 +74,17 @@ class Cache {
static Cache* cache;
// Variables miembro
std::vector<SoundResource> sounds_{}; // Vector con los sonidos
std::vector<MusicResource> musics_{}; // Vector con las musicas
std::vector<SurfaceResource> surfaces_{}; // Vector con las surfaces
std::vector<ResourcePalette> palettes_{}; // Vector con las paletas
std::vector<TextFileResource> text_files_{}; // Vector con los ficheros de texto
std::vector<TextResource> texts_{}; // Vector con los objetos de texto
std::vector<AnimationResource> animations_{}; // Vector con las animaciones
std::vector<RoomResource> rooms_{}; // Vector con las habitaciones
std::vector<SoundResource> sounds_; // Vector con los sonidos
std::vector<MusicResource> musics_; // Vector con las musicas
std::vector<SurfaceResource> surfaces_; // Vector con las surfaces
std::vector<ResourcePalette> palettes_; // Vector con las paletas
std::vector<TextFileResource> text_files_; // Vector con los ficheros de texto
std::vector<TextResource> texts_; // Vector con los objetos de texto
std::vector<AnimationResource> animations_; // Vector con las animaciones
std::vector<RoomResource> rooms_; // Vector con las habitaciones
ResourceCount count_{}; // Contador de recursos
std::shared_ptr<Text> loading_text_{}; // Texto para la pantalla de carga
std::shared_ptr<Text> loading_text_; // Texto para la pantalla de carga
};
} // namespace Resource

View File

@@ -109,8 +109,8 @@ void List::loadFromString(const std::string& config_content, const std::string&
}
// Extraer campos
std::string type_str = asset["type"].get_value<std::string>();
std::string path = asset["path"].get_value<std::string>();
auto type_str = asset["type"].get_value<std::string>();
auto path = asset["path"].get_value<std::string>();
// Valores por defecto
bool required = true;

View File

@@ -13,7 +13,7 @@ namespace Resource {
// Entry metadata for each resource in the pack
struct ResourceEntry {
std::string filename{}; // Relative path within pack
std::string filename; // Relative path within pack
uint64_t offset{0}; // Byte offset in data block
uint64_t size{0}; // Size in bytes
uint32_t checksum{0}; // CRC32 checksum for verification
@@ -60,8 +60,8 @@ class Pack {
static auto readFile(const std::string& filepath) -> std::vector<uint8_t>; // File I/O
std::unordered_map<std::string, ResourceEntry> resources_{}; // Member variables
std::vector<uint8_t> data_{}; // Encrypted data block
std::unordered_map<std::string, ResourceEntry> resources_; // Member variables
std::vector<uint8_t> data_; // Encrypted data block
bool loaded_{false};
};

View File

@@ -15,48 +15,48 @@ struct JA_Sound_t;
// Estructura para almacenar ficheros de sonido y su nombre
struct SoundResource {
std::string name{}; // Nombre del sonido
std::string name; // Nombre del sonido
JA_Sound_t* sound{nullptr}; // Objeto con el sonido
};
// Estructura para almacenar ficheros musicales y su nombre
struct MusicResource {
std::string name{}; // Nombre de la musica
std::string name; // Nombre de la musica
JA_Music_t* music{nullptr}; // Objeto con la música
};
// Estructura para almacenar objetos Surface y su nombre
struct SurfaceResource {
std::string name{}; // Nombre de la surface
std::shared_ptr<Surface> surface{}; // Objeto con la surface
std::string name; // Nombre de la surface
std::shared_ptr<Surface> surface; // Objeto con la surface
};
// Estructura para almacenar objetos Palette y su nombre
struct ResourcePalette {
std::string name{}; // Nombre de la surface
std::string name; // Nombre de la surface
Palette palette{}; // Paleta
};
// Estructura para almacenar ficheros TextFile y su nombre
struct TextFileResource {
std::string name{}; // Nombre del fichero
std::shared_ptr<Text::File> text_file{}; // Objeto con los descriptores de la fuente de texto
std::string name; // Nombre del fichero
std::shared_ptr<Text::File> text_file; // Objeto con los descriptores de la fuente de texto
};
// Estructura para almacenar objetos Text y su nombre
struct TextResource {
std::string name{}; // Nombre del objeto
std::shared_ptr<Text> text{}; // Objeto
std::string name; // Nombre del objeto
std::shared_ptr<Text> text; // Objeto
};
// Estructura para almacenar ficheros animaciones y su nombre
struct AnimationResource {
std::string name{}; // Nombre del fichero
std::vector<uint8_t> yaml_data{}; // Bytes del archivo YAML sin parsear
std::string name; // Nombre del fichero
std::vector<uint8_t> yaml_data; // Bytes del archivo YAML sin parsear
};
// Estructura para almacenar habitaciones y su nombre
struct RoomResource {
std::string name{}; // Nombre de la habitación
std::shared_ptr<Room::Data> room{}; // Habitación
std::string name; // Nombre de la habitación
std::shared_ptr<Room::Data> room; // Habitación
};