diff options
author | rodri <rgl@antares-labs.eu> | 2023-10-11 10:23:02 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2023-10-11 10:23:02 +0000 |
commit | 891e6af8da9b09659355c663e55330b2b60ef3a9 (patch) | |
tree | ea7420814399beb9fc0dd03137041825760eb60b | |
parent | 81f081e0f4d1de2bb044744c5a295871c65c296d (diff) | |
download | boids-891e6af8da9b09659355c663e55330b2b60ef3a9.tar.gz boids-891e6af8da9b09659355c663e55330b2b60ef3a9.tar.bz2 boids-891e6af8da9b09659355c663e55330b2b60ef3a9.zip |
-rw-r--r-- | main.c | 31 |
1 files changed, 28 insertions, 3 deletions
@@ -6,6 +6,8 @@ #include <keyboard.h> #include <geometry.h> +#define HZ2MS(hz) (1000/(hz)) + enum { TERMINALV = 40, BORDER = 100 @@ -43,6 +45,8 @@ RFrame worldrf; Image *pal[NCOLOR]; Flock *flock; int nbirds; +int paused; +QLock pauselk; void flockseparate(Flock*); void flockalign(Flock*); @@ -240,10 +244,10 @@ rmb(Mousectl *mc, Keyboardctl *kc) static Menu menu = { .item = items }; char buf[128]; - switch(menuhit(3, mc, &menu, nil)){ + switch(menuhit(3, mc, &menu, _screen)){ case NBIRDS: snprint(buf, sizeof buf, "%d", nbirds); - enter("nbirds", buf, sizeof buf, mc, kc, nil); + enter("nbirds", buf, sizeof buf, mc, kc, _screen); nbirds = strtol(buf, nil, 10); case RESET: srand(time(nil)); @@ -267,12 +271,32 @@ key(Rune r) case 'q': threadexitsall(nil); case ' ': - flock->step(flock); + if(paused) + qunlock(&pauselk); + else + qlock(&pauselk); + paused = !paused; break; } } void +runsim(void *) +{ + Ioproc *io; + + io = ioproc(); + + for(;;){ + qlock(&pauselk); + flock->step(flock); + qunlock(&pauselk); + redraw(); + iosleep(io, HZ2MS(24)); + } +} + +void usage(void) { fprint(2, "usage: %s [-n nbirds]\n", argv0); @@ -313,6 +337,7 @@ threadmain(int argc, char *argv[]) display->locking = 1; unlockdisplay(display); + threadcreate(runsim, nil, mainstacksize); redraw(); for(;;){ |