diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d2a9ddf85..7754fe686 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ D2X-Rebirth Changelog -------- arch/include/event.h, arch/sdl/window.c, main/automap.c, main/dumpmine.c, main/editor/med.c, main/escort.c, main/game.c, main/gamecntl.c, main/gamesave.c, main/gameseq.c, main/kconfig.c, main/net_ipx.c, main/net_udp.c, main/newmenu.c: Add EVENT_WINDOW_DEACTIVATED; move many game_flush_inputs, start_time and stop_time calls to game_handler as well as digi_pause_digi_sounds and digi_resume_digi_sounds main/inferno.c: Hide all other windows before showing error dialog, hopefully so errors don't happen while the error dialog is there +arch/include/event.h, arch/sdl/window.c, main/game.c, main/inferno.c, main/newmenu.c: Put LeaveGame longjmp back, but in response to new EVENT_WINDOW_CLOSED, fixing demo issues; fix compiler error in last commit 20100201 -------- diff --git a/arch/include/event.h b/arch/include/event.h index c595a9548..400eb83e3 100644 --- a/arch/include/event.h +++ b/arch/include/event.h @@ -27,6 +27,7 @@ typedef enum event_type EVENT_WINDOW_DEACTIVATED, EVENT_WINDOW_DRAW, EVENT_WINDOW_CLOSE, + EVENT_WINDOW_CLOSED, EVENT_USER // spare for use by modules that use windows (e.g. newmenu) } event_type; diff --git a/arch/sdl/window.c b/arch/sdl/window.c index 9aab960a9..c767d077f 100644 --- a/arch/sdl/window.c +++ b/arch/sdl/window.c @@ -65,6 +65,7 @@ int window_close(window *wind) { window *prev; d_event event; + int (*w_callback)(window *wind, d_event *event, void *data) = wind->w_callback; event.type = EVENT_WINDOW_DEACTIVATED; // Deactivate first window_send_event(wind, &event); @@ -92,6 +93,10 @@ int window_close(window *wind) } d_free(wind); + + event.type = EVENT_WINDOW_CLOSED; + w_callback(wind, &event, NULL); // callback needs to recognise this is a NULL pointer! + return 1; } diff --git a/main/game.c b/main/game.c index 74f2c3527..becd21b1e 100644 --- a/main/game.c +++ b/main/game.c @@ -22,6 +22,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include #include #include +#include #ifdef OGL #include "ogl_init.h" @@ -1161,6 +1162,7 @@ window *game_setup(void) void game_render_frame(); window *Game_wind = NULL; +jmp_buf LeaveGame; // Event handler for the game int game_handler(window *wind, d_event *event, void *data) @@ -1269,6 +1271,10 @@ int game_handler(window *wind, d_event *event, void *data) return 0; // continue closing break; + case EVENT_WINDOW_CLOSED: + longjmp(LeaveGame, 0); + break; + default: return 0; break; @@ -1284,8 +1290,11 @@ void game() { Game_wind = game_setup(); - while (Game_wind) - event_process(); + if (setjmp(LeaveGame) == 0) + { + while (Game_wind) + event_process(); + } } //called at the end of the program diff --git a/main/inferno.c b/main/inferno.c index cda38fe99..c6fd3f7aa 100644 --- a/main/inferno.c +++ b/main/inferno.c @@ -214,7 +214,7 @@ void error_messagebox(char *s) // Hide all windows so they don't interfere // Don't care about unfreed pointers on exit; trying to close the windows may cause problems - for (wind = window_get_front(), wind != NULL; wind = window_get_front()) + for (wind = window_get_front(); wind != NULL; wind = window_get_front()) window_set_visible(wind, 0); nm_messagebox( TXT_SORRY, 1, TXT_OK, s ); diff --git a/main/newmenu.c b/main/newmenu.c index 3566544ae..4360cf3fe 100644 --- a/main/newmenu.c +++ b/main/newmenu.c @@ -1248,6 +1248,9 @@ int newmenu_draw(window *wind, newmenu *menu) int newmenu_handler(window *wind, d_event *event, newmenu *menu) { + if (event->type == EVENT_WINDOW_CLOSED) + return 0; + if (menu->subfunction) { int rval = (*menu->subfunction)(menu, event, menu->userdata); @@ -1928,6 +1931,9 @@ int listbox_draw(window *wind, listbox *lb) int listbox_handler(window *wind, d_event *event, listbox *lb) { + if (event->type == EVENT_WINDOW_CLOSED) + return 0; + if (lb->listbox_callback) { int rval = (*lb->listbox_callback)(lb, event, lb->userdata);