Move num_active_udp_games into netgame_list_game_menu
This commit is contained in:
parent
a1bdd81d41
commit
27f18be3ca
|
@ -318,7 +318,6 @@ static std::array<UDP_mdata_store, UDP_MDATA_STOR_QUEUE_SIZE> UDP_mdata_queue;
|
|||
static std::array<UDP_mdata_check, MAX_PLAYERS> UDP_mdata_trace;
|
||||
static UDP_sequence_packet UDP_sync_player; // For rejoin object syncing
|
||||
static std::array<UDP_netgame_info_lite, UDP_MAX_NETGAMES> Active_udp_games;
|
||||
static unsigned num_active_udp_games;
|
||||
static int num_active_udp_changed;
|
||||
static uint16_t UDP_MyPort;
|
||||
static sockaddr_in GBcast; // global Broadcast address clients and hosts will use for lite_info exchange over LAN
|
||||
|
@ -1102,11 +1101,23 @@ struct netgame_list_game_menu_items
|
|||
}
|
||||
};
|
||||
|
||||
struct netgame_list_game_menu;
|
||||
|
||||
netgame_list_game_menu *netgame_list_menu;
|
||||
|
||||
struct netgame_list_game_menu : netgame_list_game_menu_items, direct_join, newmenu
|
||||
{
|
||||
unsigned num_active_udp_games = 0;
|
||||
netgame_list_game_menu(grs_canvas &src) :
|
||||
newmenu(menu_title{"NETGAMES"}, menu_subtitle{nullptr}, menu_filename{nullptr}, tiny_mode_flag::tiny, tab_processing_flag::process, adjusted_citem::create(menus, 0), src)
|
||||
{
|
||||
assert(!netgame_list_menu);
|
||||
netgame_list_menu = this;
|
||||
}
|
||||
~netgame_list_game_menu()
|
||||
{
|
||||
assert(netgame_list_menu == this);
|
||||
netgame_list_menu = nullptr;
|
||||
}
|
||||
virtual window_event_result event_handler(const d_event &event) override;
|
||||
};
|
||||
|
@ -1547,8 +1558,6 @@ void net_udp_list_join_game(grs_canvas &canvas)
|
|||
net_udp_flush(UDP_Socket);
|
||||
net_udp_listen(); // Throw out old info
|
||||
|
||||
num_active_udp_games = 0;
|
||||
|
||||
Active_udp_games = {};
|
||||
|
||||
gr_set_fontcolor(canvas, BM_XRGB(15, 15, 23),-1);
|
||||
|
@ -2927,6 +2936,9 @@ static void net_udp_process_game_info(const uint8_t *data, uint_fast32_t, const
|
|||
uint_fast32_t len = 0;
|
||||
if (lite_info)
|
||||
{
|
||||
const auto menu = netgame_list_menu;
|
||||
if (!menu)
|
||||
return;
|
||||
UDP_netgame_info_lite recv_game;
|
||||
|
||||
recv_game.game_addr = game_addr;
|
||||
|
@ -2956,7 +2968,7 @@ static void net_udp_process_game_info(const uint8_t *data, uint_fast32_t, const
|
|||
|
||||
num_active_udp_changed = 1;
|
||||
|
||||
auto r = partial_range(Active_udp_games, num_active_udp_games);
|
||||
auto r = partial_range(Active_udp_games, menu->num_active_udp_games);
|
||||
auto i = std::find_if(r.begin(), r.end(), [&recv_game](const UDP_netgame_info_lite &g) { return !d_stricmp(g.game_name.data(), recv_game.game_name.data()) && g.GameID == recv_game.GameID; });
|
||||
if (i == Active_udp_games.end())
|
||||
{
|
||||
|
@ -2986,13 +2998,13 @@ static void net_udp_process_game_info(const uint8_t *data, uint_fast32_t, const
|
|||
if (i == r.end())
|
||||
{
|
||||
if (i->numconnected)
|
||||
num_active_udp_games++;
|
||||
++ menu->num_active_udp_games;
|
||||
}
|
||||
else if (!i->numconnected)
|
||||
{
|
||||
// Delete this game
|
||||
std::move(std::next(i), r.end(), i);
|
||||
num_active_udp_games--;
|
||||
-- menu->num_active_udp_games;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue