aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-11-14 22:27:39 +0100
committer hop311 <hop3114@gmail.com>2023-11-15 21:06:16 +0100
commite031758cf68535e97045c07f36e2524676447778 (patch)
treed6e49915c414c86ce808b2e1d7289c7e4e7d76df /src/openvic-simulation/map
parenta00b558a53edb40c9e6789790036f0b618e80ec1 (diff)
Striped mapmode and improved distributions
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Map.cpp29
-rw-r--r--src/openvic-simulation/map/Map.hpp14
-rw-r--r--src/openvic-simulation/map/Province.cpp2
-rw-r--r--src/openvic-simulation/map/Province.hpp12
-rw-r--r--src/openvic-simulation/map/Region.cpp13
-rw-r--r--src/openvic-simulation/map/Region.hpp3
6 files changed, 42 insertions, 31 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) {
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp
index d11ad8e..db67390 100644
--- a/src/openvic-simulation/map/Map.hpp
+++ b/src/openvic-simulation/map/Map.hpp
@@ -14,7 +14,10 @@ namespace OpenVic {
struct Mapmode : HasIdentifier {
friend struct Map;
- using colour_func_t = std::function<colour_t(Map const&, Province const&)>;
+ /* Bottom 32 bits are the base colour, top 32 are the stripe colour, both in ARGB format with the alpha channels
+ * controlling interpolation with the terrain colour (0 = all terrain, 255 = all corresponding RGB) */
+ using base_stripe_t = uint64_t;
+ using colour_func_t = std::function<base_stripe_t(Map const&, Province const&)>;
using index_t = size_t;
private:
@@ -29,7 +32,7 @@ namespace OpenVic {
Mapmode(Mapmode&&) = default;
index_t get_index() const;
- colour_t get_colour(Map const& map, Province const& province) const;
+ base_stripe_t get_base_stripe_colours(Map const& map, Province const& province) const;
};
struct GoodManager;
@@ -98,7 +101,12 @@ namespace OpenVic {
bool add_mapmode(std::string_view identifier, Mapmode::colour_func_t colour_func);
IDENTIFIER_REGISTRY_ACCESSORS(mapmode)
Mapmode const* get_mapmode_by_index(size_t index) const;
- static constexpr size_t MAPMODE_COLOUR_SIZE = 4;
+
+ /* The mapmode colour image contains of a list of base colours and stripe colours. Each colour is four bytes
+ * in RGBA format, with the alpha value being used to interpolate with the terrain colour, so A = 0 is fully terrain
+ * and A = 255 is fully the RGB colour packaged with A. The base and stripe colours for each province are packed
+ * together adjacently, so each province's entry is 8 bytes long. The list contains Province::MAX_INDEX + 1 entries,
+ * that is the maximum allowed number of provinces plus one for the index-zero "null province". */
bool generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const;
bool setup(BuildingManager const& building_manager, PopManager const& pop_manager);
diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp
index 4b76210..1b47dea 100644
--- a/src/openvic-simulation/map/Province.cpp
+++ b/src/openvic-simulation/map/Province.cpp
@@ -16,7 +16,7 @@ Province::index_t Province::get_index() const {
return index;
}
-Region* Province::get_region() const {
+Region const* Province::get_region() const {
return region;
}
diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp
index eda05fb..21a974f 100644
--- a/src/openvic-simulation/map/Province.hpp
+++ b/src/openvic-simulation/map/Province.hpp
@@ -65,7 +65,7 @@ namespace OpenVic {
private:
const index_t index;
- Region* region = nullptr;
+ Region const* region = nullptr;
bool on_map = false, has_region = false, water = false;
life_rating_t life_rating = 0;
colony_status_t colony_status = colony_status_t::STATE;
@@ -75,10 +75,10 @@ namespace OpenVic {
std::vector<Pop> pops;
Pop::pop_size_t total_population;
- decimal_map_t<PopType const*> PROPERTY(pop_type_distribution);
- decimal_map_t<Ideology const*> PROPERTY(ideology_distribution);
- decimal_map_t<Culture const*> PROPERTY(culture_distribution);
- decimal_map_t<Religion const*> PROPERTY(religion_distribution);
+ fixed_point_map_t<PopType const*> PROPERTY(pop_type_distribution);
+ fixed_point_map_t<Ideology const*> PROPERTY(ideology_distribution);
+ fixed_point_map_t<Culture const*> PROPERTY(culture_distribution);
+ fixed_point_map_t<Religion const*> PROPERTY(religion_distribution);
std::vector<adjacency_t> adjacencies;
province_positions_t positions;
@@ -98,7 +98,7 @@ namespace OpenVic {
Province(Province&&) = default;
index_t get_index() const;
- Region* get_region() const;
+ Region const* get_region() const;
bool get_on_map() const;
bool get_has_region() const;
bool get_water() const;
diff --git a/src/openvic-simulation/map/Region.cpp b/src/openvic-simulation/map/Region.cpp
index ac232df..e33d9c9 100644
--- a/src/openvic-simulation/map/Region.cpp
+++ b/src/openvic-simulation/map/Region.cpp
@@ -65,18 +65,15 @@ ProvinceSet::provinces_t const& ProvinceSet::get_provinces() const {
return provinces;
}
+static constexpr colour_t ERROR_REGION_COLOUR = COLOUR_COMPONENT << 16;
+
Region::Region(std::string_view new_identifier, provinces_t&& new_provinces, bool new_meta)
- : HasIdentifier { new_identifier }, ProvinceSet { std::move(new_provinces) }, meta { new_meta } {
+ : HasIdentifierAndColour {
+ new_identifier, new_provinces.size() > 0 ? new_provinces.front()->get_colour() : ERROR_REGION_COLOUR, false, false
+ }, ProvinceSet { std::move(new_provinces) }, meta { new_meta } {
lock();
}
bool Region::get_meta() const {
return meta;
}
-
-colour_t Region::get_colour() const {
- if (empty()) {
- return FULL_COLOUR << 16;
- }
- return get_provinces().front()->get_colour();
-}
diff --git a/src/openvic-simulation/map/Region.hpp b/src/openvic-simulation/map/Region.hpp
index 157b643..9119b93 100644
--- a/src/openvic-simulation/map/Region.hpp
+++ b/src/openvic-simulation/map/Region.hpp
@@ -28,7 +28,7 @@ namespace OpenVic {
/* REQUIREMENTS:
* MAP-6, MAP-44, MAP-48
*/
- struct Region : HasIdentifier, ProvinceSet {
+ struct Region : HasIdentifierAndColour, ProvinceSet {
friend struct Map;
private:
@@ -44,6 +44,5 @@ namespace OpenVic {
Region(Region&&) = default;
bool get_meta() const;
- colour_t get_colour() const;
};
}