diff options
author | rodri <rgl@antares-labs.eu> | 2024-11-08 14:21:07 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-11-08 14:21:07 +0000 |
commit | c0323562b7f330bc1cc62aa694c8251f14681f1f (patch) | |
tree | 164d1596781f740ca8a59e05bca8c807ad0ab6f7 /bts.c | |
parent | 308418de2078b951963b9d902bad6f640a60e0e5 (diff) | |
download | battleship-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.
Diffstat (limited to 'bts.c')
-rw-r--r-- | bts.c | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -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}, |