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);
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) {
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);
}
-
-