From c2e1d71fc257db38251f2396d3bd0b5f2be69533 Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Thu, 18 Jun 2015 14:30:58 +0200 Subject: [PATCH] less config reloads This removes a config reload when opening multiplayer or singleplayer campaign selection screen after playign a campaign. To do this we must make sure the default era for sp and for mp have the same id becasue otherwise we might get an id not found error. --- data/_main.cfg | 3 +- src/game_config_manager.cpp | 47 ++++++++++++++++++++--- src/game_config_manager.hpp | 12 +++++- src/game_initialization/create_engine.cpp | 11 ++---- src/game_launcher.cpp | 6 +-- 5 files changed, 61 insertions(+), 18 deletions(-) diff --git a/data/_main.cfg b/data/_main.cfg index 0e009b42519b..7b18dfaba745 100644 --- a/data/_main.cfg +++ b/data/_main.cfg @@ -32,7 +32,8 @@ #endif #else -{era_blank.cfg} +# using different default eras in sp and mp forcesus to a config reload which we dont want. +{multiplayer/eras.cfg} #endif {campaigns/} diff --git a/src/game_config_manager.cpp b/src/game_config_manager.cpp index b9d4cf47a702..8ff97ddda69c 100644 --- a/src/game_config_manager.cpp +++ b/src/game_config_manager.cpp @@ -101,7 +101,18 @@ bool game_config_manager::init_game_config(FORCE_RELOAD_CONFIG force_reload) return true; } - +/// returns true if every define in special is also defined in general +bool map_includes(const preproc_map& general, const preproc_map& special) +{ + BOOST_FOREACH(const preproc_map::value_type& pair, special) + { + preproc_map::const_iterator it = general.find(pair.first); + if (it == general.end() || it->second != pair.second) { + return false; + } + } + return true; +} void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, game_classification const* classification) { @@ -112,10 +123,13 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, 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; + if(!game_config_.empty()) { + if((force_reload == NO_FORCE_RELOAD) && old_defines_map_ == cache_.get_preproc_map()) { + return; + } + if((force_reload == NO_INCLUDE_RELOAD) && map_includes(old_defines_map_, cache_.get_preproc_map())) { + return; + } } loadscreen::global_loadscreen_manager loadscreen_manager(disp_.video()); @@ -540,4 +554,27 @@ void game_config_manager::load_game_config_for_game( throw; } } +void game_config_manager::load_game_config_for_create(bool is_mp) +{ + game_config::scoped_preproc_define multiplayer("MULTIPLAYER", is_mp); + + typedef boost::shared_ptr define; + try{ + load_game_config(NO_INCLUDE_RELOAD); + } + catch(game::error&) { + cache_.clear_defines(); + + std::deque previous_defines; + BOOST_FOREACH(const preproc_map::value_type& preproc, old_defines_map_) { + define new_define + (new game_config::scoped_preproc_define(preproc.first)); + previous_defines.push_back(new_define); + } + + load_game_config(NO_FORCE_RELOAD); + + throw; + } +} diff --git a/src/game_config_manager.hpp b/src/game_config_manager.hpp index d6a0011c4f78..5bae0531286d 100644 --- a/src/game_config_manager.hpp +++ b/src/game_config_manager.hpp @@ -29,8 +29,15 @@ class game_config_manager game_config_manager(const commandline_options& cmdline_opts, game_display& disp, const bool jump_to_editor); ~game_config_manager(); - - enum FORCE_RELOAD_CONFIG { FORCE_RELOAD, NO_FORCE_RELOAD }; + enum FORCE_RELOAD_CONFIG + { + /// Always reload config + FORCE_RELOAD, + /// Dont reload if the previous defines equal the new defines + NO_FORCE_RELOAD, + /// Dont reload if the previous defines include the new defines + NO_INCLUDE_RELOAD, + }; const config& game_config() const { return game_config_; } const preproc_map& old_defines_map() const { return old_defines_map_; } @@ -41,6 +48,7 @@ class game_config_manager void load_game_config_for_editor(); void load_game_config_for_game(const game_classification& classification); + void load_game_config_for_create(bool is_mp); static game_config_manager * get(); diff --git a/src/game_initialization/create_engine.cpp b/src/game_initialization/create_engine.cpp index b17f74a3ec19..7f57b214c82f 100644 --- a/src/game_initialization/create_engine.cpp +++ b/src/game_initialization/create_engine.cpp @@ -420,13 +420,7 @@ create_engine::create_engine(game_display& disp, saved_game& state) : state_.classification().campaign_type = type; state_.mp_settings().show_configure = configure; state_.mp_settings().show_connect = connect; - - if (!(type == game_classification::CAMPAIGN_TYPE::SCENARIO && - game_config_manager::get()->old_defines_map().count("TITLE_SCREEN") != 0)) - { - game_config_manager::get()-> - load_game_config_for_game(state_.classification()); - } + game_config_manager::get()->load_game_config_for_create(type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER); //TODO the editor dir is already configurable, is the preferences value filesystem::get_files_in_dir(filesystem::get_user_data_dir() + "/editor/maps", &user_map_names_, @@ -1077,6 +1071,9 @@ void create_engine::init_all_levels() if (!data["allow_new_game"].to_bool(true)) continue; + if (!data["campaign_id"].empty()) + continue; + if (data.has_attribute("map_generation") || data.has_attribute("scenario_generation")) { random_map_ptr new_random_map(new random_map(data)); random_maps_.push_back(new_random_map); diff --git a/src/game_launcher.cpp b/src/game_launcher.cpp index ba873ed41491..90c285bc6410 100644 --- a/src/game_launcher.cpp +++ b/src/game_launcher.cpp @@ -942,9 +942,9 @@ bool game_launcher::play_multiplayer() } - - game_config_manager::get()-> - load_game_config_for_game(state_.classification()); + //create_engine already calls game_config_manager::get()->load_config + //game_config_manager::get()-> + // load_game_config_for_game(state_.classification()); events::discard_input(); // prevent the "keylogger" effect cursor::set(cursor::NORMAL);