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
5c923e864d
commit
9fd714a083
|
@ -1,5 +1,9 @@
|
|||
D1X-Rebirth Changelog
|
||||
|
||||
20100202
|
||||
--------
|
||||
arch/include/event.h, arch/sdl/window.c, main/automap.c, main/dumpmine.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
|
||||
|
|
|
@ -8,6 +8,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)
|
||||
|
|
|
@ -527,18 +527,9 @@ 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;
|
||||
|
@ -607,8 +598,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
|
||||
|
|
|
@ -558,10 +558,8 @@ void write_game_text_file(char *filename)
|
|||
char ErrorMessage[200];
|
||||
|
||||
sprintf( ErrorMessage, "ERROR: Unable to open output file %s\n", my_filename );
|
||||
stop_time();
|
||||
gr_palette_load(gr_palette);
|
||||
nm_messagebox( NULL, 1, "Ok", ErrorMessage );
|
||||
start_time();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -853,10 +851,8 @@ void say_totals_all(void)
|
|||
char ErrorMessage[200];
|
||||
|
||||
sprintf( ErrorMessage, "ERROR: Unable to open output file levels.all\n");
|
||||
stop_time();
|
||||
gr_palette_load(gr_palette);
|
||||
nm_messagebox( NULL, 1, "Ok", ErrorMessage );
|
||||
start_time();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -918,10 +914,8 @@ say_totals_all();
|
|||
char ErrorMessage[200];
|
||||
|
||||
sprintf( ErrorMessage, "ERROR: Unable to open output file textures.dmp\n");
|
||||
stop_time();
|
||||
gr_palette_load(gr_palette);
|
||||
nm_messagebox( NULL, 1, "Ok", ErrorMessage );
|
||||
start_time();
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
28
main/game.c
28
main/game.c
|
@ -181,14 +181,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);
|
||||
|
@ -975,7 +968,6 @@ window *game_setup(void)
|
|||
#endif
|
||||
|
||||
fix_object_segs();
|
||||
game_flush_inputs();
|
||||
|
||||
return game_wind;
|
||||
}
|
||||
|
@ -991,6 +983,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;
|
||||
|
|
|
@ -264,12 +264,10 @@ int pause_handler(window *wind, d_event *event, char *msg)
|
|||
break;
|
||||
|
||||
case EVENT_WINDOW_CLOSE:
|
||||
game_flush_inputs();
|
||||
reset_cockpit();
|
||||
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;
|
||||
|
@ -299,10 +297,8 @@ int do_game_pause()
|
|||
}
|
||||
#endif
|
||||
|
||||
digi_pause_all();
|
||||
digi_pause_midi(); // sound pausing handled by game_handler
|
||||
ext_music_pause();
|
||||
stop_time();
|
||||
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);
|
||||
|
@ -1241,7 +1237,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 && (Fuelcen_seconds_left < 10)))
|
||||
{
|
||||
game_flush_inputs();
|
||||
do_automap(0);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1461,14 +1461,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();
|
||||
}
|
||||
}
|
||||
convert_name_to_LVL(temp_filename,filename);
|
||||
|
@ -1487,10 +1484,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1296,7 +1296,6 @@ void StartNewLevelSub(int level_num, int page_in_textures)
|
|||
init_morphs();
|
||||
init_all_matcens();
|
||||
reset_palette_add();
|
||||
game_flush_inputs(); // clear out the keyboard
|
||||
|
||||
if (!(Game_mode & GM_MULTI) && !Cheats_enabled)
|
||||
set_highest_level(Current_level_num);
|
||||
|
|
|
@ -115,7 +115,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;
|
||||
|
@ -924,10 +923,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...
|
||||
|
@ -969,25 +965,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
|
||||
|
|
|
@ -4029,7 +4029,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;
|
||||
|
||||
|
@ -4045,8 +4044,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);
|
||||
}
|
||||
|
|
|
@ -4325,7 +4325,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;
|
||||
|
||||
|
@ -4341,8 +4340,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;
|
||||
|
@ -1260,6 +1259,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;
|
||||
|
@ -1280,21 +1283,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;
|
||||
|
||||
|
@ -1328,7 +1316,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;
|
||||
|
@ -1351,17 +1338,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);
|
||||
|
@ -1540,12 +1516,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;
|
||||
|
@ -1599,9 +1569,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
|
||||
|
@ -1972,6 +1939,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;
|
||||
|
@ -1992,7 +1963,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