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
This commit is contained in:
parent
35584d725b
commit
eb92f445ca
|
@ -1,5 +1,9 @@
|
|||
D2X-Rebirth Changelog
|
||||
|
||||
20100202
|
||||
--------
|
||||
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
|
||||
|
||||
20100201
|
||||
--------
|
||||
arch/carbon/conf.h, d1x-rebirth.xcodeproj/project.pbxproj, main/kconfig.c, main/menu.c, main/net_ipx.c, main/net_udp.c, main/newmenu.c, main/newmenu.h: Leave kconfig_idle early if exiting kconfig to avoid erroneous memory access; initialise menu's citem properly; add EVENT_NEWMENU_CHANGED; activate USE_IPX in Xcode while I'm still changing net_ipx.c
|
||||
|
|
|
@ -24,6 +24,7 @@ typedef enum event_type
|
|||
EVENT_IDLE = 0,
|
||||
EVENT_KEY_COMMAND,
|
||||
EVENT_WINDOW_ACTIVATED,
|
||||
EVENT_WINDOW_DEACTIVATED,
|
||||
EVENT_WINDOW_DRAW,
|
||||
EVENT_WINDOW_CLOSE,
|
||||
EVENT_USER // spare for use by modules that use windows (e.g. newmenu)
|
||||
|
|
|
@ -29,6 +29,7 @@ static window *FirstWindow = NULL;
|
|||
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)
|
||||
{
|
||||
window *wind;
|
||||
window *prev = window_get_front();
|
||||
d_event event = { EVENT_WINDOW_ACTIVATED };
|
||||
|
||||
wind = d_malloc(sizeof(window));
|
||||
|
@ -51,29 +52,32 @@ window *window_create(grs_canvas *src, int x, int y, int w, int h, int (*event_c
|
|||
FrontWindow = wind;
|
||||
window_send_event(wind, &event);
|
||||
|
||||
if (prev)
|
||||
{
|
||||
event.type = EVENT_WINDOW_DEACTIVATED;
|
||||
window_send_event(prev, &event);
|
||||
}
|
||||
|
||||
return wind;
|
||||
}
|
||||
|
||||
int window_close(window *wind)
|
||||
{
|
||||
window *prev;
|
||||
d_event event;
|
||||
|
||||
event.type = EVENT_WINDOW_DEACTIVATED; // Deactivate first
|
||||
window_send_event(wind, &event);
|
||||
event.type = EVENT_WINDOW_CLOSE;
|
||||
|
||||
if (window_send_event(wind, &event))
|
||||
{
|
||||
event.type = EVENT_WINDOW_ACTIVATED; // Reactivate. May cause flashing of some sort, too bad
|
||||
window_send_event(wind, &event);
|
||||
return 0; // user 'handled' the event, cancelling close
|
||||
}
|
||||
|
||||
if (wind == FrontWindow)
|
||||
{
|
||||
FrontWindow = wind->prev;
|
||||
if (window_is_visible(wind))
|
||||
{
|
||||
window *w2;
|
||||
event.type = EVENT_WINDOW_ACTIVATED;
|
||||
if ((w2 = window_get_front()))
|
||||
window_send_event(w2, &event);
|
||||
}
|
||||
}
|
||||
if (wind == FirstWindow)
|
||||
FirstWindow = wind->next;
|
||||
if (wind->next)
|
||||
|
@ -81,6 +85,12 @@ int window_close(window *wind)
|
|||
if (wind->prev)
|
||||
wind->prev->next = wind->next;
|
||||
|
||||
if ((prev = window_get_front()))
|
||||
{
|
||||
event.type = EVENT_WINDOW_ACTIVATED;
|
||||
window_send_event(prev, &event);
|
||||
}
|
||||
|
||||
d_free(wind);
|
||||
return 1;
|
||||
}
|
||||
|
@ -108,6 +118,7 @@ window *window_get_next(window *wind)
|
|||
// Make wind the front window
|
||||
void window_select(window *wind)
|
||||
{
|
||||
window *prev = window_get_front();
|
||||
d_event event = { EVENT_WINDOW_ACTIVATED };
|
||||
|
||||
Assert (wind != NULL);
|
||||
|
@ -126,16 +137,30 @@ void window_select(window *wind)
|
|||
FrontWindow = wind;
|
||||
|
||||
if (window_is_visible(wind))
|
||||
{
|
||||
window_send_event(wind, &event);
|
||||
event.type = EVENT_WINDOW_DEACTIVATED;
|
||||
if (prev)
|
||||
window_send_event(prev, &event);
|
||||
}
|
||||
}
|
||||
|
||||
void window_set_visible(window *wind, int visible)
|
||||
{
|
||||
window *prev = window_get_front();
|
||||
d_event event = { EVENT_WINDOW_ACTIVATED };
|
||||
|
||||
wind->w_visible = visible;
|
||||
if (visible && (wind == FrontWindow))
|
||||
wind = window_get_front(); // get the new front window
|
||||
if (wind == prev)
|
||||
return;
|
||||
|
||||
if (wind)
|
||||
window_send_event(wind, &event);
|
||||
|
||||
event.type = EVENT_WINDOW_DEACTIVATED;
|
||||
if (prev)
|
||||
window_send_event(prev, &event);
|
||||
}
|
||||
|
||||
int window_is_visible(window *wind)
|
||||
|
|
|
@ -750,18 +750,14 @@ int automap_handler(window *wind, d_event *event, automap *am)
|
|||
d_free(am->edges);
|
||||
d_free(am->drawingListBright);
|
||||
|
||||
game_flush_inputs();
|
||||
|
||||
if (am->pause_game)
|
||||
{
|
||||
start_time();
|
||||
digi_resume_digi_sounds();
|
||||
}
|
||||
|
||||
Screen_mode=-1; set_screen_mode(SCREEN_GAME);
|
||||
init_cockpit();
|
||||
last_drawn_cockpit = -1;
|
||||
game_flush_inputs();
|
||||
d_free(am);
|
||||
window_set_visible(Game_wind, 1);
|
||||
Automap_active = 0;
|
||||
|
@ -830,8 +826,6 @@ void do_automap( int key_code )
|
|||
|
||||
if (am->pause_game) {
|
||||
window_set_visible(Game_wind, 0);
|
||||
stop_time();
|
||||
digi_pause_digi_sounds();
|
||||
}
|
||||
|
||||
//Max_edges = min(MAX_EDGES_FROM_VERTS(Num_vertices),MAX_EDGES); //make maybe smaller than max
|
||||
|
|
|
@ -560,10 +560,8 @@ void write_game_text_file(char *filename)
|
|||
char ErrorMessage[200];
|
||||
|
||||
sprintf(ErrorMessage, "ERROR: Unable to open %s\nErrno = %i", my_filename, errno);
|
||||
stop_time();
|
||||
gr_palette_load(gr_palette);
|
||||
nm_messagebox( NULL, 1, "Ok", ErrorMessage );
|
||||
start_time();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1014,10 +1012,8 @@ void say_totals_all(void)
|
|||
char ErrorMessage[200];
|
||||
|
||||
sprintf( ErrorMessage, "ERROR: Unable to open levels.all\nErrno=%i", errno );
|
||||
stop_time();
|
||||
gr_palette_load(gr_palette);
|
||||
nm_messagebox( NULL, 1, "Ok", ErrorMessage );
|
||||
start_time();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1074,10 +1070,8 @@ say_totals_all();
|
|||
char ErrorMessage[200];
|
||||
|
||||
sprintf( ErrorMessage, "ERROR: Can't open textures.dmp\nErrno=%i", errno);
|
||||
stop_time();
|
||||
gr_palette_load(gr_palette);
|
||||
nm_messagebox( NULL, 1, "Ok", ErrorMessage );
|
||||
start_time();
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -862,13 +862,10 @@ int SafetyCheck()
|
|||
int x;
|
||||
|
||||
if (mine_changed) {
|
||||
stop_time();
|
||||
x = nm_messagebox( "Warning!", 2, "Cancel", "OK", "You are about to lose work." );
|
||||
if (x<1) {
|
||||
start_time();
|
||||
return 0;
|
||||
}
|
||||
start_time();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1702,11 +1702,8 @@ int escort_menu_handler(window *wind, d_event *event, escort_menu *menu)
|
|||
break;
|
||||
|
||||
case EVENT_WINDOW_CLOSE:
|
||||
game_flush_inputs();
|
||||
|
||||
palette_restore();
|
||||
|
||||
start_time();
|
||||
digi_resume_digi_sounds();
|
||||
return 0; // continue closing
|
||||
break;
|
||||
|
@ -1770,15 +1767,10 @@ void do_escort_menu(void)
|
|||
return;
|
||||
}
|
||||
|
||||
digi_pause_digi_sounds();
|
||||
stop_time();
|
||||
|
||||
palette_save();
|
||||
apply_modified_palette();
|
||||
reset_palette_add();
|
||||
|
||||
game_flush_inputs();
|
||||
|
||||
gr_palette_load( gr_palette );
|
||||
|
||||
// This prevents the buddy from coming back if you've told him to scram.
|
||||
|
|
28
main/game.c
28
main/game.c
|
@ -195,14 +195,7 @@ void reset_palette_add()
|
|||
|
||||
void game_show_warning(char *s)
|
||||
{
|
||||
|
||||
if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
|
||||
stop_time();
|
||||
|
||||
nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
|
||||
|
||||
if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
|
||||
start_time();
|
||||
}
|
||||
|
||||
u_int32_t Game_screen_mode = SM(640,480);
|
||||
|
@ -1161,7 +1154,6 @@ window *game_setup(void)
|
|||
#endif
|
||||
|
||||
fix_object_segs();
|
||||
game_flush_inputs();
|
||||
|
||||
return game_wind;
|
||||
}
|
||||
|
@ -1177,6 +1169,26 @@ int game_handler(window *wind, d_event *event, void *data)
|
|||
|
||||
switch (event->type)
|
||||
{
|
||||
case EVENT_WINDOW_ACTIVATED:
|
||||
game_flush_inputs();
|
||||
|
||||
if (time_paused && !(((Game_mode & GM_MULTI) && (Newdemo_state != ND_STATE_PLAYBACK)) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
|
||||
start_time();
|
||||
|
||||
if ( Function_mode == FMODE_GAME && !((Game_mode & GM_MULTI) && (Newdemo_state != ND_STATE_PLAYBACK)))
|
||||
digi_resume_digi_sounds();
|
||||
break;
|
||||
|
||||
case EVENT_WINDOW_DEACTIVATED:
|
||||
game_flush_inputs();
|
||||
|
||||
if (!(((Game_mode & GM_MULTI) && (Newdemo_state != ND_STATE_PLAYBACK)) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
|
||||
stop_time();
|
||||
|
||||
if ( Function_mode == FMODE_GAME && !((Game_mode & GM_MULTI) && (Newdemo_state != ND_STATE_PLAYBACK)))
|
||||
digi_pause_digi_sounds();
|
||||
break;
|
||||
|
||||
case EVENT_IDLE:
|
||||
// GAME LOOP!
|
||||
Config_menu_flag = 0;
|
||||
|
|
|
@ -418,13 +418,11 @@ int pause_handler(window *wind, d_event *event, char *msg)
|
|||
break;
|
||||
|
||||
case EVENT_WINDOW_CLOSE:
|
||||
game_flush_inputs();
|
||||
reset_cockpit();
|
||||
palette_restore();
|
||||
start_time();
|
||||
if (EXT_MUSIC_ON)
|
||||
ext_music_resume();
|
||||
digi_resume_all();
|
||||
digi_resume_midi(); // sound pausing handled by game_handler
|
||||
d_free(msg);
|
||||
return 0; // continue closing
|
||||
break;
|
||||
|
@ -454,13 +452,11 @@ int do_game_pause()
|
|||
}
|
||||
#endif
|
||||
|
||||
digi_pause_all();
|
||||
digi_pause_midi(); // sound pausing handled by game_handler
|
||||
ext_music_pause();
|
||||
stop_time();
|
||||
palette_save();
|
||||
apply_modified_palette();
|
||||
reset_palette_add();
|
||||
game_flush_inputs();
|
||||
gr_palette_load( gr_palette );
|
||||
format_time(total_time, f2i(Players[Player_num].time_total) + Players[Player_num].hours_total*3600);
|
||||
format_time(level_time, f2i(Players[Player_num].time_level) + Players[Player_num].hours_level*3600);
|
||||
|
@ -2108,7 +2104,6 @@ void ReadControls()
|
|||
// If automap key pressed, enable automap unless you are in network mode, control center destroyed and < 10 seconds left
|
||||
if ( Controls.automap_down_count && !((Game_mode & GM_MULTI) && Control_center_destroyed && (Countdown_seconds_left < 10)))
|
||||
{
|
||||
game_flush_inputs();
|
||||
do_automap(0);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1559,14 +1559,11 @@ int save_level_sub(char * filename, int compiled_version)
|
|||
char ErrorMessage[200];
|
||||
|
||||
sprintf( ErrorMessage, "Warning: %i errors in this mine!\n", Errors_in_mine );
|
||||
stop_time();
|
||||
gr_palette_load(gr_palette);
|
||||
|
||||
if (nm_messagebox( NULL, 2, "Cancel Save", "Save", ErrorMessage )!=1) {
|
||||
start_time();
|
||||
return 1;
|
||||
}
|
||||
start_time();
|
||||
}
|
||||
}
|
||||
// change_filename_extension(temp_filename,filename,".LVL");
|
||||
|
@ -1590,10 +1587,8 @@ int save_level_sub(char * filename, int compiled_version)
|
|||
sprintf( ErrorMessage, \
|
||||
"ERROR: Cannot write to '%s'.\nYou probably need to check out a locked\nversion of the file. You should save\nthis under a different filename, and then\ncheck out a locked copy by typing\n\'co -l %s.lvl'\nat the DOS prompt.\n"
|
||||
, temp_filename, fname );
|
||||
stop_time();
|
||||
gr_palette_load(gr_palette);
|
||||
nm_messagebox( NULL, 1, "Ok", ErrorMessage );
|
||||
start_time();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1751,7 +1751,6 @@ void StartNewLevelSub(int level_num, int page_in_textures, int secret_flag)
|
|||
reset_palette_add();
|
||||
init_thief_for_level();
|
||||
init_stuck_objects();
|
||||
game_flush_inputs(); // clear out the keyboard
|
||||
if (!(Game_mode & GM_MULTI))
|
||||
filter_objects_from_level();
|
||||
|
||||
|
|
|
@ -133,7 +133,6 @@ typedef struct kc_menu
|
|||
int citem;
|
||||
int old_axis[JOY_MAX_AXES];
|
||||
ubyte changing;
|
||||
ubyte time_stopped;
|
||||
ubyte q_fade_i; // for flashing the question mark
|
||||
#ifdef NEWMENU_MOUSE
|
||||
ubyte mouse_state, omouse_state;
|
||||
|
@ -975,10 +974,7 @@ int kconfig_handler(window *wind, d_event *event, kc_menu *menu)
|
|||
break;
|
||||
|
||||
case EVENT_WINDOW_CLOSE:
|
||||
game_flush_inputs();
|
||||
newmenu_hide_cursor();
|
||||
if (menu->time_stopped)
|
||||
start_time();
|
||||
d_free(menu);
|
||||
|
||||
// Update save values...
|
||||
|
@ -1022,25 +1018,12 @@ void kconfig_sub(kc_item * items,int nitems, char *title)
|
|||
return;
|
||||
|
||||
memset(menu, 0, sizeof(kc_menu));
|
||||
menu->time_stopped = 0;
|
||||
menu->items = items;
|
||||
menu->nitems = nitems;
|
||||
menu->title = title;
|
||||
menu->citem = 0;
|
||||
menu->changing = 0;
|
||||
|
||||
#ifdef NETWORK
|
||||
if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
|
||||
#else
|
||||
if (Endlevel_sequence)
|
||||
#endif
|
||||
{
|
||||
menu->time_stopped = 1;
|
||||
stop_time();
|
||||
}
|
||||
|
||||
game_flush_inputs();
|
||||
|
||||
#ifdef NEWMENU_MOUSE
|
||||
menu->mouse_state = menu->omouse_state = 0;
|
||||
#endif
|
||||
|
|
|
@ -5750,7 +5750,6 @@ static int show_game_rules_handler(window *wind, d_event *event, netgame_info *n
|
|||
break;
|
||||
|
||||
case EVENT_WINDOW_CLOSE:
|
||||
game_flush_inputs();
|
||||
return 0; // continue closing
|
||||
break;
|
||||
|
||||
|
@ -5766,8 +5765,6 @@ void net_ipx_show_game_rules(netgame_info *netgame)
|
|||
{
|
||||
gr_set_current_canvas(NULL);
|
||||
|
||||
game_flush_inputs();
|
||||
|
||||
window_create(&grd_curscreen->sc_canvas, (SWIDTH - FSPACX(320))/2, (SHEIGHT - FSPACY(200))/2, FSPACX(320), FSPACY(200),
|
||||
(int (*)(window *, d_event *, void *))show_game_rules_handler, netgame);
|
||||
}
|
||||
|
|
|
@ -4794,7 +4794,6 @@ static int show_game_rules_handler(window *wind, d_event *event, netgame_info *n
|
|||
break;
|
||||
|
||||
case EVENT_WINDOW_CLOSE:
|
||||
game_flush_inputs();
|
||||
return 0; // continue closing
|
||||
break;
|
||||
|
||||
|
@ -4810,8 +4809,6 @@ void net_udp_show_game_rules(netgame_info *netgame)
|
|||
{
|
||||
gr_set_current_canvas(NULL);
|
||||
|
||||
game_flush_inputs();
|
||||
|
||||
window_create(&grd_curscreen->sc_canvas, (SWIDTH - FSPACX(320))/2, (SHEIGHT - FSPACY(200))/2, FSPACX(320), FSPACY(200),
|
||||
(int (*)(window *, d_event *, void *))show_game_rules_handler, netgame);
|
||||
}
|
||||
|
|
|
@ -84,7 +84,6 @@ struct newmenu
|
|||
int tiny_mode;
|
||||
int scroll_offset, last_scroll_check, max_displayable;
|
||||
int all_text; //set true if all text items
|
||||
int sound_stopped,time_stopped;
|
||||
int is_scroll_box; // Is this a scrolling box? Set to false at init
|
||||
int max_on_menu;
|
||||
int mouse_state, omouse_state, dblclick_flag;
|
||||
|
@ -1270,6 +1269,10 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu)
|
|||
newmenu_show_cursor();
|
||||
break;
|
||||
|
||||
case EVENT_WINDOW_DEACTIVATED:
|
||||
newmenu_hide_cursor();
|
||||
break;
|
||||
|
||||
case EVENT_KEY_COMMAND:
|
||||
return newmenu_key_command(wind, event, menu);
|
||||
break;
|
||||
|
@ -1290,21 +1293,6 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu)
|
|||
return 1; // cancel close and do it in newmenu_do4 instead
|
||||
}
|
||||
|
||||
newmenu_hide_cursor();
|
||||
game_flush_inputs();
|
||||
|
||||
if (menu->time_stopped)
|
||||
start_time();
|
||||
|
||||
if ( menu->sound_stopped )
|
||||
digi_resume_digi_sounds();
|
||||
|
||||
if (!menu->done) // closing from outside newmenu.c
|
||||
{
|
||||
menu->citem = -1;
|
||||
menu->done = 1;
|
||||
}
|
||||
|
||||
d_free(menu);
|
||||
break;
|
||||
|
||||
|
@ -1338,7 +1326,6 @@ int newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item,
|
|||
menu->last_scroll_check = -1;
|
||||
menu->all_text = 0;
|
||||
menu->is_scroll_box = 0;
|
||||
menu->sound_stopped = menu->time_stopped = 0;
|
||||
menu->max_on_menu = MAXDISPLAYABLEITEMS;
|
||||
menu->dblclick_flag = 0;
|
||||
menu->title = title;
|
||||
|
@ -1361,17 +1348,6 @@ int newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item,
|
|||
|
||||
menu->max_displayable=nitems;
|
||||
|
||||
if ( Function_mode == FMODE_GAME && !((Game_mode & GM_MULTI) && (Newdemo_state != ND_STATE_PLAYBACK))) {
|
||||
digi_pause_digi_sounds();
|
||||
menu->sound_stopped = 1;
|
||||
}
|
||||
|
||||
if (!(((Game_mode & GM_MULTI) && (Newdemo_state != ND_STATE_PLAYBACK)) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
|
||||
{
|
||||
menu->time_stopped = 1;
|
||||
stop_time();
|
||||
}
|
||||
|
||||
save_canvas = grd_curcanv;
|
||||
|
||||
gr_set_current_canvas(NULL);
|
||||
|
@ -1550,12 +1526,6 @@ int newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item,
|
|||
wind = window_create(&grd_curscreen->sc_canvas, menu->x, menu->y, menu->w, menu->h, (int (*)(window *, d_event *, void *))newmenu_handler, menu);
|
||||
if (!wind)
|
||||
{
|
||||
if (menu->time_stopped)
|
||||
start_time();
|
||||
|
||||
if ( menu->sound_stopped )
|
||||
digi_resume_digi_sounds();
|
||||
|
||||
d_free(menu);
|
||||
|
||||
return -1;
|
||||
|
@ -1609,9 +1579,6 @@ int newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item,
|
|||
}
|
||||
}
|
||||
|
||||
// Clear mouse, joystick to clear button presses.
|
||||
game_flush_inputs();
|
||||
|
||||
#ifdef NEWMENU_MOUSE
|
||||
menu->mouse_state = menu->omouse_state = 0;
|
||||
#endif
|
||||
|
@ -1982,6 +1949,10 @@ int listbox_handler(window *wind, d_event *event, listbox *lb)
|
|||
newmenu_show_cursor();
|
||||
break;
|
||||
|
||||
case EVENT_WINDOW_DEACTIVATED:
|
||||
newmenu_hide_cursor();
|
||||
break;
|
||||
|
||||
case EVENT_KEY_COMMAND:
|
||||
return listbox_key_command(wind, event, lb);
|
||||
break;
|
||||
|
@ -2002,7 +1973,6 @@ int listbox_handler(window *wind, d_event *event, listbox *lb)
|
|||
return 1; // cancel close and do it in newmenu_listbox1 instead
|
||||
}
|
||||
|
||||
newmenu_hide_cursor();
|
||||
d_free(lb);
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in a new issue