Passant std::cout a SDL_Log

This commit is contained in:
2025-03-27 19:57:30 +01:00
parent c6288918b2
commit 8afca398e9
27 changed files with 588 additions and 764 deletions

View File

@@ -1,9 +1,9 @@
#include "input.h"
#include <SDL3/SDL.h> // Para SDL_GetError
#include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_init.h> // Para SDL_INIT_GAMEPAD, SDL_InitSubSystem
#include <SDL3/SDL_keyboard.h> // Para SDL_GetKeyboardState
#include <SDL3/SDL_log.h> // Para SDL_LogInfo, SDL_LogCategory, SDL_Log...
#include <algorithm> // Para find
#include <iostream> // Para basic_ostream, operator<<, basic_ostr...
#include <iterator> // Para distance
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
#include <utility> // Para pair
@@ -226,7 +226,7 @@ bool Input::discoverGameControllers()
if (SDL_AddGamepadMappingsFromFile(game_controller_db_path_.c_str()) < 0)
{
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: could not load %s file: %s", game_controller_db_path_.c_str(), SDL_GetError());
}
SDL_GetJoysticks(&num_joysticks_);
@@ -244,15 +244,15 @@ bool Input::discoverGameControllers()
}
}
std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOOKING FOR GAME CONTROLLERS");
if (num_joysticks_ != num_gamepads_)
{
std::cout << "Joysticks found: " << num_joysticks_ << std::endl;
std::cout << "Gamepads found : " << num_gamepads_ << std::endl;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Joysticks found: %d", num_joysticks_);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Gamepads found : %d", num_gamepads_);
}
else
{
std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Gamepads found: %d", num_gamepads_);
}
if (num_gamepads_ > 0)
@@ -267,19 +267,19 @@ bool Input::discoverGameControllers()
{
connected_controllers_.push_back(pad);
const std::string name = SDL_GetGamepadNameForID(i);
std::cout << "#" << i << ": " << name << std::endl;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "#%d: %s", i, name.c_str());
controller_names_.push_back(name);
}
else
{
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetError() = %s", SDL_GetError());
}
}
SDL_SetGamepadEventsEnabled(true);
}
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** FINISHED LOOKING FOR GAME CONTROLLERS");
return found;
}
@@ -321,12 +321,12 @@ void Input::printBindings(InputDeviceToUse device, int controller_index) const
}
// Muestra el nombre del mando
std::cout << "\n" + controller_names_.at(controller_index) << std::endl;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n%s", controller_names_.at(controller_index).c_str());
// Muestra los botones asignados
for (auto bi : button_inputs_)
{
std::cout << to_string(bi) << " : " << controller_bindings_.at(controller_index).at(static_cast<int>(bi)).button << std::endl;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%s : %d", to_string(bi).c_str(), controller_bindings_.at(controller_index).at(static_cast<int>(bi)).button);
}
}
}