aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-11-08 14:21:07 +0000
committerrodri <rgl@antares-labs.eu>2024-11-08 14:21:07 +0000
commitc0323562b7f330bc1cc62aa694c8251f14681f1f (patch)
tree164d1596781f740ca8a59e05bca8c807ad0ab6f7
parent308418de2078b951963b9d902bad6f640a60e0e5 (diff)
downloadbattleship-c0323562b7f330bc1cc62aa694c8251f14681f1f.tar.gz
battleship-c0323562b7f330bc1cc62aa694c8251f14681f1f.tar.bz2
battleship-c0323562b7f330bc1cc62aa694c8251f14681f1f.zip
bts: poll matches automatically.
before, it was necessary for the user to press w every time they wanted to get the most recent list of matches, which is dumb.
-rw-r--r--bts.c30
-rw-r--r--dat.h2
2 files changed, 27 insertions, 5 deletions
diff --git a/bts.c b/bts.c
index dc42b60..84cb040 100644
--- a/bts.c
+++ b/bts.c
@@ -871,11 +871,6 @@ key(Rune r)
threadexitsall(nil);
nbsend(reconnc, nil);
break;
- case 'w':
- if(game.state != Waiting0)
- break;
- chanprint(egress, "watch\n");
- break;
}
}
@@ -1073,6 +1068,29 @@ soundproc(void *)
}
void
+timerproc(void *)
+{
+ uvlong t0, Δt, acc;
+
+ threadsetname("timer");
+
+ t0 = nsec();
+ acc = 0;
+ for(;;){
+ Δt = nsec() - t0;
+ acc += Δt;
+
+ if(game.state == Waiting0 && acc >= 5*SEC){
+ chanprint(egress, "watch\n");
+ acc = 0;
+ }
+
+ t0 += Δt;
+ sleep(HZ2MS(10));
+ }
+}
+
+void
netrecvthread(void *arg)
{
Ioproc *io;
@@ -1208,6 +1226,8 @@ threadmain(int argc, char *argv[])
threadcreate(netsendthread, &fd, mainstacksize);
nbsend(drawchan, nil);
+ proccreate(timerproc, nil, mainstacksize);
+
enum { MOUSE, RESIZE, KEYS, DRAW, RECONN, NONE };
Alt a[] = {
[MOUSE] {mc->c, &mc->Mouse, CHANRCV},
diff --git a/dat.h b/dat.h
index fba1c16..c7b7cee 100644
--- a/dat.h
+++ b/dat.h
@@ -1,3 +1,5 @@
+#define SEC 1000000000ULL
+
enum {
Twater,
Tship,