Modified WolframAutomata to loop with new settings upon completing a simulation.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Sun, 21 Mar 2021 23:14:22 +0000 (16:14 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Sun, 21 Mar 2021 23:14:22 +0000 (16:14 -0700)
hacks/WolframAutomata/WolframAutomata.c

index 35482df..c788f01 100644 (file)
@@ -11,7 +11,7 @@
 /* TODO: Explain the data structures in detail. */
 /* TODO: Explain all the options, like the various starting conditions. */
 /* TODO: Explain all the dependencies like libXpm. */
 /* TODO: Explain the data structures in detail. */
 /* TODO: Explain all the options, like the various starting conditions. */
 /* TODO: Explain all the dependencies like libXpm. */
-
+/* TODO: Explain that the program is inherently double-buffered but if you don't have VSync turned on, all those alternating lines are going to look terrible when they scroll upward. */
 
 /* TODO: Add a #define for the hack version. */
 /* TODO: Check manpage for all functions I use and ensure my includes are correct. I don't want to depend on picking up includes via screenhack.h. */
 
 /* TODO: Add a #define for the hack version. */
 /* TODO: Check manpage for all functions I use and ensure my includes are correct. I don't want to depend on picking up includes via screenhack.h. */
@@ -266,6 +266,22 @@ render_current_generation(struct state * state)
 /* Screenhack API Functions                                                   */
 /* -------------------------------------------------------------------------- */
 
 /* Screenhack API Functions                                                   */
 /* -------------------------------------------------------------------------- */
 
+static Bool
+WolframAutomata_event(Display * dpy, Window win, void * closure, XEvent * event)
+{
+    return False;
+}
+
+static void
+WolframAutomata_free(Display * dpy, Window win, void * closure)
+{
+    struct state * state = closure;
+    XFreeGC(state->dpy, state->gc);
+    XFreePixmap(state->dpy, state->evolution_history);
+    free(state->current_generation);
+    free(state);
+}
+
 static void *
 WolframAutomata_init(Display * dpy, Window win)
 {
 static void *
 WolframAutomata_init(Display * dpy, Window win)
 {
@@ -478,8 +494,8 @@ WolframAutomata_draw(Display * dpy, Window win, void * closure)
     } else {
         // TODO: Wait for a second or two, clear the screen and do a new iteration with suitably changed settings.
         // Note: Since we can't actually loop or sleep here, we need to add a flag to the state struct to indicate that we're in an 'admiration timewindow' (and indicate when it should end)
     } else {
         // TODO: Wait for a second or two, clear the screen and do a new iteration with suitably changed settings.
         // Note: Since we can't actually loop or sleep here, we need to add a flag to the state struct to indicate that we're in an 'admiration timewindow' (and indicate when it should end)
-        printf("infinite hamster wheel\n");
-        while (1) continue;
+        WolframAutomata_free(dpy, win, state);
+        closure = WolframAutomata_init(dpy, win);
     }
 
     // Calculate the vertical offset of the current 'window' into the history
     }
 
     // Calculate the vertical offset of the current 'window' into the history
@@ -536,22 +552,6 @@ static XrmOptionDescRec WolframAutomata_options[] = {
     { 0, 0, 0, 0 }
 };
 
     { 0, 0, 0, 0 }
 };
 
-static Bool
-WolframAutomata_event(Display * dpy, Window win, void * closure, XEvent * event)
-{
-    return False;
-}
-
-static void
-WolframAutomata_free(Display * dpy, Window win, void * closure)
-{
-    struct state * state = closure;
-    XFreeGC(state->dpy, state->gc);
-    XFreePixmap(state->dpy, state->evolution_history);
-    free(state->current_generation);
-    free(state);
-}
-
 static void
 WolframAutomata_reshape(Display * dpy, Window win, void * closure, unsigned int w, unsigned int h)
 {
 static void
 WolframAutomata_reshape(Display * dpy, Window win, void * closure, unsigned int w, unsigned int h)
 {