acabat amb SDL_Log

This commit is contained in:
2025-03-27 20:56:21 +01:00
parent 8afca398e9
commit 36b3048070
11 changed files with 340 additions and 128 deletions

View File

@@ -5,6 +5,7 @@
#include <sstream> // Para basic_stringstream #include <sstream> // Para basic_stringstream
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "utils.h" // Para printWithDots
// Carga las animaciones en un vector(Animations) desde un fichero // Carga las animaciones en un vector(Animations) desde un fichero
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path) 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); 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<std::string> buffer; std::vector<std::string> buffer;
std::string line; std::string line;

View File

@@ -4,7 +4,7 @@
#include <SDL3/SDL_error.h> // Para SDL_GetError #include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_gamepad.h> // Para SDL_GamepadButton #include <SDL3/SDL_gamepad.h> // Para SDL_GamepadButton
#include <SDL3/SDL_init.h> // Para SDL_Init, SDL_Quit, SDL_INIT_AUDIO #include <SDL3/SDL_init.h> // Para SDL_Init, SDL_Quit, SDL_INIT_AUDIO
#include <SDL3/SDL_log.h> // Para SDL_Log, SDL_LogCategory, SDL_LogE... #include <SDL3/SDL.h> // Para SDL_Log, SDL_LogCategory, SDL_LogE...
#include <SDL3/SDL_scancode.h> // Para SDL_Scancode #include <SDL3/SDL_scancode.h> // Para SDL_Scancode
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOOLONG #include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOOLONG
#include <stdio.h> // Para printf, perror #include <stdio.h> // Para printf, perror
@@ -56,7 +56,11 @@ Director::Director(int argc, const char *argv[])
section::attract_mode = section::AttractMode::TITLE_TO_DEMO; section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
#endif #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 // Inicia la semilla aleatoria usando el tiempo actual en segundos
std::srand(static_cast<unsigned int>(std::time(nullptr))); std::srand(static_cast<unsigned int>(std::time(nullptr)));
@@ -74,7 +78,7 @@ Director::Director(int argc, const char *argv[])
Director::~Director() Director::~Director()
{ {
close(); close();
SDL_Log("\nBye!"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!");
} }
// Inicializa todo // Inicializa todo
@@ -258,6 +262,8 @@ void Director::initJailAudio()
} }
else else
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** SDL_AUDIO: INITIALIZING\n");
JA_Init(48000, SDL_AUDIO_S16LE, 2); JA_Init(48000, SDL_AUDIO_S16LE, 2);
if (options.audio.enabled) if (options.audio.enabled)
{ {
@@ -270,7 +276,7 @@ void Director::initJailAudio()
JA_SetSoundVolume(0); 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; 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; return (section::options == section::Options::QUIT_WITH_CONTROLLER) ? 1 : 0;
} }

View File

@@ -208,7 +208,7 @@ namespace GIF
throw std::runtime_error("Formato de archivo GIF inválido."); 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; ScreenDescriptor screen_descriptor;
readBytes(buffer, &screen_descriptor, sizeof(ScreenDescriptor)); readBytes(buffer, &screen_descriptor, sizeof(ScreenDescriptor));
@@ -216,7 +216,7 @@ namespace GIF
w = screen_descriptor.width; w = screen_descriptor.width;
h = screen_descriptor.height; 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; int color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
std::vector<RGB> global_color_table; std::vector<RGB> global_color_table;
@@ -278,7 +278,6 @@ namespace GIF
} }
else if (block_type == IMAGE_DESCRIPTOR) else if (block_type == IMAGE_DESCRIPTOR)
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Procesando Image Descriptor...");
return processImageDescriptor(buffer, global_color_table, color_resolution_bits); return processImageDescriptor(buffer, global_color_table, color_resolution_bits);
} }
else else
@@ -289,7 +288,7 @@ namespace GIF
block_type = *buffer++; block_type = *buffer++;
} }
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "GIF procesado correctamente."); SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "GIF procesado correctamente.");
return std::vector<uint8_t>{}; return std::vector<uint8_t>{};
} }

View File

@@ -36,9 +36,6 @@ Input::Input(const std::string &game_controller_db_path)
// Inicializa el subsistema SDL_INIT_GAMEPAD // Inicializa el subsistema SDL_INIT_GAMEPAD
initSDL(); initSDL();
// Busca si hay mandos conectados
discoverGameControllers();
// Inicializa los vectores // Inicializa los vectores
key_bindings_.resize(static_cast<int>(InputAction::SIZE), KeyBindings()); key_bindings_.resize(static_cast<int>(InputAction::SIZE), KeyBindings());
controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(InputAction::SIZE), ControllerBindings())); controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(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_) if (num_joysticks_ != num_gamepads_)
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Joysticks found: %d", num_joysticks_); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Joysticks found: %d", num_joysticks_);
@@ -279,7 +276,7 @@ bool Input::discoverGameControllers()
SDL_SetGamepadEventsEnabled(true); 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; return found;
} }
@@ -440,7 +437,9 @@ void Input::initSDL()
} }
else 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");
} }
} }
} }

View File

@@ -116,7 +116,7 @@ bool ManageHiScoreTable::loadFromFile(const std::string &file_path)
table_.push_back(entry); 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); SDL_CloseIO(file);
} }
else else

View File

@@ -66,7 +66,7 @@ bool loadOptionsFile(std::string file_path)
if (file.good()) if (file.good())
{ {
// Procesa el fichero línea a línea // 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; std::string line;
while (std::getline(file, line)) while (std::getline(file, line))
{ {
@@ -78,7 +78,6 @@ bool loadOptionsFile(std::string file_path)
// Procesa las dos subcadenas // Procesa las dos subcadenas
if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length()))) 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()); SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown parameter: %s", line.substr(0, pos).c_str());
success = false; success = false;
} }
@@ -184,7 +183,7 @@ bool setOptions(const std::string &var, const std::string &value)
auto success = true; auto success = true;
// Opciones de video // Opciones de video
if (var == "video.mode") if (var == "video.fullscreen")
{ {
options.video.fullscreen = stringToBool(value); options.video.fullscreen = stringToBool(value);
} }

View File

@@ -9,80 +9,10 @@
Param param; Param param;
// Calcula variables a partir de otras variables // Calcula variables a partir de otras variables
void precalculateZones() 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<float>(param.game.width), static_cast<float>(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;
}
// Asigna variables a partir de dos cadenas // Asigna variables a partir de dos cadenas
bool setParams(const std::string &var, const std::string &value) 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;
}
// Establece valores por defecto a las variables // Establece valores por defecto a las variables
void initParam() 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); 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; std::string line, param1, param2;
while (std::getline(file, line)) 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 // Realiza cálculos adicionales después de cargar los parámetros
precalculateZones(); 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;
}

View File

@@ -52,7 +52,7 @@ void Resource::clear()
// Carga todos los recursos // Carga todos los recursos
void Resource::load() void Resource::load()
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** LOADING RESOURCES"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES");
loadSounds(); loadSounds();
loadMusics(); loadMusics();
loadTextures(); loadTextures();
@@ -62,7 +62,7 @@ void Resource::load()
addPalettes(); addPalettes();
createText(); createText();
createTextures(); createTextures();
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** RESOURCES LOADED"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** RESOURCES LOADED");
} }
// Recarga todos los recursos // Recarga todos los recursos
@@ -179,7 +179,7 @@ DemoData &Resource::getDemoData(int index)
// Carga los sonidos // Carga los sonidos
void Resource::loadSounds() 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); auto list = Asset::get()->getListByType(AssetType::SOUND);
sounds_.clear(); sounds_.clear();
@@ -187,14 +187,14 @@ void Resource::loadSounds()
{ {
auto name = getFileName(l); auto name = getFileName(l);
sounds_.emplace_back(ResourceSound(name, JA_LoadSound(l.c_str()))); 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 // Carga las músicas
void Resource::loadMusics() 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); auto list = Asset::get()->getListByType(AssetType::MUSIC);
musics_.clear(); musics_.clear();
@@ -202,14 +202,14 @@ void Resource::loadMusics()
{ {
auto name = getFileName(l); auto name = getFileName(l);
musics_.emplace_back(ResourceMusic(name, JA_LoadMusic(l.c_str()))); 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 // Carga las texturas
void Resource::loadTextures() 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); auto list = Asset::get()->getListByType(AssetType::BITMAP);
textures_.clear(); textures_.clear();
@@ -217,14 +217,13 @@ void Resource::loadTextures()
{ {
auto name = getFileName(l); auto name = getFileName(l);
textures_.emplace_back(ResourceTexture(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l))); textures_.emplace_back(ResourceTexture(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l)));
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Texture : %s [ LOADED ]", name.c_str());
} }
} }
// Carga los ficheros de texto // Carga los ficheros de texto
void Resource::loadTextFiles() 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); auto list = Asset::get()->getListByType(AssetType::FONT);
text_files_.clear(); text_files_.clear();
@@ -232,14 +231,13 @@ void Resource::loadTextFiles()
{ {
auto name = getFileName(l); auto name = getFileName(l);
text_files_.emplace_back(ResourceTextFile(name, loadTextFile(l))); text_files_.emplace_back(ResourceTextFile(name, loadTextFile(l)));
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "TextFile : %s [ LOADED ]", name.c_str());
} }
} }
// Carga las animaciones // Carga las animaciones
void Resource::loadAnimations() 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); auto list = Asset::get()->getListByType(AssetType::ANIMATION);
animations_.clear(); animations_.clear();
@@ -247,23 +245,21 @@ void Resource::loadAnimations()
{ {
auto name = getFileName(l); auto name = getFileName(l);
animations_.emplace_back(ResourceAnimation(name, loadAnimationsFromFile(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 // Carga los datos para el modo demostración
void Resource::loadDemoData() 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("demo1.bin")));
demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get("demo2.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 // Añade paletas a las texturas
void Resource::addPalettes() void Resource::addPalettes()
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ">> PALETTES"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> PALETTES");
// Jugador 1 // Jugador 1
getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_1_coffee_palette.gif")); 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) {} : 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 // Tamaño normal
std::vector<NameAndText> strings = { std::vector<NameAndText> strings = {
@@ -307,7 +303,7 @@ void Resource::createTextures()
for (const auto &s : strings) for (const auto &s : strings)
{ {
textures_.emplace_back(ResourceTexture(s.name, text->writeToTexture(s.text, 1, -2))); 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 // Tamaño doble
@@ -322,7 +318,7 @@ void Resource::createTextures()
for (const auto &s : strings2X) for (const auto &s : strings2X)
{ {
textures_.emplace_back(ResourceTexture(s.name, text2->writeToTexture(s.text, 1, -4))); 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) {} : 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<ResourceInfo> resources = { std::vector<ResourceInfo> resources = {
{"04b_25", "04b_25.png", "04b_25.txt"}, {"04b_25", "04b_25.png", "04b_25.txt"},
@@ -353,7 +349,7 @@ void Resource::createText()
texts_.emplace_back(ResourceText(resource.key, std::make_shared<Text>( texts_.emplace_back(ResourceText(resource.key, std::make_shared<Text>(
getTexture(resource.textureFile), getTexture(resource.textureFile),
getTextFile(resource.textFile)))); getTextFile(resource.textFile))));
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Text : %s [ DONE ]", resource.key.c_str()); printWithDots("Text : ", resource.key, "[ DONE ]");
} }
} }

View File

@@ -313,6 +313,8 @@ bool Screen::initSDL()
} }
else else
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** SDL_VIDEO: INITIALIZING\n");
getDisplayInfo(); getDisplayInfo();
// Establece el filtro de la textura // 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; return success;
} }
@@ -378,7 +380,7 @@ void Screen::getDisplayInfo()
SDL_DisplayID instance_id = displays[i]; SDL_DisplayID instance_id = displays[i];
const char *name = SDL_GetDisplayName(instance_id); 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]); auto DM = SDL_GetCurrentDisplayMode(displays[0]);

View File

@@ -1,3 +1,4 @@
#define STB_IMAGE_IMPLEMENTATION
#include "texture.h" #include "texture.h"
#include <SDL3/SDL_error.h> // Para SDL_GetError #include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_log.h> // Para SDL_LogError, SDL_LogCategory, SDL_Log... #include <SDL3/SDL_log.h> // 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 "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a...
#include "utils.h" // Para getFileName, Color, printWithDots #include "utils.h" // Para getFileName, Color, printWithDots
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" // Para stbi_failure_reason, stbi_image_free
// Constructor // Constructor
Texture::Texture(SDL_Renderer *renderer, const std::string &path) Texture::Texture(SDL_Renderer *renderer, const std::string &path)
: renderer_(renderer), : renderer_(renderer),
@@ -73,7 +71,7 @@ bool Texture::loadFromFile(const std::string &file_path)
} }
else else
{ {
printWithDots("Image : ", getFileName(file_path), "[ LOADED ]"); printWithDots("Texture : ", getFileName(file_path), "[ LOADED ]");
} }
int pitch; int pitch;
@@ -286,7 +284,7 @@ std::shared_ptr<Surface> Texture::loadSurface(const std::string &file_path)
width_ = w; width_ = w;
height_ = h; 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; return surface;
} }
@@ -331,7 +329,7 @@ std::vector<Uint32> Texture::loadPaletteFromFile(const std::string &file_path)
} }
else else
{ {
printWithDots("Image : ", getFileName(file_path), "[ LOADED ]"); printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
} }
// Obtener el tamaño del archivo y leerlo en un buffer // Obtener el tamaño del archivo y leerlo en un buffer
@@ -360,7 +358,7 @@ std::vector<Uint32> Texture::loadPaletteFromFile(const std::string &file_path)
palette.push_back((color << 8) | 0xFF); // Resultado: 0xRRGGBBAA 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; return palette;
} }

View File

@@ -302,13 +302,31 @@ bool stringInVector(const std::vector<std::string> &vec, const std::string &str)
// Imprime por pantalla una línea de texto de tamaño fijo rellena con puntos // 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) void printWithDots(const std::string &text1, const std::string &text2, const std::string &text3)
{ {
std::string output = text1; const size_t TOTAL_WIDTH = 50;
size_t dots_count = 50 - text1.length() - text3.length();
output.append(dots_count, '.');
output.append(text2);
output.append(text3);
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 // Carga el fichero de datos para la demo