diff --git a/source/animated_sprite.cpp b/source/animated_sprite.cpp index e8d4784..41bbbd5 100644 --- a/source/animated_sprite.cpp +++ b/source/animated_sprite.cpp @@ -5,6 +5,7 @@ #include // Para basic_stringstream #include // Para runtime_error #include "texture.h" // Para Texture +#include "utils.h" // Para printWithDots // Carga las animaciones en un vector(Animations) desde un fichero AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path) @@ -16,7 +17,7 @@ AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path) throw std::runtime_error("Fichero no encontrado: " + file_path); } - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Animation file loaded: %s", file_path.c_str()); + printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]"); std::vector buffer; std::string line; diff --git a/source/director.cpp b/source/director.cpp index f165f7a..832ade2 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -4,7 +4,7 @@ #include // Para SDL_GetError #include // Para SDL_GamepadButton #include // Para SDL_Init, SDL_Quit, SDL_INIT_AUDIO -#include // Para SDL_Log, SDL_LogCategory, SDL_LogE... +#include // Para SDL_Log, SDL_LogCategory, SDL_LogE... #include // Para SDL_Scancode #include // Para errno, EEXIST, EACCES, ENAMETOOLONG #include // Para printf, perror @@ -56,7 +56,11 @@ Director::Director(int argc, const char *argv[]) section::attract_mode = section::AttractMode::TITLE_TO_DEMO; #endif - SDL_Log("Game start"); + // Establece el nivel de prioridad de la categoría de registro + SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); + SDL_SetLogPriority(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR); + + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Game start"); // Inicia la semilla aleatoria usando el tiempo actual en segundos std::srand(static_cast(std::time(nullptr))); @@ -74,7 +78,7 @@ Director::Director(int argc, const char *argv[]) Director::~Director() { close(); - SDL_Log("\nBye!"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!"); } // Inicializa todo @@ -258,6 +262,8 @@ void Director::initJailAudio() } else { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** SDL_AUDIO: INITIALIZING\n"); + JA_Init(48000, SDL_AUDIO_S16LE, 2); if (options.audio.enabled) { @@ -270,7 +276,7 @@ void Director::initJailAudio() JA_SetSoundVolume(0); } - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SDL_AUDIO: Initialization complete."); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** SDL_AUDIO: INITIALIZATION COMPLETE\n"); } } @@ -683,7 +689,7 @@ int Director::run() break; } - SDL_Log("\nGame end %s", return_code.c_str()); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nGame end %s", return_code.c_str()); return (section::options == section::Options::QUIT_WITH_CONTROLLER) ? 1 : 0; } diff --git a/source/gif.cpp b/source/gif.cpp index 3637a19..e42ebab 100644 --- a/source/gif.cpp +++ b/source/gif.cpp @@ -208,7 +208,7 @@ namespace GIF throw std::runtime_error("Formato de archivo GIF inválido."); } - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Procesando GIF con cabecera: %s", headerStr.c_str()); + SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "Procesando GIF con cabecera: %s", headerStr.c_str()); ScreenDescriptor screen_descriptor; readBytes(buffer, &screen_descriptor, sizeof(ScreenDescriptor)); @@ -216,7 +216,7 @@ namespace GIF w = screen_descriptor.width; h = screen_descriptor.height; - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Resolución del GIF: %dx%d", w, h); + SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "Resolución del GIF: %dx%d", w, h); int color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1; std::vector global_color_table; @@ -278,7 +278,6 @@ namespace GIF } else if (block_type == IMAGE_DESCRIPTOR) { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Procesando Image Descriptor..."); return processImageDescriptor(buffer, global_color_table, color_resolution_bits); } else @@ -289,7 +288,7 @@ namespace GIF block_type = *buffer++; } - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "GIF procesado correctamente."); + SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "GIF procesado correctamente."); return std::vector{}; } diff --git a/source/input.cpp b/source/input.cpp index 88c0fa7..b91d72a 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -36,9 +36,6 @@ Input::Input(const std::string &game_controller_db_path) // Inicializa el subsistema SDL_INIT_GAMEPAD initSDL(); - // Busca si hay mandos conectados - discoverGameControllers(); - // Inicializa los vectores key_bindings_.resize(static_cast(InputAction::SIZE), KeyBindings()); controller_bindings_.resize(num_gamepads_, std::vector(static_cast(InputAction::SIZE), ControllerBindings())); @@ -244,7 +241,7 @@ bool Input::discoverGameControllers() } } - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOOKING FOR GAME CONTROLLERS"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> LOOKING FOR GAME CONTROLLERS"); if (num_joysticks_ != num_gamepads_) { SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Joysticks found: %d", num_joysticks_); @@ -279,7 +276,7 @@ bool Input::discoverGameControllers() SDL_SetGamepadEventsEnabled(true); } - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** FINISHED LOOKING FOR GAME CONTROLLERS"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> FINISHED LOOKING FOR GAME CONTROLLERS"); return found; } @@ -440,7 +437,9 @@ void Input::initSDL() } else { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SDL_GAMEPAD: Initialization complete."); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** SDL_GAMEPAD: INITIALIZING"); + discoverGameControllers(); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** SDL_GAMEPAD: INITIALIZATION COMPLETE\n"); } } } \ No newline at end of file diff --git a/source/manage_hiscore_table.cpp b/source/manage_hiscore_table.cpp index d7499d4..e49e27c 100644 --- a/source/manage_hiscore_table.cpp +++ b/source/manage_hiscore_table.cpp @@ -116,7 +116,7 @@ bool ManageHiScoreTable::loadFromFile(const std::string &file_path) table_.push_back(entry); } - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Reading file: %s", getFileName(file_path).c_str()); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(file_path).c_str()); SDL_CloseIO(file); } else diff --git a/source/options.cpp b/source/options.cpp index b4cf35e..8b811ad 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -66,7 +66,7 @@ bool loadOptionsFile(std::string file_path) if (file.good()) { // Procesa el fichero línea a línea - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Reading file: %s", getFileName(file_path).c_str()); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(file_path).c_str()); std::string line; while (std::getline(file, line)) { @@ -78,7 +78,6 @@ bool loadOptionsFile(std::string file_path) // Procesa las dos subcadenas if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length()))) { - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: file %s", getFileName(file_path).c_str()); SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown parameter: %s", line.substr(0, pos).c_str()); success = false; } @@ -184,7 +183,7 @@ bool setOptions(const std::string &var, const std::string &value) auto success = true; // Opciones de video - if (var == "video.mode") + if (var == "video.fullscreen") { options.video.fullscreen = stringToBool(value); } diff --git a/source/param.cpp b/source/param.cpp index 69bf30d..7426ac1 100644 --- a/source/param.cpp +++ b/source/param.cpp @@ -9,80 +9,10 @@ Param param; // Calcula variables a partir de otras variables -void precalculateZones() -{ - // playArea - param.game.play_area.center_x = param.game.play_area.rect.w / 2; - param.game.play_area.first_quarter_x = param.game.play_area.rect.w / 4; - param.game.play_area.third_quarter_x = param.game.play_area.rect.w / 4 * 3; - param.game.play_area.center_y = param.game.play_area.rect.h / 2; - param.game.play_area.first_quarter_y = param.game.play_area.rect.h / 4; - param.game.play_area.third_quarter_y = param.game.play_area.rect.h / 4 * 3; - - // gameArea - param.game.game_area.rect = {0, 0, static_cast(param.game.width), static_cast(param.game.height)}; - param.game.game_area.center_x = param.game.game_area.rect.w / 2; - param.game.game_area.first_quarter_x = param.game.game_area.rect.w / 4; - param.game.game_area.third_quarter_x = param.game.game_area.rect.w / 4 * 3; - param.game.game_area.center_y = param.game.game_area.rect.h / 2; - param.game.game_area.first_quarter_y = param.game.game_area.rect.h / 4; - param.game.game_area.third_quarter_y = param.game.game_area.rect.h / 4 * 3; -} +void precalculateZones(); // Asigna variables a partir de dos cadenas -bool setParams(const std::string &var, const std::string &value) -{ - // Indicador de éxito en la asignación - auto success = true; - - // GAME - if (var == "game.width") - { - param.game.width = std::stoi(value); - } - else if (var == "game.height") - { - param.game.height = std::stoi(value); - } - else if (var == "game.item_size") - { - param.game.item_size = std::stoi(value); - } - else if (var == "game.coffee_machine_w") - { - param.game.coffee_machine_w = std::stoi(value); - } - else if (var == "game.coffee_machine_h") - { - param.game.coffee_machine_h = std::stoi(value); - } - else if (var == "game.play_area.rect.x") - { - param.game.play_area.rect.x = std::stoi(value); - } - else if (var == "game.play_area.rect.y") - { - param.game.play_area.rect.y = std::stoi(value); - } - else if (var == "game.play_area.rect.w") - { - param.game.play_area.rect.w = std::stoi(value); - } - else if (var == "game.play_area.rect.h") - { - param.game.play_area.rect.h = std::stoi(value); - } - else if (var == "game.enter_name_seconds") - { - param.game.enter_name_seconds = std::stoi(value); - } - else - { - success = false; - } - - return success; -} +bool setParams(const std::string &var, const std::string &value); // Establece valores por defecto a las variables void initParam() @@ -149,7 +79,7 @@ void loadParamsFromFile(const std::string &file_path) throw std::runtime_error("No se pudo abrir el archivo: " + file_path); } - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Leyendo archivo: %s", getFileName(file_path).c_str()); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(file_path).c_str()); std::string line, param1, param2; while (std::getline(file, line)) @@ -178,3 +108,267 @@ void loadParamsFromFile(const std::string &file_path) // Realiza cálculos adicionales después de cargar los parámetros precalculateZones(); } + +// Asigna variables a partir de dos cadenas +bool setParams(const std::string &var, const std::string &value) +{ + // Indicador de éxito en la asignación + auto success = true; + + // GAME + if (var == "game.width") + { + param.game.width = std::stoi(value); + } + + else if (var == "game.height") + { + param.game.height = std::stoi(value); + } + + else if (var == "game.item_size") + { + param.game.item_size = std::stoi(value); + } + + else if (var == "game.coffee_machine_w") + { + param.game.coffee_machine_w = std::stoi(value); + } + + else if (var == "game.coffee_machine_h") + { + param.game.coffee_machine_h = std::stoi(value); + } + + else if (var == "game.play_area.rect.x") + { + param.game.play_area.rect.x = std::stoi(value); + } + + else if (var == "game.play_area.rect.y") + { + param.game.play_area.rect.y = std::stoi(value); + } + + else if (var == "game.play_area.rect.w") + { + param.game.play_area.rect.w = std::stoi(value); + } + + else if (var == "game.play_area.rect.h") + { + param.game.play_area.rect.h = std::stoi(value); + } + + else if (var == "game.enter_name_seconds") + { + param.game.enter_name_seconds = std::stoi(value); + } + + // FADE + else if (var == "fade.num_squares_width") + { + param.fade.num_squares_width = std::stoi(value); + } + + else if (var == "fade.num_squares_height") + { + param.fade.num_squares_height = std::stoi(value); + } + + else if (var == "fade.random_squares_delay") + { + param.fade.random_squares_delay = std::stoi(value); + } + + else if (var == "fade.random_squares_mult") + { + param.fade.random_squares_mult = std::stoi(value); + } + + else if (var == "fade.post_duration") + { + param.fade.post_duration = std::stoi(value); + } + + else if (var == "fade.venetian_size") + { + param.fade.venetian_size = std::stoi(value); + } + + // SCOREBOARD + else if (var == "scoreboard.x") + { + param.scoreboard.x = std::stoi(value); + } + + else if (var == "scoreboard.y") + { + param.scoreboard.y = std::stoi(value); + } + + else if (var == "scoreboard.w") + { + param.scoreboard.w = std::stoi(value); + } + + else if (var == "scoreboard.h") + { + param.scoreboard.h = std::stoi(value); + } + + // TITLE + else if (var == "title.press_start_position") + { + param.title.press_start_position = std::stoi(value); + } + + else if (var == "title.title_duration") + { + param.title.title_duration = std::stoi(value); + } + + else if (var == "title.arcade_edition_position") + { + param.title.arcade_edition_position = std::stoi(value); + } + + else if (var == "title.title_c_c_position") + { + param.title.title_c_c_position = std::stoi(value); + } + + // BACKGROUND + else if (var == "background.attenuate_color.r") + { + param.background.attenuate_color.r = std::stoi(value); + } + + else if (var == "background.attenuate_color.g") + { + param.background.attenuate_color.g = std::stoi(value); + } + + else if (var == "background.attenuate_color.b") + { + param.background.attenuate_color.b = std::stoi(value); + } + + else if (var == "background.attenuate_alpha") + { + param.background.attenuate_alpha = std::stoi(value); + } + + // BALLOON + else if (var == "balloon_1.vel") + { + param.balloon.at(0).vel = std::stof(value); + } + + else if (var == "balloon_1.grav") + { + param.balloon.at(0).grav = std::stof(value); + } + + else if (var == "balloon_2.vel") + { + param.balloon.at(1).vel = std::stof(value); + } + + else if (var == "balloon_2.grav") + { + param.balloon.at(1).grav = std::stof(value); + } + + else if (var == "balloon_3.vel") + { + param.balloon.at(2).vel = std::stof(value); + } + + else if (var == "balloon_3.grav") + { + param.balloon.at(2).grav = std::stof(value); + } + + else if (var == "balloon_4.vel") + { + param.balloon.at(3).vel = std::stof(value); + } + + else if (var == "balloon_4.grav") + { + param.balloon.at(3).grav = std::stof(value); + } + + // NOTIFICACIONES + else if (var == "notification.pos_h") + { + if (value == "LEFT") + { + param.notification.pos_h = NotifyPosition::LEFT; + } + else if (value == "MIDDLE") + { + param.notification.pos_h = NotifyPosition::MIDDLE; + } + else + { + param.notification.pos_h = NotifyPosition::RIGHT; + } + } + + else if (var == "notification.pos_v") + { + param.notification.pos_v = value == "TOP" ? NotifyPosition::TOP : NotifyPosition::BOTTOM; + } + + else if (var == "notification.sound") + { + param.notification.sound = stringToBool(value); + } + + else if (var == "notification.color.r") + { + param.notification.color.r = std::stoi(value); + } + + else if (var == "notification.color.g") + { + param.notification.color.g = std::stoi(value); + } + + else if (var == "notification.color.b") + { + param.notification.color.b = std::stoi(value); + } + + // RESTO + else + { + success = false; + } + + return success; +} + +// Calcula variables a partir de otras variables +void precalculateZones() +{ + // playArea + param.game.play_area.center_x = param.game.play_area.rect.w / 2; + param.game.play_area.first_quarter_x = param.game.play_area.rect.w / 4; + param.game.play_area.third_quarter_x = param.game.play_area.rect.w / 4 * 3; + param.game.play_area.center_y = param.game.play_area.rect.h / 2; + param.game.play_area.first_quarter_y = param.game.play_area.rect.h / 4; + param.game.play_area.third_quarter_y = param.game.play_area.rect.h / 4 * 3; + + // gameArea + param.game.game_area.rect = {0, 0, param.game.width, param.game.height}; + param.game.game_area.center_x = param.game.game_area.rect.w / 2; + param.game.game_area.first_quarter_x = param.game.game_area.rect.w / 4; + param.game.game_area.third_quarter_x = param.game.game_area.rect.w / 4 * 3; + param.game.game_area.center_y = param.game.game_area.rect.h / 2; + param.game.game_area.first_quarter_y = param.game.game_area.rect.h / 4; + param.game.game_area.third_quarter_y = param.game.game_area.rect.h / 4 * 3; +} \ No newline at end of file diff --git a/source/resource.cpp b/source/resource.cpp index 6390c74..1bc09da 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -52,7 +52,7 @@ void Resource::clear() // Carga todos los recursos void Resource::load() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** LOADING RESOURCES"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES"); loadSounds(); loadMusics(); loadTextures(); @@ -62,7 +62,7 @@ void Resource::load() addPalettes(); createText(); createTextures(); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** RESOURCES LOADED"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** RESOURCES LOADED"); } // Recarga todos los recursos @@ -179,7 +179,7 @@ DemoData &Resource::getDemoData(int index) // Carga los sonidos void Resource::loadSounds() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> SOUND FILES"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> SOUND FILES"); auto list = Asset::get()->getListByType(AssetType::SOUND); sounds_.clear(); @@ -187,14 +187,14 @@ void Resource::loadSounds() { auto name = getFileName(l); sounds_.emplace_back(ResourceSound(name, JA_LoadSound(l.c_str()))); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Sound : %s [ LOADED ]", name.c_str()); + printWithDots("Sound : ", name, "[ LOADED ]"); } } // Carga las músicas void Resource::loadMusics() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> MUSIC FILES"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> MUSIC FILES"); auto list = Asset::get()->getListByType(AssetType::MUSIC); musics_.clear(); @@ -202,14 +202,14 @@ void Resource::loadMusics() { auto name = getFileName(l); musics_.emplace_back(ResourceMusic(name, JA_LoadMusic(l.c_str()))); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Music : %s [ LOADED ]", name.c_str()); + printWithDots("Music : ", name, "[ LOADED ]"); } } // Carga las texturas void Resource::loadTextures() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> TEXTURES"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXTURES"); auto list = Asset::get()->getListByType(AssetType::BITMAP); textures_.clear(); @@ -217,14 +217,13 @@ void Resource::loadTextures() { auto name = getFileName(l); textures_.emplace_back(ResourceTexture(name, std::make_shared(Screen::get()->getRenderer(), l))); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Texture : %s [ LOADED ]", name.c_str()); } } // Carga los ficheros de texto void Resource::loadTextFiles() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> TEXT FILES"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXT FILES"); auto list = Asset::get()->getListByType(AssetType::FONT); text_files_.clear(); @@ -232,14 +231,13 @@ void Resource::loadTextFiles() { auto name = getFileName(l); text_files_.emplace_back(ResourceTextFile(name, loadTextFile(l))); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "TextFile : %s [ LOADED ]", name.c_str()); } } // Carga las animaciones void Resource::loadAnimations() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> ANIMATIONS"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> ANIMATIONS"); auto list = Asset::get()->getListByType(AssetType::ANIMATION); animations_.clear(); @@ -247,23 +245,21 @@ void Resource::loadAnimations() { auto name = getFileName(l); animations_.emplace_back(ResourceAnimation(name, loadAnimationsFromFile(l))); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Animation : %s [ LOADED ]", name.c_str()); } } // Carga los datos para el modo demostración void Resource::loadDemoData() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> DEMO FILES"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES"); demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get("demo1.bin"))); demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get("demo2.bin"))); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Demo data loaded."); } // Añade paletas a las texturas void Resource::addPalettes() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> PALETTES"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> PALETTES"); // Jugador 1 getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_1_coffee_palette.gif")); @@ -291,7 +287,7 @@ void Resource::createTextures() : name(name_init), text(text_init) {} }; - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> CREATING TEXTURES"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> CREATING TEXTURES"); // Tamaño normal std::vector strings = { @@ -307,7 +303,7 @@ void Resource::createTextures() for (const auto &s : strings) { textures_.emplace_back(ResourceTexture(s.name, text->writeToTexture(s.text, 1, -2))); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Texture : %s [ DONE ]", s.name.c_str()); + printWithDots("Texture : ", s.name, "[ DONE ]"); } // Tamaño doble @@ -322,7 +318,7 @@ void Resource::createTextures() for (const auto &s : strings2X) { textures_.emplace_back(ResourceTexture(s.name, text2->writeToTexture(s.text, 1, -4))); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Texture : %s [ DONE ]", s.name.c_str()); + printWithDots("Texture : ", s.name, "[ DONE ]"); } } @@ -338,7 +334,7 @@ void Resource::createText() : key(k), textureFile(tFile), textFile(txtFile) {} }; - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> CREATING TEXT OBJECTS"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> CREATING TEXT OBJECTS"); std::vector resources = { {"04b_25", "04b_25.png", "04b_25.txt"}, @@ -353,7 +349,7 @@ void Resource::createText() texts_.emplace_back(ResourceText(resource.key, std::make_shared( getTexture(resource.textureFile), getTextFile(resource.textFile)))); - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Text : %s [ DONE ]", resource.key.c_str()); + printWithDots("Text : ", resource.key, "[ DONE ]"); } } diff --git a/source/screen.cpp b/source/screen.cpp index 56f0b79..4790a1e 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -313,6 +313,8 @@ bool Screen::initSDL() } else { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** SDL_VIDEO: INITIALIZING\n"); + getDisplayInfo(); // Establece el filtro de la textura @@ -362,7 +364,7 @@ bool Screen::initSDL() } } - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SDL_VIDEO: Initialization complete."); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** SDL_VIDEO: INITIALIZATION COMPLETE\n"); return success; } @@ -378,7 +380,7 @@ void Screen::getDisplayInfo() SDL_DisplayID instance_id = displays[i]; const char *name = SDL_GetDisplayName(instance_id); - SDL_Log("Display %" SDL_PRIu32 ": %s", instance_id, name ? name : "Unknown"); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Display %" SDL_PRIu32 ": %s", instance_id, name ? name : "Unknown"); } auto DM = SDL_GetCurrentDisplayMode(displays[0]); diff --git a/source/texture.cpp b/source/texture.cpp index 2ce3c4c..08ffe09 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -1,3 +1,4 @@ +#define STB_IMAGE_IMPLEMENTATION #include "texture.h" #include // Para SDL_GetError #include // Para SDL_LogError, SDL_LogCategory, SDL_Log... @@ -12,9 +13,6 @@ #include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a... #include "utils.h" // Para getFileName, Color, printWithDots -#define STB_IMAGE_IMPLEMENTATION -#include "stb_image.h" // Para stbi_failure_reason, stbi_image_free - // Constructor Texture::Texture(SDL_Renderer *renderer, const std::string &path) : renderer_(renderer), @@ -73,7 +71,7 @@ bool Texture::loadFromFile(const std::string &file_path) } else { - printWithDots("Image : ", getFileName(file_path), "[ LOADED ]"); + printWithDots("Texture : ", getFileName(file_path), "[ LOADED ]"); } int pitch; @@ -286,7 +284,7 @@ std::shared_ptr Texture::loadSurface(const std::string &file_path) width_ = w; height_ = h; - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "GIF %s cargado correctamente.", file_path.c_str()); + SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "GIF %s cargado correctamente.", file_path.c_str()); return surface; } @@ -331,7 +329,7 @@ std::vector Texture::loadPaletteFromFile(const std::string &file_path) } else { - printWithDots("Image : ", getFileName(file_path), "[ LOADED ]"); + printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]"); } // Obtener el tamaño del archivo y leerlo en un buffer @@ -360,7 +358,7 @@ std::vector Texture::loadPaletteFromFile(const std::string &file_path) palette.push_back((color << 8) | 0xFF); // Resultado: 0xRRGGBBAA } - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Paleta cargada correctamente desde %s", file_path.c_str()); + SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "Paleta cargada correctamente desde %s", file_path.c_str()); return palette; } diff --git a/source/utils.cpp b/source/utils.cpp index 9e99c26..9fe1f29 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -302,13 +302,31 @@ bool stringInVector(const std::vector &vec, const std::string &str) // Imprime por pantalla una línea de texto de tamaño fijo rellena con puntos void printWithDots(const std::string &text1, const std::string &text2, const std::string &text3) { - std::string output = text1; - size_t dots_count = 50 - text1.length() - text3.length(); - output.append(dots_count, '.'); - output.append(text2); - output.append(text3); + const size_t TOTAL_WIDTH = 50; - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%s", output.c_str()); + // Calcula el ancho del campo para text2 restando la longitud de text1 y text3 + size_t fieldWidth = TOTAL_WIDTH > (text1.size() + text3.size()) + ? TOTAL_WIDTH - text1.size() - text3.size() + : 0; + + // Prepara el bloque a imprimir a partir de text2 + std::string fieldText; + if (text2.size() < fieldWidth) + { + // Si text2 es más corto, lo rellenamos a la derecha con puntos + fieldText = text2 + std::string(fieldWidth - text2.size(), '.'); + } + else + { + // Si es demasiado largo, lo cortamos + fieldText = text2.substr(0, fieldWidth); + } + + // Concatena todo + std::string formatted_text = text1 + fieldText + text3; + + // Imprime la línea formateada usando SDL_LogInfo + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%s", formatted_text.c_str()); } // Carga el fichero de datos para la demo