@@ -287,6 +287,9 @@ bool Dataloader::_load_interface_files(UIManager& ui_manager) const {
287287 static const std::vector<std::string_view> gui_files {
288288 " province_interface.gui" , " topbar.gui"
289289 };
290+
291+ ui_manager.reserve_more_scenes (gui_files.size ());
292+
290293 for (std::string_view const & gui_file : gui_files) {
291294 if (!ui_manager.load_gui_file (
292295 gui_file, parse_defines (lookup_file (append_string_views (interface_directory, gui_file))).get_file_node ()
@@ -307,8 +310,10 @@ bool Dataloader::_load_pop_types(GameManager& game_manager) {
307310 IdeologyManager const & ideology_manager = game_manager.get_politics_manager ().get_ideology_manager ();
308311
309312 static constexpr std::string_view pop_type_directory = " poptypes" ;
313+
310314 const path_vector_t pop_type_files = lookup_files_in_dir (pop_type_directory, " .txt" );
311- pop_manager.reserve_pop_types (pop_type_files.size ());
315+
316+ pop_manager.reserve_all_pop_types (pop_type_files.size ());
312317
313318 bool ret = apply_to_files (
314319 pop_type_files,
@@ -318,8 +323,8 @@ bool Dataloader::_load_pop_types(GameManager& game_manager) {
318323 );
319324 }
320325 );
321- pop_manager. lock_stratas ();
322- pop_manager.lock_pop_types ();
326+
327+ pop_manager.lock_all_pop_types ();
323328
324329 if (pop_manager.get_slave_sprite () <= 0 ) {
325330 Logger::error (" No slave pop type sprite found!" );
@@ -343,8 +348,12 @@ bool Dataloader::_load_units(GameManager& game_manager) const {
343348
344349 UnitManager& unit_manager = game_manager.get_military_manager ().get_unit_manager ();
345350
351+ const path_vector_t unit_files = lookup_files_in_dir (units_directory, " .txt" );
352+
353+ unit_manager.reserve_more_units (unit_files.size ());
354+
346355 bool ret = apply_to_files (
347- lookup_files_in_dir (units_directory, " .txt " ) ,
356+ unit_files ,
348357 [&game_manager, &unit_manager](fs::path const & file) -> bool {
349358 return unit_manager.load_unit_file (
350359 game_manager.get_economy_manager ().get_good_manager (), parse_defines (file).get_file_node ()
@@ -481,112 +490,152 @@ bool Dataloader::_load_decisions(GameManager& game_manager) {
481490
482491bool Dataloader::_load_history (GameManager& game_manager, bool unused_history_file_warnings) const {
483492
484- /* Country History */
485- static constexpr std::string_view country_history_directory = " history/countries" ;
486- bool ret = apply_to_files (
487- lookup_basic_indentifier_prefixed_files_in_dir (country_history_directory, " .txt" ),
488- [this , &game_manager, unused_history_file_warnings](fs::path const & file) -> bool {
489- const std::string filename = file.stem ().string ();
490- const std::string_view country_id = extract_basic_identifier_prefix (filename);
491-
492- Country const * country = game_manager.get_country_manager ().get_country_by_identifier (country_id);
493- if (country == nullptr ) {
494- if (unused_history_file_warnings) {
495- Logger::warning (" Found history file for non-existent country: " , country_id);
493+ bool ret = true ;
494+
495+ {
496+ /* Country History */
497+ CountryHistoryManager& country_history_manager = game_manager.get_history_manager ().get_country_manager ();
498+
499+ static constexpr std::string_view country_history_directory = " history/countries" ;
500+ const path_vector_t country_history_files =
501+ lookup_basic_indentifier_prefixed_files_in_dir (country_history_directory, " .txt" );
502+
503+ country_history_manager.reserve_more_country_histories (country_history_files.size ());
504+
505+ ret &= apply_to_files (
506+ country_history_files,
507+ [this , &game_manager, &country_history_manager, unused_history_file_warnings](fs::path const & file) -> bool {
508+ const std::string filename = file.stem ().string ();
509+ const std::string_view country_id = extract_basic_identifier_prefix (filename);
510+
511+ Country const * country = game_manager.get_country_manager ().get_country_by_identifier (country_id);
512+ if (country == nullptr ) {
513+ if (unused_history_file_warnings) {
514+ Logger::warning (" Found history file for non-existent country: " , country_id);
515+ }
516+ return true ;
496517 }
497- return true ;
518+
519+ return country_history_manager.load_country_history_file (
520+ game_manager, *this , *country, parse_defines (file).get_file_node ()
521+ );
498522 }
523+ );
499524
500- return game_manager.get_history_manager ().get_country_manager ().load_country_history_file (
501- game_manager, *this , *country, parse_defines (file).get_file_node ()
502- );
503- }
504- );
505- game_manager.get_history_manager ().get_country_manager ().lock_country_histories ();
525+ country_history_manager.lock_country_histories ();
526+ }
506527
507528 {
508529 DeploymentManager& deployment_manager = game_manager.get_military_manager ().get_deployment_manager ();
530+
509531 deployment_manager.lock_deployments ();
532+
510533 if (deployment_manager.get_missing_oob_file_count () > 0 ) {
511534 Logger::warning (deployment_manager.get_missing_oob_file_count (), " missing OOB files!" );
512535 }
513536 }
514537
515- /* Province History */
516- static constexpr std::string_view province_history_directory = " history/provinces" ;
517- ret &= apply_to_files (
518- lookup_basic_indentifier_prefixed_files_in_dir_recursive (province_history_directory, " .txt" ),
519- [this , &game_manager, unused_history_file_warnings](fs::path const & file) -> bool {
520- const std::string filename = file.stem ().string ();
521- const std::string_view province_id = extract_basic_identifier_prefix (filename);
522-
523- Province const * province = game_manager.get_map ().get_province_by_identifier (province_id);
524- if (province == nullptr ) {
525- if (unused_history_file_warnings) {
526- Logger::warning (" Found history file for non-existent province: " , province_id);
538+ {
539+ /* Province History */
540+ ProvinceHistoryManager& province_history_manager = game_manager.get_history_manager ().get_province_manager ();
541+ Map const & map = game_manager.get_map ();
542+
543+ static constexpr std::string_view province_history_directory = " history/provinces" ;
544+ const path_vector_t province_history_files =
545+ lookup_basic_indentifier_prefixed_files_in_dir_recursive (province_history_directory, " .txt" );
546+
547+ province_history_manager.reserve_more_province_histories (province_history_files.size ());
548+
549+ ret &= apply_to_files (
550+ province_history_files,
551+ [this , &game_manager, &province_history_manager, &map, unused_history_file_warnings](fs::path const & file) -> bool {
552+ const std::string filename = file.stem ().string ();
553+ const std::string_view province_id = extract_basic_identifier_prefix (filename);
554+
555+ Province const * province = map.get_province_by_identifier (province_id);
556+ if (province == nullptr ) {
557+ if (unused_history_file_warnings) {
558+ Logger::warning (" Found history file for non-existent province: " , province_id);
559+ }
560+ return true ;
527561 }
528- return true ;
562+
563+ return province_history_manager.load_province_history_file (
564+ game_manager, *province, parse_defines (file).get_file_node ()
565+ );
529566 }
567+ );
530568
531- return game_manager.get_history_manager ().get_province_manager ().load_province_history_file (
532- game_manager, *province, parse_defines (file).get_file_node ()
533- );
534- }
535- );
569+ /* Pop History */
570+ static constexpr std::string_view pop_history_directory = " history/pops/" ;
571+
572+ const string_set_t pop_history_dirs = lookup_dirs_in_dir (pop_history_directory);
573+ const Date last_bookmark_date = game_manager.get_history_manager ().get_bookmark_manager ().get_last_bookmark_date ();
574+
575+ for (std::string const & dir : pop_history_dirs) {
576+ bool successful = false ;
577+ const Date date = Date::from_string (dir, &successful);
578+
579+ if (successful && date <= last_bookmark_date) {
580+ bool non_integer_size = false ;
581+
582+ ret &= apply_to_files (
583+ lookup_files_in_dir (StringUtils::append_string_views (pop_history_directory, dir), " .txt" ),
584+ [this , &game_manager, &province_history_manager, date, &non_integer_size](fs::path const & file) -> bool {
585+ return province_history_manager.load_pop_history_file (
586+ game_manager, date, parse_defines (file).get_file_node (), &non_integer_size
587+ );
588+ }
589+ );
536590
537- /* Pop History */
538- static constexpr std::string_view pop_history_directory = " history/pops/" ;
539- const string_set_t pop_history_dirs = lookup_dirs_in_dir (pop_history_directory);
540- const Date last_bookmark_date = game_manager.get_history_manager ().get_bookmark_manager ().get_last_bookmark_date ();
541- for (std::string const & dir : pop_history_dirs) {
542- bool successful = false ;
543- const Date date = Date::from_string (dir, &successful);
544- if (successful && date <= last_bookmark_date) {
545- bool non_integer_size = false ;
546- ret &= apply_to_files (
547- lookup_files_in_dir (StringUtils::append_string_views (pop_history_directory, dir), " .txt" ),
548- [this , &game_manager, date, &non_integer_size](fs::path const & file) -> bool {
549- return game_manager.get_history_manager ().get_province_manager ().load_pop_history_file (
550- game_manager, date, parse_defines (file).get_file_node (), &non_integer_size
551- );
591+ if (non_integer_size) {
592+ Logger::warning (" Non-integer pop sizes in pop history files for " , date);
552593 }
553- );
554- if (non_integer_size) {
555- Logger::warning (" Non-integer pop sizes in pop history files for " , date);
556594 }
557595 }
596+
597+ province_history_manager.lock_province_histories (map, false );
558598 }
559599
560- game_manager.get_history_manager ().get_province_manager ().lock_province_histories (game_manager.get_map (), false );
600+ {
601+ /* Diplomacy History */
602+ DiplomaticHistoryManager& diplomatic_history_manager = game_manager.get_history_manager ().get_diplomacy_manager ();
561603
562- /* Diplomacy History */
563- static constexpr std::string_view diplomacy_history_directory = " history/diplomacy" ;
564- ret &= apply_to_files (
565- lookup_files_in_dir (diplomacy_history_directory, " .txt" ),
566- [this , &game_manager](fs::path const & file) -> bool {
567- return game_manager.get_history_manager ().get_diplomacy_manager ().load_diplomacy_history_file (
568- game_manager.get_country_manager (), parse_defines (file).get_file_node ()
569- );
570- }
571- );
604+ static constexpr std::string_view diplomacy_history_directory = " history/diplomacy" ;
572605
573- /* War History */
574- static constexpr std::string_view war_history_directory = " history/wars" ;
575- ret &= apply_to_files (
576- lookup_files_in_dir (war_history_directory, " .txt" ),
577- [this , &game_manager](fs::path const & file) -> bool {
578- return game_manager.get_history_manager ().get_diplomacy_manager ().load_war_history_file (
579- game_manager, parse_defines (file).get_file_node ()
580- );
581- }
582- );
583- game_manager.get_history_manager ().get_diplomacy_manager ().lock_diplomatic_history ();
606+ ret &= apply_to_files (
607+ lookup_files_in_dir (diplomacy_history_directory, " .txt" ),
608+ [this , &game_manager, &diplomatic_history_manager](fs::path const & file) -> bool {
609+ return diplomatic_history_manager.load_diplomacy_history_file (
610+ game_manager.get_country_manager (), parse_defines (file).get_file_node ()
611+ );
612+ }
613+ );
614+
615+ /* War History */
616+ static constexpr std::string_view war_history_directory = " history/wars" ;
617+ const path_vector_t war_history_files = lookup_files_in_dir (war_history_directory, " .txt" );
618+
619+ diplomatic_history_manager.reserve_more_wars (war_history_files.size ());
620+
621+ ret &= apply_to_files (
622+ war_history_files,
623+ [this , &game_manager, &diplomatic_history_manager](fs::path const & file) -> bool {
624+ return diplomatic_history_manager.load_war_history_file (
625+ game_manager, parse_defines (file).get_file_node ()
626+ );
627+ }
628+ );
629+
630+ diplomatic_history_manager.lock_diplomatic_history ();
631+ }
584632
585633 return ret;
586634}
587635
588636bool Dataloader::_load_events (GameManager& game_manager) {
589637 static constexpr std::string_view events_directory = " events" ;
638+
590639 const bool ret = apply_to_files (
591640 lookup_files_in_dir (events_directory, " .txt" ),
592641 [this , &game_manager](fs::path const & file) -> bool {
@@ -595,6 +644,7 @@ bool Dataloader::_load_events(GameManager& game_manager) {
595644 );
596645 }
597646 );
647+
598648 game_manager.get_event_manager ().lock_events ();
599649 return ret;
600650}
@@ -959,9 +1009,13 @@ bool Dataloader::load_defines(GameManager& game_manager) {
9591009 return ret;
9601010}
9611011
962- #define PARSE_SCRIPTS (name, mgr ) \
963- if (!mgr.parse_scripts(game_manager)) { Logger::error (" Failed to parse " , name, " scripts!" ); ret = false ; } \
964- else Logger::info(" Successfully parsed " , name, " scripts!" );
1012+ #define PARSE_SCRIPTS (name, manager ) \
1013+ if (!manager.parse_scripts(game_manager)) { \
1014+ Logger::error (" Failed to parse " , name, " scripts!" ); \
1015+ ret = false ; \
1016+ } else { \
1017+ Logger::info (" Successfully parsed " , name, " scripts!" ); \
1018+ }
9651019
9661020bool Dataloader::parse_scripts (GameManager& game_manager) const {
9671021 bool ret = true ;
0 commit comments