diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cgol.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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(); |