corregit el bug introduit en c35889a840
This commit is contained in:
@@ -325,17 +325,6 @@ void Input::initSDLGamePad() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::resetJustPressed() {
|
|
||||||
for (auto& key : keyboard_.bindings) {
|
|
||||||
key.second.just_pressed = false;
|
|
||||||
}
|
|
||||||
for (auto& gamepad : gamepads_) {
|
|
||||||
for (auto& binding : gamepad->bindings) {
|
|
||||||
binding.second.just_pressed = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Input::resetInputStates() {
|
void Input::resetInputStates() {
|
||||||
// Resetear todos los KeyBindings.active a false
|
// Resetear todos los KeyBindings.active a false
|
||||||
for (auto& key : keyboard_.bindings) {
|
for (auto& key : keyboard_.bindings) {
|
||||||
@@ -360,7 +349,7 @@ void Input::update() {
|
|||||||
bool key_is_down_now = key_states[binding.second.scancode];
|
bool key_is_down_now = key_states[binding.second.scancode];
|
||||||
|
|
||||||
// El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo
|
// El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo
|
||||||
binding.second.just_pressed = binding.second.just_pressed || (key_is_down_now && !binding.second.is_held);
|
binding.second.just_pressed = key_is_down_now && !binding.second.is_held;
|
||||||
binding.second.is_held = key_is_down_now;
|
binding.second.is_held = key_is_down_now;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,16 +367,6 @@ void Input::update() {
|
|||||||
|
|
||||||
auto Input::handleEvent(const SDL_Event& event) -> std::string {
|
auto Input::handleEvent(const SDL_Event& event) -> std::string {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_EVENT_KEY_DOWN:
|
|
||||||
if (!event.key.repeat) {
|
|
||||||
for (auto& [action, binding] : keyboard_.bindings) {
|
|
||||||
if (binding.scancode == event.key.scancode) {
|
|
||||||
binding.just_pressed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_EVENT_GAMEPAD_ADDED:
|
case SDL_EVENT_GAMEPAD_ADDED:
|
||||||
return addGamepad(event.gdevice.which);
|
return addGamepad(event.gdevice.which);
|
||||||
case SDL_EVENT_GAMEPAD_REMOVED:
|
case SDL_EVENT_GAMEPAD_REMOVED:
|
||||||
|
|||||||
@@ -177,7 +177,6 @@ class Input {
|
|||||||
|
|
||||||
// --- Métodos de reseteo de estado de entrada ---
|
// --- Métodos de reseteo de estado de entrada ---
|
||||||
void resetInputStates();
|
void resetInputStates();
|
||||||
void resetJustPressed();
|
|
||||||
|
|
||||||
// --- Eventos ---
|
// --- Eventos ---
|
||||||
auto handleEvent(const SDL_Event& event) -> std::string;
|
auto handleEvent(const SDL_Event& event) -> std::string;
|
||||||
|
|||||||
@@ -1128,7 +1128,6 @@ auto Game::allPlayersAreNotPlaying() -> bool {
|
|||||||
|
|
||||||
// Comprueba los eventos que hay en cola
|
// Comprueba los eventos que hay en cola
|
||||||
void Game::handleEvents() {
|
void Game::handleEvents() {
|
||||||
input_->resetJustPressed();
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user