diff options
Diffstat (limited to 'extension')
4 files changed, 40 insertions, 26 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation -Subproject 5550b237fa9b6f8c6a86eea0de9d32e28a626dc +Subproject 00a3121dd43a3b6e8f5a6efa2d3b6560ef78c37 diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp index 3610efb..69330a4 100644 --- a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp @@ -45,7 +45,7 @@ namespace OpenVic { * - weight: float */ godot::Error set_slices_array(godot_pie_chart_data_t const& new_slices); - /* Generate slice data from a distribution of HasIdentifierAndColour derived objects, sorted by their weight. + /* Generate slice data from a distribution of objects satisfying HasGetIdentifierAndGetColour, sorted by their weight. * The resulting Array of Dictionaries can be used as an argument for set_slices_array. */ template<typename Container> static godot_pie_chart_data_t distribution_to_slices_array(Container const& dist) @@ -53,17 +53,18 @@ namespace OpenVic { ( /* fixed_point_map_t<T const*>, T derived from HasIdentifierAndColour */ utility::is_specialization_of_v<Container, tsl::ordered_map> && - std::derived_from<std::remove_pointer_t<typename Container::key_type>, HasIdentifierAndColour> && + HasGetIdentifierAndGetColour<std::remove_pointer_t<typename Container::key_type>> && std::is_same_v<typename Container::mapped_type, fixed_point_t> ) || ( /* IndexedMap<T, fixed_point_t>, T derived from HasIdentifierAndColour */ utility::is_specialization_of_v<Container, IndexedMap> && - std::derived_from<typename Container::key_t, HasIdentifierAndColour> && + HasGetIdentifierAndGetColour<typename Container::key_type> && std::is_same_v<typename Container::value_t, fixed_point_t> ) ) { using namespace godot; - using entry_t = std::pair<HasIdentifierAndColour const*, fixed_point_t>; + using key_type = std::remove_pointer_t<typename Container::key_type>; + using entry_t = std::pair<key_type const*, fixed_point_t>; std::vector<entry_t> sorted_dist; if constexpr (utility::is_specialization_of_v<Container, tsl::ordered_map>) { @@ -78,7 +79,7 @@ namespace OpenVic { for (size_t index = 0; index < dist.size(); ++index) { fixed_point_t const& value = dist[index]; if (value != 0) { - HasIdentifierAndColour const* key = &dist(index); + key_type const* key = &dist(index); sorted_dist.emplace_back(key, value); } } diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp index 97a6956..0dcc8ff 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp @@ -59,7 +59,12 @@ namespace OpenVic { * - Nationality (Culture) * - Issues * - Vote */ - std::array<fixed_point_map_t<HasIdentifierAndColour const*>, DISTRIBUTION_COUNT> distributions; + fixed_point_map_t<PopType const*> workforce_distribution; + fixed_point_map_t<Religion const*> religion_distribution; + fixed_point_map_t<Ideology const*> ideology_distribution; + fixed_point_map_t<Culture const*> culture_distribution; + fixed_point_map_t<Issue const*> issue_distribution; + fixed_point_map_t<CountryParty const*> vote_distribution; enum PopSortKey { NONE, SORT_SIZE, SORT_TYPE, SORT_CULTURE, SORT_RELIGION, SORT_LOCATION, SORT_MILITANCY, SORT_CONSCIOUSNESS, diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp index c96ef02..1bef050 100644 --- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp +++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp @@ -379,9 +379,12 @@ Error MenuSingleton::_population_menu_update_pops() { Error MenuSingleton::_population_menu_update_filtered_pops() { population_menu.filtered_pops.clear(); - for (fixed_point_map_t<HasIdentifierAndColour const*>& distribution : population_menu.distributions) { - distribution.clear(); - } + population_menu.workforce_distribution.clear(); + population_menu.religion_distribution.clear(); + population_menu.ideology_distribution.clear(); + population_menu.culture_distribution.clear(); + population_menu.issue_distribution.clear(); + population_menu.vote_distribution.clear(); for (Pop const* pop : population_menu.pops) { if (population_menu.pop_filters[&pop->get_type()].selected) { @@ -390,20 +393,22 @@ Error MenuSingleton::_population_menu_update_filtered_pops() { } for (Pop const* pop : population_menu.filtered_pops) { - population_menu.distributions[0][&pop->get_type()] += pop->get_size(); - population_menu.distributions[1][&pop->get_religion()] += pop->get_size(); - population_menu.distributions[2] += - pop->get_ideologies() * fixed_point_t::parse(pop->get_size()); - population_menu.distributions[3][&pop->get_culture()] += pop->get_size(); - population_menu.distributions[4] += - cast_map<HasIdentifierAndColour>(pop->get_issues() * fixed_point_t::parse(pop->get_size())); - population_menu.distributions[5] += - pop->get_votes() * fixed_point_t::parse(pop->get_size()); + const fixed_point_t pop_size = fixed_point_t::parse(pop->get_size()); + + population_menu.workforce_distribution[&pop->get_type()] += pop->get_size(); + population_menu.religion_distribution[&pop->get_religion()] += pop->get_size(); + population_menu.ideology_distribution += pop->get_ideologies() * fixed_point_t::parse(pop->get_size()); + population_menu.culture_distribution[&pop->get_culture()] += pop->get_size(); + population_menu.issue_distribution += pop->get_issues() * fixed_point_t::parse(pop->get_size()); + population_menu.vote_distribution += pop->get_votes() * fixed_point_t::parse(pop->get_size()); } - for (fixed_point_map_t<HasIdentifierAndColour const*>& distribution : population_menu.distributions) { - normalise_fixed_point_map(distribution); - } + normalise_fixed_point_map(population_menu.workforce_distribution); + normalise_fixed_point_map(population_menu.religion_distribution); + normalise_fixed_point_map(population_menu.ideology_distribution); + normalise_fixed_point_map(population_menu.culture_distribution); + normalise_fixed_point_map(population_menu.issue_distribution); + normalise_fixed_point_map(population_menu.vote_distribution); return _population_menu_sort_pops(); } @@ -825,11 +830,14 @@ PackedStringArray MenuSingleton::get_population_menu_distribution_setup_info() c TypedArray<Array> MenuSingleton::get_population_menu_distribution_info() const { TypedArray<Array> array; - ERR_FAIL_COND_V(array.resize(population_menu.distributions.size()) != OK, {}); - - for (int32_t idx = 0; idx < array.size(); ++idx) { - array[idx] = GFXPieChartTexture::distribution_to_slices_array(population_menu.distributions[idx]); - } + ERR_FAIL_COND_V(array.resize(population_menu_t::DISTRIBUTION_COUNT) != OK, {}); + + array[0] = GFXPieChartTexture::distribution_to_slices_array(population_menu.workforce_distribution); + array[1] = GFXPieChartTexture::distribution_to_slices_array(population_menu.religion_distribution); + array[2] = GFXPieChartTexture::distribution_to_slices_array(population_menu.ideology_distribution); + array[3] = GFXPieChartTexture::distribution_to_slices_array(population_menu.culture_distribution); + array[4] = GFXPieChartTexture::distribution_to_slices_array(population_menu.issue_distribution); + array[5] = GFXPieChartTexture::distribution_to_slices_array(population_menu.vote_distribution); return array; } |