migrant input: ja compila, ja no peta... falta descomentar mig codi

This commit is contained in:
2025-07-31 12:02:16 +02:00
parent 2d9a6e744e
commit 89a0638a89
13 changed files with 171 additions and 142 deletions

View File

@@ -5,6 +5,7 @@
#include <iostream>
#include <memory> // Para std::unique_ptr
#include <string> // Para basic_string, string
#include <unordered_map>
#include <vector> // Para vector
/*
@@ -92,21 +93,58 @@ class Input {
: button(btn), is_held(is_held), just_pressed(just_pressed), axis_active(axis_act) {}
};
struct Keyboard {
std::unordered_map<Input::Action, KeyState> bindings;
Keyboard()
: bindings{
{Input::Action::UP, KeyState(SDL_SCANCODE_UP)},
{Input::Action::DOWN, KeyState(SDL_SCANCODE_DOWN)},
{Input::Action::LEFT, KeyState(SDL_SCANCODE_LEFT)},
{Input::Action::RIGHT, KeyState(SDL_SCANCODE_RIGHT)},
{Input::Action::FIRE_LEFT, KeyState(SDL_SCANCODE_Q)},
{Input::Action::FIRE_CENTER, KeyState(SDL_SCANCODE_W)},
{Input::Action::FIRE_RIGHT, KeyState(SDL_SCANCODE_E)},
{Input::Action::START, KeyState(SDL_SCANCODE_RETURN)},
{Input::Action::SERVICE, KeyState(SDL_SCANCODE_0)},
{Input::Action::SM_SELECT, KeyState(SDL_SCANCODE_RETURN)},
{Input::Action::SM_BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
{Input::Action::EXIT, KeyState(SDL_SCANCODE_ESCAPE)},
{Input::Action::PAUSE, KeyState(SDL_SCANCODE_P)},
{Input::Action::BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
{Input::Action::WINDOW_DEC_SIZE, KeyState(SDL_SCANCODE_F1)},
{Input::Action::WINDOW_INC_SIZE, KeyState(SDL_SCANCODE_F2)},
{Input::Action::WINDOW_FULLSCREEN, KeyState(SDL_SCANCODE_F3)},
{Input::Action::TOGGLE_VIDEO_SHADERS, KeyState(SDL_SCANCODE_F4)},
{Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, KeyState(SDL_SCANCODE_F5)},
{Input::Action::TOGGLE_VIDEO_VSYNC, KeyState(SDL_SCANCODE_F6)},
{Input::Action::TOGGLE_AUDIO, KeyState(SDL_SCANCODE_F7)},
{Input::Action::TOGGLE_AUTO_FIRE, KeyState(SDL_SCANCODE_F8)},
{Input::Action::CHANGE_LANG, KeyState(SDL_SCANCODE_F9)},
{Input::Action::RESET, KeyState(SDL_SCANCODE_F10)},
{Input::Action::SHOW_INFO, KeyState(SDL_SCANCODE_F12)}} {}
};
struct Gamepad {
SDL_Gamepad *pad;
SDL_JoystickID instance_id;
std::string name;
std::vector<ButtonState> button_states;
std::unordered_map<Input::Action, ButtonState> bindings;
Gamepad(SDL_Gamepad *gamepad)
: pad(gamepad),
instance_id(SDL_GetJoystickID(SDL_GetGamepadJoystick(gamepad))),
name(std::string(SDL_GetGamepadName(gamepad)) + " #" + std::to_string(instance_id)) {}
name(std::string(SDL_GetGamepadName(gamepad)) + " #" + std::to_string(instance_id)),
bindings{
{Input::Action::FIRE_LEFT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)},
{Input::Action::FIRE_CENTER, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)},
{Input::Action::FIRE_RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_EAST)},
{Input::Action::START, ButtonState(SDL_GAMEPAD_BUTTON_START)},
{Input::Action::SERVICE, ButtonState(SDL_GAMEPAD_BUTTON_BACK)}} {}
~Gamepad() {
if (pad) {
SDL_CloseGamepad(pad);
// std::cout << "Gamepad cerrado (ID " << instance_id << ")\n";
}
}
};
@@ -154,7 +192,7 @@ class Input {
// --- Variables internas ---
std::vector<std::shared_ptr<Gamepad>> gamepads_; // Mandos conectados
std::vector<KeyState> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
Keyboard keyboard_; // Estructura con las asociaciones de teclas a acciones
std::vector<Action> button_inputs_; // Inputs asignados al jugador y a botones, excluyendo direcciones
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt