From c0323562b7f330bc1cc62aa694c8251f14681f1f Mon Sep 17 00:00:00 2001 From: rodri Date: Fri, 8 Nov 2024 14:21:07 +0000 Subject: 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. --- bts.c | 30 +++++++++++++++++++++++++----- dat.h | 2 ++ 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; } } @@ -1072,6 +1067,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) { @@ -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, -- cgit v1.2.3