Move window_is_visible,window_set_visible to be window methods

Shrink w_visible to uint8_t.  Move it to pack better.
This commit is contained in:
Kp 2021-11-01 03:37:18 +00:00
parent 8eafbe6197
commit 57780e0450
13 changed files with 78 additions and 73 deletions

View file

@ -202,7 +202,7 @@ window_event_result event_send(const d_event &event)
window_event_result handled = window_event_result::ignored;
for (wind = window_get_front(); wind && handled == window_event_result::ignored; wind = window_get_prev(*wind))
if (window_is_visible(*wind))
if (wind->is_visible())
{
handled = window_send_event(*wind, event);
@ -242,7 +242,7 @@ window_event_result event_process(void)
const d_event event{EVENT_WINDOW_DRAW}; // then draw all visible windows
for (wind = window_get_first(); wind != nullptr;)
{
if (window_is_visible(*wind))
if (wind->is_visible())
{
auto prev = window_get_prev(*wind);
auto result = window_send_event(*wind, event);

View file

@ -27,7 +27,7 @@ static window *FirstWindow = nullptr;
window::window(grs_canvas &src, const int x, const int y, const int w, const int h) :
// Default to visible and modal
w_visible(1), prev(FrontWindow)
prev(FrontWindow)
{
gr_init_sub_canvas(w_canv, src, x, y, w, h);
@ -155,10 +155,10 @@ void window_select(window &wind)
}
}
window *window_set_visible(window &w, int visible)
window *window::set_visible(uint8_t visible)
{
window *prev = window_get_front();
w.w_visible = visible;
w_visible = visible;
auto wind = window_get_front(); // get the new front window
if (wind == prev)
return wind;

View file

@ -33,7 +33,6 @@ window *window_get_first();
window *window_get_next(window &wind);
window *window_get_prev(window &wind);
void window_select(window &wind);
window *window_set_visible(window &wind, int visible);
#if !DXX_USE_OGL
void window_update_canvases();
#endif

View file

@ -31,9 +31,9 @@ class window
public:
grs_subcanvas w_canv; // the window's canvas to draw to
private:
int w_visible; // whether it's visible
class window *prev; // the previous window in the doubly linked list
class window *next = nullptr; // the next window in the doubly linked list
uint8_t w_visible = 1; // whether it's visible
uint8_t w_modal = 1; // modal = accept all user input exclusively
bool *w_exists = nullptr; // optional pointer to a tracking variable
public:
@ -49,24 +49,15 @@ public:
friend window *window_get_front();
friend window *window_get_first();
friend void window_select(window &wind);
friend window *window_set_visible(window &wind, int visible);
#if !DXX_USE_OGL
friend void window_update_canvases();
#endif
friend window *window_set_visible(window *wind, int visible)
{
return window_set_visible(*wind, visible);
}
int is_visible()
uint8_t is_visible() const
{
return w_visible;
}
friend int window_is_visible(window &wind)
{
return wind.is_visible();
}
window *set_visible(uint8_t visible);
void set_modal(uint8_t modal)
{

View file

@ -163,7 +163,7 @@ static void menu_draw(const MENU &menu)
static void menu_show(MENU &menu)
{
window_set_visible(menu.wind, 1);
menu.wind->set_visible(1);
// Mark as displayed.
menu.Displayed = 1;
}
@ -186,7 +186,7 @@ static void menu_hide(MENU &menu)
if (!menu.Displayed) return;
if (&menu != Menu[0] && menu.wind)
window_set_visible(*menu.wind, 0); // don't draw or receive events
menu.wind->set_visible(0); // don't draw or receive events
menu.Active = 0;
if (&menu == Menu[0] && menu.wind)

View file

@ -1193,7 +1193,7 @@ window_event_result automap::event_handler(const d_event &event)
* Eventually, grd_curcanv will be removed entirely.
*/
gr_set_default_canvas();
window_set_visible(*Game_wind, 1);
Game_wind->set_visible(1);
Automap_active = 0;
multi_send_msgsend_state(msgsend_none);
return window_event_result::ignored; // continue closing
@ -1224,7 +1224,7 @@ void do_automap()
am->pause_game = !((Game_mode & GM_MULTI) && (!Endlevel_sequence)); // Set to 1 if everything is paused during automap...No pause during net.
if (am->pause_game) {
window_set_visible(*Game_wind, 0);
Game_wind->set_visible(0);
}
else
{

View file

@ -674,9 +674,10 @@ window_event_result start_endlevel_sequence()
#if defined(DXX_BUILD_DESCENT_II)
if (PLAYING_BUILTIN_MISSION) // only play movie for built-in mission
{
window_set_visible(*Game_wind, 0); // suspend the game, including drawing
const auto g = Game_wind;
g->set_visible(0); // suspend the game, including drawing
start_endlevel_movie();
window_set_visible(*Game_wind, 1);
g->set_visible(1);
}
strcpy(last_palette_loaded,""); //force palette load next time
#endif
@ -715,9 +716,10 @@ window_event_result start_endlevel_sequence()
if (PLAYING_BUILTIN_MISSION) // only play movie for built-in mission
if (!(Game_mode & GM_MULTI))
{
window_set_visible(*Game_wind, 0); // suspend the game, including drawing
const auto g = Game_wind;
g->set_visible(0); // suspend the game, including drawing
endlevel_movie_played = start_endlevel_movie();
window_set_visible(*Game_wind, 1);
g->set_visible(1);
}
if (!(!(Game_mode & GM_MULTI) && (endlevel_movie_played == movie_play_status::skipped) && endlevel_data_loaded))

View file

@ -1414,7 +1414,8 @@ static window_event_result HandleTestKey(fvmsegptridx &vmsegptridx, int key, con
case KEY_E + KEY_DEBUGGED:
{
window_set_visible(*Game_wind, 0); // don't let the game do anything while we set the editor up
const auto g = Game_wind;
g->set_visible(0); // don't let the game do anything while we set the editor up
auto old_gamestate = gamestate;
gamestate = editor_gamestate::unsaved; // saved game editing mode
@ -1422,7 +1423,7 @@ static window_event_result HandleTestKey(fvmsegptridx &vmsegptridx, int key, con
// If editor failed to load, carry on playing
if (!EditorWindow)
{
window_set_visible(*Game_wind, 1);
g->set_visible(1);
gamestate = old_gamestate;
return window_event_result::handled;
}
@ -1657,9 +1658,10 @@ void levelwarp_menu::handle_close_event()
*/
if (l > Last_level)
return;
window_set_visible(*Game_wind, 0);
const auto g = Game_wind;
g->set_visible(0);
StartNewLevel(l);
window_set_visible(*Game_wind, 1);
g->set_visible(1);
}
window_event_result levelwarp_menu::event_handler(const d_event &event)

View file

@ -1477,8 +1477,9 @@ window_event_result ExitSecretLevel()
if (Newdemo_state == ND_STATE_PLAYBACK)
return window_event_result::ignored;
if (Game_wind)
window_set_visible(*Game_wind, 0);
const auto g = Game_wind;
if (g)
g->set_visible(0);
if (!LevelUniqueControlCenterState.Control_center_destroyed)
{
@ -1507,8 +1508,8 @@ window_event_result ExitSecretLevel()
}
}
if (Game_wind)
window_set_visible(*Game_wind, 1);
if (g)
g->set_visible(1);
reset_time();
return result;
@ -1550,8 +1551,9 @@ void EnterSecretLevel(void)
Assert(! (Game_mode & GM_MULTI) );
if (Game_wind)
window_set_visible(*Game_wind, 0);
const auto g = Game_wind;
if (g)
g->set_visible(0);
digi_play_sample( SOUND_SECRET_EXIT, F1_0 ); // after above call which stops all sounds
@ -1589,8 +1591,8 @@ void EnterSecretLevel(void)
// END NMN
// do_cloak_invul_stuff();
if (Game_wind)
window_set_visible(*Game_wind, 1);
if (g)
g->set_visible(1);
reset_time();
}
#endif
@ -1600,8 +1602,9 @@ window_event_result PlayerFinishedLevel(int secret_flag)
{
auto &Objects = LevelUniqueObjectState.Objects;
auto &vmobjptr = Objects.vmptr;
if (Game_wind)
window_set_visible(*Game_wind, 0);
const auto g = Game_wind;
if (g)
g->set_visible(0);
//credit the player for hostages
auto &player_info = get_local_plrobj().ctype.player_info;
@ -1631,8 +1634,8 @@ window_event_result PlayerFinishedLevel(int secret_flag)
auto result = AdvanceLevel(secret_flag); //now go on to the next one (if one)
if (Game_wind)
window_set_visible(*Game_wind, 1);
if (g)
g->set_visible(1);
reset_time();
return result;
@ -1857,14 +1860,15 @@ window_event_result DoPlayerDead()
#endif
{
if (Game_wind)
window_set_visible(*Game_wind, 0);
const auto g = Game_wind;
if (g)
g->set_visible(0);
result = AdvanceLevel(0); //if finished, go on to next level
init_player_stats_new_ship(Player_num);
last_drawn_cockpit = -1;
if (Game_wind)
window_set_visible(*Game_wind, 1);
if (g)
g->set_visible(1);
}
#if defined(DXX_BUILD_DESCENT_II)
} else if (Current_level_num < 0) {

View file

@ -335,7 +335,7 @@ int hide_menus(void)
i = wind;
if (!wind)
break;
wind = window_set_visible(*wind, 0);
wind = wind->set_visible(0);
}
Assert(window_get_front() == NULL);
return 1;
@ -355,7 +355,7 @@ void show_menus(void)
// window_exists could return a false positive if a new window was created
// with the same pointer value as the deleted one, so killing window_exists (call and function)
// if (window_exists(i))
window_set_visible(std::exchange(i, nullptr), 1);
std::exchange(i, nullptr)->set_visible(1);
}
}

View file

@ -1988,8 +1988,9 @@ void multi_disconnect_player(const playernum_t pnum)
if (pnum == multi_who_is_master()) // Host has left - Quit game!
{
if (Game_wind)
window_set_visible(*Game_wind, 0);
const auto g = Game_wind;
if (g)
g->set_visible(0);
struct host_left_game : passive_messagebox
{
host_left_game() :
@ -1998,8 +1999,8 @@ void multi_disconnect_player(const playernum_t pnum)
}
};
run_blocking_newmenu<host_left_game>();
if (Game_wind)
window_set_visible(*Game_wind, 1);
if (g)
g->set_visible(1);
multi_quit_game = 1;
game_leave_menus();
return;
@ -3142,11 +3143,12 @@ void multi_consistency_error(int reset)
if (++count < 10)
return;
if (Game_wind)
window_set_visible(*Game_wind, 0);
const auto g = Game_wind;
if (g)
g->set_visible(0);
nm_messagebox_str(menu_title{nullptr}, nm_messagebox_tie(TXT_OK), menu_subtitle{TXT_CONSISTENCY_ERROR});
if (Game_wind)
window_set_visible(*Game_wind, 1);
if (g)
g->set_visible(1);
count = 0;
multi_quit_game = 1;
game_leave_menus();

View file

@ -3119,17 +3119,20 @@ static void net_udp_process_dump(ubyte *data, int, const _sockaddr &sender_addr)
{
case DUMP_PKTTIMEOUT:
case DUMP_KICKED:
if (Game_wind)
window_set_visible(*Game_wind, 0);
{
const auto g = Game_wind;
if (g)
g->set_visible(0);
if (data[1] == DUMP_PKTTIMEOUT)
nm_messagebox_str(menu_title{nullptr}, nm_messagebox_tie(TXT_OK), menu_subtitle{"You were removed from the game.\nYou failed receiving important\npackets. Sorry."});
else if (data[1] == DUMP_KICKED)
nm_messagebox_str(menu_title{nullptr}, nm_messagebox_tie(TXT_OK), menu_subtitle{"You were kicked by Host!"});
if (Game_wind)
window_set_visible(*Game_wind, 1);
if (g)
g->set_visible(1);
multi_quit_game = 1;
game_leave_menus();
break;
}
default:
if (data[1] > DUMP_LEVEL) // invalid dump... heh
break;
@ -5194,11 +5197,12 @@ static void net_udp_noloss_add_queue_pkt(fix64 time, const ubyte *data, ushort d
else // I am just a client. I gotta go.
{
Netgame.PacketLossPrevention = 0; // Disable PLP - otherwise we get stuck in an infinite loop here. NOTE: We could as well clean the whole queue to continue protect our disconnect signal bit it's not that important - we just wanna leave.
if (Game_wind)
window_set_visible(*Game_wind, 0);
const auto g = Game_wind;
if (g)
g->set_visible(0);
nm_messagebox_str(menu_title{nullptr}, nm_messagebox_tie(TXT_OK), menu_subtitle{"You left the game. You failed\nsending important packets.\nSorry."});
if (Game_wind)
window_set_visible(*Game_wind, 1);
if (g)
g->set_visible(1);
multi_quit_game = 1;
game_leave_menus();
}
@ -5395,11 +5399,12 @@ void net_udp_noloss_process_queue(fix64 time)
else // We are client, so we gotta go.
{
Netgame.PacketLossPrevention = 0; // Disable PLP - otherwise we get stuck in an infinite loop here. NOTE: We could as well clean the whole queue to continue protect our disconnect signal bit it's not that important - we just wanna leave.
if (Game_wind)
window_set_visible(*Game_wind, 0);
const auto g = Game_wind;
if (g)
g->set_visible(0);
nm_messagebox_str(menu_title{nullptr}, nm_messagebox_tie(TXT_OK), menu_subtitle{"You left the game. You failed\nsending important packets.\nSorry."});
if (Game_wind)
window_set_visible(*Game_wind, 1);
if (g)
g->set_visible(1);
multi_quit_game = 1;
game_leave_menus();
}

View file

@ -1939,8 +1939,8 @@ int state_restore_all_sub(const d_level_shared_destructible_light_state &LevelSh
init_player_stats_game(Player_num);
}
if (Game_wind)
window_set_visible(*Game_wind, 0);
if (const auto g = Game_wind)
g->set_visible(0);
//Read player info
@ -2498,9 +2498,9 @@ int state_restore_all_sub(const d_level_shared_destructible_light_state &LevelSh
}
else
state_set_next_autosave(GameUniqueState, PlayerCfg.SPGameplayOptions.AutosaveInterval);
if (Game_wind)
if (!window_is_visible(*Game_wind))
window_set_visible(*Game_wind, 1);
if (const auto g = Game_wind)
if (!g->is_visible())
g->set_visible(1);
reset_time();
return 1;