From: Christian Heller Date: Sat, 20 Jul 2013 03:54:50 +0000 (+0200) Subject: Moved game exiting into its own function. X-Git-Tag: tce~1143 X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=c330529615cc0c5f6772d7e342bc1c442e1f3519;p=plomrogue Moved game exiting into its own function. --- diff --git a/src/main.c b/src/main.c index 4ed9ba8..693f204 100644 --- a/src/main.c +++ b/src/main.c @@ -135,7 +135,7 @@ int main (int argc, char *argv[]) { else quit_called = meta_keys(key, &world, &win_meta, &win_keys, &win_map, &win_info, &win_log); if (1 == quit_called) - break; } } + exit_game(&world, &map); } } // Interactive mode. else { @@ -161,14 +161,4 @@ int main (int argc, char *argv[]) { else quit_called = meta_keys(key, &world, &win_meta, &win_keys, &win_map, &win_info, &win_log); if (1 == quit_called) - break; } } - - // Clean up and exit. - free(map.cells); - for (key = 0; key <= world.keyswindata->max; key++) - free(world.keybindings[key].name); - free(world.keybindings); - free(world.keyswindata); - free(world.log); - endwin(); - exit (EXIT_SUCCESS); } + exit_game(&world, &map); } } } diff --git a/src/misc.c b/src/misc.c index cff4264..cb650a0 100644 --- a/src/misc.c +++ b/src/misc.c @@ -10,6 +10,18 @@ #include "main.h" #include "yx_uint16.h" +extern void exit_game(struct World * world, struct Map * map) { +// Clean up and exit. + endwin(); + free(map->cells); + uint16_t key; + for (key = 0; key <= world->keyswindata->max; key++) + free(world->keybindings[key].name); + free(world->keybindings); + free(world->keyswindata); + free(world->log); + exit (EXIT_SUCCESS); } + extern void textfile_sizes (FILE * file, uint16_t * linemax_p, uint16_t * n_lines_p) { // Learn largest line length (linemax_p) and (n_lines_p if not set to NULL) number of lines. uint16_t n_lines = 0; diff --git a/src/misc.h b/src/misc.h index 5d90d15..b3b9a13 100644 --- a/src/misc.h +++ b/src/misc.h @@ -10,6 +10,7 @@ struct WinMeta; struct Win; struct Map; +extern void exit_game(struct World *, struct Map *); extern void textfile_sizes (FILE *, uint16_t *, uint16_t *); extern uint16_t rrand(char, uint32_t); extern void update_log (struct World *, char *);