From 20848f707109f41eb39afbd2cdb3147a286c7dbe Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Sun, 21 Mar 2021 16:14:22 -0700 Subject: [PATCH] Modified WolframAutomata to loop with new settings upon completing a simulation. --- hacks/WolframAutomata/WolframAutomata.c | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/hacks/WolframAutomata/WolframAutomata.c b/hacks/WolframAutomata/WolframAutomata.c index 35482df..c788f01 100644 --- a/hacks/WolframAutomata/WolframAutomata.c +++ b/hacks/WolframAutomata/WolframAutomata.c @@ -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 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. */ @@ -266,6 +266,22 @@ render_current_generation(struct state * state) /* 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) { @@ -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) - 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 @@ -536,22 +552,6 @@ static XrmOptionDescRec WolframAutomata_options[] = { { 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) { -- 2.20.1