Skip to content

Commit

Permalink
Pass the lobby_info reference around like a hot potato
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Sep 20, 2016
1 parent dcc34fc commit dc69c7f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/game_initialization/multiplayer.cpp
Expand Up @@ -453,10 +453,10 @@ static void enter_wait_mode(CVideo& video, const config& game_config, saved_game
}

static void enter_create_mode(CVideo& video, const config& game_config, saved_game& state, twesnothd_connection* wesnothd_connection,
bool local_players_only = false);
lobby_info& li, bool local_players_only = false);

static bool enter_connect_mode(CVideo& video, const config& game_config,
saved_game& state, twesnothd_connection* wesnothd_connection,
saved_game& state, twesnothd_connection* wesnothd_connection, lobby_info& li,
bool local_players_only = false)
{
DBG_MP << "entering connect mode" << std::endl;
Expand All @@ -477,7 +477,7 @@ static bool enter_connect_mode(CVideo& video, const config& game_config,
ng::connect_engine_ptr connect_engine(new ng::connect_engine(state, true, campaign_info.get()));

if(preferences::new_lobby()) {
gui2::tmp_staging dlg(game_config, *connect_engine);
gui2::tmp_staging dlg(game_config, *connect_engine, li);
dlg.show(video);

if(dlg.get_retval() == gui2::twindow::OK) {
Expand Down Expand Up @@ -516,7 +516,7 @@ static bool enter_connect_mode(CVideo& video, const config& game_config,
break;
}
case mp::ui::CREATE:
enter_create_mode(video, game_config, state, wesnothd_connection, local_players_only);
enter_create_mode(video, game_config, state, wesnothd_connection, li, local_players_only);
if (wesnothd_connection) {
wesnothd_connection->send_data(config("leave_game"));
}
Expand All @@ -533,11 +533,11 @@ static bool enter_connect_mode(CVideo& video, const config& game_config,
return true;
}

static bool enter_configure_mode(CVideo& video, const config& game_config, saved_game& state, twesnothd_connection* wesnothd_connection,
static bool enter_configure_mode(CVideo& video, const config& game_config, saved_game& state, twesnothd_connection* wesnothd_connection, lobby_info& li,
bool local_players_only = false);

static void enter_create_mode(CVideo& video, const config& game_config,
saved_game& state, twesnothd_connection* wesnothd_connection, bool local_players_only)
saved_game& state, twesnothd_connection* wesnothd_connection, lobby_info& li, bool local_players_only)
{
DBG_MP << "entering create mode" << std::endl;

Expand All @@ -552,7 +552,7 @@ static void enter_create_mode(CVideo& video, const config& game_config,
dlg.show(video);

if(dlg.get_retval() == gui2::twindow::OK) {
enter_connect_mode(video, game_config, state, wesnothd_connection, local_players_only);
enter_connect_mode(video, game_config, state, wesnothd_connection, li, local_players_only);
} else if(wesnothd_connection) {
wesnothd_connection->send_data(config("refresh_lobby"));
}
Expand All @@ -575,10 +575,10 @@ static void enter_create_mode(CVideo& video, const config& game_config,

switch (res) {
case mp::ui::CREATE:
configure_canceled = !enter_configure_mode(video, game_config, state, wesnothd_connection, local_players_only);
configure_canceled = !enter_configure_mode(video, game_config, state, wesnothd_connection, li, local_players_only);
break;
case mp::ui::LOAD_GAME:
connect_canceled = !enter_connect_mode(video, game_config, state, wesnothd_connection, local_players_only);
connect_canceled = !enter_connect_mode(video, game_config, state, wesnothd_connection, li, local_players_only);
break;
case mp::ui::QUIT:
default:
Expand All @@ -592,7 +592,7 @@ static void enter_create_mode(CVideo& video, const config& game_config,
}

static bool enter_configure_mode(CVideo& video, const config& game_config,
saved_game& state, twesnothd_connection* wesnothd_connection, bool local_players_only)
saved_game& state, twesnothd_connection* wesnothd_connection, lobby_info& li, bool local_players_only)
{
DBG_MP << "entering configure mode" << std::endl;

Expand All @@ -618,7 +618,7 @@ static bool enter_configure_mode(CVideo& video, const config& game_config,

switch (res) {
case mp::ui::CREATE:
connect_canceled = !enter_connect_mode(video, game_config, state, wesnothd_connection, local_players_only);
connect_canceled = !enter_connect_mode(video, game_config, state, wesnothd_connection, li, local_players_only);
break;
case mp::ui::QUIT:
default:
Expand Down Expand Up @@ -757,7 +757,9 @@ void start_local_game(CVideo& video, const config& game_config,
gamechat.clear_history();
gamelist.clear();
preferences::set_message_private(false);
enter_create_mode(video, game_config, state, nullptr, true);
// TODO: should lobby_info take a nullptr in this case, or should we pass the installed_addons data here too?
lobby_info li(game_config, std::vector<std::string>());
enter_create_mode(video, game_config, state, nullptr, li, true);
}

void start_local_game_commandline(CVideo& video, const config& game_config,
Expand Down

1 comment on commit dc69c7f

@CelticMinstrel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, a hot potato. (I think this really is the right way to do it though.)

Please sign in to comment.