mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
fix: double input issue
This commit is contained in:
@@ -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.
|
// 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) {
|
int input_getdat(time_t time) {
|
||||||
static u8 movdat = 0, nmovdat = 0;
|
static u8 movdat = 0, nmovdat = 0, lmovdat = 0;
|
||||||
int mov = movdat, nmov = nmovdat;
|
int mov = movdat, nmov = nmovdat, lmov = lmovdat;
|
||||||
|
|
||||||
// process the event
|
// process the event
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
@@ -65,15 +65,16 @@ int input_getdat(time_t time) {
|
|||||||
|
|
||||||
// compute the current movement
|
// compute the current movement
|
||||||
int mask = timeout_mask(time);
|
int mask = timeout_mask(time);
|
||||||
int cmov = movdat & mask;
|
|
||||||
|
|
||||||
// handle releasing of keys
|
// handle releasing of keys
|
||||||
nmovdat &= movdat;
|
mov &= ~(nmov & lmov & mask); // only remove the keys that have been pressed since lmov
|
||||||
movdat &= ~(nmovdat & mask);
|
lmov = mov;
|
||||||
|
nmov &= mov;
|
||||||
|
int cmov = mov & mask;
|
||||||
|
|
||||||
// write to static variables (shrinking the values, and memory usage)
|
// write to static variables (shrinking the values, and memory usage)
|
||||||
movdat = mov;
|
movdat = mov;
|
||||||
|
lmovdat = lmov;
|
||||||
nmovdat = nmov;
|
nmovdat = nmov;
|
||||||
|
|
||||||
return cmov;
|
return cmov;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user