diff --git a/src/io/window.c b/src/io/window.c index 2b9f3f7..3c44c66 100644 --- a/src/io/window.c +++ b/src/io/window.c @@ -18,7 +18,7 @@ static SDL_Window* win = NULL; static bool close = false; static audiodata music; -static void window_init(struct gamedata const* gdat) { +void window_init(struct gamedata const* gdat) { assert(!win && !close); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) fatal(ERROR_SDL_INIT, "SDL could not initialize! SDL Error: %s", SDL_GetError()); @@ -32,7 +32,7 @@ static void window_init(struct gamedata const* gdat) { music = audio_wav_load("korobeiniki.wav"); } -static void window_free(void) { +void window_free(void) { assert(win); render_free(); SDL_DestroyWindow(win); @@ -43,9 +43,7 @@ static void window_free(void) { audio_device_free(); } -void window_open(struct gamedata const* gdat) { - window_init(gdat); - +void window_open(void) { while (!close) { game_update(input_getdat()); render_update(); @@ -54,8 +52,6 @@ void window_open(struct gamedata const* gdat) { if (time_poll(time_pull(), music.ms, &timeout)) audio_play(&music); } - - window_free(); } void window_close(void) { diff --git a/src/io/window.h b/src/io/window.h index ad5eed7..40df18b 100644 --- a/src/io/window.h +++ b/src/io/window.h @@ -6,5 +6,7 @@ #define SCREEN_WIDTH ((COLUMNS + 6) * PX_DENS) // window width #define SCREEN_HEIGHT ((COLUMNS) * PX_DENS / COLUMNS * ROWS) // window height -void window_open(struct gamedata const*); +void window_init(struct gamedata const*); +void window_open(void); void window_close(void); +void window_free(void); diff --git a/src/main.c b/src/main.c index 9aa6c56..2bc72a4 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,7 @@ static void stop(void) { debug("stopping...", ); window_close(); + window_free(); SDL_Quit(); } @@ -17,7 +18,8 @@ int main(int argc, char** argv) { // register stop as exit function atexit(stop); - window_open(game_init()); + window_init(game_init()); + window_open(); return 0; }