eliminat molt de ruido de la consola de log

This commit is contained in:
2026-04-14 13:04:24 +02:00
parent f5da35bfb2
commit cf7ea6cc9c
27 changed files with 144 additions and 383 deletions

View File

@@ -7,6 +7,7 @@
#include <exception> // Para exception
#include <filesystem> // Para exists, path, remove
#include <fstream> // Para basic_ofstream, basic_ios, basic_ostream::write, ios, ofstream
#include <iostream> // Para std::cout
#include <ranges> // Para __find_if_fn, find_if, __find_fn, find
#include <stdexcept> // Para runtime_error
#include <utility> // Para move
@@ -19,7 +20,6 @@
#include "resource_helper.hpp" // Para loadFile
#include "screen.hpp" // Para Screen
#include "text.hpp" // Para Text
#include "ui/logger.hpp" // Para info, CR, dots
#include "utils.hpp" // Para getFileName
#include "version.h" // Para APP_NAME, GIT_HASH
@@ -80,21 +80,16 @@ Resource::~Resource() {
// Carga los recursos esenciales que siempre se necesitan (modo lazy)
void Resource::loadEssentialResources() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading essential resources for lazy mode");
// Cargar recursos de texto básicos que se usan para crear texturas
loadTextFilesQuiet(); // <- VERSIÓN SILENCIOSA
loadEssentialTextures(); // Ya es silenciosa
createText(); // Crear objetos de texto
createTextTextures(); // Crear texturas generadas (game_text_xxx)
createPlayerTextures(); // Crea las texturas de jugadores con todas sus variantes de paleta
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Essential resources loaded");
}
// Carga los ficheros de texto del juego (versión silenciosa)
void Resource::loadTextFilesQuiet() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXT FILES (quiet load)");
auto list = Asset::get()->getListByType(Asset::Type::FONT);
for (const auto& l : list) {
@@ -103,7 +98,6 @@ void Resource::loadTextFilesQuiet() {
auto it = std::ranges::find_if(text_files_, [&name](const auto& t) -> auto { return t.name == name; });
if (it != text_files_.end()) {
it->text_file = Text::loadFile(l);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Text file loaded: %s", name.c_str());
}
}
}
@@ -141,8 +135,6 @@ void Resource::loadEssentialTextures() {
// Inicializa las listas de recursos sin cargar el contenido (modo lazy)
void Resource::initResourceLists() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Initializing resource lists for lazy loading");
// Inicializa lista de sonidos
auto sound_list = Asset::get()->getListByType(Asset::Type::SOUND);
sounds_.clear();
@@ -200,8 +192,6 @@ void Resource::initResourceLists() {
for (const auto& text_name : TEXT_OBJECTS) {
texts_.emplace_back(text_name); // Constructor con nullptr por defecto
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Resource lists initialized for lazy loading");
}
// Obtiene el sonido a partir de un nombre (con carga perezosa)
@@ -216,7 +206,7 @@ auto Resource::getSound(const std::string& name) -> JA_Sound_t* {
return it->sound;
}
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Sonido no encontrado %s", name.c_str());
std::cout << "Error: Sonido no encontrado " << name << '\n';
throw std::runtime_error("Sonido no encontrado: " + name);
}
@@ -232,7 +222,7 @@ auto Resource::getMusic(const std::string& name) -> JA_Music_t* {
return it->music;
}
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Música no encontrada %s", name.c_str());
std::cout << "Error: Música no encontrada " << name << '\n';
throw std::runtime_error("Música no encontrada: " + name);
}
@@ -248,7 +238,7 @@ auto Resource::getTexture(const std::string& name) -> std::shared_ptr<Texture> {
return it->texture;
}
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Imagen no encontrada %s", name.c_str());
std::cout << "Error: Imagen no encontrada " << name << '\n';
throw std::runtime_error("Imagen no encontrada: " + name);
}
@@ -264,7 +254,7 @@ auto Resource::getTextFile(const std::string& name) -> std::shared_ptr<Text::Fil
return it->text_file;
}
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: TextFile no encontrado %s", name.c_str());
std::cout << "Error: TextFile no encontrado " << name << '\n';
throw std::runtime_error("TextFile no encontrado: " + name);
}
@@ -280,7 +270,7 @@ auto Resource::getText(const std::string& name) -> std::shared_ptr<Text> {
return it->text;
}
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Text no encontrado %s", name.c_str());
std::cout << "Error: Text no encontrado " << name << '\n';
throw std::runtime_error("Text no encontrado: " + name);
}
@@ -296,14 +286,14 @@ auto Resource::getAnimation(const std::string& name) -> AnimationsFileBuffer& {
return it->animation;
}
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Animación no encontrada %s", name.c_str());
std::cout << "Error: Animación no encontrada " << name << '\n';
throw std::runtime_error("Animación no encontrada: " + name);
}
// Obtiene el fichero con los datos para el modo demostración a partir de un índice
auto Resource::getDemoData(int index) -> DemoData& {
if (index < 0 || std::cmp_greater_equal(index, demos_.size())) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index %d out of range for demo data (size: %d)", index, static_cast<int>(demos_.size()));
std::cout << "Index " << index << " out of range for demo data (size: " << static_cast<int>(demos_.size()) << ")" << '\n';
static DemoData empty_demo_;
return empty_demo_;
}
@@ -313,7 +303,6 @@ auto Resource::getDemoData(int index) -> DemoData& {
// --- Métodos de carga perezosa ---
auto Resource::loadSoundLazy(const std::string& name) -> JA_Sound_t* {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading sound lazily: %s", name.c_str());
auto sound_list = Asset::get()->getListByType(Asset::Type::SOUND);
for (const auto& file : sound_list) {
if (getFileName(file) == name) {
@@ -329,7 +318,6 @@ auto Resource::loadSoundLazy(const std::string& name) -> JA_Sound_t* {
}
auto Resource::loadMusicLazy(const std::string& name) -> JA_Music_t* {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading music lazily: %s", name.c_str());
auto music_list = Asset::get()->getListByType(Asset::Type::MUSIC);
for (const auto& file : music_list) {
if (getFileName(file) == name) {
@@ -345,7 +333,6 @@ auto Resource::loadMusicLazy(const std::string& name) -> JA_Music_t* {
}
auto Resource::loadTextureLazy(const std::string& name) -> std::shared_ptr<Texture> {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading texture lazily: %s", name.c_str());
auto texture_list = Asset::get()->getListByType(Asset::Type::BITMAP);
for (const auto& file : texture_list) {
if (getFileName(file) == name) {
@@ -356,7 +343,6 @@ auto Resource::loadTextureLazy(const std::string& name) -> std::shared_ptr<Textu
}
auto Resource::loadTextFileLazy(const std::string& name) -> std::shared_ptr<Text::File> {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading text file lazily: %s", name.c_str());
auto text_file_list = Asset::get()->getListByType(Asset::Type::FONT);
for (const auto& file : text_file_list) {
if (getFileName(file) == name) {
@@ -367,8 +353,6 @@ auto Resource::loadTextFileLazy(const std::string& name) -> std::shared_ptr<Text
}
auto Resource::loadTextLazy(const std::string& name) -> std::shared_ptr<Text> {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading text object lazily: %s", name.c_str());
// Mapeo de objetos de texto a sus recursos
struct TextMapping {
std::string key;
@@ -406,7 +390,6 @@ auto Resource::loadTextLazy(const std::string& name) -> std::shared_ptr<Text> {
}
auto Resource::loadAnimationLazy(const std::string& name) -> AnimationsFileBuffer {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading animation lazily: %s", name.c_str());
auto animation_list = Asset::get()->getListByType(Asset::Type::ANIMATION);
for (const auto& file : animation_list) {
if (getFileName(file) == name) {
@@ -470,7 +453,6 @@ void Resource::loadSounds() {
auto list = Asset::get()->getListByType(Asset::Type::SOUND);
sounds_.clear();
int failed = 0;
for (const auto& l : list) {
auto name = getFileName(l);
updateLoadingProgress(name);
@@ -482,12 +464,10 @@ void Resource::loadSounds() {
sound = JA_LoadSound(l.c_str());
}
if (sound == nullptr) {
Logger::error(" Sound load failed: " + name);
++failed;
std::cout << "Sound load failed: " << name << '\n';
}
sounds_.emplace_back(name, sound);
}
Logger::info("Sounds loaded: " + std::to_string(list.size() - failed) + "/" + std::to_string(list.size()));
}
// Carga las músicas del juego
@@ -495,7 +475,6 @@ void Resource::loadMusics() {
auto list = Asset::get()->getListByType(Asset::Type::MUSIC);
musics_.clear();
int failed = 0;
for (const auto& l : list) {
auto name = getFileName(l);
updateLoadingProgress(name);
@@ -507,12 +486,10 @@ void Resource::loadMusics() {
music = JA_LoadMusic(l.c_str());
}
if (music == nullptr) {
Logger::error(" Music load failed: " + name);
++failed;
std::cout << "Music load failed: " << name << '\n';
}
musics_.emplace_back(name, music);
}
Logger::info("Musics loaded: " + std::to_string(list.size() - failed) + "/" + std::to_string(list.size()));
}
// Carga las texturas del juego
@@ -525,7 +502,6 @@ void Resource::loadTextures() {
updateLoadingProgress(name);
textures_.emplace_back(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l));
}
Logger::info("Textures loaded: " + std::to_string(list.size()));
}
// Carga los ficheros de texto del juego
@@ -538,7 +514,6 @@ void Resource::loadTextFiles() {
updateLoadingProgress(name);
text_files_.emplace_back(name, Text::loadFile(l));
}
Logger::info("Text files loaded: " + std::to_string(list.size()));
}
// Carga las animaciones del juego
@@ -551,7 +526,6 @@ void Resource::loadAnimations() {
updateLoadingProgress(name);
animations_.emplace_back(name, loadAnimationsFromFile(l));
}
Logger::info("Animations loaded: " + std::to_string(list.size()));
}
// Carga los datos para el modo demostración
@@ -564,7 +538,6 @@ void Resource::loadDemoData() {
updateLoadingProgress(name);
demos_.emplace_back(loadDemoDataFromFile(l));
}
Logger::info("Demo files loaded: " + std::to_string(list.size()));
}
// Crea las texturas de jugadores con todas sus variantes de paleta
@@ -641,7 +614,6 @@ void Resource::createPlayerTextures() {
textures_.emplace_back(texture_name, texture);
}
}
Logger::info("Player textures created: " + std::to_string(players.size() * 4));
}
// Crea texturas a partir de textos para mostrar puntuaciones y mensajes
@@ -683,8 +655,6 @@ void Resource::createTextTextures() {
for (const auto& s : strings2) {
textures_.emplace_back(s.name, text2->writeDXToTexture(Text::STROKE, s.text, -4, Colors::NO_COLOR_MOD, 1, param.game.item_text_outline_color));
}
Logger::info("Text textures created: " + std::to_string(strings1.size() + strings2.size()));
}
// Crea los objetos de texto a partir de los archivos de textura y texto
@@ -728,7 +698,6 @@ void Resource::createText() {
texts_.emplace_back(resource.key, std::make_shared<Text>(getTexture(resource.texture_file), getTextFile(resource.text_file)));
}
}
Logger::info("Text objects created: " + std::to_string(resources.size()));
}
// Vacía el vector de sonidos y libera la memoria asociada
@@ -847,7 +816,6 @@ void Resource::renderProgress() {
// Carga los datos para el modo demostración (sin mostrar progreso)
void Resource::loadDemoDataQuiet() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES (quiet load)");
auto list = Asset::get()->getListByType(Asset::Type::DEMODATA);
demos_.clear();