11#include " GameManager.hpp"
22
33#include < chrono>
4-
54#include < cstddef>
65#include < string_view>
76
7+ #include < range/v3/algorithm/contains.hpp>
8+ #include < range/v3/algorithm/find_if.hpp>
9+
810#include " openvic-simulation/dataloader/Dataloader.hpp"
11+ #include " openvic-simulation/types/OrderedContainers.hpp"
912#include " openvic-simulation/utility/Logger.hpp"
1013
1114using namespace OpenVic ;
@@ -65,12 +68,8 @@ bool GameManager::load_mod_descriptors() {
6568 return true ;
6669}
6770
68- bool GameManager::load_mods (
69- Dataloader::path_vector_t & roots,
70- Dataloader::path_vector_t & replace_paths,
71- utility::forwardable_span<const memory::string> requested_mods
72- ) {
73- if (requested_mods.empty ()) {
71+ bool GameManager::load_mods (memory::vector<memory::string> const & mods_to_find) {
72+ if (mods_to_find.empty ()) {
7473 return true ;
7574 }
7675
@@ -81,10 +80,8 @@ bool GameManager::load_mods(
8180 /* Check loaded mod descriptors for requested mods, using either full name or user directory name
8281 * (Historical Project Mod 0.4.6 or HPM both valid, for example), and load them plus their dependencies.
8382 */
84- for (std::string_view requested_mod : requested_mods) {
85- auto it = std::find_if (
86- mod_manager.get_mods ().begin (),
87- mod_manager.get_mods ().end (),
83+ for (std::string_view requested_mod : mods_to_find) {
84+ memory::vector<Mod>::const_iterator it = ranges::find_if (mod_manager.get_mods (),
8885 [&requested_mod](Mod const & mod) -> bool {
8986 return mod.get_identifier () == requested_mod || mod.get_user_dir () == requested_mod;
9087 }
@@ -118,27 +115,28 @@ bool GameManager::load_mods(
118115 }
119116 }
120117
118+ Dataloader::path_vector_t roots = dataloader.get_roots ();
119+ roots.reserve (load_list.size () + roots.size ());
120+
121+ vector_ordered_set<fs::path> replace_paths;
122+
121123 /* Actually registers all roots and replace paths to be loaded by the game. */
122124 for (Mod const * mod : load_list) {
123125 roots.emplace_back (roots[0 ] / mod->get_dataloader_root_path ());
124126 for (std::string_view path : mod->get_replace_paths ()) {
125- if (std::find (replace_paths.begin (), replace_paths.end (), path) == replace_paths.end ()) {
126- replace_paths.emplace_back (path);
127- }
127+ replace_paths.emplace (path);
128128 }
129129 }
130130
131131 /* Load only vanilla and push an error if mod loading failed. */
132132 if (ret) {
133- mod_manager.set_loaded_mods (std::move ( load_list.release () ));
133+ mod_manager.set_loaded_mods (load_list.release ());
134134 } else {
135135 mod_manager.set_loaded_mods ({});
136- replace_paths.clear ();
137- roots.erase (roots.begin ()+1 , roots.end ());
138136 Logger::error (" Mod loading failed, loading base only!" );
139137 }
140138
141- if (!dataloader.set_roots (roots, replace_paths, false )) {
139+ if (!dataloader.set_roots (roots, replace_paths. values_container () , false )) {
142140 Logger::error (" Failed to set dataloader roots!" );
143141 ret = false ;
144142 }
0 commit comments