From cd8a1c3f0dd3ee001afb3c2bc0516f4fa0a8c1d1 Mon Sep 17 00:00:00 2001 From: BroGamer <64546358+BroGamer4256@users.noreply.github.com> Date: Sun, 10 Sep 2023 19:15:30 +1200 Subject: [PATCH] Add queue input system --- src/bnusio.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/bnusio.cpp b/src/bnusio.cpp index 6f1d0b7..b1b04d1 100644 --- a/src/bnusio.cpp +++ b/src/bnusio.cpp @@ -78,10 +78,48 @@ u16 drumMax = 20000; u16 lastHitValue = drumMin; Keybindings *analogButtons[] = {&P1_LEFT_BLUE, &P1_LEFT_RED, &P1_RIGHT_RED, &P1_RIGHT_BLUE, &P2_LEFT_BLUE, &P2_LEFT_RED, &P2_RIGHT_RED, &P2_RIGHT_BLUE}; +u16 buttonWaitPeriodP1 = 0; +u16 buttonWaitPeriodP2 = 0; +std::queue buttonQueueP1; +std::queue buttonQueueP2; + u16 bnusio_GetAnalogIn (u8 which) { auto button = analogButtons[which]; - if (IsButtonTapped (*button)) { + if (which == 0) { + if (buttonWaitPeriodP1 > 0) buttonWaitPeriodP1--; + if (buttonWaitPeriodP2 > 0) buttonWaitPeriodP2--; + } + bool isP1 = which / 4 == 0; + if ((isP1 && !buttonQueueP1.empty ()) || (!isP1 && !buttonQueueP2.empty ())) { + if ((isP1 && buttonQueueP1.front () == which && buttonWaitPeriodP1 == 0) || (!isP1 && buttonQueueP2.front () == which && buttonWaitPeriodP2 == 0)) { + if (isP1) { + buttonQueueP1.pop (); + buttonWaitPeriodP1 = 4; + } else { + buttonQueueP2.pop (); + buttonWaitPeriodP2 = 4; + } + + lastHitValue++; + if (lastHitValue >= drumMax) lastHitValue = drumMin; + return lastHitValue; + } + if (IsButtonTapped (*button)) { + if (isP1) buttonQueueP1.push (which); + else buttonQueueP2.push (which); + } + return 0; + } else if (IsButtonTapped (*button)) { + if (isP1 && buttonWaitPeriodP1 > 0) { + buttonQueueP1.push (which); + return 0; + } else if (!isP1 && buttonWaitPeriodP2 > 0) { + buttonQueueP2.push (which); + return 0; + } + if (isP1) buttonWaitPeriodP1 = 4; + else buttonWaitPeriodP2 = 4; lastHitValue++; if (lastHitValue >= drumMax) lastHitValue = drumMin; return lastHitValue;