From 651dbe5ad79484663b59b64fc3ec9afc83c714bb Mon Sep 17 00:00:00 2001 From: Inori Date: Mon, 2 Sep 2019 12:48:18 -0400 Subject: [PATCH] Delay repeating raw keystates --- src/input.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/input.cpp b/src/input.cpp index 598c5a8f..9778a0ab 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -454,7 +454,9 @@ struct InputPrivate uint8_t *rawStatesOld; Input::ButtonCode repeating; + int rawRepeating; unsigned int repeatCount; + unsigned int rawRepeatCount; struct { @@ -560,7 +562,15 @@ struct InputPrivate b.pressed = rawStates[scancode]; b.triggered = (rawStates[scancode] && !rawStatesOld[scancode]); - b.repeated = (rawStates[scancode] && rawStatesOld[scancode]); + + bool repeated; + if (rgssVer >= 2) + repeated = rawRepeatCount >= 23 && ((rawRepeatCount+1) % 6) == 0; + else + repeated = rawRepeatCount >= 15 && ((rawRepeatCount+1) % 4) == 0; + + b.repeated = repeated; + return b; break; } @@ -738,6 +748,24 @@ struct InputPrivate void updateRaw() { memcpy(rawStates, shState->eThread().keyStates, SDL_NUM_SCANCODES); + + for (int i = 1; i < 255; i++) + { + if (rawStates[i] && rawStatesOld[i]) + { + if (rawRepeating == i) + { + rawRepeatCount++; + } + else + { + rawRepeatCount = 0; + rawRepeating = i; + } + + break; + } + } } void updateDir4()