]> git.friedersdorff.com Git - max/gol.git/commitdiff
Modifications
authorMaximilian Friedersdorff <max@friedersdorff.com>
Fri, 31 Mar 2017 15:05:58 +0000 (16:05 +0100)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Fri, 31 Mar 2017 15:05:58 +0000 (16:05 +0100)
gol.c

diff --git a/gol.c b/gol.c
index eba691465dce3df4c21208363d93c9ce50590eba..e5e5c4f05072cfe0f374a0d52c0f435bc35faf12 100644 (file)
--- a/gol.c
+++ b/gol.c
@@ -11,6 +11,67 @@ void quit(int e_st)
 
 void init_state(struct gol_board *state); 
 
+void simulate(struct gol_board *state, SDL_Surface *screen);
+
+int main(int argc, char* args[])
+{
+       struct gol_board state = {
+               .live_cells = NULL,
+               .n = 0,
+               .size = 0,
+               .max_x = 0,
+               .min_x = 0,
+               .max_y = 0,
+               .min_y = 0
+       };
+       SDL_Window* window = NULL;
+       SDL_Surface* screen = NULL;
+
+
+       state.live_cells = malloc(10 * sizeof(typeof(*state.live_cells)))
+       if (!state.live_cells) {
+               return 1;
+       }
+       
+       init_state(&state);
+       
+       
+
+       if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
+               quit(1);
+       }
+
+       //screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
+
+       window = SDL_CreateWindow("SDL Tutorial",
+                                 SDL_WINDOWPOS_UNDEFINED,
+                                 SDL_WINDOWPOS_UNDEFINED,
+                                 640,
+                                 320,
+                                 SDL_WINDOW_SHOWN);
+       if (!window) {
+               quit(1);
+       }
+
+       screen = SDL_GetWindowSurface(window);
+       if (!screen) {
+               quit(1);
+       }
+       
+       // Main loop
+       simulate(&state, screen);
+       
+
+       SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
+       SDL_UpdateWindowSurface(window);
+
+       SDL_Delay(2000);
+
+       SDL_DestroyWindow(window);
+       quit(0);
+}
+
+
 void init_state(struct gol_board *state) {
        // Create the initial state. This is a glider gun (hopefully)
        gol_vivify(state, 12, 0);
@@ -51,23 +112,8 @@ void init_state(struct gol_board *state) {
        gol_vivify(state, 24, 7);
 }
 
-int main(int argc, char* args[])
+void simulate(struct gol_board *state, SDL_Surface *screen)
 {
-       struct gol_board state = {
-               .live_cells = malloc(10 * sizeof(typeof(*state.live_cells))),
-               .n = 0,
-               .size = 10,
-               .max_x = 0,
-               .min_x = 0,
-               .max_y = 0,
-               .min_y = 0
-       };
-       if (!state.live_cells) {
-               return 1;
-       }
-       
-       init_state(&state);
-       
        for (unsigned int i = 0; i < 1000; ++i) {
                printf("Generation %d\n", i);
                for (unsigned int j = 0; j < state.n; j += 2) {
@@ -75,41 +121,8 @@ int main(int argc, char* args[])
                                state.live_cells[j + 1]);
                }
                printf("\n");
-               gol_tick(&state);
-       }
-
-
-       SDL_Window* window = NULL;
-       SDL_Surface* screen = NULL;
-
-       if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
-               quit(1);
-       }
-
-       //screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
-
-       window = SDL_CreateWindow("SDL Tutorial",
-                                 SDL_WINDOWPOS_UNDEFINED,
-                                 SDL_WINDOWPOS_UNDEFINED,
-                                 640,
-                                 320,
-                                 SDL_WINDOW_SHOWN);
-       if (!window) {
-               quit(1);
-       }
-
-       screen = SDL_GetWindowSurface(window);
-       if (!screen) {
-               quit(1);
+               if (!gol_tick(state)) {
+                       //Pannick
+               }
        }
-
-       SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
-       SDL_UpdateWindowSurface(window);
-
-       SDL_Delay(2000);
-
-       SDL_DestroyWindow(window);
-       quit(0);
 }
-
-