Skip to content

Commit

Permalink
Game Config Manager: utilize unique_ptrs over shared_ptrs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Nov 5, 2017
1 parent 3b9e73f commit 2277926
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/game_config_manager.cpp
Expand Up @@ -526,28 +526,30 @@ void game_config_manager::load_game_config_for_game(
game_config::scoped_preproc_define mptest("MP_TEST", cmdline_opts_.mptest &&
classification.campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER);

typedef std::shared_ptr<game_config::scoped_preproc_define> define;
//
// NOTE: these deques aren't used here, but the objects within are utilized as RAII helpers.
//

typedef std::unique_ptr<game_config::scoped_preproc_define> define;

std::deque<define> extra_defines;
for (const std::string& extra_define : classification.campaign_xtra_defines) {
define new_define(new game_config::scoped_preproc_define(extra_define));
extra_defines.push_back(new_define);
for(const std::string& extra_define : classification.campaign_xtra_defines) {
extra_defines.emplace_back(new game_config::scoped_preproc_define(extra_define));
}

std::deque<define> modification_defines;
for (const std::string& mod_define : classification.mod_defines) {
define new_define(new game_config::scoped_preproc_define(mod_define, !mod_define.empty()));
modification_defines.push_back(new_define);
for(const std::string& mod_define : classification.mod_defines) {
modification_defines.emplace_back(new game_config::scoped_preproc_define(mod_define, !mod_define.empty()));
}

try{
try {
load_game_config_with_loadscreen(NO_FORCE_RELOAD, &classification);
}
catch(game::error&) {
} catch(game::error&) {
cache_.clear_defines();

std::deque<define> previous_defines;
for (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);
for(const preproc_map::value_type& preproc : old_defines_map_) {
previous_defines.emplace_back(new game_config::scoped_preproc_define(preproc.first));
}

load_game_config_with_loadscreen(NO_FORCE_RELOAD);
Expand All @@ -563,7 +565,7 @@ void game_config_manager::load_game_config_for_create(bool is_mp, bool is_test)
///During an mp game the default difficuly define is also defined so better already load it now if we alreeady must reload config cache.
game_config::scoped_preproc_define normal(DEFAULT_DIFFICULTY, !map_includes(old_defines_map_, cache_.get_preproc_map()));

typedef std::shared_ptr<game_config::scoped_preproc_define> define;
typedef std::unique_ptr<game_config::scoped_preproc_define> define;
try{
load_game_config_with_loadscreen(NO_INCLUDE_RELOAD);
}
Expand All @@ -572,8 +574,7 @@ void game_config_manager::load_game_config_for_create(bool is_mp, bool is_test)

std::deque<define> previous_defines;
for (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);
previous_defines.emplace_back(new game_config::scoped_preproc_define(preproc.first));
}

load_game_config_with_loadscreen(NO_FORCE_RELOAD);
Expand Down

0 comments on commit 2277926

Please sign in to comment.