Skip to content

Commit

Permalink
MP: wait at the loading screen until initial lobby data is fetched
Browse files Browse the repository at this point in the history
This does require some more usability improvements in the future, though. First off, this change was introduced
to get rid of that pause when the lobby is first opened before any contents appears. However, this change only
affects the initial connection, not any subsequent returns to the lobby.

Second, this also means the user doesn't have a way to quit to the titlescreen if the data fetching is taking an
especially long time anymore. It was suggested instead of this, we add some indicator to the lobby that data is
being fetched, but I don't know if that's really feasible with our toolkit. Still, we should add some way to exit
the loading screen if this is taking too long.

Lastly (and building on the above, though this is a more general issue), if at any point the server conks out and
doesn't send the lobby data, or a handshake, or anything, there's no way to exit the loading screen at that point.
Need to come up with a solution for that - either a timeout, or an exit button.
  • Loading branch information
Vultraz committed Nov 9, 2017
1 parent 192fbdc commit e41534d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
43 changes: 38 additions & 5 deletions src/game_initialization/multiplayer.cpp
Expand Up @@ -49,6 +49,8 @@ static lg::log_domain log_mp("mp/main");

namespace
{
config initial_lobby_config;

/** Opens a new server connection and prompts the client for login credentials, if necessary. */
wesnothd_connection_ptr open_connection(CVideo& video, std::string host)
{
Expand Down Expand Up @@ -82,8 +84,6 @@ wesnothd_connection_ptr open_connection(CVideo& video, std::string host)
return sock;
}

config data;

// Start stage
gui2::dialogs::loading_screen::progress(loading_stage::connect_to_server);

Expand All @@ -95,6 +95,16 @@ wesnothd_connection_ptr open_connection(CVideo& video, std::string host)

gui2::dialogs::loading_screen::progress(loading_stage::waiting);

config data;

// Clear the initial saved config to be sure we don't swap old data
// into `data` when we grab the new game/user list.
initial_lobby_config.clear();

bool received_join_lobby = false;
bool received_join_game = false;
bool received_gamelist = false;

// Then, log in and wait for the lobby/game join prompt.
do {
if(!sock) {
Expand Down Expand Up @@ -149,7 +159,7 @@ wesnothd_connection_ptr open_connection(CVideo& video, std::string host)

// Continue if we did not get a direction to login
if(!data.has_child("mustlogin")) {
continue;
goto data_check;
}

// Enter login loop
Expand Down Expand Up @@ -334,9 +344,27 @@ wesnothd_connection_ptr open_connection(CVideo& video, std::string host)
// is still going to be nullptr
if(!*error) break;
} // end login loop
} while(!(data.child("join_lobby") || data.child("join_game")));

if(!data.has_child("join_lobby")) {
data_check:

if(data.has_child("join_lobby")) {
received_join_lobby = true;

gui2::dialogs::loading_screen::progress(loading_stage::download_lobby_data);
}

if(data.has_child("join_game")) {
received_join_game = true;
}

if(data.has_child("gamelist")) {
received_gamelist = true;

std::swap(initial_lobby_config, data);
}
} while(!(received_join_lobby && received_gamelist) && !received_join_game);

if(!received_join_lobby) {
return wesnothd_connection_ptr();
}

Expand Down Expand Up @@ -493,6 +521,11 @@ bool enter_lobby_mode(mp_workflow_helper_ptr helper, const std::vector<std::stri
mp::lobby_info li(helper->game_config, installed_addons);
helper->lobby_info = &li;

if(!initial_lobby_config.empty()) {
li.process_gamelist(initial_lobby_config);
initial_lobby_config.clear();
}

int dlg_retval = 0;
int dlg_joined_game_id = 0;
{
Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogs/loading_screen.cpp
Expand Up @@ -69,6 +69,7 @@ static const std::map<loading_stage, std::string> stage_names {
{ loading_stage::redirect, N_("Connecting to redirected server") },
{ loading_stage::next_scenario, N_("Waiting for next scenario") },
{ loading_stage::download_level_data, N_("Getting game data") },
{ loading_stage::download_lobby_data, N_("Downloading lobby data") },
};

namespace gui2
Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogs/loading_screen.hpp
Expand Up @@ -59,6 +59,7 @@ enum class loading_stage
redirect,
next_scenario,
download_level_data,
download_lobby_data,
none,
};

Expand Down
10 changes: 8 additions & 2 deletions src/gui/dialogs/multiplayer/lobby.cpp
Expand Up @@ -139,7 +139,7 @@ mp_lobby::mp_lobby(const config& game_config, mp::lobby_info& info, wesnothd_con
, filter_text_(nullptr)
, selected_game_id_()
, player_list_()
, player_list_dirty_(false)
, player_list_dirty_(true)
, gamelist_dirty_(true)
, last_gamelist_update_(0)
, gamelist_diff_update_(true)
Expand Down Expand Up @@ -822,7 +822,13 @@ void mp_lobby::pre_show(window& window)
game_filter_reload();

// Force first update to be directly.
mp_lobby::network_handler();
update_gamelist();
update_playerlist();

// TODO: currently getting a crash in the chatbox if we use this.
// -- vultraz, 2017-11-10
//mp_lobby::network_handler();

lobby_update_timer_ = add_timer(
game_config::lobby_network_timer, std::bind(&mp_lobby::network_handler, this), true);

Expand Down

0 comments on commit e41534d

Please sign in to comment.