X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fworm.c;h=2029b34f9e3cefdd00d0c3d4a03ef3b88baf103a;hb=b5df67bc6814f67b5562171c53e3720a30819bba;hp=d78f9b9621ed9c184140ad17cff8a9f7bcfa10ae;hpb=d44d7f381ba0173521cb788ba3adb12e261e5c96;p=ncurses.git diff --git a/test/worm.c b/test/worm.c index d78f9b96..2029b34f 100644 --- a/test/worm.c +++ b/test/worm.c @@ -61,7 +61,7 @@ Options: traces will be dumped. The program stops and waits for one character of input at the beginning and end of the interval. - $Id: worm.c,v 1.56 2008/02/23 23:08:57 tom Exp $ + $Id: worm.c,v 1.58 2008/10/04 21:54:09 tom Exp $ */ #include @@ -109,6 +109,7 @@ static const char *field; static int length = 16, number = 3; static chtype trail = ' '; +static unsigned pending; #ifdef TRACE static int generation, trace_start, trace_end; #endif /* TRACE */ @@ -227,6 +228,8 @@ draw_worm(WINDOW *win, void *data) { WORM *w = (WORM *) data; const struct options *op; + unsigned mask = ~(1 << (w - worm)); + chtype attrs = w->attrs | ((mask & pending) ? A_REVERSE : 0); int x; int y; @@ -236,7 +239,7 @@ draw_worm(WINDOW *win, void *data) if ((x = w->xpos[h = w->head]) < 0) { wmove(win, y = w->ypos[h] = last_y, x = w->xpos[h] = 0); - waddch(win, w->attrs); + waddch(win, attrs); refs[y][x]++; } else { y = w->ypos[h]; @@ -299,7 +302,7 @@ draw_worm(WINDOW *win, void *data) if (y < 0) y = 0; - waddch(win, w->attrs); + waddch(win, attrs); w->ypos[h] = y; w->xpos[h] = x; @@ -311,9 +314,11 @@ draw_worm(WINDOW *win, void *data) #ifdef USE_PTHREADS static bool -quit_worm(void) +quit_worm(int bitnum) { + pending |= (1 << bitnum); napms(10); /* let the other thread(s) have a chance */ + pending &= ~(1 << bitnum); return quitting; } @@ -322,7 +327,7 @@ start_worm(void *arg) { unsigned long compare = 0; Trace(("start_worm")); - while (!quit_worm()) { + while (!quit_worm(((struct worm *) arg) - worm)) { while (compare < sequence) { ++compare; use_window(stdscr, draw_worm, arg); @@ -351,7 +356,7 @@ draw_all_worms(void) } #else for (n = 0, w = &worm[0]; n < number; n++, w++) { - if (use_window(stdscr, draw_worm, w)) + if (USING_WINDOW2(stdscr, draw_worm, w)) done = TRUE; } #endif