From 00db0cda7e200d84f4f94eba0618913163110cf1 Mon Sep 17 00:00:00 2001 From: Quinn Date: Tue, 1 Jul 2025 12:04:30 +0200 Subject: [PATCH] fix: double input issue --- src/io/input.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/io/input.c b/src/io/input.c index 0848394..40b3845 100644 --- a/src/io/input.c +++ b/src/io/input.c @@ -50,8 +50,8 @@ static int timeout_mask(time_t time) { // NOTE: if an action is mapped to multiple keys, pressing both and releasing one will cause the action to be disabled. Minor issue, Won't fix. int input_getdat(time_t time) { - static u8 movdat = 0, nmovdat = 0; - int mov = movdat, nmov = nmovdat; + static u8 movdat = 0, nmovdat = 0, lmovdat = 0; + int mov = movdat, nmov = nmovdat, lmov = lmovdat; // process the event SDL_Event e; @@ -65,15 +65,16 @@ int input_getdat(time_t time) { // compute the current movement int mask = timeout_mask(time); - int cmov = movdat & mask; // handle releasing of keys - nmovdat &= movdat; - movdat &= ~(nmovdat & mask); + mov &= ~(nmov & lmov & mask); // only remove the keys that have been pressed since lmov + lmov = mov; + nmov &= mov; + int cmov = mov & mask; // write to static variables (shrinking the values, and memory usage) movdat = mov; + lmovdat = lmov; nmovdat = nmov; - return cmov; }