MP Lobby: refactor use of exception out of lobby config reload request
This commit is contained in:
parent
7ef80b301b
commit
e16588812a
4 changed files with 19 additions and 44 deletions
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2015 - 2016 by Chris Beck <render787@gmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
#ifndef LOBBY_RELOAD_REQUEST_EXCEPTION_HPP_INCLUDED
|
||||
#define LOBBY_RELOAD_REQUEST_EXCEPTION_HPP_INCLUDED
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace mp {
|
||||
|
||||
struct lobby_reload_request_exception : game::error {
|
||||
lobby_reload_request_exception() : game::error("Lobby requested to reload the game config and launch again") {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -18,7 +18,6 @@
|
|||
#include "config_assign.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "game_config_manager.hpp"
|
||||
#include "game_initialization/lobby_reload_request_exception.hpp"
|
||||
#include "game_initialization/mp_game_utils.hpp"
|
||||
#include "game_initialization/playcampaign.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
|
@ -443,7 +442,7 @@ static void enter_create_mode(mp_workflow_helper_ptr helper)
|
|||
}
|
||||
}
|
||||
|
||||
static void enter_lobby_mode(mp_workflow_helper_ptr helper, const std::vector<std::string>& installed_addons)
|
||||
static bool enter_lobby_mode(mp_workflow_helper_ptr helper, const std::vector<std::string>& installed_addons)
|
||||
{
|
||||
DBG_MP << "entering lobby mode" << std::endl;
|
||||
|
||||
|
@ -500,11 +499,16 @@ static void enter_lobby_mode(mp_workflow_helper_ptr helper, const std::vector<st
|
|||
}
|
||||
|
||||
break;
|
||||
case gui2::dialogs::mp_lobby::RELOAD_CONFIG:
|
||||
// Let this function's caller reload the config and re-call.
|
||||
return false;
|
||||
default:
|
||||
// Needed to handle the Quit signal and exit the loop
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Pubic entry points for the MP workflow */
|
||||
|
@ -529,24 +533,22 @@ void start_client(CVideo& video, const config& game_config, saved_game& state, c
|
|||
}
|
||||
|
||||
mp_workflow_helper_ptr workflow_helper;
|
||||
bool re_enter;
|
||||
bool re_enter = false;
|
||||
|
||||
do {
|
||||
workflow_helper.reset(new mp_workflow_helper(video, *game_config_ptr, state, connection.get(), nullptr));
|
||||
re_enter = false;
|
||||
|
||||
try {
|
||||
enter_lobby_mode(workflow_helper, installed_addons);
|
||||
} catch(lobby_reload_request_exception&) {
|
||||
re_enter = true;
|
||||
// A return of false means a config reload was requested, so do that and then loop.
|
||||
re_enter = !enter_lobby_mode(workflow_helper, installed_addons);
|
||||
|
||||
if(re_enter) {
|
||||
game_config_manager* gcm = game_config_manager::get();
|
||||
gcm->reload_changed_game_config();
|
||||
gcm->load_game_config_for_game(state.classification()); // NOTE: Using reload_changed_game_config only doesn't seem to work here
|
||||
|
||||
game_config_ptr = &gcm->game_config();
|
||||
|
||||
installed_addons = ::installed_addons(); // Refersh the installed add-on list for this session.
|
||||
installed_addons = ::installed_addons(); // Refresh the installed add-on list for this session.
|
||||
|
||||
connection->send_data(config("refresh_lobby"));
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
#include "formatter.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "game_initialization/lobby_reload_request_exception.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "lobby_preferences.hpp"
|
||||
#include "playmp_controller.hpp"
|
||||
|
@ -930,10 +929,6 @@ static bool handle_addon_requirements_gui(CVideo& v, const std::vector<mp::game_
|
|||
// Begin download session
|
||||
ad_hoc_addon_fetch_session(v, needs_download);
|
||||
|
||||
// TODO: get rid of evil exception throwing. Boooo! In any case, this is here to reload the game config
|
||||
// and the installed_addons list that the lobby has.
|
||||
throw mp::lobby_reload_request_exception();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -970,6 +965,11 @@ bool mp_lobby::do_game_join(int idx, bool observe)
|
|||
|
||||
if(!handle_addon_requirements_gui(window_->video(), game.required_addons, game.addons_outcome)) {
|
||||
return false;
|
||||
} else {
|
||||
// Addons have been downloaded, so the game_config and installed addons list need to be reloaded.
|
||||
// The lobby is closed and reopened.
|
||||
window_->set_retval(RELOAD_CONFIG);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,8 @@ public:
|
|||
QUIT,
|
||||
JOIN,
|
||||
OBSERVE,
|
||||
CREATE
|
||||
CREATE,
|
||||
RELOAD_CONFIG
|
||||
};
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Add table
Reference in a new issue