mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 14:05:45 +01:00
make window freeing more manual
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user