summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. 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)
commit77f2a708186cd8c620b534ab7dbf4cf7682dba9d (patch)
treeb9a90e730596b6e3d6f731070ebc1ac4a0955599
parent36ef8f3e4affd47a77d40cf09c3b06ea496b4f84 (diff)
downloadcgol-cgol-0.1.zip
cgol-cgol-0.1.tar.gz
cgol-cgol-0.1.tar.bz2
Obey the generations limit.cgol-0.1.1cgol-0.1
-rw-r--r--src/cgol.c13
1 files changed, 10 insertions, 3 deletions
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();