From 60cf16c8de6c1dfb621d6d85b618a7e125fda964 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Wed, 11 Jun 2025 22:40:00 +0200 Subject: [PATCH] Add key repeat --- TODO.txt | 2 +- game.h | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/TODO.txt b/TODO.txt index 82d2ae9..386da09 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,7 +2,6 @@ fuck issue trackers :D =========== GENERAL ============== -- menu: key repeat? - controller supports? analog input could be "tapping" the keys with varying frequency - frontends: @@ -45,6 +44,7 @@ fuck issue trackers :D =========== HANDLED ============== - should drifting make a sound? NO NEED +- menu: key repeat? - replay validation? maybe yes? - ghost color - make reverse maps diff --git a/game.h b/game.h index 37a3bf3..461bdae 100644 --- a/game.h +++ b/game.h @@ -1366,6 +1366,17 @@ void LCR_gameSaveReplay(void) LCR_gamePopupMessage(LCR_texts[LCR_TEXTS_SAVED]); } +/** + Checks if given key is either immediately pressed or repeated after being + held for some time. +*/ +uint8_t LCR_gameKeyActive(uint8_t key) +{ + return LCR_game.keyStates[key] == 1 || + (LCR_game.keyStates[key] >= (1200 / LCR_SETTING_FPS) + && ((LCR_game.frame & 0x03) == 0)); +} + /** Helper subroutine, handles user input during main loop frame, EXCEPT for the driving input (that is handled in the loop itself). @@ -1470,7 +1481,7 @@ void LCR_gameHandleInput(void) LCR_game.menu.selectedItem = 0; LCR_audioPlaySound(LCR_SOUND_CLICK); } - else if (LCR_game.keyStates[LCR_KEY_UP] == 1) + else if (LCR_gameKeyActive(LCR_KEY_UP)) { LCR_LOG1("menu item up"); @@ -1487,7 +1498,7 @@ void LCR_gameHandleInput(void) scrolled = -1; } } - else if (LCR_game.keyStates[LCR_KEY_DOWN] == 1) + else if (LCR_gameKeyActive(LCR_KEY_DOWN)) { LCR_LOG1("menu item down");