diff options
author | hop311 <hop3114@gmail.com> | 2023-11-14 22:27:39 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2023-11-15 21:06:16 +0100 |
commit | e031758cf68535e97045c07f36e2524676447778 (patch) | |
tree | d6e49915c414c86ce808b2e1d7289c7e4e7d76df /src/openvic-simulation/map/Map.cpp | |
parent | a00b558a53edb40c9e6789790036f0b618e80ec1 (diff) |
Striped mapmode and improved distributions
Diffstat (limited to 'src/openvic-simulation/map/Map.cpp')
-rw-r--r-- | src/openvic-simulation/map/Map.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp index 7e2213e..261a13e 100644 --- a/src/openvic-simulation/map/Map.cpp +++ b/src/openvic-simulation/map/Map.cpp @@ -24,7 +24,7 @@ Mapmode::index_t Mapmode::get_index() const { return index; } -colour_t Mapmode::get_colour(Map const& map, Province const& province) const { +Mapmode::base_stripe_t Mapmode::get_base_stripe_colours(Map const& map, Province const& province) const { return colour_func ? colour_func(map, province) : NULL_COLOUR; } @@ -254,15 +254,23 @@ bool Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) cons mapmode = &Mapmode::ERROR_MAPMODE; } // Skip past Province::NULL_INDEX - for (size_t i = 0; i < MAPMODE_COLOUR_SIZE; ++i) { + for (size_t i = 0; i < sizeof(Mapmode::base_stripe_t); ++i) { *target++ = 0; } for (Province const& province : provinces.get_items()) { - const colour_t colour = mapmode->get_colour(*this, province); - *target++ = (colour >> 16) & FULL_COLOUR; - *target++ = (colour >> 8) & FULL_COLOUR; - *target++ = colour & FULL_COLOUR; - *target++ = (colour >> 24) & FULL_COLOUR; + const Mapmode::base_stripe_t base_stripe = mapmode->get_base_stripe_colours(*this, province); + const colour_t base_colour = static_cast<colour_t>(base_stripe); + const colour_t stripe_colour = static_cast<colour_t>(base_stripe >> (sizeof(colour_t) * 8)); + + *target++ = (base_colour >> 16) & COLOUR_COMPONENT; // red + *target++ = (base_colour >> 8) & COLOUR_COMPONENT; // green + *target++ = (base_colour >> 0) & COLOUR_COMPONENT; // blue + *target++ = (base_colour >> 24) & COLOUR_COMPONENT; // alpha + + *target++ = (stripe_colour >> 16) & COLOUR_COMPONENT; // red + *target++ = (stripe_colour >> 8) & COLOUR_COMPONENT; // green + *target++ = (stripe_colour >> 0) & COLOUR_COMPONENT; // blue + *target++ = (stripe_colour >> 24) & COLOUR_COMPONENT; // alpha } return ret; } @@ -489,7 +497,7 @@ bool Map::load_map_images(fs::path const& province_path, fs::path const& terrain uint8_t const* terrain_data = terrain_bmp.get_pixel_data().data(); std::vector<bool> province_checklist(provinces.size()); - std::vector<decimal_map_t<TerrainType const*>> terrain_type_pixels_list(provinces.size()); + std::vector<fixed_point_map_t<TerrainType const*>> terrain_type_pixels_list(provinces.size()); bool ret = true; std::unordered_set<colour_t> unrecognised_province_colours; @@ -553,9 +561,8 @@ bool Map::load_map_images(fs::path const& province_path, fs::path const& terrain size_t missing = 0; for (size_t idx = 0; idx < province_checklist.size(); ++idx) { Province* province = provinces.get_item_by_index(idx); - province->_set_terrain_type( - reinterpret_cast<TerrainType const*>(get_largest_item(terrain_type_pixels_list[idx]).first) - ); + const fixed_point_map_const_iterator_t<TerrainType const*> largest = get_largest_item(terrain_type_pixels_list[idx]); + province->_set_terrain_type(largest != terrain_type_pixels_list[idx].end() ? largest->first : nullptr); province->on_map = province_checklist[idx]; if (!province->on_map) { if (detailed_errors) { |