Ejemplo n.º 1
0
void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload)
{
	// Make sure that 'debug mode' symbol is set
	// if command line parameter is selected
	// also if we're in multiplayer and actual debug mode is disabled.
	game_config::scoped_preproc_define debug_mode("DEBUG_MODE",
	    game_config::debug || game_config::mp_debug);

	// Game_config already holds requested config in memory.
	if(!game_config_.empty() &&
		(force_reload == NO_FORCE_RELOAD)
		&& old_defines_map_ == cache_.get_preproc_map()) {
		return;
	}

	loadscreen::global_loadscreen_manager loadscreen_manager(disp_.video());
	cursor::setter cur(cursor::WAIT);

	// The loadscreen will erase the titlescreen.
	// NOTE: even without loadscreen, needed after MP lobby.
	try {
		// Read all game configs.
		// First we should load data/,
		// then handle terrains so that they are last loaded from data/.
		// 2nd everything in userdata.
		loadscreen::start_stage("verify cache");
		data_tree_checksum();
		loadscreen::start_stage("create cache");

		// Start transaction so macros are shared.
		game_config::config_cache_transaction main_transaction;

		cache_.get_config(game_config::path +"/data", game_config_);

		main_transaction.lock();

		// Put the gfx rules aside so that we can prepend the add-on
		// rules to them.
		config core_terrain_rules;
		core_terrain_rules.splice_children(game_config_, "terrain_graphics");

		load_addons_cfg();

		// Extract the Lua scripts at toplevel.
		extract_preload_scripts(game_config_);
		game_config_.clear_children("lua");

		// Put the gfx rules back to game config.
		game_config_.splice_children(core_terrain_rules, "terrain_graphics");

		set_multiplayer_hashes();
		set_color_info();
		set_unit_data();

		terrain_builder::set_terrain_rules_cfg(game_config());
		::init_strings(game_config());
		theme::set_known_themes(&game_config());
	} catch(game::error& e) {
		ERR_CONFIG << "Error loading game configuration files\n";
		gui2::show_error_message(disp_.video(),
			_("Error loading game configuration files: '") +
			e.message + _("' (The game will now exit)"));
		throw;
	}

	old_defines_map_ = cache_.get_preproc_map();

	// Set new binary paths.
	paths_manager_.set_paths(game_config());
}
Ejemplo n.º 2
0
void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload,
	game_classification const* classification)
{
	// Make sure that 'debug mode' symbol is set
	// if command line parameter is selected
	// also if we're in multiplayer and actual debug mode is disabled.
	game_config::scoped_preproc_define debug_mode("DEBUG_MODE",
	    game_config::debug || game_config::mp_debug);

	// Game_config already holds requested config in memory.
	if(!game_config_.empty() &&
		(force_reload == NO_FORCE_RELOAD)
		&& old_defines_map_ == cache_.get_preproc_map()) {
		return;
	}

	loadscreen::global_loadscreen_manager loadscreen_manager(disp_.video());
	cursor::setter cur(cursor::WAIT);

	// The loadscreen will erase the titlescreen.
	// NOTE: even without loadscreen, needed after MP lobby.
	try {
		// Read all game configs.
		// First we should load data/,
		// then handle terrains so that they are last loaded from data/.
		// 2nd everything in userdata.
		loadscreen::start_stage("verify cache");
		data_tree_checksum();
		loadscreen::start_stage("create cache");

		// Start transaction so macros are shared.
		game_config::config_cache_transaction main_transaction;

		// Load the selected core
		cache_.get_config(get_wml_location(preferences::wml_tree_root()), game_config_);
		// Load the mainline core definitions to make sure switching back is always possible.
		config default_core_cfg;
		cache_.get_config(game_config::path + "/data/cores.cfg", default_core_cfg);
		game_config_.append(default_core_cfg);

		main_transaction.lock();

		// Put the gfx rules aside so that we can prepend the add-on
		// rules to them.
		config core_terrain_rules;
		core_terrain_rules.splice_children(game_config_, "terrain_graphics");

		load_addons_cfg();

		// If multiplayer campaign is being loaded, [scenario] tags should
		// become [multiplayer] tags and campaign's id should be added to them
		// to allow to recognize which scenarios belongs to a loaded campaign.
		if (classification != NULL) {
			if (classification->campaign_type == game_classification::MULTIPLAYER &&
				!classification->campaign_define.empty()) {

				const config& campaign = game_config().find_child("campaign",
					"define", classification->campaign_define);
				const std::string& campaign_id = campaign["id"];
				const bool require_campaign =
					campaign["require_campaign"].to_bool(true);

				const config::const_child_itors &ci =
					game_config().child_range("scenario");
				std::vector<config> scenarios(ci.first, ci.second);

				game_config_.clear_children("scenario");

				BOOST_FOREACH(config& cfg, scenarios) {
					cfg["campaign_id"] = campaign_id;
					cfg["require_scenario"] = require_campaign;
					game_config_.add_child(lexical_cast<std::string>(game_classification::MULTIPLAYER), cfg);
				}
			}
		}

		// Extract the Lua scripts at toplevel.
		extract_preload_scripts(game_config_);
		game_config_.clear_children("lua");

		// Put the gfx rules back to game config.
		game_config_.splice_children(core_terrain_rules, "terrain_graphics");

		set_multiplayer_hashes();
		set_color_info();
		set_unit_data();

		terrain_builder::set_terrain_rules_cfg(game_config());
		::init_strings(game_config());
		theme::set_known_themes(&game_config());
	} catch(game::error& e) {