From 928c521599b2b18e8964aeb445c3ca5a55bacbd1 Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 17 Jul 2024 00:01:03 +0100 Subject: Use IndexedMap + helper function support --- .../openvic-extension/singletons/MenuSingleton.cpp | 21 ++++++++++++--------- .../openvic-extension/singletons/ModelSingleton.cpp | 14 ++++++++++---- .../openvic-extension/singletons/ModelSingleton.hpp | 9 ++++++--- .../openvic-extension/singletons/PopulationMenu.cpp | 6 +++--- 4 files changed, 31 insertions(+), 19 deletions(-) (limited to 'extension/src/openvic-extension/singletons') diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp index b4baf40..36e5f58 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp @@ -226,19 +226,22 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { ret[province_info_total_population_key] = province->get_total_population(); - fixed_point_map_t const& pop_types = province->get_pop_type_distribution(); - if (!pop_types.empty()) { - ret[province_info_pop_types_key] = GFXPieChartTexture::distribution_to_slices_array(pop_types); + GFXPieChartTexture::godot_pie_chart_data_t pop_types = + GFXPieChartTexture::distribution_to_slices_array(province->get_pop_type_distribution()); + if (!pop_types.is_empty()) { + ret[province_info_pop_types_key] = std::move(pop_types); } - fixed_point_map_t const& ideologies = province->get_ideology_distribution(); - if (!ideologies.empty()) { - ret[province_info_pop_ideologies_key] = GFXPieChartTexture::distribution_to_slices_array(ideologies); + GFXPieChartTexture::godot_pie_chart_data_t ideologies = + GFXPieChartTexture::distribution_to_slices_array(province->get_ideology_distribution()); + if (!ideologies.is_empty()) { + ret[province_info_pop_ideologies_key] = std::move(ideologies); } - fixed_point_map_t const& cultures = province->get_culture_distribution(); - if (!cultures.empty()) { - ret[province_info_pop_cultures_key] = GFXPieChartTexture::distribution_to_slices_array(cultures); + GFXPieChartTexture::godot_pie_chart_data_t cultures = + GFXPieChartTexture::distribution_to_slices_array(province->get_culture_distribution()); + if (!cultures.is_empty()) { + ret[province_info_pop_cultures_key] = std::move(cultures); } std::vector const& cores = province->get_cores(); diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.cpp b/extension/src/openvic-extension/singletons/ModelSingleton.cpp index 7dea1bd..5fb9cf8 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.cpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.cpp @@ -4,6 +4,8 @@ #include +#include + #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/utility/ClassBindings.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -180,8 +182,12 @@ Dictionary ModelSingleton::make_model_dict(GFX::Actor const& actor) const { /* Returns false if an error occurs while trying to add a unit model for the province, true otherwise. * Returning true doesn't necessarily mean a unit was added, e.g. when units is empty. */ -template T> -bool ModelSingleton::add_unit_dict(ordered_set const& units, TypedArray& unit_array) const { +template +bool ModelSingleton::add_unit_dict( + ordered_set*> const& units, TypedArray& unit_array +) const { + using _UnitInstanceGroup = UnitInstanceGroupBranched; + GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, false); @@ -204,7 +210,7 @@ bool ModelSingleton::add_unit_dict(ordered_set const& units, TypedArrayget_country_definition(); @@ -220,7 +226,7 @@ bool ModelSingleton::add_unit_dict(ordered_set const& units, TypedArrayget_sprite(); std::string_view mount_actor_name, mount_attach_node_name; - if constexpr (std::same_as) { + if constexpr (Branch == UnitType::branch_t::LAND) { RegimentType const* regiment_type = reinterpret_cast(display_unit_type); if (!regiment_type->get_sprite_override().empty()) { diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.hpp b/extension/src/openvic-extension/singletons/ModelSingleton.hpp index ad1a6d8..8030ffd 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.hpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.hpp @@ -3,7 +3,8 @@ #include #include -#include +#include +#include namespace OpenVic { struct BuildingInstance; @@ -31,8 +32,10 @@ namespace OpenVic { godot::Dictionary make_animation_dict(GFX::Actor::Animation const& animation) const; godot::Dictionary make_model_dict(GFX::Actor const& actor) const; - template T> - bool add_unit_dict(ordered_set const& units, godot::TypedArray& unit_array) const; + template + bool add_unit_dict( + ordered_set*> const& units, godot::TypedArray& unit_array + ) const; bool add_building_dict( BuildingInstance const& building, ProvinceInstance const& province, diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp index 1237e86..db2ac53 100644 --- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp +++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp @@ -407,12 +407,12 @@ void MenuSingleton::_population_menu_update_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] += - cast_map(pop->get_ideologies() * static_cast(pop->get_size())); + pop->get_ideologies() * static_cast(static_cast(pop->get_size())); population_menu.distributions[3][&pop->get_culture()] += pop->get_size(); population_menu.distributions[4] += cast_map(pop->get_issues() * static_cast(pop->get_size())); population_menu.distributions[5] += - cast_map(pop->get_votes() * static_cast(pop->get_size())); + pop->get_votes() * static_cast(static_cast(pop->get_size())); } for (fixed_point_map_t& distribution : population_menu.distributions) { @@ -467,7 +467,7 @@ MenuSingleton::sort_func_t MenuSingleton::_get_population_menu_sort_func(populat }; case SORT_IDEOLOGY: return [](Pop const* a, Pop const* b) -> bool { - return sorted_fixed_map_less_than(a->get_ideologies(), b->get_ideologies()); + return sorted_indexed_map_less_than(a->get_ideologies(), b->get_ideologies()); }; case SORT_ISSUES: return [](Pop const* a, Pop const* b) -> bool { -- cgit v1.2.3-56-ga3b1