diff options
author | CptAlanSmith <123112708+CptAlanSmith@users.noreply.github.com> | 2023-09-23 20:25:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-23 20:25:15 +0200 |
commit | 005a8026bb424779a146e00cc48621ff1d72b807 (patch) | |
tree | dde15211e31d861b61711bf6aebdeb8713393d53 /src/openvic-simulation/dataloader | |
parent | ebea2e473eefa3945508b0bf622a472b62d70d3b (diff) |
Testing (#23)
* Fixes for building scons
* Initial proof of concept auto-testing
Shows how we can pull loaded data and display it back
* Re-did headless
Because hubert insisted it be done like this ;)
* Auto-Testing Framework Basics
* Requirements Calculations
* Fix for messy merge (teach me to use merge tools)
* Fixing up misc merge issues to fully reconcile with master changes
* Re-added missing getters
* Move of testing files due to folder reorgs
* Use new accessors + int reading fix
---------
Co-authored-by: Hop311 <hop3114@gmail.com>
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 33 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.hpp | 3 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.hpp | 40 |
3 files changed, 42 insertions, 34 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 7cd955d..1bdbf7a 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -7,7 +7,6 @@ #include "openvic-simulation/GameManager.hpp" #include "openvic-simulation/utility/Logger.hpp" -#include "units/Unit.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -156,18 +155,18 @@ bool Dataloader::_load_pop_types(PopManager& pop_manager, fs::path const& pop_ty return ret; } -bool Dataloader::_load_units(UnitManager& unit_manager, fs::path const& units_directory) const { +bool Dataloader::_load_units(GameManager& game_manager, fs::path const& units_directory) const { const bool ret = apply_to_files_in_dir(units_directory, ".txt", - [&unit_manager](fs::path const& file) -> bool { - return unit_manager.load_unit_file(_parse_defines(file).get_file_node()); + [&game_manager](fs::path const& file) -> bool { + return game_manager.get_unit_manager().load_unit_file(game_manager.get_good_manager(), _parse_defines(file).get_file_node()); } ); - unit_manager.lock_units(); + game_manager.get_unit_manager().lock_units(); return ret; } bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_directory) const { - Map& map = game_manager.map; + Map& map = game_manager.get_map(); static const fs::path defaults_filename = "default.map"; static const std::string default_definitions = "definition.csv"; @@ -241,7 +240,7 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di ret = false; } - if (!map.load_province_positions(game_manager.building_manager, _parse_defines(lookup_file(map_directory / positions)).get_file_node())) { + if (!map.load_province_positions(game_manager.get_building_manager(), _parse_defines(lookup_file(map_directory / positions)).get_file_node())) { Logger::error("Failed to load province positions file!"); ret = false; } @@ -273,35 +272,35 @@ bool Dataloader::load_defines(GameManager& game_manager) const { bool ret = true; - if (!game_manager.good_manager.load_goods_file(_parse_defines(lookup_file(goods_file)).get_file_node())) { + if (!game_manager.get_good_manager().load_goods_file(_parse_defines(lookup_file(goods_file)).get_file_node())) { Logger::error("Failed to load goods!"); ret = false; } - if (!_load_pop_types(game_manager.pop_manager, pop_type_directory)) { + if (!_load_pop_types(game_manager.get_pop_manager(), pop_type_directory)) { Logger::error("Failed to load pop types!"); ret = false; } - if (!game_manager.pop_manager.culture_manager.load_graphical_culture_type_file(_parse_defines(lookup_file(graphical_culture_type_file)).get_file_node())) { + if (!game_manager.get_pop_manager().get_culture_manager().load_graphical_culture_type_file(_parse_defines(lookup_file(graphical_culture_type_file)).get_file_node())) { Logger::error("Failed to load graphical culture types!"); ret = false; } - if (!game_manager.pop_manager.culture_manager.load_culture_file(_parse_defines(lookup_file(culture_file)).get_file_node())) { + if (!game_manager.get_pop_manager().get_culture_manager().load_culture_file(_parse_defines(lookup_file(culture_file)).get_file_node())) { Logger::error("Failed to load cultures!"); ret = false; } - if (!game_manager.pop_manager.religion_manager.load_religion_file(_parse_defines(lookup_file(religion_file)).get_file_node())) { + if (!game_manager.get_pop_manager().get_religion_manager().load_religion_file(_parse_defines(lookup_file(religion_file)).get_file_node())) { Logger::error("Failed to load religions!"); ret = false; } - if (!game_manager.ideology_manager.load_ideology_file(_parse_defines(lookup_file(ideology_file)).get_file_node())) { + if (!game_manager.get_ideology_manager().load_ideology_file(_parse_defines(lookup_file(ideology_file)).get_file_node())) { Logger::error("Failed to load ideologies!"); ret = false; } - if (!game_manager.issue_manager.load_issues_file(_parse_defines(lookup_file(issues_file)).get_file_node())) { + if (!game_manager.get_issue_manager().load_issues_file(_parse_defines(lookup_file(issues_file)).get_file_node())) { Logger::error("Failed to load issues!"); ret = false; } - if (!_load_units(game_manager.unit_manager, units_directory)) { + if (!_load_units(game_manager, units_directory)) { Logger::error("Failed to load units!"); ret = false; } @@ -316,9 +315,9 @@ bool Dataloader::load_defines(GameManager& game_manager) const { bool Dataloader::load_pop_history(GameManager& game_manager, fs::path const& path) const { return apply_to_files_in_dir(path, ".txt", [&game_manager](fs::path const& file) -> bool { - return _parse_defines_callback(game_manager.map.expect_province_dictionary( + return _parse_defines_callback(game_manager.get_map().expect_province_dictionary( [&game_manager](Province& province, ast::NodeCPtr value) -> bool { - return province.load_pop_list(game_manager.pop_manager, value); + return province.load_pop_list(game_manager.get_pop_manager(), value); } ))(file); } diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp index 9e15102..e935091 100644 --- a/src/openvic-simulation/dataloader/Dataloader.hpp +++ b/src/openvic-simulation/dataloader/Dataloader.hpp @@ -5,7 +5,6 @@ #include <vector> #include "openvic-simulation/dataloader/NodeTools.hpp" -#include "units/Unit.hpp" namespace OpenVic { namespace fs = std::filesystem; @@ -22,7 +21,7 @@ namespace OpenVic { path_vector_t roots; bool _load_pop_types(PopManager& pop_manager, fs::path const& pop_type_directory) const; - bool _load_units(UnitManager& unit_manager, fs::path const& units_directory) const; + bool _load_units(GameManager& unit_manager, fs::path const& units_directory) const; bool _load_map_dir(GameManager& game_manager, fs::path const& map_directory) const; public: diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index 5c22e11..e49cab6 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -138,6 +138,14 @@ namespace OpenVic { } template<typename T> + callback_t<T&&> move_variable_callback(T& var) { + return [&var](T&& val) -> bool { + var = std::move(val); + return true; + }; + } + + template<typename T> requires requires(T& t) { t += T {}; } @@ -159,31 +167,33 @@ namespace OpenVic { }; } - template<typename I, typename T> - requires(std::integral<I>, std::integral<T>) - callback_t<I> _assign_variable_callback_int(const std::string_view name, T& var) { - return [&var, name](I val) -> bool { - if (std::numeric_limits<T>::lowest() <= val && val <= std::numeric_limits<T>::max()) { + template<typename T> + requires(std::integral<T>) + callback_t<uint64_t> assign_variable_callback_uint(const std::string_view name, T& var) { + return [&var, name](uint64_t val) -> bool { + if (val <= static_cast<uint64_t>(std::numeric_limits<T>::max())) { var = val; return true; } - Logger::error("Invalid ", name, ": ", val, " (valid range: [", - static_cast<int64_t>(std::numeric_limits<T>::lowest()), ", ", + Logger::error("Invalid ", name, ": ", val, " (valid range: [0, ", static_cast<uint64_t>(std::numeric_limits<T>::max()), "])"); return false; }; } template<typename T> - requires(std::integral<T>) - callback_t<uint64_t> assign_variable_callback_uint(const std::string_view name, T& var) { - return _assign_variable_callback_int<uint64_t>(name, var); - } - - template<typename T> - requires(std::integral<T>) + requires(std::signed_integral<T>) callback_t<int64_t> assign_variable_callback_int(const std::string_view name, T& var) { - return _assign_variable_callback_int<int64_t>(name, var); + return [&var, name](int64_t val) -> bool { + if (static_cast<int64_t>(std::numeric_limits<T>::lowest()) <= val && val <= static_cast<int64_t>(std::numeric_limits<T>::max())) { + var = val; + return true; + } + Logger::error("Invalid ", name, ": ", val, " (valid range: [", + static_cast<int64_t>(std::numeric_limits<T>::lowest()), ", ", + static_cast<int64_t>(std::numeric_limits<T>::max()), "])"); + return false; + }; } template<typename T> |