ref: 3db49bf5553d1e91a66dd43e37b6a77957600ca5
parent: bc00a5fd2c07b36e8862e0d0ad7b667b5c7e5ad4
author: qwx <qwx@sciops.net>
date: Sat Mar 15 07:05:41 EDT 2025
input fixes - stop key repeat once a piece is frozen - prevent key repeat from retransmitting non-repeatable actions - delay first key repeat for longer - fix swapped a/b joystick buttons
--- a/dat.h
+++ b/dat.h
@@ -49,6 +49,7 @@
Krotl = 1<<4,
Krotr = 1<<5,
Khold = 1<<6,
+ Ktriggers = K↑ | Krotl | Krotr | Khold,
Tspeed0 = 1, /* seconds */
};
--- a/fns.h
+++ b/fns.h
@@ -1,3 +1,4 @@
+void disengage(void);
int collide(int, int, int);
void hold(void);
void drop(void);
--- a/game.c
+++ b/game.c
@@ -161,6 +161,7 @@
}
}
clearlines();
+ disengage();
cur = nil;
}
--- a/gm4s.c
+++ b/gm4s.c
@@ -48,21 +48,27 @@
static void
pollproc(void *)
{
- ulong k;
+ int dt;
+ ulong k, ke, old;
- for(;;){
- if(recv(keychan, &k) < 0)
+ for(old=0;;){
+ if(recv(keychan, &ke) < 0)
return;
+ k = ke ^ ke & old;
+ old = ke & Ktriggers;
if(k == 0)
continue;
if(send(evc, &k) < 0)
return;
- for(k&=Kmove; k&Kmove; k&=Kmove){
- sleep(40);
- if(nbrecv(keychan, &k) < 0)
- return;
+ for(dt=125, k&=Kmove; k&Kmove; k&=Kmove){
+ sleep(dt);
+ switch(nbrecv(keychan, &ke)){
+ case -1: return;
+ case 1: k = ke ^ ke & old; old = ke & Ktriggers; break;
+ }
if(send(evc, &k) < 0)
return;
+ dt = 40;
}
}
}
@@ -85,6 +91,12 @@
}
void
+disengage(void)
+{
+ sendul(keychan, 0);
+}
+
+void
threadmain(int argc, char **argv)
{
ulong k;
@@ -103,8 +115,8 @@
regkey("down", Kdown, K↓);
regkey("left", Kleft, K←);
regkey("right", Kright, K→);
- regkey("a", 'z', Krotl);
- regkey("b", 'x', Krotr);
+ regkey("b", 'z', Krotl);
+ regkey("a", 'x', Krotr);
regkey("l1", ' ', Khold);
if(proccreate(pollproc, nil, 4096) < 0)
sysfatal("proccreate: %r");