Fix Pacman pause button glitches (again) (#1906)

This commit is contained in:
Mark Thompson 2024-02-16 00:50:50 -06:00 committed by GitHub
parent 13fd1b1f3b
commit ce08d93ae2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -33,23 +33,27 @@ void PacmanView::paint(Painter& painter) {
}
auto switches_raw = swizzled_switches() & ((1 << (int)Switch::Right) | (1 << (int)Switch::Left) | (1 << (int)Switch::Down) | (1 << (int)Switch::Up) | (1 << (int)Switch::Sel) | (1 << (int)Switch::Dfu));
auto switches_debounced = get_switches_state().to_ulong();
// For the Select (Start/Pause) button, wait for release to avoid repeat
uint8_t buttons_to_wait_for = (1 << (int)Switch::Sel);
if (wait_for_button_release) {
if ((switches_raw & buttons_to_wait_for) == 0)
if ((switches_debounced & buttons_to_wait_for) == 0)
wait_for_button_release = false;
switches_raw &= ~buttons_to_wait_for;
switches_debounced &= ~buttons_to_wait_for;
} else {
if (switches_raw & buttons_to_wait_for)
if (switches_debounced & buttons_to_wait_for)
wait_for_button_release = true;
}
// For the directional buttons, use the raw inputs for fastest response time
but_RIGHT = (switches_raw & (1 << (int)Switch::Right)) != 0;
but_LEFT = (switches_raw & (1 << (int)Switch::Left)) != 0;
but_DOWN = (switches_raw & (1 << (int)Switch::Down)) != 0;
but_UP = (switches_raw & (1 << (int)Switch::Up)) != 0;
but_A = (switches_raw & (1 << (int)Switch::Sel)) != 0;
// For the pause button, use the debounced input to avoid glitches, and OR in the value to make sure that we don't clear it before it's seen
but_A |= (switches_debounced & (1 << (int)Switch::Sel)) != 0;
_game.Step();
}