refactor: tornar std::ranges::{any,all,find}_of a bucles for explícits
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_GetGamepadAxis, SDL_GamepadAxis, SDL_GamepadButton, SDL_GetError, SDL_JoystickID, SDL_AddGamepadMappingsFromFile, SDL_Event, SDL_EventType, SDL_GetGamepadButton, SDL_GetKeyboardState, SDL_INIT_GAMEPAD, SDL_InitSubSystem, SDL_LogError, SDL_OpenGamepad, SDL_PollEvent, SDL_WasInit, Sint16, SDL_Gamepad, SDL_LogCategory, SDL_Scancode
|
||||
|
||||
#include <algorithm> // Para std::ranges::any_of
|
||||
#include <iostream> // Para basic_ostream, operator<<, cout, cerr
|
||||
#include <memory> // Para shared_ptr, __shared_ptr_access, allocator, operator==, make_shared
|
||||
#include <unordered_map> // Para unordered_map, _Node_iterator, operator==, _Node_iterator_base, _Node_const_iterator
|
||||
@@ -166,9 +165,12 @@ auto Input::checkAnyButton(bool repeat) -> bool {
|
||||
|
||||
// Comprueba si algún player (P1 o P2) presionó alguna acción de una lista
|
||||
auto Input::checkAnyPlayerAction(const std::span<const InputAction>& actions, bool repeat) -> bool {
|
||||
return std::ranges::any_of(actions, [this, repeat](const InputAction& action) {
|
||||
return checkActionPlayer1(action, repeat) || checkActionPlayer2(action, repeat);
|
||||
});
|
||||
for (const auto& action : actions) {
|
||||
if (checkActionPlayer1(action, repeat) || checkActionPlayer2(action, repeat)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba si hay algun mando conectado
|
||||
@@ -441,9 +443,13 @@ auto Input::addGamepad(int device_index) -> std::string {
|
||||
}
|
||||
|
||||
auto Input::removeGamepad(SDL_JoystickID id) -> std::string {
|
||||
auto it = std::ranges::find_if(gamepads_, [id](const std::shared_ptr<Gamepad>& gamepad) {
|
||||
return gamepad->instance_id == id;
|
||||
});
|
||||
auto it = gamepads_.end();
|
||||
for (auto i = gamepads_.begin(); i != gamepads_.end(); ++i) {
|
||||
if ((*i)->instance_id == id) {
|
||||
it = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (it != gamepads_.end()) {
|
||||
std::string name = (*it)->name;
|
||||
|
||||
Reference in New Issue
Block a user