input: allow holding down forward/back to move through saves

Resolves #171.
This commit is contained in:
walkawayy 2022-01-11 13:35:44 -05:00 committed by GitHub
parent 7f65d652ba
commit be830d28d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,16 +2,38 @@
#include "specific/s_input.h"
#define DELAY_FRAMES 12
#define HOLD_FRAMES 3
INPUT_STATE g_Input = { 0 };
INPUT_STATE g_InputDB = { 0 };
INPUT_STATE g_OldInputDB = { 0 };
static int32_t m_HoldBack = 0;
static int32_t m_HoldForward = 0;
static INPUT_STATE Input_GetDebounced(INPUT_STATE input);
INPUT_STATE Input_GetDebounced(INPUT_STATE input)
{
INPUT_STATE result;
result.any = input.any & ~g_OldInputDB.any;
// Allow holding down key to move faster
if (input.forward || !input.back) {
m_HoldBack = 0;
} else if (input.back && ++m_HoldBack >= DELAY_FRAMES + HOLD_FRAMES) {
result.back = 1;
m_HoldBack = DELAY_FRAMES;
}
if (!input.forward || input.back) {
m_HoldForward = 0;
} else if (input.forward && ++m_HoldForward >= DELAY_FRAMES + HOLD_FRAMES) {
result.forward = 1;
m_HoldForward = DELAY_FRAMES;
}
g_OldInputDB = input;
return result;
}