Misc 'catchup' commit on WolframAutomata.c.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Mon, 15 Mar 2021 15:39:05 +0000 (08:39 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Mon, 15 Mar 2021 15:39:05 +0000 (08:39 -0700)
hacks/WolframAutomata/WolframAutomata.c

index faab86b..59562b3 100644 (file)
 /* TODO: I suppose a lot of this stuff goes in the README instead. */
 /* TODO: Explain the data structures in detail. */
 /* TODO: Explain all the options, like the various starting conditions. */
 /* TODO: I suppose a lot of this stuff goes in the README instead. */
 /* 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: 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: Verify everything in this file is C89. Get rid of things like '//' comments, pack all my declarations upfront, no stdint, etc. */
 
 /* 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: Verify everything in this file is C89. Get rid of things like '//' comments, pack all my declarations upfront, no stdint, etc. */
 
 // Command line options
 //        directory to output XBM files of each run (and call an external command to convert to PNGs?)
 //              -save-dir STRING
 // Command line options
 //        directory to output XBM files of each run (and call an external command to convert to PNGs?)
 //              -save-dir STRING
+//              (could use libXpm to save an XPM and then convert to PNG with ImageMagick) (this is a single function call to go from pixmap -> file)
+//              (since it depends on an external library, make this whole feature optional at build-time?)
 //        number of generations to simulate
 //        number of generations to simulate
+//              -random-generations
 //              -num-generations N
 //        delay time (speed of simulation)
 //              -num-generations N
 //        delay time (speed of simulation)
+//              -random-delay
 //              -delay-usec N
 //        foreground and background color
 //              -random-colors (highest precedence)
 //              -delay-usec N
 //        foreground and background color
 //              -random-colors (highest precedence)
@@ -57,6 +63,7 @@
 //                  (the two options above only apply to the simulation under the -rule-random or -rule N options. in curated mode, starting population is defined in the curation array)
 //                  TODO: In the future, add the option for user to pass list of cell IDs to turn ON.
 //        size of pixel square (e.g. 1x1, 2x2, 3x3, etc)
 //                  (the two options above only apply to the simulation under the -rule-random or -rule N options. in curated mode, starting population is defined in the curation array)
 //                  TODO: In the future, add the option for user to pass list of cell IDs to turn ON.
 //        size of pixel square (e.g. 1x1, 2x2, 3x3, etc)
+//              -random-pixel-size
 //              -pixel-size N
 
 /* -------------------------------------------------------------------------- */
 //              -pixel-size N
 
 /* -------------------------------------------------------------------------- */
@@ -231,7 +238,12 @@ render_current_generation(struct state * state)
 static void *
 WolframAutomata_init(Display * dpy, Window win)
 {
 static void *
 WolframAutomata_init(Display * dpy, Window win)
 {
-    struct state * state = calloc(1, sizeof(*state)); // TODO: Check calloc() call
+    struct state * state = calloc(1, sizeof(*state));
+    if (!state) {
+        fprintf(stderr, "ERROR: Failed to calloc() for state struct in WolframAutomata_init().\n");
+        exit(EXIT_FAILURE);
+    }
+
     XGCValues gcv;
     XWindowAttributes xgwa;
     const struct curated_ruleset * curated_ruleset = NULL;
     XGCValues gcv;
     XWindowAttributes xgwa;
     const struct curated_ruleset * curated_ruleset = NULL;
@@ -302,7 +314,7 @@ WolframAutomata_init(Display * dpy, Window win)
     if (state->population_density < 0 || state->population_density > 100) state->population_density = 50;
     state->current_generation = calloc(1, sizeof(*state->current_generation)*state->number_of_cells);
     if (!state->current_generation) {
     if (state->population_density < 0 || state->population_density > 100) state->population_density = 50;
     state->current_generation = calloc(1, sizeof(*state->current_generation)*state->number_of_cells);
     if (!state->current_generation) {
-        fprintf(stderr, "ERROR: Failed to calloc() in WolframAutomata_init().\n");
+        fprintf(stderr, "ERROR: Failed to calloc() for cell generation in WolframAutomata_init().\n");
         exit(EXIT_FAILURE);
     }
     if (curated_ruleset) {
         exit(EXIT_FAILURE);
     }
     if (curated_ruleset) {