ref: c0323562b7f330bc1cc62aa694c8251f14681f1f
parent: 308418de2078b951963b9d902bad6f640a60e0e5
author: rodri <rgl@antares-labs.eu>
date: Fri Nov 8 09:21:07 EST 2024
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.
--- a/bts.c
+++ b/bts.c
@@ -871,11 +871,6 @@
threadexitsall(nil);
nbsend(reconnc, nil);
break;
- case 'w':
- if(game.state != Waiting0)
- break;
- chanprint(egress, "watch\n");
- break;
}
}
@@ -1073,6 +1068,29 @@
}
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;
@@ -1207,6 +1225,8 @@
threadcreate(netrecvthread, &fd, mainstacksize);
threadcreate(netsendthread, &fd, mainstacksize);
nbsend(drawchan, nil);
+
+ proccreate(timerproc, nil, mainstacksize);
enum { MOUSE, RESIZE, KEYS, DRAW, RECONN, NONE };
Alt a[] = {
--- a/dat.h
+++ b/dat.h
@@ -1,3 +1,5 @@
+#define SEC 1000000000ULL
+
enum {
Twater,
Tship,