Stop passing a milion game_config refs around during game initializaton

There are only 3 places where it's actually really needed. Used the game_config_manager
singleton to retrieve a reference in those cases.
This commit is contained in:
Charles Dang 2018-06-25 14:57:05 +11:00
parent 11ca2d8ad8
commit 4eee386664
23 changed files with 57 additions and 65 deletions

View file

@ -17,6 +17,7 @@
#include "display.hpp"
#include "events.hpp"
#include "game_config_manager.hpp"
#include "gui/core/event/handler.hpp" // gui2::is_in_dialog
#include "gui/dialogs/loading_screen.hpp"
#include "hotkey/command_executor.hpp"
@ -31,9 +32,9 @@
static lg::log_domain log_display("display");
#define ERR_DP LOG_STREAM(err, log_display)
controller_base::controller_base(const config& game_config)
controller_base::controller_base()
: events::sdl_handler(false)
, game_config_(game_config)
, game_config_(game_config_manager::get()->game_config())
, key_()
, scrolling_(false)
, scroll_up_(false)

View file

@ -61,7 +61,7 @@ class manager;
class controller_base : public events::sdl_handler, public events::pump_monitor
{
public:
controller_base(const config& game_config);
controller_base();
virtual ~controller_base();
virtual void play_slice(bool is_delay_enabled = true);

View file

@ -61,13 +61,13 @@ static std::vector<std::string> saved_windows_;
namespace editor {
editor_controller::editor_controller(const config &game_config)
: controller_base(game_config)
editor_controller::editor_controller()
: controller_base()
, mouse_handler_base()
, quit_confirmation(std::bind(&editor_controller::quit_confirm, this))
, active_menu_(editor::MAP)
, reports_(new reports())
, gui_(new editor_display(*this, controller_base::get_theme(game_config, "editor")))
, gui_(new editor_display(*this, controller_base::get_theme(game_config_, "editor")))
, tods_()
, context_manager_(new context_manager(*gui_.get(), game_config_))
, toolkit_(nullptr)
@ -81,8 +81,8 @@ editor_controller::editor_controller(const config &game_config)
toolkit_.reset(new editor_toolkit(*gui_.get(), key_, game_config_, *context_manager_.get()));
context_manager_->locs_ = toolkit_->get_palette_manager()->location_palette_.get();
context_manager_->switch_context(0, true);
init_tods(game_config);
init_music(game_config);
init_tods(game_config_);
init_music(game_config_);
get_current_map_context().set_starting_position_labels(gui());
cursor::set(cursor::NORMAL);

View file

@ -78,7 +78,7 @@ class editor_controller : public controller_base,
* to the map can be retrieved between the main loop's end and the controller's
* destruction.
*/
explicit editor_controller(const config &game_config);
editor_controller();
~editor_controller();

View file

@ -25,7 +25,7 @@ lg::log_domain log_editor("editor");
namespace editor {
EXIT_STATUS start(const config& game_conf, const std::string& filename /* = "" */,
EXIT_STATUS start(const std::string& filename /* = "" */,
bool take_screenshot /* = false */, const std::string& screenshot_filename /* = "map_screenshot.bmp" */)
{
EXIT_STATUS e = EXIT_ERROR;
@ -33,7 +33,7 @@ EXIT_STATUS start(const config& game_conf, const std::string& filename /* = "" *
hotkey::scope_changer h_;
hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
editor_controller editor(game_conf);
editor_controller editor;
if (!filename.empty() && filesystem::file_exists (filename)) {
if (filesystem::is_directory(filename)) {
editor.context_manager_->set_default_dir(filename);

View file

@ -33,6 +33,6 @@ enum EXIT_STATUS {
* go back to the titlescreen or quit to desktop altogether)
*/
EXIT_STATUS start(const config& game_config, const std::string& filename = "", bool take_screenshot = false, const std::string& screenshot_filename = "map_screenshot.bmp");
EXIT_STATUS start(const std::string& filename = "", bool take_screenshot = false, const std::string& screenshot_filename = "map_screenshot.bmp");
} //end namespace editor

View file

@ -21,6 +21,7 @@
#include "filesystem.hpp"
#include "formatter.hpp"
#include "formula/string_utils.hpp"
#include "game_config_manager.hpp"
#include "gettext.hpp"
#include "lexical_cast.hpp"
#include "log.hpp"
@ -193,7 +194,7 @@ std::string make_game_type_marker(std::string text, bool color_for_missing)
} // end anon namespace
game_info::game_info(const config& game, const config& game_config, const std::vector<std::string>& installed_addons)
game_info::game_info(const config& game, const std::vector<std::string>& installed_addons)
: id(game["id"])
, map_data(game["map_data"])
, name(game["name"])
@ -229,6 +230,8 @@ game_info::game_info(const config& game, const config& game_config, const std::v
, required_addons()
, addons_outcome(SATISFIED)
{
const config& game_config = game_config_manager::get()->game_config();
// Parse the list of addons required to join this game.
for(const config& addon : game.child_range("addon")) {
if(addon.has_attribute("id")) {

View file

@ -137,7 +137,7 @@ struct user_info
*/
struct game_info
{
game_info(const config& c, const config& game_config, const std::vector<std::string>& installed_addons);
game_info(const config& c, const std::vector<std::string>& installed_addons);
bool can_join() const;
bool can_observe() const;

View file

@ -35,9 +35,8 @@ static lg::log_domain log_lobby("lobby");
namespace mp
{
lobby_info::lobby_info(const config& game_config, const std::vector<std::string>& installed_addons)
: game_config_(game_config)
, installed_addons_(installed_addons)
lobby_info::lobby_info(const std::vector<std::string>& installed_addons)
: installed_addons_(installed_addons)
, gamelist_()
, gamelist_initialized_(false)
, rooms_()
@ -116,7 +115,7 @@ void lobby_info::process_gamelist(const config& data)
games_by_id_.clear();
for(const auto& c : gamelist_.child("gamelist").child_range("game")) {
game_info game(c, game_config_, installed_addons_);
game_info game(c, installed_addons_);
games_by_id_.emplace(game.id, std::move(game));
}
@ -160,12 +159,12 @@ bool lobby_info::process_gamelist_diff(const config& data)
if(diff_result == "new" || diff_result == "modified") {
if(current_i == games_by_id_.end()) {
games_by_id_.emplace(game_id, game_info(c, game_config_, installed_addons_));
games_by_id_.emplace(game_id, game_info(c, installed_addons_));
continue;
}
// Had a game with that id, so update it and mark it as such
current_i->second = game_info(c, game_config_, installed_addons_);
current_i->second = game_info(c, installed_addons_);
current_i->second.display_status = game_info::UPDATED;
} else if(diff_result == "deleted") {
if(current_i == games_by_id_.end()) {

View file

@ -30,7 +30,7 @@ namespace mp
class lobby_info
{
public:
explicit lobby_info(const config& game_config, const std::vector<std::string>& installed_addons);
explicit lobby_info(const std::vector<std::string>& installed_addons);
typedef std::map<int, game_info> game_info_map;
@ -143,8 +143,6 @@ public:
private:
void process_userlist();
const config& game_config_;
const std::vector<std::string>& installed_addons_;
config gamelist_;

View file

@ -442,7 +442,7 @@ void enter_wait_mode(mp_workflow_helper_ptr helper, int game_id, bool observe)
}
if(dlg_ok) {
campaign_controller controller(helper->state, helper->game_config, game_config_manager::get()->terrain_types());
campaign_controller controller(helper->state, game_config_manager::get()->terrain_types());
controller.set_mp_info(campaign_info.get());
controller.play_game();
}
@ -473,7 +473,7 @@ void enter_staging_mode(mp_workflow_helper_ptr helper)
} // end connect_engine_ptr, dlg scope
if(dlg_ok) {
campaign_controller controller(helper->state, helper->game_config, game_config_manager::get()->terrain_types());
campaign_controller controller(helper->state, game_config_manager::get()->terrain_types());
controller.set_mp_info(campaign_info.get());
controller.play_game();
}
@ -527,7 +527,7 @@ bool enter_lobby_mode(mp_workflow_helper_ptr helper, const std::vector<std::stri
sound::stop_music();
}
mp::lobby_info li(helper->game_config, installed_addons);
mp::lobby_info li(installed_addons);
helper->lobby_info = &li;
if(!initial_lobby_config.empty()) {
@ -639,16 +639,16 @@ void start_client(const config& game_config, saved_game& state, const std::strin
} while(re_enter);
}
bool goto_mp_connect(ng::connect_engine& engine, const config& game_config, wesnothd_connection* connection)
bool goto_mp_connect(ng::connect_engine& engine, wesnothd_connection* connection)
{
lobby_info li(game_config, {});
lobby_info li({});
return gui2::dialogs::mp_staging::execute(engine, li, connection);
}
bool goto_mp_wait(saved_game& state, const config& game_config, wesnothd_connection* connection, bool observe)
bool goto_mp_wait(saved_game& state, wesnothd_connection* connection, bool observe)
{
lobby_info li(game_config, std::vector<std::string>());
lobby_info li({});
gui2::dialogs::mp_join_game dlg(state, li, *connection, false, observe);
@ -671,7 +671,7 @@ void start_local_game(const config& game_config, saved_game& state)
preferences::set_message_private(false);
// 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, {});
lobby_info li({});
mp_workflow_helper_ptr workflow_helper = std::make_shared<mp_workflow_helper>(game_config, state, nullptr, &li);
enter_create_mode(workflow_helper);
@ -773,7 +773,7 @@ void start_local_game_commandline(const config& game_config, saved_game& state,
unsigned int repeat = (cmdline_opts.multiplayer_repeat) ? *cmdline_opts.multiplayer_repeat : 1;
for(unsigned int i = 0; i < repeat; i++){
saved_game state_copy(state);
campaign_controller controller(state_copy, game_config, game_config_manager::get()->terrain_types());
campaign_controller controller(state_copy, game_config_manager::get()->terrain_types());
controller.play_game();
}
}

View file

@ -57,13 +57,12 @@ void start_client(const config& game_config,
* Opens mp::connect screen and sets game state according to the
* changes made.
*/
bool goto_mp_connect(ng::connect_engine& engine,
const config& game_config, wesnothd_connection* connection);
bool goto_mp_connect(ng::connect_engine& engine, wesnothd_connection* connection);
/**
* Opens mp::wait screen and sets game state according to the
* changes made.
*/
bool goto_mp_wait(saved_game& state, const config& game_config, wesnothd_connection* connection, bool observe);
bool goto_mp_wait(saved_game& state, wesnothd_connection* connection, bool observe);
}

View file

@ -191,7 +191,7 @@ void campaign_controller::show_carryover_message(
LEVEL_RESULT campaign_controller::playsingle_scenario(end_level_data& end_level)
{
playsingle_controller playcontroller(is_replay_ ? state_.get_replay_starting_point() : state_.get_starting_point(),
state_, game_config_, tdata_, false);
state_, tdata_, false);
LOG_NG << "created objects... " << (SDL_GetTicks() - playcontroller.get_ticks()) << "\n";
@ -227,7 +227,7 @@ LEVEL_RESULT campaign_controller::playsingle_scenario(end_level_data& end_level)
LEVEL_RESULT campaign_controller::playmp_scenario(end_level_data& end_level)
{
playmp_controller playcontroller(state_.get_starting_point(), state_, game_config_, tdata_, mp_info_);
playmp_controller playcontroller(state_.get_starting_point(), state_, tdata_, mp_info_);
LEVEL_RESULT res = playcontroller.play_scenario(state_.get_starting_point());
// Check if the player started as mp client and changed to host
@ -359,7 +359,7 @@ LEVEL_RESULT campaign_controller::play_game()
if(mp_info_ && !mp_info_->is_host) {
// Opens join game dialog to get a new gamestate.
if(!mp::goto_mp_wait(state_, game_config_, &mp_info_->connection, res == LEVEL_RESULT::OBSERVER_END)) {
if(!mp::goto_mp_wait(state_, &mp_info_->connection, res == LEVEL_RESULT::OBSERVER_END)) {
return LEVEL_RESULT::QUIT;
}
@ -383,7 +383,7 @@ LEVEL_RESULT campaign_controller::play_game()
(game_config::debug && game_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER)
) {
// Opens staging dialog to allow users to make an adjustments for scenario.
if(!mp::goto_mp_connect(*connect_engine, game_config_, mp_info_ ? &mp_info_->connection : nullptr)) {
if(!mp::goto_mp_connect(*connect_engine, mp_info_ ? &mp_info_->connection : nullptr)) {
return LEVEL_RESULT::QUIT;
}
} else {

View file

@ -57,15 +57,13 @@ struct mp_campaign_info
class campaign_controller
{
saved_game& state_;
const config& game_config_;
const ter_data_cache & tdata_;
const bool is_unit_test_;
bool is_replay_;
mp_campaign_info* mp_info_;
public:
campaign_controller(saved_game& state, const config& game_config, const ter_data_cache & tdata, bool is_unit_test = false)
campaign_controller(saved_game& state, const ter_data_cache & tdata, bool is_unit_test = false)
: state_(state)
, game_config_(game_config)
, tdata_(tdata)
, is_unit_test_(is_unit_test)
, is_replay_(false)

View file

@ -466,7 +466,7 @@ bool game_launcher::play_test()
load_game_config_for_game(state_.classification());
try {
campaign_controller ccontroller(state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types());
campaign_controller ccontroller(state_, game_config_manager::get()->terrain_types());
ccontroller.play_game();
} catch(const savegame::load_game_exception &e) {
load_data_.reset(new savegame::load_game_metadata(std::move(e.data_)));
@ -500,7 +500,7 @@ int game_launcher::unit_test()
load_game_config_for_game(state_.classification());
try {
campaign_controller ccontroller(state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types(), true);
campaign_controller ccontroller(state_, game_config_manager::get()->terrain_types(), true);
LEVEL_RESULT res = ccontroller.play_game();
if (!(res == LEVEL_RESULT::VICTORY) || lg::broke_strict()) {
return 1;
@ -526,7 +526,7 @@ int game_launcher::unit_test()
}
try {
campaign_controller ccontroller(state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types(), true);
campaign_controller ccontroller(state_, game_config_manager::get()->terrain_types(), true);
LEVEL_RESULT res = ccontroller.play_replay();
if (!(res == LEVEL_RESULT::VICTORY) || lg::broke_strict()) {
std::cerr << "Observed failure on replay" << std::endl;
@ -550,8 +550,7 @@ bool game_launcher::play_screenshot_mode()
::init_textdomains(game_config_manager::get()->game_config());
editor::start(game_config_manager::get()->game_config(),
screenshot_map_, true, screenshot_filename_);
editor::start(screenshot_map_, true, screenshot_filename_);
return false;
}
@ -956,7 +955,7 @@ void game_launcher::launch_game(RELOAD_GAME_DATA reload)
});
try {
campaign_controller ccontroller(state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types());
campaign_controller ccontroller(state_, game_config_manager::get()->terrain_types());
LEVEL_RESULT result = ccontroller.play_game();
ai::manager::singleton_ = nullptr;
// don't show The End for multiplayer scenario
@ -984,7 +983,7 @@ void game_launcher::play_replay()
{
assert(!load_data_);
try {
campaign_controller ccontroller(state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types());
campaign_controller ccontroller(state_, game_config_manager::get()->terrain_types());
ccontroller.play_replay();
} catch (const savegame::load_game_exception &e) {
load_data_.reset(new savegame::load_game_metadata(std::move(e.data_)));
@ -1001,8 +1000,7 @@ editor::EXIT_STATUS game_launcher::start_editor(const std::string& filename)
::init_textdomains(game_config_manager::get()->game_config());
editor::EXIT_STATUS res = editor::start(
game_config_manager::get()->game_config(), filename);
editor::EXIT_STATUS res = editor::start(filename);
if(res != editor::EXIT_RELOAD_DATA)
return res;

View file

@ -89,10 +89,10 @@ static lg::log_domain log_engine("engine");
namespace events
{
menu_handler::menu_handler(game_display* gui, play_controller& pc, const config& game_config)
menu_handler::menu_handler(game_display* gui, play_controller& pc)
: gui_(gui)
, pc_(pc)
, game_config_(game_config)
, game_config_(game_config_manager::get()->game_config())
, last_search_()
, last_search_hit_()
{

View file

@ -45,7 +45,7 @@ namespace events
class menu_handler : private chat_handler
{
public:
menu_handler(game_display* gui, play_controller& pc, const config& game_config);
menu_handler(game_display* gui, play_controller& pc);
virtual ~menu_handler();
void set_gui(game_display* gui)

View file

@ -128,10 +128,9 @@ static void clear_resources()
play_controller::play_controller(const config& level,
saved_game& state_of_game,
const config& game_config,
const ter_data_cache& tdata,
bool skip_replay)
: controller_base(game_config)
: controller_base()
, observer()
, quit_confirmation()
, ticks_(SDL_GetTicks())
@ -144,7 +143,7 @@ play_controller::play_controller(const config& level,
, plugins_context_()
, labels_manager_()
, mouse_handler_(nullptr, *this)
, menu_handler_(nullptr, *this, game_config)
, menu_handler_(nullptr, *this)
, hotkey_handler_(new hotkey_handler(*this, saved_game_))
, soundsources_manager_()
, persist_()

View file

@ -94,7 +94,6 @@ public:
play_controller(const config& level,
saved_game& state_of_game,
const config& game_config,
const ter_data_cache& tdata,
bool skip_replay);

View file

@ -39,10 +39,10 @@ static lg::log_domain log_engine("engine");
#define LOG_NG LOG_STREAM(info, log_engine)
playmp_controller::playmp_controller(const config& level,
saved_game& state_of_game, const config& game_config,
saved_game& state_of_game,
const ter_data_cache & tdata,
mp_campaign_info* mp_info)
: playsingle_controller(level, state_of_game, game_config, tdata, mp_info && mp_info->skip_replay)
: playsingle_controller(level, state_of_game, tdata, mp_info && mp_info->skip_replay)
, network_processing_stopped_(false)
, blindfold_(*gui_, mp_info && mp_info->skip_replay_blindfolded)
, mp_info_(mp_info)

View file

@ -24,7 +24,6 @@ class playmp_controller : public playsingle_controller, public syncmp_handler
{
public:
playmp_controller(const config& level, saved_game& state_of_game,
const config& game_config,
const ter_data_cache & tdata, mp_campaign_info* mp_info);
virtual ~playmp_controller();

View file

@ -66,9 +66,8 @@ static lg::log_domain log_enginerefac("enginerefac");
#define LOG_RG LOG_STREAM(info, log_enginerefac)
playsingle_controller::playsingle_controller(const config& level,
saved_game& state_of_game,
const config& game_config, const ter_data_cache & tdata, bool skip_replay)
: play_controller(level, state_of_game, game_config, tdata, skip_replay)
saved_game& state_of_game, const ter_data_cache & tdata, bool skip_replay)
: play_controller(level, state_of_game, tdata, skip_replay)
, cursor_setter_(cursor::NORMAL)
, replay_sender_(*resources::recorder)
, network_reader_([this](config& cfg) {return receive_from_wesnothd(cfg);})

View file

@ -37,7 +37,7 @@ class playsingle_controller : public play_controller
{
public:
playsingle_controller(const config& level, saved_game& state_of_game,
const config& game_config, const ter_data_cache & tdata, bool skip_replay);
const ter_data_cache & tdata, bool skip_replay);
LEVEL_RESULT play_scenario(const config& level);
void play_scenario_init();