From 097dd32c5a8cd44863242f1b92d145dcd4e24142 Mon Sep 17 00:00:00 2001 From: zicodxx Date: Sat, 12 Feb 2011 23:58:41 +0100 Subject: [PATCH] New approach to handle a bunch of closing windows - removed window_do_close() again, reworked game_leave_menus by checking window_get_front() and closing this window until it's Game_wind, while event_process checking if window still exists after drawing and if not, take next window from previous which should be updated by then --- CHANGELOG.txt | 4 ++++ arch/include/window.h | 1 - arch/sdl/event.c | 18 +++++++++--------- arch/sdl/window.c | 12 ------------ main/game.c | 6 ++---- main/movie.c | 2 -- 6 files changed, 15 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b57d5eb7c..930a8caa4 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D2X-Rebirth Changelog +20110212 +-------- +arch/inlcude/window.h, arch/sdl/event.c, arch/sdl/window.c, main/game.c: New approach to handle a bunch of closing windows - removed window_do_close() again, reworked game_leave_menus by checking window_get_front() and closing this window until it's Game_wind, while event_process checking if window still exists after drawing and if not, take next window from previous which should be updated by then + 20110211 -------- main/gamecntl.c, main/kconfig.c, main/newmenu.c: Controls.select_weapon_count needs to be incremented differently to get non-0 when we want to select the laser type weapon; Readded jumping from first to last item in newmenu and vice versa diff --git a/arch/include/window.h b/arch/include/window.h index 4122721c0..f6bf26af0 100644 --- a/arch/include/window.h +++ b/arch/include/window.h @@ -19,7 +19,6 @@ typedef struct window window; extern window *window_create(grs_canvas *src, int x, int y, int w, int h, int (*event_callback)(window *wind, d_event *event, void *data), void *data); extern int window_close(window *wind); -extern int window_do_close(window *wind); extern int window_exists(window *wind); extern window *window_get_front(void); extern window *window_get_first(void); diff --git a/arch/sdl/event.c b/arch/sdl/event.c index 229e562d4..70506b6c0 100644 --- a/arch/sdl/event.c +++ b/arch/sdl/event.c @@ -152,19 +152,19 @@ void event_process(void) return; event.type = EVENT_WINDOW_DRAW; // then draw all visible windows - for (wind = window_get_first(); wind != NULL; wind = window_get_next(wind)) + wind = window_get_first(); + while (wind != NULL) + { + window *prev = window_get_prev(wind); if (window_is_visible(wind)) window_send_event(wind, &event); + if (!window_exists(wind)) + wind = window_get_next(prev); // the current window seemed to be closed. so take the next one from the previous which should be able to point to the one after the currently closed + else + wind = window_get_next(wind); + } gr_flip(); - - wind = window_get_first(); - while (wind != NULL) // go through all windows and actually close them if they want to - { - window *next_wind = window_get_next(wind); - window_do_close(wind); - wind = next_wind; - } } void event_toggle_focus(int activate_focus) diff --git a/arch/sdl/window.c b/arch/sdl/window.c index 504774cc4..91d1b12bd 100644 --- a/arch/sdl/window.c +++ b/arch/sdl/window.c @@ -18,7 +18,6 @@ struct window grs_canvas w_canv; // the window's canvas to draw to int (*w_callback)(window *wind, d_event *event, void *data); // the event handler int w_visible; // whether it's visible - ubyte w_closing_state; void *data; // whatever the user wants (eg menu data for 'newmenu' menus) struct window *prev; // the previous window in the doubly linked list struct window *next; // the next window in the doubly linked list @@ -42,7 +41,6 @@ window *window_create(grs_canvas *src, int x, int y, int w, int h, int (*event_c gr_init_sub_canvas(&wind->w_canv, src, x, y, w, h); wind->w_callback = event_callback; wind->w_visible = 1; // default to visible - wind->w_closing_state = 0; wind->data = data; if (FirstWindow == NULL) @@ -61,20 +59,11 @@ window *window_create(grs_canvas *src, int x, int y, int w, int h, int (*event_c } int window_close(window *wind) -{ - wind->w_closing_state = 1; // mark this window to close - - return 1; -} - -int window_do_close(window *wind) { window *prev; d_event event; int (*w_callback)(window *wind, d_event *event, void *data) = wind->w_callback; - if (!wind->w_closing_state) - return 0; if (wind == window_get_front()) WINDOW_SEND_EVENT(wind, EVENT_WINDOW_DEACTIVATED); // Deactivate first @@ -87,7 +76,6 @@ int window_do_close(window *wind) if (wind == window_get_front()) { WINDOW_SEND_EVENT(wind, EVENT_WINDOW_ACTIVATED); - wind->w_closing_state = 0; } return 0; } diff --git a/main/game.c b/main/game.c index 7ee0de224..0f0ecee59 100644 --- a/main/game.c +++ b/main/game.c @@ -1343,13 +1343,11 @@ void flicker_lights(); void game_leave_menus(void) { - window *wind; - if (!Game_wind) return; - for (wind = window_get_next(Game_wind); wind != NULL; wind = window_get_next(wind)) - window_close(wind); + while (window_get_front() != Game_wind) // go through all windows and actually close them if they want to + window_close(window_get_front()); } void GameProcessFrame(void) diff --git a/main/movie.c b/main/movie.c index 4317231d2..a7d555d09 100644 --- a/main/movie.c +++ b/main/movie.c @@ -394,7 +394,6 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy) if (must_have) con_printf(CON_URGENT, "Can't open movie <%s>: %s\n", filename, PHYSFS_getLastError()); window_close(wind); - window_do_close(wind); if (reshow) show_menus(); d_free(m); @@ -419,7 +418,6 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy) Int3(); SDL_FreeRW(filehndl); window_close(wind); - window_do_close(wind); if (reshow) show_menus(); d_free(m);