From a69a8cea12e1245b5859b3f255a76cdbf485cccf Mon Sep 17 00:00:00 2001 From: wvpm <24685035+wvpm@users.noreply.github.com> Date: Thu, 27 Nov 2025 10:55:18 +0100 Subject: [PATCH] Never break after operator --- src/headless/main.cpp | 72 +++-- src/openvic-simulation/core/Hash.hpp | 8 +- .../core/portable/Deque.hpp | 20 +- .../core/portable/ForwardableSpan.hpp | 8 +- .../core/random/RandomGenerator.hpp | 14 +- .../core/template/Concepts.hpp | 18 +- .../country/CountryInstance.cpp | 60 ++-- .../country/CountryInstanceManager.cpp | 5 +- .../dataloader/Dataloader.cpp | 38 ++- .../dataloader/NodeTools.hpp | 5 +- .../dataloader/Vic2PathSearch.cpp | 30 +- .../dataloader/Vic2PathSearch_Windows.hpp | 10 +- .../diplomacy/CountryRelation.hpp | 6 +- .../diplomacy/DiplomaticAction.cpp | 286 ++++++++---------- .../economy/GoodDefinition.cpp | 4 +- .../production/ResourceGatheringOperation.cpp | 14 +- .../history/CountryHistory.cpp | 14 +- .../history/ProvinceHistory.cpp | 14 +- src/openvic-simulation/map/MapDefinition.cpp | 16 +- src/openvic-simulation/map/MapInstance.cpp | 100 +++--- src/openvic-simulation/map/MapInstance.hpp | 10 + src/openvic-simulation/map/Mapmode.cpp | 61 ++-- .../map/ProvinceInstance.cpp | 22 +- src/openvic-simulation/map/TerrainType.cpp | 4 +- .../military/Deployment.cpp | 6 +- .../military/LeaderTrait.cpp | 8 +- .../military/UnitInstanceGroup.cpp | 4 +- src/openvic-simulation/military/UnitType.cpp | 8 +- .../pathfinding/AStarPathing.cpp | 10 +- .../pathfinding/FringePathing.cpp | 10 +- .../pathfinding/PathingBase.hpp | 9 +- .../pathfinding/PointMap.hpp | 28 +- src/openvic-simulation/population/Culture.cpp | 13 +- src/openvic-simulation/population/Pop.cpp | 19 +- .../population/PopManager.cpp | 4 +- .../research/Technology.cpp | 6 +- .../scripts/ConditionalWeight.cpp | 6 +- src/openvic-simulation/types/Colour.hpp | 20 +- src/openvic-simulation/types/CowVector.hpp | 27 +- src/openvic-simulation/types/Date.hpp | 57 ++-- .../types/IdentifierRegistry.hpp | 16 +- .../types/OrderedContainers.hpp | 42 ++- src/openvic-simulation/types/RingBuffer.hpp | 4 +- src/openvic-simulation/types/Signal.hpp | 4 +- src/openvic-simulation/utility/Containers.hpp | 14 +- tests/src/core/DualAdjacent.cpp | 21 +- tests/src/pathfinding/PointMap.cpp | 5 +- tests/src/types/FixedPoint.cpp | 19 +- tests/src/types/Signal.cpp | 7 +- tests/src/types/Vector2.cpp | 6 +- tests/src/types/Vector3.cpp | 15 +- tests/src/types/Vector4.cpp | 23 +- 52 files changed, 728 insertions(+), 522 deletions(-) diff --git a/src/headless/main.cpp b/src/headless/main.cpp index a6d6041e6..cb7ed12ba 100644 --- a/src/headless/main.cpp +++ b/src/headless/main.cpp @@ -258,44 +258,40 @@ static bool run_headless(fs::path const& root, memory::vector& m // TODO - REMOVE TEST CODE SPDLOG_INFO("===== Ranking system test... ====="); - if (game_manager.get_instance_manager()) { - const auto print_ranking_list = [ // - ](std::string_view title, OpenVic::forwardable_span countries) -> void { - memory::string countries_str; - for (CountryInstance* country : countries) { - countries_str += fmt::format( - "\n\t{} - Total #{} ({}), Prestige #{} ({}), Industry #{} ({}), Military #{} ({})", // - *country, // - country->get_total_rank(), country->total_score.get_untracked().to_string(1), // - country->get_prestige_rank(), country->get_prestige_untracked().to_string(1), - country->get_industrial_rank(), country->get_industrial_power_untracked().to_string(1), - country->get_military_rank(), country->military_power.get_untracked().to_string(1) - ); - } - SPDLOG_INFO("{}:{}", title, countries_str); - }; - - CountryInstanceManager const& country_instance_manager = - game_manager.get_instance_manager()->get_country_instance_manager(); - - OpenVic::forwardable_span great_powers = country_instance_manager.get_great_powers(); - print_ranking_list("Great Powers", great_powers); - print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers()); - print_ranking_list("All countries", country_instance_manager.get_total_ranking()); - - SPDLOG_INFO("===== RGO test... ====="); - for (size_t i = 0; i < std::min(3, great_powers.size()); ++i) { - CountryInstance const& great_power = *great_powers[i]; - ProvinceInstance const* const capital_province = great_power.get_capital(); - if (capital_province == nullptr) { - spdlog::warn_s("{} has no capital ProvinceInstance set.", great_power); - } else { - print_rgo(*capital_province); - } + InstanceManager& instance_manager = *game_manager.get_instance_manager(); + const auto print_ranking_list = []( + std::string_view title, + OpenVic::forwardable_span countries + ) -> void { + memory::string countries_str; + for (CountryInstance* country : countries) { + countries_str += fmt::format( + "\n\t{} - Total #{} ({}), Prestige #{} ({}), Industry #{} ({}), Military #{} ({})", // + *country, // + country->get_total_rank(), country->total_score.get_untracked().to_string(1), // + country->get_prestige_rank(), country->get_prestige_untracked().to_string(1), + country->get_industrial_rank(), country->get_industrial_power_untracked().to_string(1), + country->get_military_rank(), country->military_power.get_untracked().to_string(1) + ); + } + SPDLOG_INFO("{}:{}", title, countries_str); + }; + + CountryInstanceManager const& country_instance_manager = instance_manager.get_country_instance_manager(); + OpenVic::forwardable_span great_powers = country_instance_manager.get_great_powers(); + print_ranking_list("Great Powers", great_powers); + print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers()); + print_ranking_list("All countries", country_instance_manager.get_total_ranking()); + + SPDLOG_INFO("===== RGO test... ====="); + for (size_t i = 0; i < std::min(3, great_powers.size()); ++i) { + CountryInstance const& great_power = *great_powers[i]; + ProvinceInstance const* const capital_province = great_power.get_capital(); + if (capital_province == nullptr) { + spdlog::warn_s("{} has no capital ProvinceInstance set.", great_power); + } else { + print_rgo(*capital_province); } - } else { - spdlog::error_s("Instance manager not available!"); - ret = false; } if (ret) { @@ -305,7 +301,7 @@ static bool run_headless(fs::path const& root, memory::vector& m using test_time_units_t = std::chrono::milliseconds; - MapInstance& map_instance = game_manager.get_instance_manager()->get_map_instance(); + MapInstance& map_instance = instance_manager.get_map_instance(); SPDLOG_INFO("===== Land Pathfinding test... ====="); test_duration_t duration = std::chrono::duration_cast( // diff --git a/src/openvic-simulation/core/Hash.hpp b/src/openvic-simulation/core/Hash.hpp index cd839663c..ba780d02f 100644 --- a/src/openvic-simulation/core/Hash.hpp +++ b/src/openvic-simulation/core/Hash.hpp @@ -46,9 +46,11 @@ namespace OpenVic { s = h(v) << (sizeof(T) * CHAR_BIT); ( [&] { - // If args is not last pointer of args - if (static_cast(&(std::get(arg_tuple))) != - static_cast(&args)) { + void const* const args_ptr = static_cast(&args); + void const* const last_pointer_of_args = static_cast( + &(std::get(arg_tuple)) + ); + if (args_ptr != last_pointer_of_args) { s <<= sizeof(Args) * CHAR_BIT; } s |= std::hash {}(args); diff --git a/src/openvic-simulation/core/portable/Deque.hpp b/src/openvic-simulation/core/portable/Deque.hpp index 95f80dcd1..3b40113c8 100644 --- a/src/openvic-simulation/core/portable/Deque.hpp +++ b/src/openvic-simulation/core/portable/Deque.hpp @@ -1022,8 +1022,10 @@ namespace OpenVic::utility::_detail::deque { // (_Myoff() + _Mysize() - 1) is for the last element, i.e. the back() of the deque. // Divide by _Block_size to get the unmasked index of the last used block. // Add 1 to get the unmasked index of the first unused block. - const auto _Unmasked_first_unused_block_idx = - static_cast(((_Myoff() + _Mysize() - 1) / _Block_size) + 1); + const auto _Unmasked_first_unused_block_idx = static_cast( + ((_Myoff() + _Mysize() - 1) / _Block_size) + + 1 + ); const auto _First_unused_block_idx = static_cast(_Unmasked_first_unused_block_idx & _Mask); @@ -1037,8 +1039,10 @@ namespace OpenVic::utility::_detail::deque { } } - const auto _Used_block_count = - static_cast(_Unmasked_first_unused_block_idx - _Unmasked_first_used_block_idx); + const auto _Used_block_count = static_cast( + _Unmasked_first_unused_block_idx + - _Unmasked_first_used_block_idx + ); size_type _New_block_count = _Minimum_map_size; // should be power of 2 @@ -1818,8 +1822,12 @@ namespace OpenVic::utility::_detail::deque { _EXPORT_STD template _NODISCARD bool operator==(const deque<_Ty, _Alloc>& _Left, const deque<_Ty, _Alloc>& _Right) { - return _Left.size() == _Right.size() && - _STD equal(_Left._Unchecked_begin(), _Left._Unchecked_end(), _Right._Unchecked_begin()); + return _Left.size() == _Right.size() + && _STD equal( + _Left._Unchecked_begin(), + _Left._Unchecked_end(), + _Right._Unchecked_begin() + ); } #if _HAS_CXX20 diff --git a/src/openvic-simulation/core/portable/ForwardableSpan.hpp b/src/openvic-simulation/core/portable/ForwardableSpan.hpp index fe117bc0f..a4414860a 100644 --- a/src/openvic-simulation/core/portable/ForwardableSpan.hpp +++ b/src/openvic-simulation/core/portable/ForwardableSpan.hpp @@ -46,12 +46,12 @@ namespace OpenVic::_detail::forwardable_span { concept span_array_convertible = std::is_convertible_v; template - concept span_compatible_iterator = - std::contiguous_iterator && span_array_convertible>, T>; + concept span_compatible_iterator = std::contiguous_iterator + && span_array_convertible>, T>; template - concept span_compatible_sentinel_for = - std::sized_sentinel_for && !std::is_convertible_v; + concept span_compatible_sentinel_for = std::sized_sentinel_for + && !std::is_convertible_v; template struct extent_storage { diff --git a/src/openvic-simulation/core/random/RandomGenerator.hpp b/src/openvic-simulation/core/random/RandomGenerator.hpp index f569f5001..8e1f23816 100644 --- a/src/openvic-simulation/core/random/RandomGenerator.hpp +++ b/src/openvic-simulation/core/random/RandomGenerator.hpp @@ -15,10 +15,16 @@ namespace OpenVic { struct RandomGenerator { using generator_type = T; - using state_type = - std::conditional_t; - using result_type = - std::conditional_t; + using state_type = std::conditional_t< + requires { typename generator_type::state_type; }, + typename generator_type::state_type, + void + >; + using result_type = std::conditional_t< + requires { typename generator_type::result_type; }, + typename generator_type::result_type, + void + >; [[nodiscard]] OV_ALWAYS_INLINE explicit constexpr RandomGenerator() requires requires { diff --git a/src/openvic-simulation/core/template/Concepts.hpp b/src/openvic-simulation/core/template/Concepts.hpp index 3f1209a29..b8e0338c5 100644 --- a/src/openvic-simulation/core/template/Concepts.hpp +++ b/src/openvic-simulation/core/template/Concepts.hpp @@ -42,15 +42,16 @@ namespace OpenVic { concept not_same_as = !std::same_as; template> - concept move_insertable_allocator_for = - requires(Allocator& alloc, Value* value, T move) { std::allocator_traits::construct(alloc, value, move); }; + concept move_insertable_allocator_for = requires(Allocator& alloc, Value* value, T move) { + std::allocator_traits::construct(alloc, value, move); + }; template struct enable_copy_insertable : std::false_type {}; template - concept copy_insertable_allocator = enable_copy_insertable::value || - move_insertable_allocator_for; + concept copy_insertable_allocator = enable_copy_insertable::value + || move_insertable_allocator_for; template struct enable_copy_insertable> : std::is_copy_constructible {}; @@ -59,8 +60,8 @@ namespace OpenVic { struct enable_move_insertable : std::false_type {}; template - concept move_insertable_allocator = - enable_move_insertable::value || move_insertable_allocator_for; + concept move_insertable_allocator = enable_move_insertable::value + || move_insertable_allocator_for; template struct enable_move_insertable> : std::is_move_constructible {}; @@ -109,8 +110,9 @@ namespace OpenVic { }; template - concept has_index = requires { typename T::index_t; } && - derived_from_specialization_of && requires { + concept has_index = requires { typename T::index_t; } + && derived_from_specialization_of + && requires { static_cast( static_cast().index)>>(std::declval().index) ); diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp index bc9efe003..49f7953d2 100644 --- a/src/openvic-simulation/country/CountryInstance.cpp +++ b/src/openvic-simulation/country/CountryInstance.cpp @@ -676,8 +676,12 @@ bool CountryInstance::remove_unit_instance_group(UnitInstanceGroup const& group) const auto remove_from_vector = [this, &group]( memory::vector*>& unit_instance_groups ) -> bool { - const typename memory::vector*>::const_iterator it = - std::find(unit_instance_groups.begin(), unit_instance_groups.end(), &group); + using const_it_t = typename memory::vector*>::const_iterator; + const const_it_t it = std::find( + unit_instance_groups.begin(), + unit_instance_groups.end(), + &group + ); if (it != unit_instance_groups.end()) { unit_instance_groups.erase(it); @@ -1226,12 +1230,14 @@ bool CountryInstance::apply_history_to_country( ret &= add_reform(*reform); } set_optional_state(tech_school, entry.get_tech_school()); - constexpr auto set_bool_map_to_indexed_map = - [](IndexedFlatMap& target, ordered_map source) { - for (auto const& [key, value] : source) { - target[*key] = value; - } - }; + constexpr auto set_bool_map_to_indexed_map = []( + IndexedFlatMap& target, + ordered_map source + ) { + for (auto const& [key, value] : source) { + target[*key] = value; + } + }; for (auto const& [technology, level] : entry.get_technologies()) { ret &= set_technology_unlock_level(*technology, level); @@ -1466,9 +1472,9 @@ void CountryInstance::_update_technology(const Date today) { } daily_research_points += get_modifier_effect_value(*modifier_effect_cache.get_research_points()); - daily_research_points *= fixed_point_t::_1 + - get_modifier_effect_value(*modifier_effect_cache.get_research_points_modifier()) + - get_modifier_effect_value(*modifier_effect_cache.get_increase_research()); + daily_research_points *= fixed_point_t::_1 + + get_modifier_effect_value(*modifier_effect_cache.get_research_points_modifier()) + + get_modifier_effect_value(*modifier_effect_cache.get_increase_research()); if (daily_research_points.get_untracked() < 0) { daily_research_points.set(0); @@ -1592,13 +1598,15 @@ void CountryInstance::_update_military() { // Mobilisation calculations mobilisation_impact = get_modifier_effect_value(*modifier_effect_cache.get_mobilization_impact()); - mobilisation_economy_impact = get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_tech()) + - get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_country()); + mobilisation_economy_impact = get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_tech()) + + get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_economy_impact_country()); // TODO - use country_defines.get_min_mobilize_limit(); (wiki: "lowest maximum of brigades you can mobilize. (by default 3)") - mobilisation_max_regiment_count = - ((fixed_point_t::_1 + mobilisation_impact) * fixed_point_t::parse(regiment_count)).floor(); + mobilisation_max_regiment_count = ( + (fixed_point_t::_1 + mobilisation_impact) + * fixed_point_t::parse(regiment_count) + ).floor(); mobilisation_potential_regiment_count = 0; // TODO - calculate max regiments from poor citizens if (mobilisation_potential_regiment_count > mobilisation_max_regiment_count) { @@ -1612,9 +1620,9 @@ void CountryInstance::_update_military() { get_modifier_effect_value(*modifier_effect_cache.get_max_war_exhaustion()), fixed_point_t::_0 ); - organisation_regain = fixed_point_t::_1 + - get_modifier_effect_value(*modifier_effect_cache.get_org_regain()) + - get_modifier_effect_value(*modifier_effect_cache.get_morale_global()); + organisation_regain = fixed_point_t::_1 + + get_modifier_effect_value(*modifier_effect_cache.get_org_regain()) + + get_modifier_effect_value(*modifier_effect_cache.get_morale_global()); land_organisation = fixed_point_t::_1 + get_modifier_effect_value(*modifier_effect_cache.get_land_organisation()); naval_organisation = fixed_point_t::_1 + get_modifier_effect_value(*modifier_effect_cache.get_naval_organisation()); @@ -1626,12 +1634,12 @@ void CountryInstance::_update_military() { recruit_time = fixed_point_t::_1 + get_modifier_effect_value(*modifier_effect_cache.get_unit_recruitment_time()); combat_width = ( // - fixed_point_t::parse(military_defines.get_base_combat_width()) + - get_modifier_effect_value(*modifier_effect_cache.get_combat_width_additive()) + fixed_point_t::parse(military_defines.get_base_combat_width()) + + get_modifier_effect_value(*modifier_effect_cache.get_combat_width_additive()) ).floor(); dig_in_cap = get_modifier_effect_value(*modifier_effect_cache.get_dig_in_cap()).floor(); - military_tactics = military_defines.get_base_military_tactics() + - get_modifier_effect_value(*modifier_effect_cache.get_military_tactics()); + military_tactics = military_defines.get_base_military_tactics() + + get_modifier_effect_value(*modifier_effect_cache.get_military_tactics()); if (leadership_point_stockpile < 0) { leadership_point_stockpile = 0; @@ -1639,8 +1647,8 @@ void CountryInstance::_update_military() { create_leader_count = (leadership_point_stockpile / military_defines.get_leader_recruit_cost()).floor(); monthly_leadership_points += get_modifier_effect_value(*modifier_effect_cache.get_leadership()); - monthly_leadership_points *= fixed_point_t::_1 + - get_modifier_effect_value(*modifier_effect_cache.get_leadership_modifier()); + monthly_leadership_points *= fixed_point_t::_1 + + get_modifier_effect_value(*modifier_effect_cache.get_leadership_modifier()); if (monthly_leadership_points < 0) { monthly_leadership_points = 0; @@ -1876,8 +1884,8 @@ void CountryInstance::update_gamestate(const Date today, MapInstance& map_instan _update_politics(); _update_diplomacy(); - const CountryDefinition::government_colour_map_t::const_iterator it = - country_definition.get_alternative_colours().find(government_type.get_untracked()); + using const_it_t = typename CountryDefinition::government_colour_map_t::const_iterator; + const const_it_t it = country_definition.get_alternative_colours().find(government_type.get_untracked()); if (it != country_definition.get_alternative_colours().end()) { colour = it.value(); diff --git a/src/openvic-simulation/country/CountryInstanceManager.cpp b/src/openvic-simulation/country/CountryInstanceManager.cpp index 978bd4c8b..7fb15ca32 100644 --- a/src/openvic-simulation/country/CountryInstanceManager.cpp +++ b/src/openvic-simulation/country/CountryInstanceManager.cpp @@ -202,8 +202,9 @@ CountryInstance const& CountryInstanceManager::get_country_instance_by_definitio } bool CountryInstanceManager::apply_history_to_countries(InstanceManager& instance_manager) { - CountryHistoryManager const& history_manager = - instance_manager.definition_manager.get_history_manager().get_country_manager(); + CountryHistoryManager const& history_manager = instance_manager.definition_manager + .get_history_manager() + .get_country_manager(); bool ret = true; diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index d114d2851..c7f7899ed 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -12,14 +12,17 @@ #include +#include "openvic-simulation/core/template/Concepts.hpp" +#include "openvic-simulation/country/CountryDefinition.hpp" #include "openvic-simulation/DefinitionManager.hpp" +#include "openvic-simulation/history/Bookmark.hpp" +#include "openvic-simulation/history/HistoryManager.hpp" #include "openvic-simulation/interface/UI.hpp" #include "openvic-simulation/misc/GameRulesManager.hpp" #include "openvic-simulation/misc/SoundEffect.hpp" #include "openvic-simulation/utility/Logger.hpp" #include "openvic-simulation/core/string/Utility.hpp" #include "openvic-simulation/utility/Containers.hpp" -#include "openvic-simulation/core/template/Concepts.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -379,9 +382,10 @@ bool Dataloader::_load_pop_types(DefinitionManager& definition_manager) { bool ret = pop_manager.setup_stratas(); - GoodDefinitionManager const& good_definition_manager = - definition_manager.get_economy_manager().get_good_definition_manager(); - IdeologyManager const& ideology_manager = definition_manager.get_politics_manager().get_ideology_manager(); + EconomyManager const& economy_manager = definition_manager.get_economy_manager(); + GoodDefinitionManager const& good_definition_manager = economy_manager.get_good_definition_manager(); + PoliticsManager const& politics_manager = definition_manager.get_politics_manager(); + IdeologyManager const& ideology_manager = politics_manager.get_ideology_manager(); static constexpr std::string_view pop_type_directory = "poptypes"; @@ -578,8 +582,10 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse DeploymentManager& deployment_manager = definition_manager.get_military_manager().get_deployment_manager(); static constexpr std::string_view country_history_directory = "history/countries"; - const path_vector_t country_history_files = - lookup_basic_identifier_prefixed_files_in_dir(country_history_directory, ".txt"); + const path_vector_t country_history_files = lookup_basic_identifier_prefixed_files_in_dir( + country_history_directory, + ".txt" + ); country_history_manager.reserve_more_country_histories(country_history_files.size()); deployment_manager.reserve_more_deployments(country_history_files.size()); @@ -590,8 +596,10 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse const memory::string filename = file.stem().string(memory::string::allocator_type{}); const std::string_view country_id = extract_basic_identifier_prefix(filename); - CountryDefinition const* country = - definition_manager.get_country_definition_manager().get_country_definition_by_identifier(country_id); + CountryDefinitionManager const& country_definition_manager = definition_manager.get_country_definition_manager(); + CountryDefinition const* country = country_definition_manager.get_country_definition_by_identifier( + country_id + ); if (country == nullptr) { if (unused_history_file_warnings) { spdlog::warn_s("Found history file for non-existent country: {}", country_id); @@ -616,14 +624,17 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse } } + HistoryManager& history_manager = definition_manager.get_history_manager(); { /* Province History */ ProvinceHistoryManager& province_history_manager = definition_manager.get_history_manager().get_province_manager(); MapDefinition const& map_definition = definition_manager.get_map_definition(); static constexpr std::string_view province_history_directory = "history/provinces"; - const path_vector_t province_history_files = - lookup_basic_identifier_prefixed_files_in_dir_recursive(province_history_directory, ".txt"); + const path_vector_t province_history_files = lookup_basic_identifier_prefixed_files_in_dir_recursive( + province_history_directory, + ".txt" + ); province_history_manager.reserve_more_province_histories(province_history_files.size()); @@ -653,8 +664,8 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse static constexpr std::string_view pop_history_directory = "history/pops/"; const string_set_t pop_history_dirs = lookup_dirs_in_dir(pop_history_directory); - const Date last_bookmark_date = - definition_manager.get_history_manager().get_bookmark_manager().get_last_bookmark_date(); + BookmarkManager const& bookmark_manager = history_manager.get_bookmark_manager(); + const Date last_bookmark_date = bookmark_manager.get_last_bookmark_date(); for (memory::string const& dir : pop_history_dirs) { Date::from_chars_result result; @@ -685,8 +696,7 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse { /* Diplomacy History */ - DiplomaticHistoryManager& diplomatic_history_manager = - definition_manager.get_history_manager().get_diplomacy_manager(); + DiplomaticHistoryManager& diplomatic_history_manager = history_manager.get_diplomacy_manager(); static constexpr std::string_view diplomacy_history_directory = "history/diplomacy"; diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index b2e0b15df..90030f550 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -163,8 +163,9 @@ using namespace std::string_view_literals; template NodeCallback auto expect_int(callback_t& callback, int base = 10) { return expect_int64([callback](int64_t val) mutable -> bool { - if (static_cast(std::numeric_limits::lowest()) <= val && - val <= static_cast(std::numeric_limits::max())) { + if (static_cast(std::numeric_limits::lowest()) <= val + && val <= static_cast(std::numeric_limits::max()) + ) { return callback(val); } spdlog::error_s( diff --git a/src/openvic-simulation/dataloader/Vic2PathSearch.cpp b/src/openvic-simulation/dataloader/Vic2PathSearch.cpp index 11c079dc7..fef1d90b9 100644 --- a/src/openvic-simulation/dataloader/Vic2PathSearch.cpp +++ b/src/openvic-simulation/dataloader/Vic2PathSearch.cpp @@ -131,8 +131,11 @@ static fs::path _search_for_game_path(fs::path hint_path) { if (hint_empty) { #if defined(_WIN32) - static const fs::path registry_path = - Windows::ReadRegValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Paradox Interactive\\Victoria 2", "path"); + static const fs::path registry_path = Windows::ReadRegValue( + HKEY_LOCAL_MACHINE, + "SOFTWARE\\WOW6432Node\\Paradox Interactive\\Victoria 2", + "path" + ); if (!registry_path.empty()) { return registry_path; @@ -215,8 +218,12 @@ static fs::path _search_for_game_path(fs::path hint_path) { bool vic2_install_confirmed = false; // if current_path is not a regular file, this is a non-default Steam Library, skip this parser evaluation - if (fs::is_regular_file(current_path, error_code) && - (is_libraryfolders_vdf || filename_equals(libraryfolders, current_path))) { + if (fs::is_regular_file(current_path, error_code) + && ( + is_libraryfolders_vdf + || filename_equals(libraryfolders, current_path) + ) + ) { lexy_vdf::Parser parser; memory::string buffer; @@ -350,13 +357,20 @@ static fs::path _search_for_game_path(fs::path hint_path) { } bool is_Victoria_2_folder = false; - if ((is_common_folder || filename_equals(common_folder, vic2_steam_lib_directory)) && - fs::is_directory(vic2_steam_lib_directory, error_code)) { + if (( + is_common_folder + || filename_equals(common_folder, vic2_steam_lib_directory) + ) && fs::is_directory(vic2_steam_lib_directory, error_code) + ) { vic2_steam_lib_directory /= Victoria_2_folder; is_Victoria_2_folder = true; } - if ((is_Victoria_2_folder || filename_equals(Victoria_2_folder, vic2_steam_lib_directory)) && - fs::is_regular_file(vic2_steam_lib_directory / v2_game_exe, error_code)) { + + if (( + is_Victoria_2_folder + || filename_equals(Victoria_2_folder, vic2_steam_lib_directory) + ) && fs::is_regular_file(vic2_steam_lib_directory / v2_game_exe, error_code) + ) { return vic2_steam_lib_directory; } diff --git a/src/openvic-simulation/dataloader/Vic2PathSearch_Windows.hpp b/src/openvic-simulation/dataloader/Vic2PathSearch_Windows.hpp index c1c456c59..c300b617b 100644 --- a/src/openvic-simulation/dataloader/Vic2PathSearch_Windows.hpp +++ b/src/openvic-simulation/dataloader/Vic2PathSearch_Windows.hpp @@ -88,11 +88,11 @@ namespace OpenVic::Windows { } bool is_predefined() const { - return (_key_handle == HKEY_CURRENT_USER) || (_key_handle == HKEY_LOCAL_MACHINE) || - (_key_handle == HKEY_CLASSES_ROOT) || (_key_handle == HKEY_CURRENT_CONFIG) || - (_key_handle == HKEY_CURRENT_USER_LOCAL_SETTINGS) || (_key_handle == HKEY_PERFORMANCE_DATA) || - (_key_handle == HKEY_PERFORMANCE_NLSTEXT) || (_key_handle == HKEY_PERFORMANCE_TEXT) || - (_key_handle == HKEY_USERS); + return (_key_handle == HKEY_CURRENT_USER) || (_key_handle == HKEY_LOCAL_MACHINE) + || (_key_handle == HKEY_CLASSES_ROOT) || (_key_handle == HKEY_CURRENT_CONFIG) + || (_key_handle == HKEY_CURRENT_USER_LOCAL_SETTINGS) || (_key_handle == HKEY_PERFORMANCE_DATA) + || (_key_handle == HKEY_PERFORMANCE_NLSTEXT) || (_key_handle == HKEY_PERFORMANCE_TEXT) + || (_key_handle == HKEY_USERS); } LSTATUS close_key() { diff --git a/src/openvic-simulation/diplomacy/CountryRelation.hpp b/src/openvic-simulation/diplomacy/CountryRelation.hpp index 915e89763..f43a12d96 100644 --- a/src/openvic-simulation/diplomacy/CountryRelation.hpp +++ b/src/openvic-simulation/diplomacy/CountryRelation.hpp @@ -221,8 +221,10 @@ namespace OpenVic { return lhs; } - friend inline constexpr influence_value_type& - operator%=(influence_value_type& lhs, influence_value_type const& rhs) { + friend inline constexpr influence_value_type& operator%=( + influence_value_type& lhs, + influence_value_type const& rhs + ) { return lhs %= rhs.value; } diff --git a/src/openvic-simulation/diplomacy/DiplomaticAction.cpp b/src/openvic-simulation/diplomacy/DiplomaticAction.cpp index 92f7ea98c..689dea62a 100644 --- a/src/openvic-simulation/diplomacy/DiplomaticAction.cpp +++ b/src/openvic-simulation/diplomacy/DiplomaticAction.cpp @@ -78,122 +78,109 @@ bool DiplomaticActionManager::setup_diplomatic_actions() { result &= add_diplomatic_action( "form_alliance", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_country_alliance( // - arg.sender, arg.receiver, true - ); - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_country_alliance( // + arg.sender, arg.receiver, true + ); + }, } ); result &= add_diplomatic_action( "end_alliance", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_country_alliance( // - arg.sender, arg.receiver, false - ); - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_country_alliance( // + arg.sender, arg.receiver, false + ); + }, } ); result &= add_diplomatic_action( "call_ally", { .commit = [](Argument& arg) {}, - .allowed = - [](Argument const& arg) { - return false; - }, - .get_acceptance = - [](Argument const& arg) { - return 1; - }, + .allowed = [](Argument const& arg) { + return false; + }, + .get_acceptance = [](Argument const& arg) { + return 1; + }, } ); result &= add_diplomatic_action( "request_military_access", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_has_military_access_to( // - arg.sender, arg.receiver, true - ); - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_has_military_access_to( // + arg.sender, arg.receiver, true + ); + }, } ); result &= add_diplomatic_action( // "give_military_access", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_has_military_access_to( // - arg.sender, arg.receiver, true - ); - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_has_military_access_to( // + arg.sender, arg.receiver, true + ); + }, } ); result &= add_diplomatic_action( "increase_relations", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().assign_or_get_country_relation( - arg.sender, arg.receiver - ) += 25; // TODO: implement defines.diplomacy.INCREASERELATION_RELATION_ON_ACCEPT - }, - .allowed = - [](Argument const& arg) { - return false; - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().assign_or_get_country_relation( + arg.sender, arg.receiver + ) += 25; // TODO: implement defines.diplomacy.INCREASERELATION_RELATION_ON_ACCEPT + }, + .allowed = [](Argument const& arg) { + return false; + }, } ); result &= add_diplomatic_action( "decrease_relations", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().assign_or_get_country_relation( - arg.sender, arg.receiver - ) -= 25; // TODO: implement defines.diplomacy.DECREASERELATION_RELATION_ON_ACCEPT - }, - .allowed = - [](Argument const& arg) { - return false; - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().assign_or_get_country_relation( + arg.sender, arg.receiver + ) -= 25; // TODO: implement defines.diplomacy.DECREASERELATION_RELATION_ON_ACCEPT + }, + .allowed = [](Argument const& arg) { + return false; + }, } ); result &= add_diplomatic_action( "war_subsidies", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_war_subsidies_to( // - arg.sender, arg.receiver, true - ); - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_war_subsidies_to( // + arg.sender, arg.receiver, true + ); + }, } ); result &= add_diplomatic_action( "end_war_subsidies", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_war_subsidies_to( // - arg.sender, arg.receiver, false - ); - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_war_subsidies_to( // + arg.sender, arg.receiver, false + ); + }, } ); result &= add_diplomatic_action( "declare_war", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_at_war_with( // - arg.sender, arg.receiver, true - ); - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_at_war_with( // + arg.sender, arg.receiver, true + ); + }, } ); result &= add_diplomatic_action( @@ -205,24 +192,22 @@ bool DiplomaticActionManager::setup_diplomatic_actions() { result &= add_diplomatic_action( "command_units", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().assign_or_get_commands_units( // - arg.sender, arg.receiver - ) = true; - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().assign_or_get_commands_units( // + arg.sender, arg.receiver + ) = true; + }, } ); result &= add_diplomatic_action( "discredit", { .influence_cost = 25, - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_discredited_date( // - arg.sender, arg.receiver, arg.instance_manager.get_today() + 180 - ); // TODO: implement defines.diplomacy.DISCREDIT_DAYS - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_discredited_date( // + arg.sender, arg.receiver, arg.instance_manager.get_today() + 180 + ); // TODO: implement defines.diplomacy.DISCREDIT_DAYS + }, } ); result &= add_diplomatic_action( @@ -236,99 +221,88 @@ bool DiplomaticActionManager::setup_diplomatic_actions() { "ban_embassy", { .influence_cost = 65, - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_embassy_banned_date( // - arg.sender, arg.receiver, arg.instance_manager.get_today() + Timespan::from_years(1) - ); // TODO: implement defines.diplomacy.BANEMBASSY_DAYS - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_embassy_banned_date( // + arg.sender, arg.receiver, arg.instance_manager.get_today() + Timespan::from_years(1) + ); // TODO: implement defines.diplomacy.BANEMBASSY_DAYS + }, } ); result &= add_diplomatic_action( "increase_opinion", { .influence_cost = 50, - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().assign_or_get_country_opinion( // - arg.sender, arg.receiver - )++; - }, - .allowed = - [](Argument const& arg) { - return true; - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().assign_or_get_country_opinion( // + arg.sender, arg.receiver + )++; + }, + .allowed = [](Argument const& arg) { + return true; + }, } ); result &= add_diplomatic_action( "decrease_opinion", { .influence_cost = 50, - .commit = - [](Argument& arg) { - --arg.instance_manager.get_country_relation_manager().assign_or_get_country_opinion( // - std::any_cast(arg.context_data), arg.receiver - ); - }, - .allowed = - [](Argument const& arg) { - return true; - }, + .commit = [](Argument& arg) { + --arg.instance_manager.get_country_relation_manager().assign_or_get_country_opinion( // + std::any_cast(arg.context_data), arg.receiver + ); + }, + .allowed = [](Argument const& arg) { + return true; + }, } ); result &= add_diplomatic_action( "add_to_sphere", { .influence_cost = 100, - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().assign_or_get_country_opinion( // - arg.sender, arg.receiver - ) = CountryRelationManager::OpinionType::Sphere; - }, - .allowed = - [](Argument const& arg) { - return true; - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().assign_or_get_country_opinion( // + arg.sender, arg.receiver + ) = CountryRelationManager::OpinionType::Sphere; + }, + .allowed = [](Argument const& arg) { + return true; + }, } ); result &= add_diplomatic_action( "remove_from_foreign_sphere", { .influence_cost = 100, - .commit = - [](Argument& arg) { - --arg.instance_manager.get_country_relation_manager().assign_or_get_country_opinion( // - std::any_cast(arg.context_data), arg.receiver - ); - arg.instance_manager.get_country_relation_manager().assign_or_get_country_relation( // - arg.sender, arg.receiver - ) -= 10; - }, - .allowed = - [](Argument const& arg) { - return true; - }, + .commit = [](Argument& arg) { + --arg.instance_manager.get_country_relation_manager().assign_or_get_country_opinion( // + std::any_cast(arg.context_data), arg.receiver + ); + arg.instance_manager.get_country_relation_manager().assign_or_get_country_relation( // + arg.sender, arg.receiver + ) -= 10; + }, + .allowed = [](Argument const& arg) { + return true; + }, } ); result &= add_diplomatic_action( "remove_from_own_sphere", { .influence_cost = 100, - .commit = - [](Argument& arg) { - --arg.instance_manager.get_country_relation_manager().assign_or_get_country_opinion( // - arg.sender, arg.receiver - ); - arg.instance_manager.get_country_relation_manager().assign_or_get_country_relation( // - arg.sender, arg.receiver - ) -= 10; - // TODO: implement REMOVEFROMSPHERE_PRESTIGE_COST and REMOVEFROMSPHERE_INFAMY_COST - }, - .allowed = - [](Argument const& arg) { - return true; - }, + .commit = [](Argument& arg) { + --arg.instance_manager.get_country_relation_manager().assign_or_get_country_opinion( // + arg.sender, arg.receiver + ); + arg.instance_manager.get_country_relation_manager().assign_or_get_country_relation( // + arg.sender, arg.receiver + ) -= 10; + // TODO: implement REMOVEFROMSPHERE_PRESTIGE_COST and REMOVEFROMSPHERE_INFAMY_COST + }, + .allowed = [](Argument const& arg) { + return true; + }, } ); result &= add_diplomatic_action( @@ -340,23 +314,21 @@ bool DiplomaticActionManager::setup_diplomatic_actions() { result &= add_diplomatic_action( "give_vision", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_has_vision( // - arg.sender, arg.receiver, true - ); - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_has_vision( // + arg.sender, arg.receiver, true + ); + }, } ); result &= add_diplomatic_action( "remove_vision", { - .commit = - [](Argument& arg) { - arg.instance_manager.get_country_relation_manager().set_has_vision( // - arg.sender, arg.receiver, false - ); - }, + .commit = [](Argument& arg) { + arg.instance_manager.get_country_relation_manager().set_has_vision( // + arg.sender, arg.receiver, false + ); + }, } ); diplomatic_action_types.lock(); diff --git a/src/openvic-simulation/economy/GoodDefinition.cpp b/src/openvic-simulation/economy/GoodDefinition.cpp index dc63c6e61..e8b86444a 100644 --- a/src/openvic-simulation/economy/GoodDefinition.cpp +++ b/src/openvic-simulation/economy/GoodDefinition.cpp @@ -136,8 +136,8 @@ bool GoodDefinitionManager::generate_modifiers(ModifierManager& modifier_manager using enum ModifierEffect::format_t; using enum ModifierEffect::target_t; - IndexedFlatMap& good_effects = - modifier_manager.modifier_effect_cache.good_effects; + using good_effects_map_t = IndexedFlatMap; + good_effects_map_t& good_effects = modifier_manager.modifier_effect_cache.good_effects; good_effects = std::move(decltype(ModifierEffectCache::good_effects){get_good_definitions()}); diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp index 2a189a9e0..5b6664da5 100644 --- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp +++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp @@ -268,8 +268,9 @@ fixed_point_t ResourceGatheringOperation::produce() { + location.get_modifier_effect_value(*modifier_effect_cache.get_local_rgo_output()); if (production_type.get_is_farm_for_tech()) { - const fixed_point_t farm_rgo_throughput_and_output = - location.get_modifier_effect_value(*modifier_effect_cache.get_farm_rgo_throughput_and_output()); + const fixed_point_t farm_rgo_throughput_and_output = location.get_modifier_effect_value( + *modifier_effect_cache.get_farm_rgo_throughput_and_output() + ); throughput_multiplier += farm_rgo_throughput_and_output; output_multiplier += farm_rgo_throughput_and_output; } @@ -280,8 +281,9 @@ fixed_point_t ResourceGatheringOperation::produce() { } if (production_type.get_is_mine_for_tech()) { - const fixed_point_t mine_rgo_throughput_and_output = - location.get_modifier_effect_value(*modifier_effect_cache.get_mine_rgo_throughput_and_output()); + const fixed_point_t mine_rgo_throughput_and_output = location.get_modifier_effect_value( + *modifier_effect_cache.get_mine_rgo_throughput_and_output() + ); throughput_multiplier += mine_rgo_throughput_and_output; output_multiplier += mine_rgo_throughput_and_output; } @@ -305,8 +307,8 @@ fixed_point_t ResourceGatheringOperation::produce() { } const fixed_point_t effect_multiplier = job.get_effect_multiplier(); - fixed_point_t relative_to_workforce = - fixed_point_t::parse(employees_of_type) / fixed_point_t::parse(max_employee_count_cache); + fixed_point_t relative_to_workforce = fixed_point_t::parse(employees_of_type) + / fixed_point_t::parse(max_employee_count_cache); const fixed_point_t amount = job.get_amount(); if (effect_multiplier != fixed_point_t::_1 && relative_to_workforce > amount) { relative_to_workforce = amount; diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp index ca62311bf..27aed4db1 100644 --- a/src/openvic-simulation/history/CountryHistory.cpp +++ b/src/openvic-simulation/history/CountryHistory.cpp @@ -342,10 +342,16 @@ bool CountryHistoryManager::load_country_history_file( decltype(country_histories)::iterator it = country_histories.find(&country); if (it == country_histories.end()) { - const std::pair result = - country_histories.emplace(&country, CountryHistoryMap { country, ideology_keys, government_type_keys }); - if (result.second) { - it = result.first; + auto const [new_it, result] = country_histories.emplace( + &country, + CountryHistoryMap { + country, + ideology_keys, + government_type_keys + } + ); + if (result) { + it = new_it; } else { spdlog::error_s("Failed to create country history map for country {}", country); return false; diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp index f788cf329..3427f10e5 100644 --- a/src/openvic-simulation/history/ProvinceHistory.cpp +++ b/src/openvic-simulation/history/ProvinceHistory.cpp @@ -26,8 +26,8 @@ bool ProvinceHistoryMap::_load_history_entry( ) { BuildingTypeManager const& building_type_manager = definition_manager.get_economy_manager().get_building_type_manager(); CountryDefinitionManager const& country_definition_manager = definition_manager.get_country_definition_manager(); - GoodDefinitionManager const& good_definition_manager = - definition_manager.get_economy_manager().get_good_definition_manager(); + EconomyManager const& economy_manager = definition_manager.get_economy_manager(); + GoodDefinitionManager const& good_definition_manager = economy_manager.get_good_definition_manager(); IdeologyManager const& ideology_manager = definition_manager.get_politics_manager().get_ideology_manager(); TerrainTypeManager const& terrain_type_manager = definition_manager.get_map_definition().get_terrain_type_manager(); @@ -240,10 +240,12 @@ ProvinceHistoryMap const* ProvinceHistoryManager::get_province_history(ProvinceD ProvinceHistoryMap* ProvinceHistoryManager::_get_or_make_province_history(ProvinceDefinition const& province) { decltype(province_histories)::iterator it = province_histories.find(&province); if (it == province_histories.end()) { - const std::pair result = - province_histories.emplace(&province, ProvinceHistoryMap { province }); - if (result.second) { - it = result.first; + auto const [new_it, result] = province_histories.emplace( + &province, + ProvinceHistoryMap { province } + ); + if (result) { + it = new_it; } else { spdlog::error_s("Failed to create province history map for province {}", province); return nullptr; diff --git a/src/openvic-simulation/map/MapDefinition.cpp b/src/openvic-simulation/map/MapDefinition.cpp index cf13e30da..2174a8377 100644 --- a/src/openvic-simulation/map/MapDefinition.cpp +++ b/src/openvic-simulation/map/MapDefinition.cpp @@ -730,8 +730,12 @@ void MapDefinition::_trace_river(BMP& rivers_bmp, ivec2_t start, river_t& river) for (const auto& neighbour : neighbours) { ivec2_t neighbour_pos = { segment.point.x + neighbour.offset.x, segment.point.y + neighbour.offset.y }; - if (neighbour_pos.x < 0 || neighbour_pos.y < 0 || neighbour_pos.x >= rivers_bmp.get_width() || - neighbour_pos.y >= rivers_bmp.get_height() || segment.direction == neighbour.old_direction) { + if (neighbour_pos.x < 0 + || neighbour_pos.y < 0 + || neighbour_pos.x >= rivers_bmp.get_width() + || neighbour_pos.y >= rivers_bmp.get_height() + || segment.direction == neighbour.old_direction + ) { continue; } @@ -839,10 +843,10 @@ bool MapDefinition::load_map_images(fs::path const& province_path, fs::path cons return false; } - if (province_bmp.get_width() != terrain_bmp.get_width() || - province_bmp.get_height() != terrain_bmp.get_height() || - province_bmp.get_width() != rivers_bmp.get_width() || - province_bmp.get_height() != rivers_bmp.get_height() + if (province_bmp.get_width() != terrain_bmp.get_width() + || province_bmp.get_height() != terrain_bmp.get_height() + || province_bmp.get_width() != rivers_bmp.get_width() + || province_bmp.get_height() != rivers_bmp.get_height() ) { spdlog::error_s( "Mismatched map BMP dims: provinces:{}x{}, terrain: {}x{}, rivers: {}x{}", diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp index 8b3e416ec..a4c62f9f9 100644 --- a/src/openvic-simulation/map/MapInstance.cpp +++ b/src/openvic-simulation/map/MapInstance.cpp @@ -89,48 +89,72 @@ bool MapInstance::apply_history_to_provinces( bool ret = true; for (ProvinceInstance& province : get_province_instances()) { - ProvinceDefinition const& province_definition = province.province_definition; - if (!province_definition.is_water()) { - ProvinceHistoryMap const* history_map = history_manager.get_province_history(&province_definition); - - if (history_map != nullptr) { - ProvinceHistoryEntry const* pop_history_entry = nullptr; - ProductionType const* rgo_production_type_nullable = nullptr; - - for (auto const& [entry_date, entry] : history_map->get_entries()) { - if (entry_date > date) { - if (pop_history_entry != nullptr) { - break; - } - } else { - province.apply_history_to_province(*entry, country_manager); - std::optional const& rgo_production_type_nullable_optional = - entry->get_rgo_production_type_nullable(); - if (rgo_production_type_nullable_optional.has_value()) { - rgo_production_type_nullable = rgo_production_type_nullable_optional.value(); - } - } - - if (!entry->get_pops().empty()) { - pop_history_entry = entry.get(); - } - } - - if (pop_history_entry == nullptr) { - spdlog::warn_s("No pop history entry for province {} for date {}", province, date); - } else { - ret &= province.add_pop_vec( - pop_history_entry->get_pops(), - pop_deps - ); - province.setup_pop_test_values(issue_manager); - } - - ret &= province.set_rgo_production_type_nullable(rgo_production_type_nullable); + ret &= apply_history_to_province( + history_manager, + date, + country_manager, + issue_manager, + pop_deps, + province + ); + } + + return ret; +} + +bool MapInstance::apply_history_to_province( + ProvinceHistoryManager const& history_manager, + const Date date, + CountryInstanceManager& country_manager, + IssueManager const& issue_manager, + PopDeps const& pop_deps, + ProvinceInstance& province +) { + ProvinceDefinition const& province_definition = province.province_definition; + if (province_definition.is_water()) { + return true; + } + + ProvinceHistoryMap const* history_map = history_manager.get_province_history(&province_definition); + + if (history_map == nullptr) { + return true; + } + + ProvinceHistoryEntry const* pop_history_entry = nullptr; + ProductionType const* rgo_production_type_nullable = nullptr; + + for (auto const& [entry_date, entry] : history_map->get_entries()) { + if (entry_date > date) { + if (pop_history_entry != nullptr) { + break; + } + } else { + province.apply_history_to_province(*entry, country_manager); + std::optional const& rgo_production_type_nullable_optional + = entry->get_rgo_production_type_nullable(); + if (rgo_production_type_nullable_optional.has_value()) { + rgo_production_type_nullable = rgo_production_type_nullable_optional.value(); } } + + if (!entry->get_pops().empty()) { + pop_history_entry = entry.get(); + } + } + + bool ret = true; + if (pop_history_entry == nullptr) { + spdlog::warn_s("No pop history entry for province {} for date {}", province, date); + } else { + ret &= province.add_pop_vec( + pop_history_entry->get_pops(), + pop_deps + ); + province.setup_pop_test_values(issue_manager); } + ret &= province.set_rgo_production_type_nullable(rgo_production_type_nullable); return ret; } diff --git a/src/openvic-simulation/map/MapInstance.hpp b/src/openvic-simulation/map/MapInstance.hpp index af29a0c2d..2fb27b561 100644 --- a/src/openvic-simulation/map/MapInstance.hpp +++ b/src/openvic-simulation/map/MapInstance.hpp @@ -1,5 +1,6 @@ #pragma once +#include "openvic-simulation/core/Typedefs.hpp" #include "openvic-simulation/map/ProvinceDefinition.hpp" #include "openvic-simulation/map/ProvinceInstance.hpp" #include "openvic-simulation/map/State.hpp" @@ -39,6 +40,15 @@ namespace OpenVic { ArmyAStarPathing PROPERTY_REF(land_pathing); NavyAStarPathing PROPERTY_REF(sea_pathing); + OV_SPEED_INLINE bool apply_history_to_province( + ProvinceHistoryManager const& history_manager, + const Date date, + CountryInstanceManager& country_manager, + IssueManager const& issue_manager, + PopDeps const& pop_deps, + ProvinceInstance& province + ); + public: MapInstance( MapDefinition const& new_map_definition, diff --git a/src/openvic-simulation/map/Mapmode.cpp b/src/openvic-simulation/map/Mapmode.cpp index 85ea5a7cf..ad044a3ee 100644 --- a/src/openvic-simulation/map/Mapmode.cpp +++ b/src/openvic-simulation/map/Mapmode.cpp @@ -338,43 +338,44 @@ bool MapmodeManager::setup_mapmodes(MapDefinition const& map_definition) { MapInstance const& map_instance, ProvinceInstance const& province, CountryInstance const* player_country, ProvinceInstance const* selected_province ) -> Mapmode::base_stripe_t { - if (selected_province != nullptr) { - ProvinceDefinition const& selected_province_definition = selected_province->province_definition; + if (selected_province == nullptr) { + return colour_argb_t::null(); + } - if (*selected_province == province) { - return (0xFFFFFF_argb).with_alpha(ALPHA_VALUE); - } + ProvinceDefinition const& selected_province_definition = selected_province->province_definition; - ProvinceDefinition const* province_definition = &province.province_definition; - - colour_argb_t base = colour_argb_t::null(), stripe = colour_argb_t::null(); - ProvinceDefinition::adjacency_t const* adj = - selected_province_definition.get_adjacency_to(province_definition); - - if (adj != nullptr) { - colour_argb_t::integer_type base_int; - switch (adj->get_type()) { - using enum ProvinceDefinition::adjacency_t::type_t; - case LAND: base_int = 0x00FF00; break; - case WATER: base_int = 0x0000FF; break; - case COASTAL: base_int = 0xF9D199; break; - case IMPASSABLE: base_int = 0x8B4513; break; - case STRAIT: base_int = 0x00FFFF; break; - case CANAL: base_int = 0x888888; break; - default: base_int = 0xFF0000; break; - } - base = colour_argb_t::from_integer(base_int).with_alpha(ALPHA_VALUE); - stripe = base; - } + if (*selected_province == province) { + return (0xFFFFFF_argb).with_alpha(ALPHA_VALUE); + } + + ProvinceDefinition const* province_definition = &province.province_definition; - if (selected_province_definition.has_adjacency_going_through(province_definition)) { - stripe = (0xFFFF00_argb).with_alpha(ALPHA_VALUE); + colour_argb_t base = colour_argb_t::null(), stripe = colour_argb_t::null(); + ProvinceDefinition::adjacency_t const* adj = selected_province_definition.get_adjacency_to( + province_definition + ); + + if (adj != nullptr) { + colour_argb_t::integer_type base_int; + switch (adj->get_type()) { + using enum ProvinceDefinition::adjacency_t::type_t; + case LAND: base_int = 0x00FF00; break; + case WATER: base_int = 0x0000FF; break; + case COASTAL: base_int = 0xF9D199; break; + case IMPASSABLE: base_int = 0x8B4513; break; + case STRAIT: base_int = 0x00FFFF; break; + case CANAL: base_int = 0x888888; break; + default: base_int = 0xFF0000; break; } + base = colour_argb_t::from_integer(base_int).with_alpha(ALPHA_VALUE); + stripe = base; + } - return { base, stripe }; + if (selected_province_definition.has_adjacency_going_through(province_definition)) { + stripe = (0xFFFF00_argb).with_alpha(ALPHA_VALUE); } - return colour_argb_t::null(); + return { base, stripe }; } ); } diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index e45e3fb89..e1edf047c 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -240,10 +240,16 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) { using enum colony_status_t; - const fixed_point_t pop_size_per_regiment_multiplier = - colony_status == PROTECTORATE ? military_defines.get_pop_size_per_regiment_protectorate_multiplier() - : colony_status == COLONY ? military_defines.get_pop_size_per_regiment_colony_multiplier() - : is_owner_core() ? fixed_point_t::_1 : military_defines.get_pop_size_per_regiment_non_core_multiplier(); + fixed_point_t pop_size_per_regiment_multiplier; + if (colony_status == PROTECTORATE) { + pop_size_per_regiment_multiplier = military_defines.get_pop_size_per_regiment_protectorate_multiplier(); + } else if (colony_status == COLONY) { + pop_size_per_regiment_multiplier = military_defines.get_pop_size_per_regiment_colony_multiplier(); + } else if (is_owner_core()) { + pop_size_per_regiment_multiplier = fixed_point_t::_1; + } else { + pop_size_per_regiment_multiplier = military_defines.get_pop_size_per_regiment_non_core_multiplier(); + } for (Pop& pop : pops) { pops_cache_by_type.at(*pop.get_type()).push_back(&pop); @@ -441,8 +447,12 @@ bool ProvinceInstance::remove_unit_instance_group(UnitInstanceGroup const& group const auto remove_from_vector = [this, &group]( memory::vector*>& unit_instance_groups ) -> bool { - const typename memory::vector*>::const_iterator it = - std::find(unit_instance_groups.begin(), unit_instance_groups.end(), &group); + using const_it_t = typename memory::vector*>::const_iterator; + const const_it_t it = std::find( + unit_instance_groups.begin(), + unit_instance_groups.end(), + &group + ); if (it != unit_instance_groups.end()) { unit_instance_groups.erase(it); diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp index 510c232a3..585d5c3de 100644 --- a/src/openvic-simulation/map/TerrainType.cpp +++ b/src/openvic-simulation/map/TerrainType.cpp @@ -42,8 +42,8 @@ TerrainTypeMapping::TerrainTypeMapping( bool TerrainTypeManager::generate_modifiers(ModifierManager& modifier_manager) const { using enum ModifierEffect::format_t; - IndexedFlatMap& unit_terrain_effects = - modifier_manager.modifier_effect_cache.unit_terrain_effects; + using terrain_effects_map_t = IndexedFlatMap; + terrain_effects_map_t& unit_terrain_effects = modifier_manager.modifier_effect_cache.unit_terrain_effects; unit_terrain_effects = std::move(decltype(ModifierEffectCache::unit_terrain_effects){get_terrain_types()}); diff --git a/src/openvic-simulation/military/Deployment.cpp b/src/openvic-simulation/military/Deployment.cpp index 49640eda2..2eecc3eaa 100644 --- a/src/openvic-simulation/military/Deployment.cpp +++ b/src/openvic-simulation/military/Deployment.cpp @@ -65,8 +65,10 @@ bool DeploymentManager::load_oob_file( static constexpr std::string_view oob_directory = "history/units/"; - const fs::path lookedup_path = - dataloader.lookup_file(append_string_views(oob_directory, history_path), false); + const fs::path lookedup_path = dataloader.lookup_file( + append_string_views(oob_directory, history_path), + false + ); if (lookedup_path.empty()) { missing_oob_files.emplace(history_path); diff --git a/src/openvic-simulation/military/LeaderTrait.cpp b/src/openvic-simulation/military/LeaderTrait.cpp index 972fd6131..9bff5c2e5 100644 --- a/src/openvic-simulation/military/LeaderTrait.cpp +++ b/src/openvic-simulation/military/LeaderTrait.cpp @@ -115,10 +115,10 @@ bool LeaderTraitManager::load_leader_traits_file(ModifierManager const& modifier using enum LeaderTrait::trait_type_t; - ret &= - expect_dictionary_keys("personality", ONE_EXACTLY, trait_callback(PERSONALITY), "background", ONE_EXACTLY, trait_callback(BACKGROUND))( - root - ); + ret &= expect_dictionary_keys( + "personality", ONE_EXACTLY, trait_callback(PERSONALITY), + "background", ONE_EXACTLY, trait_callback(BACKGROUND) + )(root); lock_leader_traits(); diff --git a/src/openvic-simulation/military/UnitInstanceGroup.cpp b/src/openvic-simulation/military/UnitInstanceGroup.cpp index c8eae8ae7..6c55991d6 100644 --- a/src/openvic-simulation/military/UnitInstanceGroup.cpp +++ b/src/openvic-simulation/military/UnitInstanceGroup.cpp @@ -522,8 +522,8 @@ bool UnitInstanceManager::create_leader( } // TODO - make starting prestige a random proportion of the maximum random prestige - const fixed_point_t starting_prestige = - military_defines.get_leader_max_random_prestige() * static_cast(item_selection_counter++ % 11) / 10; + const fixed_point_t starting_prestige = military_defines.get_leader_max_random_prestige() + * static_cast(item_selection_counter++ % 11) / 10; generate_leader(country, { name, diff --git a/src/openvic-simulation/military/UnitType.cpp b/src/openvic-simulation/military/UnitType.cpp index e07fa3923..2c38ac3fb 100644 --- a/src/openvic-simulation/military/UnitType.cpp +++ b/src/openvic-simulation/military/UnitType.cpp @@ -382,8 +382,8 @@ bool UnitTypeManager::generate_modifiers(ModifierManager& modifier_manager) cons generate_stat_modifiers(modifier_manager.modifier_effect_cache.army_base_effects, "army_base"); - IndexedFlatMap& regiment_type_effects = - modifier_manager.modifier_effect_cache.regiment_type_effects; + using regiment_type_effects_map_t = IndexedFlatMap; + regiment_type_effects_map_t& regiment_type_effects = modifier_manager.modifier_effect_cache.regiment_type_effects; regiment_type_effects = std::move(decltype(ModifierEffectCache::regiment_type_effects){get_regiment_types()}); @@ -393,8 +393,8 @@ bool UnitTypeManager::generate_modifiers(ModifierManager& modifier_manager) cons generate_stat_modifiers(modifier_manager.modifier_effect_cache.navy_base_effects, "navy_base"); - IndexedFlatMap& ship_type_effects = - modifier_manager.modifier_effect_cache.ship_type_effects; + using ship_type_effects_map_t = IndexedFlatMap; + ship_type_effects_map_t& ship_type_effects = modifier_manager.modifier_effect_cache.ship_type_effects; ship_type_effects = std::move(decltype(ModifierEffectCache::ship_type_effects){get_ship_types()}); diff --git a/src/openvic-simulation/pathfinding/AStarPathing.cpp b/src/openvic-simulation/pathfinding/AStarPathing.cpp index a19550d00..bfb86492a 100644 --- a/src/openvic-simulation/pathfinding/AStarPathing.cpp +++ b/src/openvic-simulation/pathfinding/AStarPathing.cpp @@ -41,9 +41,13 @@ bool AStarPathing::_solve(search_iterator begin_point, search_iterator end_point search_iterator p = open_list.front(); // The currently processed point. // Find point closer to end_point, or same distance to end_point but closer to begin_point. - if (last_closest_point == search.end() || last_closest_point.value().abs_f_score > p.value().abs_f_score || - (last_closest_point.value().abs_f_score >= p.value().abs_f_score && // - last_closest_point.value().g_score > p.value().g_score)) { + if (last_closest_point == search.end() + || last_closest_point.value().abs_f_score > p.value().abs_f_score + || ( + last_closest_point.value().abs_f_score >= p.value().abs_f_score + && last_closest_point.value().g_score > p.value().g_score + ) + ) { last_closest_point = p; } diff --git a/src/openvic-simulation/pathfinding/FringePathing.cpp b/src/openvic-simulation/pathfinding/FringePathing.cpp index bdf67e635..84315e4ce 100644 --- a/src/openvic-simulation/pathfinding/FringePathing.cpp +++ b/src/openvic-simulation/pathfinding/FringePathing.cpp @@ -59,9 +59,13 @@ bool FringePathing::_solve(search_iterator begin_point, search_iterator end_poin } // Find point closer to end_point, or same distance to end_point but closer to begin_point. - if (last_closest_point == search.end() || last_closest_point.value().abs_f_score > p.value().abs_f_score || - (last_closest_point.value().abs_f_score >= p.value().abs_f_score && // - last_closest_point.value().g_score > p.value().g_score)) { + if (last_closest_point == search.end() + || last_closest_point.value().abs_f_score > p.value().abs_f_score + || ( + last_closest_point.value().abs_f_score >= p.value().abs_f_score + && last_closest_point.value().g_score > p.value().g_score + ) + ) { last_closest_point = p; } diff --git a/src/openvic-simulation/pathfinding/PathingBase.hpp b/src/openvic-simulation/pathfinding/PathingBase.hpp index 3ab4f0bf4..e75c16494 100644 --- a/src/openvic-simulation/pathfinding/PathingBase.hpp +++ b/src/openvic-simulation/pathfinding/PathingBase.hpp @@ -19,12 +19,15 @@ namespace OpenVic { using search_key_type = KeyT; using search_value_type = ValueT; using search_pair_type = std::pair; - using search_allocator_type = - foonathan::memory::std_allocator>; + using search_allocator_type = foonathan::memory::std_allocator< + search_pair_type, + memory::tracker + >; using search_container_type = std::vector; using search_map_type = tsl::ordered_map< search_key_type, search_value_type, // - std::hash, std::equal_to, search_allocator_type, search_container_type>; + std::hash, std::equal_to, search_allocator_type, search_container_type + >; using search_iterator = search_map_type::iterator; using search_const_iterator = search_map_type::const_iterator; diff --git a/src/openvic-simulation/pathfinding/PointMap.hpp b/src/openvic-simulation/pathfinding/PointMap.hpp index cde85f497..0f2082f43 100644 --- a/src/openvic-simulation/pathfinding/PointMap.hpp +++ b/src/openvic-simulation/pathfinding/PointMap.hpp @@ -21,12 +21,15 @@ namespace OpenVic { using points_key_type = uint64_t; using points_value_type = Point; using points_pair_type = std::pair; - using points_allocator_type = - foonathan::memory::std_allocator>; + using points_allocator_type = foonathan::memory::std_allocator< + points_pair_type, + memory::tracker + >; using points_container_type = std::vector; using points_map_type = tsl::ordered_map< points_key_type, points_value_type, // - std::hash, std::equal_to, points_allocator_type, points_container_type>; + std::hash, std::equal_to, points_allocator_type, points_container_type + >; using points_iterator = points_map_type::iterator; using points_const_iterator = points_map_type::const_iterator; @@ -62,15 +65,17 @@ namespace OpenVic { struct SegmentHash { inline constexpr std::size_t operator()(Segment const& segment) const { - return hash_murmur3(hash_murmur3(segment.key.first) << 32) | - hash_murmur3(segment.key.second); + return hash_murmur3(hash_murmur3(segment.key.first) << 32) + | hash_murmur3(segment.key.second); } }; using segments_type = Segment; using segments_hash_type = SegmentHash; - using segments_allocator_type = - foonathan::memory::std_allocator>; + using segments_allocator_type = foonathan::memory::std_allocator< + segments_type, + memory::tracker + >; using segments_container_type = std::vector; using segments_set_type = tsl::ordered_set< segments_type, segments_hash_type, std::equal_to, segments_allocator_type, segments_container_type>; @@ -79,13 +84,16 @@ namespace OpenVic { struct Point { using neighbor_point_id_type = points_key_type; - using neighbors_allocator_type = - foonathan::memory::std_allocator>; + using neighbors_allocator_type = foonathan::memory::std_allocator< + neighbor_point_id_type, + memory::tracker + >; using neighbors_container_type = std::vector; using neighbors_type = tsl::ordered_set< neighbor_point_id_type, // std::hash, std::equal_to, neighbors_allocator_type, - neighbors_container_type>; + neighbors_container_type + >; using neighbors_iterator = neighbors_type::iterator; using neighbors_const_iterator = neighbors_type::const_iterator; diff --git a/src/openvic-simulation/population/Culture.cpp b/src/openvic-simulation/population/Culture.cpp index 3880ee4a0..7c53d4330 100644 --- a/src/openvic-simulation/population/Culture.cpp +++ b/src/openvic-simulation/population/Culture.cpp @@ -271,9 +271,16 @@ bool CultureManager::find_cultural_leader_pictures(Dataloader const& dataloader) unit_branch_t branch, leader_count_t& leader_count ) -> void { while ( - leader_count < std::numeric_limits::max() && - !dataloader.lookup_file( - make_leader_picture_path(make_leader_picture_name(cultural_type, branch, leader_count)), false + leader_count < std::numeric_limits::max() + && !dataloader.lookup_file( + make_leader_picture_path( + make_leader_picture_name( + cultural_type, + branch, + leader_count + ) + ), + false ).empty() ) { leader_count++; diff --git a/src/openvic-simulation/population/Pop.cpp b/src/openvic-simulation/population/Pop.cpp index 3a6a8d59f..33aeeb93d 100644 --- a/src/openvic-simulation/population/Pop.cpp +++ b/src/openvic-simulation/population/Pop.cpp @@ -89,8 +89,12 @@ void Pop::setup_pop_test_values(IssueManager const& issue_manager) { num_migrated_external = test_size(1); num_migrated_colonial = test_size(2); - total_change = - num_grown + num_promoted + num_demoted + num_migrated_internal + num_migrated_external + num_migrated_colonial; + total_change = num_grown + + num_promoted + + num_demoted + + num_migrated_internal + + num_migrated_external + + num_migrated_colonial; /* Generates a number between 0 and max (inclusive) and sets map[&key] to it if it's at least min. */ auto test_weight_indexed = [](IndexedFlatMap& map, U const& key, int32_t min, int32_t max) -> void { @@ -249,10 +253,13 @@ void Pop::update_gamestate( if (type->can_be_recruited) { MilitaryDefines const& military_defines = define_manager.get_military_defines(); - if ( - size < military_defines.get_min_pop_size_for_regiment() || owner == nullptr || - !is_culture_status_allowed(owner->get_allowed_regiment_cultures(), culture_status) - ) { + const bool is_pop_size_too_small = size < military_defines.get_min_pop_size_for_regiment(); + const bool is_culture_not_allowed = owner == nullptr + || !is_culture_status_allowed( + owner->get_allowed_regiment_cultures(), + culture_status + ); + if (is_pop_size_too_small || is_culture_not_allowed) { max_supported_regiments = 0; } else { max_supported_regiments = (fixed_point_t::parse(size) / ( diff --git a/src/openvic-simulation/population/PopManager.cpp b/src/openvic-simulation/population/PopManager.cpp index 6b5b0f45b..48f8cf1af 100644 --- a/src/openvic-simulation/population/PopManager.cpp +++ b/src/openvic-simulation/population/PopManager.cpp @@ -489,8 +489,8 @@ bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const { static constexpr bool HAS_NO_EFFECT = true; - IndexedFlatMap& strata_effects = - modifier_manager.modifier_effect_cache.strata_effects; + using strata_effects_map_t = IndexedFlatMap; + strata_effects_map_t& strata_effects = modifier_manager.modifier_effect_cache.strata_effects; strata_effects = std::move(decltype(ModifierEffectCache::strata_effects){get_stratas()}); diff --git a/src/openvic-simulation/research/Technology.cpp b/src/openvic-simulation/research/Technology.cpp index 03465761a..5ac4cd186 100644 --- a/src/openvic-simulation/research/Technology.cpp +++ b/src/openvic-simulation/research/Technology.cpp @@ -3,6 +3,7 @@ #include "openvic-simulation/economy/BuildingType.hpp" #include "openvic-simulation/military/UnitType.hpp" #include "openvic-simulation/modifier/ModifierManager.hpp" +#include "modifier/ModifierEffectCache.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -245,8 +246,9 @@ bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) co using enum ModifierEffect::format_t; using enum ModifierEffect::target_t; - IndexedFlatMap& research_bonus_effects = - modifier_manager.modifier_effect_cache.research_bonus_effects; + ModifierEffectCache& modifier_effect_cache = modifier_manager.modifier_effect_cache; + using technology_folder_effects_map_t = IndexedFlatMap; + technology_folder_effects_map_t& research_bonus_effects = modifier_effect_cache.research_bonus_effects; research_bonus_effects = std::move(decltype(ModifierEffectCache::research_bonus_effects){get_technology_folders()}); diff --git a/src/openvic-simulation/scripts/ConditionalWeight.cpp b/src/openvic-simulation/scripts/ConditionalWeight.cpp index 91ca609c9..422e4bda3 100644 --- a/src/openvic-simulation/scripts/ConditionalWeight.cpp +++ b/src/openvic-simulation/scripts/ConditionalWeight.cpp @@ -130,9 +130,9 @@ bool ConditionalWeight::parse_scripts(DefinitionManager const& definition_ template bool ConditionalWeight::operator==(ConditionalWeight const& other) const { - return initial_scope == other.initial_scope && - this_scope == other.this_scope && - from_scope == other.from_scope; + return initial_scope == other.initial_scope + && this_scope == other.this_scope + && from_scope == other.from_scope; } template struct OpenVic::ConditionalWeight; diff --git a/src/openvic-simulation/types/Colour.hpp b/src/openvic-simulation/types/Colour.hpp index 587bcc27b..b30633f72 100644 --- a/src/openvic-simulation/types/Colour.hpp +++ b/src/openvic-simulation/types/Colour.hpp @@ -362,8 +362,9 @@ namespace OpenVic { template requires( - _ColourTraits::has_alpha && std::same_as && - std::same_as + _ColourTraits::has_alpha + && std::same_as + && std::same_as ) OV_SPEED_INLINE explicit constexpr basic_colour_t(basic_colour_t const& colour) requires(colour_traits::has_alpha) @@ -371,8 +372,9 @@ namespace OpenVic { template requires( - !_ColourTraits::has_alpha && std::same_as && - std::same_as + !_ColourTraits::has_alpha + && std::same_as + && std::same_as ) OV_SPEED_INLINE explicit constexpr basic_colour_t( basic_colour_t const& colour, value_type a = max_value @@ -382,8 +384,8 @@ namespace OpenVic { template requires( - std::same_as && - std::same_as + std::same_as + && std::same_as ) OV_SPEED_INLINE explicit constexpr basic_colour_t(basic_colour_t const& colour) requires(!colour_traits::has_alpha) @@ -588,8 +590,10 @@ namespace OpenVic { constexpr double GREEN_MULTIPLIER = 0.7151522; constexpr double BLUE_MULTIPLIER = 0.0721750; - double luminance = std::pow(red / max_value, POWER) * RED_MULTIPLIER + - std::pow(green / max_value, POWER) * GREEN_MULTIPLIER + std::pow(blue, POWER) * BLUE_MULTIPLIER; + double luminance = std::pow(red / max_value, POWER) * RED_MULTIPLIER + + std::pow(green / max_value, POWER) + * GREEN_MULTIPLIER + std::pow(blue, POWER) + * BLUE_MULTIPLIER; return luminance >= LUMINANCE_FLIP ? basic_colour_t::from_floats(0, 0, 0) : basic_colour_t::from_floats(1, 1, 1); } diff --git a/src/openvic-simulation/types/CowVector.hpp b/src/openvic-simulation/types/CowVector.hpp index 86dbf85c2..fd8bfddaf 100644 --- a/src/openvic-simulation/types/CowVector.hpp +++ b/src/openvic-simulation/types/CowVector.hpp @@ -93,8 +93,11 @@ namespace OpenVic { swap(other, *this); } else if (!other.empty()) { _data = _allocate_payload(other.size()); - _data->array_end = - uninitialized_move(other._data->array, other._data->array_end, _data->array, alloc); + _data->array_end = uninitialized_move( + other._data->array, + other._data->array_end, + _data->array, alloc + ); destroy(_data->array, _data->array_end, alloc); _data->array_end = _data->array; } @@ -124,8 +127,9 @@ namespace OpenVic { cow_vector tmp = std::move(x); writer& tmp_writer = *reinterpret_cast(&tmp); - if constexpr (allocator_traits::propagate_on_container_move_assignment::value || - allocator_traits::is_always_equal::value) { + if constexpr (allocator_traits::propagate_on_container_move_assignment::value + || allocator_traits::is_always_equal::value + ) { self_writer.swap(tmp_writer); } else if (alloc == x.alloc) { self_writer.swap(tmp_writer); @@ -436,8 +440,12 @@ namespace OpenVic { if constexpr (move_insertable_allocator) { _relocate(_data->array, _data->array_end, new_data->array, alloc); } else { - new_data->array_end = - uninitialized_move(_data->array, _data->array_end, new_data->array, alloc); + new_data->array_end = uninitialized_move( + _data->array, + _data->array_end, + new_data->array, + alloc + ); destroy(_data->array, _data->array_end, alloc); } _deallocate_payload(_data); @@ -1084,8 +1092,11 @@ namespace OpenVic { }; template - inline constexpr cow_vector::size_type cow_vector::payload::content_size = - std::max(1ul, (sizeof(payload) - sizeof(array)) / sizeof(T)); + inline constexpr cow_vector::size_type cow_vector::payload::content_size + = std::max( + 1ul, + (sizeof(payload) - sizeof(array)) / sizeof(T) + ); template [[nodiscard]] inline bool operator==(cow_vector const& x, cow_vector const& y) { diff --git a/src/openvic-simulation/types/Date.hpp b/src/openvic-simulation/types/Date.hpp index 90c45b410..78a2ec739 100644 --- a/src/openvic-simulation/types/Date.hpp +++ b/src/openvic-simulation/types/Date.hpp @@ -113,8 +113,9 @@ namespace OpenVic { using month_t = uint8_t; using day_t = uint8_t; - static constexpr std::array DAYS_IN_MONTH = - std::to_array({ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }); + static constexpr std::array DAYS_IN_MONTH = std::to_array( + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } + ); static constexpr Timespan::day_t MONTHS_IN_YEAR = DAYS_IN_MONTH.size(); static constexpr Timespan::day_t MAX_DAYS_IN_MONTH = *ranges::max_element(DAYS_IN_MONTH); @@ -347,9 +348,11 @@ namespace OpenVic { OV_SPEED_INLINE constexpr stack_string to_array(bool pad_year = false, bool pad_month = true, bool pad_day = true) const; struct stack_string final : StackString< - fmt::detail::count_digits(uint64_t(std::numeric_limits::max())) + - fmt::detail::count_digits(uint64_t(MONTHS_IN_YEAR)) + - fmt::detail::count_digits(uint64_t(MAX_DAYS_IN_MONTH)) + 4> { + fmt::detail::count_digits(uint64_t(std::numeric_limits::max())) + + fmt::detail::count_digits(uint64_t(MONTHS_IN_YEAR)) + + fmt::detail::count_digits(uint64_t(MAX_DAYS_IN_MONTH)) + + 4 + > { protected: using StackString::StackString; friend OV_SPEED_INLINE constexpr stack_string Date::to_array(bool pad_year, bool pad_month, bool pad_day) const; @@ -511,8 +514,9 @@ namespace OpenVic { Date date = from_string(str, from_chars); OV_ERR_FAIL_COND_V_MSG( - from_chars->ec == std::errc::invalid_argument && from_chars->type == errc_type::year && - from_chars->ptr == from_chars->type_first, + from_chars->ec == std::errc::invalid_argument + && from_chars->type == errc_type::year + && from_chars->ptr == from_chars->type_first, date, "Could not parse year value." ); OV_ERR_FAIL_COND_V_MSG( @@ -524,13 +528,15 @@ namespace OpenVic { "Only year value could be found." ); OV_ERR_FAIL_COND_V_MSG( - from_chars->ec == std::errc::invalid_argument && from_chars->type == errc_type::year && - from_chars->ptr != from_chars->type_first, + from_chars->ec == std::errc::invalid_argument + && from_chars->type == errc_type::year + && from_chars->ptr != from_chars->type_first, date, memory::fmt::format("Year value was missing a separator (\"{}\").", SEPARATOR_CHARACTER) ); OV_ERR_FAIL_COND_V_MSG( - from_chars->ec == std::errc::invalid_argument && from_chars->type == errc_type::month && - from_chars->ptr == from_chars->type_first, + from_chars->ec == std::errc::invalid_argument + && from_chars->type == errc_type::month + && from_chars->ptr == from_chars->type_first, date, "Could not parse month value." ); OV_ERR_FAIL_COND_V_MSG( @@ -538,8 +544,9 @@ namespace OpenVic { "Month value cannot be 0." ); OV_ERR_FAIL_COND_V_MSG( - from_chars->ec == std::errc::value_too_large && from_chars->type == errc_type::month && - from_chars->ptr == from_chars->type_first, + from_chars->ec == std::errc::value_too_large + && from_chars->type == errc_type::month + && from_chars->ptr == from_chars->type_first, date, memory::fmt::format("Month value cannot be larger than {}.", MONTHS_IN_YEAR) ); OV_ERR_FAIL_COND_V_MSG( @@ -547,21 +554,24 @@ namespace OpenVic { "Only year and month value could be found." ); OV_ERR_FAIL_COND_V_MSG( - from_chars->ec == std::errc::invalid_argument && from_chars->type == errc_type::month && - from_chars->ptr != from_chars->type_first, + from_chars->ec == std::errc::invalid_argument + && from_chars->type == errc_type::month + && from_chars->ptr != from_chars->type_first, date, memory::fmt::format("Month value was missing a separator (\"{}\").", SEPARATOR_CHARACTER) ); OV_ERR_FAIL_COND_V_MSG( - from_chars->ec == std::errc::invalid_argument && from_chars->type == errc_type::day && - from_chars->ptr == from_chars->type_first, + from_chars->ec == std::errc::invalid_argument + && from_chars->type == errc_type::day + && from_chars->ptr == from_chars->type_first, date, "Could not parse day value." ); OV_ERR_FAIL_COND_V_MSG( from_chars->ec == std::errc::not_supported && from_chars->type == errc_type::day, date, "Day value cannot be 0." ); OV_ERR_FAIL_COND_V_MSG( - from_chars->ec == std::errc::value_too_large && from_chars->type == errc_type::day && - from_chars->ptr == from_chars->type_first, + from_chars->ec == std::errc::value_too_large + && from_chars->type == errc_type::day + && from_chars->ptr == from_chars->type_first, date, memory::fmt::format("Day value cannot be larger than {} for {}.", DAYS_IN_MONTH[date.get_month() - 1], date.get_month()) ); @@ -600,8 +610,13 @@ namespace OpenVic { OV_SPEED_INLINE constexpr Date::stack_string Date::to_array(bool pad_year, bool pad_month, bool pad_day) const { stack_string str {}; - std::to_chars_result result = - to_chars(str._array.data(), str._array.data() + str._array.size(), pad_year, pad_month, pad_day); + std::to_chars_result result = to_chars( + str._array.data(), + str._array.data() + str._array.size(), + pad_year, + pad_month, + pad_day + ); str._string_size = result.ptr - str.data(); return str; } diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index 577bd61ea..a4afa81cf 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -113,9 +113,8 @@ namespace OpenVic { /* Registry Storage Info - how items are stored and indexed, and item-index conversion functions. */ template typename StorageInfo, typename Item> - concept RegistryStorageInfo = - std::same_as::storage_type::value_type, Item> && - requires( + concept RegistryStorageInfo = std::same_as::storage_type::value_type, Item> + && requires( typename StorageInfo::storage_type& items, typename StorageInfo::storage_type const& const_items, typename StorageInfo::index_type index ) { @@ -161,8 +160,8 @@ namespace OpenVic { string_map_case Case = StringMapCaseSensitive /* Identifier map parameters */ > requires( - RegistryItemInfo<_ItemInfo, typename ValueInfo::internal_value_type> && - RegistryStorageInfo<_StorageInfo, typename _ItemInfo::item_type> + RegistryItemInfo<_ItemInfo, typename ValueInfo::internal_value_type> + && RegistryStorageInfo<_StorageInfo, typename _ItemInfo::item_type> ) class UniqueKeyRegistry { public: @@ -582,8 +581,11 @@ namespace OpenVic { has_get_identifier Value, template typename StorageInfo = RegistryStorageInfoVector, string_map_case Case = StringMapCaseSensitive > - using IdentifierPointerRegistry = - ValueRegistry>, StorageInfo, Case>; + using IdentifierPointerRegistry = ValueRegistry< + RegistryValueInfoPointer>, + StorageInfo, + Case + >; template< has_get_identifier Value, template typename StorageInfo = RegistryStorageInfoVector, diff --git a/src/openvic-simulation/types/OrderedContainers.hpp b/src/openvic-simulation/types/OrderedContainers.hpp index d3af3e8ee..e140c1565 100644 --- a/src/openvic-simulation/types/OrderedContainers.hpp +++ b/src/openvic-simulation/types/OrderedContainers.hpp @@ -50,16 +50,30 @@ namespace OpenVic { class Key, class T, class Hash = container_hash, class KeyEqual = std::equal_to<>, class RawAllocator = foonathan::memory::default_allocator, class IndexType = std::uint_least32_t, class Allocator = foonathan::memory::std_allocator, memory::tracker>> - using vector_ordered_map = - tsl::ordered_map, Allocator>, IndexType>; + using vector_ordered_map = tsl::ordered_map< + Key, + T, + Hash, + KeyEqual, + Allocator, + std::vector, Allocator>, + IndexType + >; // Useful for stable memory addresses (so long as you don't remove or insert values) template< class Key, class T, class Hash = container_hash, class KeyEqual = std::equal_to<>, class RawAllocator = foonathan::memory::default_allocator, class IndexType = std::uint_least32_t, class Allocator = foonathan::memory::std_allocator, memory::tracker>> - using deque_ordered_map = - tsl::ordered_map, Allocator>, IndexType>; + using deque_ordered_map = tsl::ordered_map< + Key, + T, + Hash, + KeyEqual, + Allocator, + OpenVic::utility::deque, Allocator>, + IndexType + >; template< class Key, class T, class Hash = container_hash, class KeyEqual = std::equal_to<>, @@ -79,8 +93,14 @@ namespace OpenVic { class Key, class Hash = container_hash, class KeyEqual = std::equal_to<>, class RawAllocator = foonathan::memory::default_allocator, class IndexType = std::uint_least32_t, class Allocator = foonathan::memory::std_allocator>> - using deque_ordered_set = - tsl::ordered_set, IndexType>; + using deque_ordered_set = tsl::ordered_set< + Key, + Hash, + KeyEqual, + Allocator, + OpenVic::utility::deque, + IndexType + >; template< class Key, class Hash = container_hash, class KeyEqual = std::equal_to<>, @@ -161,8 +181,14 @@ namespace OpenVic { template< class Key, class RawAllocator = foonathan::memory::default_allocator, class IndexType = std::uint_least32_t, class Allocator = foonathan::memory::std_allocator>> - using case_insensitive_deque_ordered_set = - deque_ordered_set; + using case_insensitive_deque_ordered_set = deque_ordered_set< + Key, + case_insensitive_string_hash, + case_insensitive_string_equal, + RawAllocator, + IndexType, + Allocator + >; template< class Key, class RawAllocator = foonathan::memory::default_allocator, class IndexType = std::uint_least32_t, diff --git a/src/openvic-simulation/types/RingBuffer.hpp b/src/openvic-simulation/types/RingBuffer.hpp index 94b43bf17..82e751b65 100644 --- a/src/openvic-simulation/types/RingBuffer.hpp +++ b/src/openvic-simulation/types/RingBuffer.hpp @@ -191,8 +191,8 @@ namespace OpenVic { } RingBuffer& operator=(RingBuffer&& other) noexcept( - allocator_traits::propagate_on_container_move_assignment::value || - std::is_nothrow_move_constructible::value + allocator_traits::propagate_on_container_move_assignment::value + || std::is_nothrow_move_constructible::value ) { if (allocator_traits::propagate_on_container_move_assignment::value || _allocator == other._allocator) { // We're either getting the other's allocator or they're already the same, diff --git a/src/openvic-simulation/types/Signal.hpp b/src/openvic-simulation/types/Signal.hpp index 882ed3d46..bfe1e7421 100644 --- a/src/openvic-simulation/types/Signal.hpp +++ b/src/openvic-simulation/types/Signal.hpp @@ -1052,8 +1052,8 @@ namespace OpenVic::_detail::signal { */ template requires( - (Callable || Callable || MemberFunctionPointer) && - function_traits::is_disconnectable + (Callable || Callable || MemberFunctionPointer) + && function_traits::is_disconnectable ) size_t disconnect(C const& c) { return disconnect_if([&](slot_ptr const& s) { diff --git a/src/openvic-simulation/utility/Containers.hpp b/src/openvic-simulation/utility/Containers.hpp index eb115a663..b567f2680 100644 --- a/src/openvic-simulation/utility/Containers.hpp +++ b/src/openvic-simulation/utility/Containers.hpp @@ -233,8 +233,11 @@ namespace OpenVic::memory { using deque = OpenVic::utility::memory::deque>; template - using basic_string = - std::basic_string, foonathan::memory::std_allocator>>; + using basic_string = std::basic_string< + CharT, + std::char_traits, + foonathan::memory::std_allocator> + >; template using string_alloc = basic_string; @@ -256,8 +259,11 @@ namespace OpenVic::memory { using queue = std::queue; template, class RawAllocator = foonathan::memory::default_allocator> - using basic_stringstream = - std::basic_stringstream>>; + using basic_stringstream = std::basic_stringstream< + T, + CharTraits, + foonathan::memory::std_allocator> + >; template using stringstream_alloc = basic_stringstream, RawAllocator>; diff --git a/tests/src/core/DualAdjacent.cpp b/tests/src/core/DualAdjacent.cpp index 88cc72954..dedf8e0fb 100644 --- a/tests/src/core/DualAdjacent.cpp +++ b/tests/src/core/DualAdjacent.cpp @@ -153,20 +153,29 @@ TEST_CASE("remove_if_dual_adjacent", "[algorithm][dual-adjacent][remove_if_dual_ remove_if_dual_adjacent(vector_down.begin(), vector_down.end(), std::bind_front(callback_bind, 9)) == vector_down.end() ); CHECK( - remove_if_dual_adjacent(vector_spread.begin(), vector_spread.end(), std::bind_front(callback_bind, 5)) == - vector_spread.end() + remove_if_dual_adjacent( + vector_spread.begin(), + vector_spread.end(), + std::bind_front(callback_bind, 5) + ) == vector_spread.end() ); CHECK( // remove_if_dual_adjacent(vector_up.begin(), vector_up.end(), std::bind_front(callback_bind, 9)) == vector_up.end() - 1 ); CHECK( - remove_if_dual_adjacent(vector_down.begin(), vector_down.end(), std::bind_front(callback_bind, 1)) == - vector_down.end() - 1 + remove_if_dual_adjacent( + vector_down.begin(), + vector_down.end(), + std::bind_front(callback_bind, 1) + ) == vector_down.end() - 1 ); CHECK( - remove_if_dual_adjacent(vector_spread.begin(), vector_spread.end(), std::bind_front(callback_bind, 6)) == - vector_spread.end() - 1 + remove_if_dual_adjacent( + vector_spread.begin(), + vector_spread.end(), + std::bind_front(callback_bind, 6) + ) == vector_spread.end() - 1 ); static constexpr auto removed_vector_up = std::to_array({ 1, 2, 3, 5, 6, 7, 8, 9, 9 }); diff --git a/tests/src/pathfinding/PointMap.cpp b/tests/src/pathfinding/PointMap.cpp index 21951a1fb..99ce148a1 100644 --- a/tests/src/pathfinding/PointMap.cpp +++ b/tests/src/pathfinding/PointMap.cpp @@ -74,8 +74,9 @@ TEST_CASE("PointMap Add/Remove", "[point-map][point-map-add-remove]") { // Tests for get_closest_position_in_segment. a.connect_points(2, 3); CHECK( - a.get_closest_position_in_segment(fvec2_t { fixed_point_t::_0_50, fixed_point_t::_0_50 }) == - fvec2_t { fixed_point_t::_0_50, 1 } + a.get_closest_position_in_segment( + fvec2_t { fixed_point_t::_0_50, fixed_point_t::_0_50 } + ) == fvec2_t { fixed_point_t::_0_50, 1 } ); a.connect_points(3, 4); diff --git a/tests/src/types/FixedPoint.cpp b/tests/src/types/FixedPoint.cpp index 56809e310..771b03d09 100644 --- a/tests/src/types/FixedPoint.cpp +++ b/tests/src/types/FixedPoint.cpp @@ -161,13 +161,17 @@ TEST_CASE("fixed_point_t Parse methods", "[fixed_point_t][fixed_point_t-parse]") fixed_point_t fp = fixed_point_t::_0; CHECK( - fp.from_chars(plus_fixed_point_str.data(), plus_fixed_point_str.data() + plus_fixed_point_str.size()).ec == - std::errc::invalid_argument + fp.from_chars( + plus_fixed_point_str.data(), + plus_fixed_point_str.data() + plus_fixed_point_str.size() + ).ec == std::errc::invalid_argument ); CHECK(fp == 0.0_a); CHECK( - fp.from_chars_with_plus(plus_fixed_point_str.data(), plus_fixed_point_str.data() + plus_fixed_point_str.size()).ec == - std::errc {} + fp.from_chars_with_plus( + plus_fixed_point_str.data(), + plus_fixed_point_str.data() + plus_fixed_point_str.size() + ).ec == std::errc {} ); CHECK(fp == 4.5432_a); } @@ -285,8 +289,11 @@ TEST_CASE("fixed_point_t Operators", "[fixed_point_t][fixed_point_t-operators]") CONSTEXPR_CHECK(((int32_t)decimal4) == 3); CONSTEXPR_CHECK( - fixed_point_t::mul_div(fixed_point_t::parse_raw(2), fixed_point_t::parse_raw(3), fixed_point_t::parse_raw(6)) == - fixed_point_t::parse_raw(1) + fixed_point_t::mul_div( + fixed_point_t::parse_raw(2), + fixed_point_t::parse_raw(3), + fixed_point_t::parse_raw(6) + ) == fixed_point_t::parse_raw(1) ); } diff --git a/tests/src/types/Signal.cpp b/tests/src/types/Signal.cpp index cdeb6f274..8a8d31e38 100644 --- a/tests/src/types/Signal.cpp +++ b/tests/src/types/Signal.cpp @@ -16,8 +16,11 @@ using namespace OpenVic; using namespace std::string_view_literals; -using SignalTypes = - snitch::type_list, nothread::signal, basic_signal>; +using SignalTypes = snitch::type_list< + OpenVic::signal, + nothread::signal, + basic_signal +>; void test_func(int& sum, int i) { sum += i; diff --git a/tests/src/types/Vector2.cpp b/tests/src/types/Vector2.cpp index 154605cc2..823882fb4 100644 --- a/tests/src/types/Vector2.cpp +++ b/tests/src/types/Vector2.cpp @@ -142,8 +142,7 @@ TEST_CASE("fvec2_t Operators", "[vec2_t][fvec2_t][fvec2_t-operators]") { CONSTEXPR_CHECK(power1 + power2 == testing::approx_vec2 { 1.25, 1.625 }); CONSTEXPR_CHECK( - decimal1 - decimal2 == - testing::approx_vec2 { + decimal1 - decimal2 == testing::approx_vec2 { (1.1_a).epsilon(testing::INACCURATE_EPSILON), // (1.5_a).epsilon(testing::INACCURATE_EPSILON) // } @@ -151,8 +150,7 @@ TEST_CASE("fvec2_t Operators", "[vec2_t][fvec2_t][fvec2_t-operators]") { CONSTEXPR_CHECK(power1 - power2 == testing::approx_vec2 { 0.25, 1.375 }); CONSTEXPR_CHECK( - decimal1 * decimal2 == - testing::approx_vec2 { + decimal1 * decimal2 == testing::approx_vec2 { (2.76_a).epsilon(testing::INACCURATE_EPSILON), // (16.66_a).epsilon(testing::INACCURATE_EPSILON) // } diff --git a/tests/src/types/Vector3.cpp b/tests/src/types/Vector3.cpp index daecfa4ea..0516e898a 100644 --- a/tests/src/types/Vector3.cpp +++ b/tests/src/types/Vector3.cpp @@ -116,9 +116,12 @@ TEST_CASE("dvec3_t Length methods", "[vec3_t][dvec3_t][dvec3_t-length]") { TEST_CASE("fvec3_t Operators", "[vec3_t][fvec3_t][fvec3_t-operators]") { static constexpr fixed_point_t _2_30 = fixed_point_t::_2 + fixed_point_t::_0_20 + fixed_point_t::_0_10; static constexpr fixed_point_t _4_90 = fixed_point_t::_4 + fixed_point_t::_0_50 + fixed_point_t::_0_20 * 2; - static constexpr fixed_point_t _7_80 = // - fixed_point_t::_4 + fixed_point_t::_2 + fixed_point_t::_1 + fixed_point_t::_0_50 + fixed_point_t::_0_20 + - fixed_point_t::_0_10; + static constexpr fixed_point_t _7_80 = fixed_point_t::_4 + + fixed_point_t::_2 + + fixed_point_t::_1 + + fixed_point_t::_0_50 + + fixed_point_t::_0_20 + + fixed_point_t::_0_10; static constexpr fixed_point_t _1_20 = fixed_point_t::_0_20 * 6; static constexpr fixed_point_t _3_40 = fixed_point_t::_0_20 * 17; static constexpr fixed_point_t _5_60 = fixed_point_t::_4 + fixed_point_t::_1_50 + fixed_point_t::_0_10; @@ -137,8 +140,7 @@ TEST_CASE("fvec3_t Operators", "[vec3_t][fvec3_t][fvec3_t-operators]") { CONSTEXPR_CHECK(power1 + power2 == testing::approx_vec3(1.25, 1.625, 0.875)); CONSTEXPR_CHECK( - decimal1 - decimal2 == - testing::approx_vec3 { + decimal1 - decimal2 == testing::approx_vec3 { (1.1_a).epsilon(testing::INACCURATE_EPSILON), // (1.5_a).epsilon(testing::INACCURATE_EPSILON), // (2.2_a).epsilon(testing::INACCURATE_EPSILON) // @@ -147,8 +149,7 @@ TEST_CASE("fvec3_t Operators", "[vec3_t][fvec3_t][fvec3_t-operators]") { CONSTEXPR_CHECK(power1 - power2 == testing::approx_vec3(0.25, 1.375, 0.375)); CONSTEXPR_CHECK( - decimal1 * decimal2 == - testing::approx_vec3 { + decimal1 * decimal2 == testing::approx_vec3 { (2.76_a).epsilon(testing::INACCURATE_EPSILON), // (16.66_a).epsilon(testing::INACCURATE_EPSILON), // (43.68_a).epsilon(testing::INACCURATE_EPSILON) // diff --git a/tests/src/types/Vector4.cpp b/tests/src/types/Vector4.cpp index 8f7ce9bb8..293c06d96 100644 --- a/tests/src/types/Vector4.cpp +++ b/tests/src/types/Vector4.cpp @@ -115,9 +115,12 @@ TEST_CASE("dvec4_t Length methods", "[vec4_t][dvec4_t][dvec4_t-length]") { TEST_CASE("fvec4_t Operators", "[vec4_t][fvec4_t][fvec4_t-operators]") { static constexpr fixed_point_t _2_30 = fixed_point_t::_2 + fixed_point_t::_0_20 + fixed_point_t::_0_10; static constexpr fixed_point_t _4_90 = fixed_point_t::_4 + fixed_point_t::_0_50 + fixed_point_t::_0_20 * 2; - static constexpr fixed_point_t _7_80 = // - fixed_point_t::_4 + fixed_point_t::_2 + fixed_point_t::_1 + fixed_point_t::_0_50 + fixed_point_t::_0_20 + - fixed_point_t::_0_10; + static constexpr fixed_point_t _7_80 = fixed_point_t::_4 + + fixed_point_t::_2 + + fixed_point_t::_1 + + fixed_point_t::_0_50 + + fixed_point_t::_0_20 + + fixed_point_t::_0_10; static constexpr fixed_point_t _3_20 = fixed_point_t::_2 + fixed_point_t::_1 + fixed_point_t::_0_20; static constexpr fixed_point_t _1_20 = fixed_point_t::_0_20 * 6; static constexpr fixed_point_t _3_40 = fixed_point_t::_0_20 * 17; @@ -138,8 +141,7 @@ TEST_CASE("fvec4_t Operators", "[vec4_t][fvec4_t][fvec4_t-operators]") { CONSTEXPR_CHECK(power1 + power2 == testing::approx_vec4(1.25, 1.625, 0.875, 0.875)); CONSTEXPR_CHECK( - decimal1 - decimal2 == - testing::approx_vec4 { + decimal1 - decimal2 == testing::approx_vec4 { (1.1_a).epsilon(testing::INACCURATE_EPSILON), // (1.5_a).epsilon(testing::INACCURATE_EPSILON), // (2.2_a).epsilon(testing::INACCURATE_EPSILON), // @@ -150,8 +152,7 @@ TEST_CASE("fvec4_t Operators", "[vec4_t][fvec4_t][fvec4_t-operators]") { CONSTEXPR_CHECK(power1 - power2 == testing::approx_vec4(0.25, 1.375, 0.375, -0.625)); CONSTEXPR_CHECK( - decimal1 * decimal2 == - testing::approx_vec4 { + decimal1 * decimal2 == testing::approx_vec4 { (2.76_a).epsilon(testing::INACCURATE_EPSILON), // (16.66_a).epsilon(testing::INACCURATE_EPSILON), // (43.68_a).epsilon(testing::INACCURATE_EPSILON), // @@ -162,8 +163,12 @@ TEST_CASE("fvec4_t Operators", "[vec4_t][fvec4_t][fvec4_t-operators]") { CONSTEXPR_CHECK(int1 / int2 == testing::approx_vec4(4, 2.5, 3, 2)); CONSTEXPR_CHECK( - decimal1 / decimal2 == - testing::approx_vec4(1.91666666666666666, 1.44117647058823529, 1.39285714285714286, 1.88235294118) + decimal1 / decimal2 == testing::approx_vec4( + 1.91666666666666666, + 1.44117647058823529, + 1.39285714285714286, + 1.88235294118 + ) ); CONSTEXPR_CHECK(power1 / power2 == testing::approx_vec4(1.5, 12.0, 2.5, 1.0 / 6.0));