Skip to content

Commit

Permalink
replace resources::config_manager with game_config_manager::get()
Browse files Browse the repository at this point in the history
This makes more sense, the main reason for resources was to hold
pointers to children of play_controller. For classes that are
legitimately singletons are essentially never destroyed or
reconstructed there's very little reason to put it in resources.
  • Loading branch information
cbeck88 committed Nov 25, 2014
1 parent 1897cfe commit e09a516
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 89 deletions.
13 changes: 10 additions & 3 deletions src/game_config_manager.cpp
Expand Up @@ -27,7 +27,6 @@
#include "loadscreen.hpp"
#include "log.hpp"
#include "preferences.hpp"
#include "resources.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "terrain_builder.hpp"
#include "terrain_type_data.hpp"
Expand All @@ -41,6 +40,8 @@ static lg::log_domain log_config("config");
#define WRN_CONFIG LOG_STREAM(warn, log_config)
#define LOG_CONFIG LOG_STREAM(info, log_config)

static game_config_manager * singleton;

game_config_manager::game_config_manager(
const commandline_options& cmdline_opts,
game_display& display,
Expand All @@ -53,7 +54,8 @@ game_config_manager::game_config_manager(
paths_manager_(),
cache_(game_config::config_cache::instance())
{
resources::config_manager = this;
assert(!singleton);
singleton = this;

if(cmdline_opts_.nocache) {
cache_.set_use_cache(false);
Expand All @@ -65,7 +67,12 @@ game_config_manager::game_config_manager(

game_config_manager::~game_config_manager()
{
resources::config_manager = NULL;
assert(singleton);
singleton = NULL;
}

game_config_manager * game_config_manager::get() {
return singleton;
}

bool game_config_manager::init_game_config(FORCE_RELOAD_CONFIG force_reload)
Expand Down
2 changes: 2 additions & 0 deletions src/game_config_manager.hpp
Expand Up @@ -42,6 +42,8 @@ class game_config_manager
void load_game_config_for_editor();
void load_game_config_for_game(const game_classification& classification);

static game_config_manager * get();

private:
game_config_manager(const game_config_manager&);
void operator=(const game_config_manager&);
Expand Down
3 changes: 1 addition & 2 deletions src/game_initialization/configure_engine.cpp
@@ -1,7 +1,6 @@
#include "configure_engine.hpp"
#include "formula_string_utils.hpp"
#include "game_config_manager.hpp"
#include "resources.hpp"
#include "settings.hpp"

#include <boost/foreach.hpp>
Expand Down Expand Up @@ -30,7 +29,7 @@ configure_engine::configure_engine(saved_game& state) :
set_use_map_settings(use_map_settings_default());

BOOST_FOREACH(const config& scenario,
resources::config_manager->game_config().child_range("multiplayer")) {
game_config_manager::get()->game_config().child_range("multiplayer")) {

if (!scenario["campaign_id"].empty() &&
(scenario["allow_new_game"].to_bool(true) || game_config::debug)) {
Expand Down
1 change: 0 additions & 1 deletion src/game_initialization/connect_engine.cpp
Expand Up @@ -21,7 +21,6 @@
#include "map.hpp"
#include "multiplayer_ui.hpp"
#include "mp_game_utils.hpp"
#include "resources.hpp"
#include "tod_manager.hpp"

#include <boost/foreach.hpp>
Expand Down
27 changes: 13 additions & 14 deletions src/game_initialization/create_engine.cpp
Expand Up @@ -27,7 +27,6 @@
#include "generators/map_create.hpp"
#include "map_exception.hpp"
#include "minimap.hpp"
#include "resources.hpp"
#include "saved_game.hpp"
#include "wml_separators.hpp"
#include "wml_exception.hpp"
Expand Down Expand Up @@ -161,7 +160,7 @@ void scenario::set_metadata()
const std::string& map_data = data_["map_data"];

try {
map_.reset(new gamemap(resources::config_manager->terrain_types(),
map_.reset(new gamemap(game_config_manager::get()->terrain_types(),
map_data));
} catch(incorrect_map_format_error& e) {
data_["description"] = _("Map could not be loaded: ") + e.message;
Expand Down Expand Up @@ -405,7 +404,7 @@ create_engine::create_engine(game_display& disp, saved_game& state) :
mods_(),
state_(state),
disp_(disp),
dependency_manager_(resources::config_manager->game_config(), disp.video()),
dependency_manager_(game_config_manager::get()->game_config(), disp.video()),
generator_(NULL)
{
DBG_MP << "restoring game config\n";
Expand All @@ -420,9 +419,9 @@ create_engine::create_engine(game_display& disp, saved_game& state) :
state_.mp_settings().show_connect = connect;

if (!(type == game_classification::SCENARIO &&
resources::config_manager->old_defines_map().count("TITLE_SCREEN") != 0))
game_config_manager::get()->old_defines_map().count("TITLE_SCREEN") != 0))
{
resources::config_manager->
game_config_manager::get()->
load_game_config_for_game(state_.classification());
}

Expand All @@ -442,7 +441,7 @@ create_engine::create_engine(game_display& disp, saved_game& state) :
state_.mp_settings().saved_game = false;

BOOST_FOREACH (const std::string& str, preferences::modifications()) {
if (resources::config_manager->
if (game_config_manager::get()->
game_config().find_child("modification", "id", str))
state_.mp_settings().active_mods.push_back(str);
}
Expand Down Expand Up @@ -524,11 +523,11 @@ void create_engine::prepare_for_new_level()
void create_engine::prepare_for_era_and_mods()
{
state_.classification().era_define =
resources::config_manager->game_config().find_child(
game_config_manager::get()->game_config().find_child(
"era", "id", get_parameters().mp_era)["define"].str();
BOOST_FOREACH(const std::string& mod_id, get_parameters().active_mods) {
state_.classification().mod_defines.push_back(
resources::config_manager->game_config().find_child(
game_config_manager::get()->game_config().find_child(
"modification", "id", mod_id)["define"].str());
}
}
Expand Down Expand Up @@ -642,7 +641,7 @@ void create_engine::prepare_for_saved_game()
{
DBG_MP << "preparing mp_game_settings for saved game\n";

resources::config_manager->load_game_config_for_game(state_.classification());
game_config_manager::get()->load_game_config_for_game(state_.classification());
//The save migh be a start-of-scenario save so make sure we have the scenario data loaded.
state_.expand_scenario();
state_.mp_settings().saved_game = true;
Expand Down Expand Up @@ -994,7 +993,7 @@ const mp_game_settings& create_engine::get_parameters()
void create_engine::init_all_levels()
{
if (const config &generic_multiplayer =
resources::config_manager->game_config().child(
game_config_manager::get()->game_config().child(
"generic_multiplayer")) {
config gen_mp_data = generic_multiplayer;

Expand All @@ -1011,7 +1010,7 @@ void create_engine::init_all_levels()
bool add_map = true;
boost::scoped_ptr<gamemap> map;
try {
map.reset(new gamemap(resources::config_manager->terrain_types(),
map.reset(new gamemap(game_config_manager::get()->terrain_types(),
user_map_data["map_data"]));
} catch (incorrect_map_format_error& e) {
user_map_data["description"] = _("Map could not be loaded: ") +
Expand Down Expand Up @@ -1069,7 +1068,7 @@ void create_engine::init_all_levels()

// Stand-alone scenarios.
BOOST_FOREACH(const config &data,
resources::config_manager->game_config().child_range(
game_config_manager::get()->game_config().child_range(
lexical_cast<std::string> (game_classification::MULTIPLAYER)))
{
if (!data["allow_new_game"].to_bool(true))
Expand All @@ -1088,7 +1087,7 @@ void create_engine::init_all_levels()

// Campaigns.
BOOST_FOREACH(const config &data,
resources::config_manager->game_config().child_range("campaign"))
game_config_manager::get()->game_config().child_range("campaign"))
{
const std::string& type = data["type"];
bool mp = state_.classification().campaign_type == game_classification::MULTIPLAYER;
Expand Down Expand Up @@ -1116,7 +1115,7 @@ void create_engine::init_extras(const MP_EXTRA extra_type)
const std::string extra_name = (extra_type == ERA) ? "era" : "modification";

BOOST_FOREACH(const config &extra,
resources::config_manager->game_config().child_range(extra_name)) {
game_config_manager::get()->game_config().child_range(extra_name)) {

extras_metadata_ptr new_extras_metadata(new extras_metadata());
new_extras_metadata->id = extra["id"].str();
Expand Down
7 changes: 3 additions & 4 deletions src/game_initialization/mp_game_utils.cpp
Expand Up @@ -22,7 +22,6 @@
#include "gettext.hpp"
#include "log.hpp"
#include "mp_options.hpp"
#include "resources.hpp"
#include "savegame.hpp"
#include "tod_manager.hpp"
#include "unit_id.hpp"
Expand Down Expand Up @@ -99,7 +98,7 @@ config initial_level_config(saved_game& state)
// Initialize the list of sides available for the current era.
// We also need this no not get a segfault in mp_connect for ai configuation
const config &era_cfg =
resources::config_manager->game_config().find_child("era", "id", era);
game_config_manager::get()->game_config().find_child("era", "id", era);
if (!era_cfg) {
if (!params.saved_game)
{
Expand All @@ -116,7 +115,7 @@ config initial_level_config(saved_game& state)
{
/*config& cfg = */level.add_child("era", era_cfg);

const config& custom_side = resources::config_manager->
const config& custom_side = game_config_manager::get()->
game_config().find_child("multiplayer_side", "id", "Custom");
level.child("era").add_child_at("multiplayer_side", custom_side, 0);

Expand All @@ -126,7 +125,7 @@ config initial_level_config(saved_game& state)
const std::vector<std::string>& mods = params.active_mods;
for (unsigned i = 0; i < mods.size(); i++) {
/*config& cfg = */level.add_child("modification",
resources::config_manager->
game_config_manager::get()->
game_config().find_child("modification", "id", mods[i]));
}

Expand Down
14 changes: 6 additions & 8 deletions src/game_initialization/multiplayer.cpp
Expand Up @@ -39,11 +39,9 @@
#include "multiplayer_lobby.hpp"
#include "playcampaign.hpp"
#include "playmp_controller.hpp"
#include "resources.hpp"
#include "settings.hpp"
#include "sound.hpp"
#include "unit_id.hpp"
#include "resources.hpp"
#include "game_config_manager.hpp"

#include <boost/bind.hpp>
Expand Down Expand Up @@ -467,7 +465,7 @@ static void enter_wait_mode(game_display& disp, const config& game_config,

switch (res) {
case mp::ui::PLAY:
play_game(disp, state, game_config, resources::config_manager->terrain_types(), IO_CLIENT,
play_game(disp, state, game_config, game_config_manager::get()->terrain_types(), IO_CLIENT,
preferences::skip_mp_replay() && observe, true, preferences::blindfold_replay() && observe);
recorder.clear();

Expand Down Expand Up @@ -511,7 +509,7 @@ static bool enter_connect_mode(game_display& disp, const config& game_config,

switch (res) {
case mp::ui::PLAY:
play_game(disp, state, game_config, resources::config_manager->terrain_types(), IO_SERVER, false,
play_game(disp, state, game_config, game_config_manager::get()->terrain_types(), IO_SERVER, false,
!local_players_only);
recorder.clear();

Expand Down Expand Up @@ -821,11 +819,11 @@ void start_local_game_commandline(game_display& disp, const config& game_config,
classification.campaign_type = game_classification::MULTIPLAYER;
classification.scenario_define = level_preload["define"].str();
classification.era_define = era_cfg_preload["define"].str();
resources::config_manager->load_game_config_for_game(classification);
game_config_manager::get()->load_game_config_for_game(classification);
}

const config& era_cfg = resources::config_manager->game_config().find_child("era", "id", parameters.mp_era);
const config& level = resources::config_manager->game_config().find_child("multiplayer", "id", parameters.name);
const config& era_cfg = game_config_manager::get()->game_config().find_child("era", "id", parameters.mp_era);
const config& level = game_config_manager::get()->game_config().find_child("multiplayer", "id", parameters.name);

if (cmdline_opts.multiplayer_side) {
for(std::vector<boost::tuple<unsigned int, std::string> >::const_iterator
Expand Down Expand Up @@ -893,7 +891,7 @@ void start_local_game_commandline(game_display& disp, const config& game_config,
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);
play_game(disp, state_copy, game_config, resources::config_manager->terrain_types(), IO_SERVER, false, false);
play_game(disp, state_copy, game_config, game_config_manager::get()->terrain_types(), IO_SERVER, false, false);
}
recorder.clear();
}
Expand Down
3 changes: 1 addition & 2 deletions src/game_initialization/multiplayer_create.cpp
Expand Up @@ -36,7 +36,6 @@
#include "minimap.hpp"
#include "multiplayer_create.hpp"
#include "filesystem.hpp"
#include "resources.hpp"
#include "savegame.hpp"
#include "log.hpp"
#include "wml_exception.hpp"
Expand Down Expand Up @@ -264,7 +263,7 @@ void create::process_event()
try
{
savegame::loadgame load(disp_,
resources::config_manager->game_config(), engine_.get_state());
game_config_manager::get()->game_config(), engine_.get_state());
load.load_multiplayer_game();

engine_.prepare_for_saved_game();
Expand Down
13 changes: 6 additions & 7 deletions src/game_initialization/multiplayer_wait.cpp
Expand Up @@ -24,7 +24,6 @@
#include "marked-up_text.hpp"
#include "mp_game_utils.hpp"
#include "multiplayer_wait.hpp"
#include "resources.hpp"
#include "statistics.hpp"
#include "saved_game.hpp"
#include "mp_ui_alerts.hpp"
Expand Down Expand Up @@ -208,7 +207,7 @@ wait::~wait()
state_ = saved_game();
state_.classification().campaign_type = game_classification::MULTIPLAYER;

resources::config_manager->
game_config_manager::get()->
load_game_config_for_game(state_.classification());
}
} catch (...) {}
Expand All @@ -235,15 +234,15 @@ void wait::join_game(bool observe)
state_ = saved_game();
state_.classification().campaign_type = game_classification::MULTIPLAYER;

const config* campaign = &resources::config_manager->
const config* campaign = &game_config_manager::get()->
game_config().find_child("campaign", "id",
level_.child("multiplayer")["mp_campaign"]);

const config* scenario = &resources::config_manager->
const config* scenario = &game_config_manager::get()->
game_config().find_child("multiplayer", "id",
level_.child(lexical_cast<std::string>(game_classification::MULTIPLAYER))["id"]);

const config* era = &resources::config_manager->
const config* era = &game_config_manager::get()->
game_config().find_child("era", "id", level_.child("era")["id"]);

if (*campaign) {
Expand All @@ -264,7 +263,7 @@ void wait::join_game(bool observe)
(*era)["define"].str();

BOOST_FOREACH(const config& mod, level_.child_range("modification")) {
const config* modification = &resources::config_manager->
const config* modification = &game_config_manager::get()->
game_config().find_child("modification", "id", mod["id"]);
if (*modification) {
state_.classification().mod_defines.push_back(
Expand All @@ -274,7 +273,7 @@ void wait::join_game(bool observe)


// Make sure that we have the same config as host, if possible.
resources::config_manager->
game_config_manager::get()->
load_game_config_for_game(state_.classification());
}

Expand Down
2 changes: 1 addition & 1 deletion src/game_initialization/singleplayer.cpp
Expand Up @@ -115,7 +115,7 @@ bool enter_create_mode(game_display& disp, const config& game_config,
return false;
}

configure_canceled = !enter_configure_mode(disp, resources::config_manager->game_config(),
configure_canceled = !enter_configure_mode(disp, game_config_manager::get()->game_config(),
state, jump_to_campaign, local_players_only);

} while (configure_canceled);
Expand Down

0 comments on commit e09a516

Please sign in to comment.