diff options
author | P. J. McDermott <pjm@nac.net> | 2011-12-18 04:25:48 (EST) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2011-12-18 04:25:48 (EST) |
commit | 77f2a708186cd8c620b534ab7dbf4cf7682dba9d (patch) | |
tree | b9a90e730596b6e3d6f731070ebc1ac4a0955599 /src | |
parent | 36ef8f3e4affd47a77d40cf09c3b06ea496b4f84 (diff) | |
download | cgol-cgol-0.1.1.zip cgol-cgol-0.1.1.tar.gz cgol-cgol-0.1.1.tar.bz2 |
Obey the generations limit.cgol-0.1.1cgol-0.1
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(); |