#include "mazeoflife.h" #ifdef __EMSCRIPTEN__ #include #endif #include #include #include #include #include #include #include #include "sdl.h" #include "state.h" #include "titlestate.h" static void main_loop(void* arg) { Game& game = *static_cast(arg); std::unique_ptr next_state = (*game.state)(game); if (next_state) { game.state = std::move(next_state); } if (game.should_quit) { #ifdef __EMSCRIPTEN__ emscripten_cancel_main_loop(); #else exit(0); #endif } } int main(int, char**) { Game game; std::random_device randomEngine; game.rng = std::mt19937(randomEngine()); game.window = window_ptr( SDL_CreateWindow("Maze of Life", 100, 100, 480, 480, SDL_WINDOW_SHOWN)); if (!game.window) { throw sdl_error(); } SDL_Surface* icon = SDL_LoadBMP("resources/icon.bmp"); SDL_SetWindowIcon(game.window.get(), icon); game.renderer = renderer_ptr( SDL_CreateRenderer(game.window.get(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)); if (!game.renderer) { throw sdl_error(); } game.state = std::make_unique(game); #ifdef __EMSCRIPTEN__ emscripten_set_main_loop_arg(main_loop, &game, 0, 1); #else for (;;) { main_loop(&game); } #endif }