From 77f2a708186cd8c620b534ab7dbf4cf7682dba9d Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sun, 18 Dec 2011 04:25:48 -0500 Subject: Obey the generations limit. --- diff --git a/src/cgol.c b/src/cgol.c index d6b28e3..3bc1686 100644 --- a/src/cgol.c +++ b/src/cgol.c @@ -44,7 +44,7 @@ static bool *grid_cur, *grid_next; int main(int argc, char **argv) { - int opt, c; + int opt, i, c; width = 0; height = 0; @@ -86,12 +86,19 @@ main(int argc, char **argv) /* TODO: Write a better main event loop with a good controller and timer. */ timeout(1000); - for (;;) { + + /* NB: i starts at -1 so we don't exit immediately after showing the last + * desired state. */ + for (i = -1; gens == 0 || i < gens; ++i) { c = getch(); if (c == 'q') { break; } - tick(); + /* Calculate the next generation only if it is to be shown on the + * screen. */ + if (gens == 0 || i + 1 < gens) { + tick(); + } } fini_game(); -- cgit v0.9.1