migrant a SDL3
This commit is contained in:
@@ -52,7 +52,7 @@ void Input::bindKey(InputAction input, SDL_Scancode code)
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(int controller_index, InputAction input, SDL_GameControllerButton button)
|
||||
void Input::bindGameControllerButton(int controller_index, InputAction input, SDL_GamepadButton button)
|
||||
{
|
||||
if (controller_index < num_gamepads_)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ bool Input::checkInput(InputAction input, bool repeat, InputDeviceToUse device,
|
||||
|
||||
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
||||
const bool *keyStates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
@@ -119,13 +119,13 @@ bool Input::checkInput(InputAction input, bool repeat, InputDeviceToUse device,
|
||||
{
|
||||
if (repeat)
|
||||
{
|
||||
success_controller = SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0;
|
||||
success_controller = SDL_GetGamepadButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!controller_bindings_.at(controller_index).at(input_index).active)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0)
|
||||
if (SDL_GetGamepadButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0)
|
||||
{
|
||||
controller_bindings_.at(controller_index).at(input_index).active = true;
|
||||
success_controller = true;
|
||||
@@ -137,7 +137,7 @@ bool Input::checkInput(InputAction input, bool repeat, InputDeviceToUse device,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) == 0)
|
||||
if (SDL_GetGamepadButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) == 0)
|
||||
{
|
||||
controller_bindings_.at(controller_index).at(input_index).active = false;
|
||||
}
|
||||
@@ -156,7 +156,7 @@ bool Input::checkAnyInput(InputDeviceToUse device, int controller_index)
|
||||
{
|
||||
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||
const bool *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
for (int i = 0; i < (int)key_bindings_.size(); ++i)
|
||||
{
|
||||
@@ -174,7 +174,7 @@ bool Input::checkAnyInput(InputDeviceToUse device, int controller_index)
|
||||
{
|
||||
for (int i = 0; i < (int)controller_bindings_.size(); ++i)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][i].button) != 0 && !controller_bindings_[controller_index][i].active)
|
||||
if (SDL_GetGamepadButton(connected_controllers_[controller_index], controller_bindings_[controller_index][i].button) != 0 && !controller_bindings_[controller_index][i].active)
|
||||
{
|
||||
controller_bindings_[controller_index][i].active = true;
|
||||
return true;
|
||||
@@ -222,26 +222,26 @@ bool Input::discoverGameControllers()
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||
if (SDL_WasInit(SDL_INIT_GAMEPAD) != 1)
|
||||
{
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
||||
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;
|
||||
}
|
||||
|
||||
num_joysticks_ = SDL_NumJoysticks();
|
||||
SDL_GetJoysticks(&num_joysticks_);
|
||||
num_gamepads_ = 0;
|
||||
|
||||
// Cuenta el número de mandos
|
||||
joysticks_.clear();
|
||||
for (int i = 0; i < num_joysticks_; ++i)
|
||||
{
|
||||
auto joy = SDL_JoystickOpen(i);
|
||||
auto joy = SDL_OpenJoystick(i);
|
||||
joysticks_.push_back(joy);
|
||||
if (SDL_IsGameController(i))
|
||||
if (SDL_IsGamepad(i))
|
||||
{
|
||||
num_gamepads_++;
|
||||
}
|
||||
@@ -265,11 +265,11 @@ bool Input::discoverGameControllers()
|
||||
for (int i = 0; i < num_gamepads_; i++)
|
||||
{
|
||||
// Abre el mando y lo añade a la lista
|
||||
auto pad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||
auto pad = SDL_OpenGamepad(i);
|
||||
if (SDL_GamepadConnected(pad) == 1)
|
||||
{
|
||||
connected_controllers_.push_back(pad);
|
||||
const std::string name = SDL_GameControllerNameForIndex(i);
|
||||
const std::string name = SDL_GetGamepadNameForID(i);
|
||||
std::cout << "#" << i << ": " << name << std::endl;
|
||||
controller_names_.push_back(name);
|
||||
}
|
||||
@@ -279,7 +279,7 @@ bool Input::discoverGameControllers()
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
SDL_SetGamepadEventsEnabled(true);
|
||||
}
|
||||
|
||||
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||
@@ -300,7 +300,7 @@ int Input::getJoyIndex(int id) const
|
||||
{
|
||||
for (int i = 0; i < num_joysticks_; ++i)
|
||||
{
|
||||
if (SDL_JoystickInstanceID(joysticks_[i]) == id)
|
||||
if (SDL_GetJoystickID(joysticks_[i]) == id)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@@ -334,8 +334,8 @@ void Input::printBindings(InputDeviceToUse device, int controller_index) const
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
||||
SDL_GameControllerButton Input::getControllerBinding(int controller_index, InputAction input) const
|
||||
// Obtiene el SDL_GamepadButton asignado a un input
|
||||
SDL_GamepadButton Input::getControllerBinding(int controller_index, InputAction input) const
|
||||
{
|
||||
return controller_bindings_[controller_index][static_cast<int>(input)].button;
|
||||
}
|
||||
@@ -391,16 +391,16 @@ bool Input::checkAxisInput(InputAction input, int controller_index, bool repeat)
|
||||
switch (input)
|
||||
{
|
||||
case InputAction::LEFT:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -threshold;
|
||||
axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTX) < -threshold;
|
||||
break;
|
||||
case InputAction::RIGHT:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > threshold;
|
||||
axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTX) > threshold;
|
||||
break;
|
||||
case InputAction::UP:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -threshold;
|
||||
axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTY) < -threshold;
|
||||
break;
|
||||
case InputAction::DOWN:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > threshold;
|
||||
axis_active_now = SDL_GetGamepadAxis(connected_controllers_[controller_index], SDL_GAMEPAD_AXIS_LEFTY) > threshold;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user