aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2
diff options
context:
space:
mode:
Diffstat (limited to 'extension/src/openvic2')
-rw-r--r--extension/src/openvic2/map/Map.cpp27
-rw-r--r--extension/src/openvic2/map/Map.hpp13
2 files changed, 25 insertions, 15 deletions
diff --git a/extension/src/openvic2/map/Map.cpp b/extension/src/openvic2/map/Map.cpp
index 90f2420..4e7c0bb 100644
--- a/extension/src/openvic2/map/Map.cpp
+++ b/extension/src/openvic2/map/Map.cpp
@@ -159,7 +159,7 @@ Province const* Map::get_province_by_colour(colour_t colour) const {
}
index_t Map::get_province_index_at(size_t x, size_t y) const {
- if (x < width && y < height) return province_index_image[x + y * width];
+ if (x < width && y < height) return province_shape_image[x + y * width].index;
return NULL_INDEX;
}
@@ -175,8 +175,8 @@ static colour_t colour_at(uint8_t const* colour_data, int32_t idx) {
return (colour_data[idx * 3] << 16) | (colour_data[idx * 3 + 1] << 8) | colour_data[idx * 3 + 2];
}
-return_t Map::generate_province_index_image(size_t new_width, size_t new_height, uint8_t const* colour_data) {
- if (!province_index_image.empty()) {
+return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data) {
+ if (!province_shape_image.empty()) {
Logger::error("Province index image has already been generated!");
return FAILURE;
}
@@ -194,7 +194,7 @@ return_t Map::generate_province_index_image(size_t new_width, size_t new_height,
}
width = new_width;
height = new_height;
- province_index_image.resize(width * height);
+ province_shape_image.resize(width * height);
std::vector<bool> province_checklist(provinces.get_item_count());
return_t ret = SUCCESS;
@@ -207,22 +207,23 @@ return_t Map::generate_province_index_image(size_t new_width, size_t new_height,
if (x > 0) {
const int32_t jdx = idx - 1;
if (colour_at(colour_data, jdx) == colour) {
- province_index_image[idx] = province_index_image[jdx];
+ province_shape_image[idx] = province_shape_image[jdx];
continue;
}
}
if (y > 0) {
const int32_t jdx = idx - width;
if (colour_at(colour_data, jdx) == colour) {
- province_index_image[idx] = province_index_image[jdx];
+ province_shape_image[idx] = province_shape_image[jdx];
continue;
}
}
Province const* province = get_province_by_colour(colour);
if (province != nullptr) {
const index_t index = province->get_index();
- province_index_image[idx] = index;
province_checklist[index - 1] = true;
+ province_shape_image[idx].index = index;
+ province_shape_image[idx].terrain = !province->is_water();
continue;
}
if (unrecognised_colours.find(colour) == unrecognised_colours.end()) {
@@ -230,7 +231,8 @@ return_t Map::generate_province_index_image(size_t new_width, size_t new_height,
Logger::error("Unrecognised province colour ", Province::colour_to_hex_string(colour), " at (", x, ", ", y, ")");
ret = FAILURE;
}
- province_index_image[idx] = NULL_INDEX;
+ province_shape_image[idx].index = NULL_INDEX;
+ province_shape_image[idx].terrain = 0;
}
}
@@ -251,8 +253,8 @@ size_t Map::get_height() const {
return height;
}
-std::vector<index_t> const& Map::get_province_index_image() const {
- return province_index_image;
+std::vector<Map::shape_pixel_t> const& Map::get_province_shape_image() const {
+ return province_shape_image;
}
return_t Map::add_mapmode(std::string const& identifier, Mapmode::colour_func_t colour_func) {
@@ -293,13 +295,14 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target)
Logger::error("Invalid mapmode index: ", index);
return FAILURE;
}
- target += 4; // Skip past Province::NULL_INDEX
+ // Skip past Province::NULL_INDEX
+ for (size_t i = 0; i < MAPMODE_COLOUR_SIZE; ++i)
+ *target++ = 0;
for (Province const& province : provinces.get_items()) {
const colour_t colour = mapmode->get_colour(*this, province);
*target++ = (colour >> 16) & 0xFF;
*target++ = (colour >> 8) & 0xFF;
*target++ = colour & 0xFF;
- *target++ = province.is_water() ? 0 : 255;
}
return SUCCESS;
}
diff --git a/extension/src/openvic2/map/Map.hpp b/extension/src/openvic2/map/Map.hpp
index 9150772..a664d96 100644
--- a/extension/src/openvic2/map/Map.hpp
+++ b/extension/src/openvic2/map/Map.hpp
@@ -26,6 +26,12 @@ namespace OpenVic2 {
* MAP-4
*/
struct Map {
+ #pragma pack(push, 1)
+ struct shape_pixel_t {
+ Province::index_t index;
+ uint8_t terrain;
+ };
+ #pragma pack(pop)
private:
IdentifierRegistry<Province> provinces;
IdentifierRegistry<Region> regions;
@@ -34,7 +40,7 @@ namespace OpenVic2 {
size_t water_province_count = 0;
size_t width = 0, height = 0;
- std::vector<index_t> province_index_image;
+ std::vector<shape_pixel_t> province_shape_image;
public:
Map();
@@ -57,16 +63,17 @@ namespace OpenVic2 {
Region* get_region_by_identifier(std::string const& identifier);
Region const* get_region_by_identifier(std::string const& identifier) const;
- return_t generate_province_index_image(size_t new_width, size_t new_height, uint8_t const* colour_data);
+ return_t generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data);
size_t get_width() const;
size_t get_height() const;
- std::vector<index_t> const& get_province_index_image() const;
+ std::vector<shape_pixel_t> const& get_province_shape_image() const;
return_t add_mapmode(std::string const& identifier, Mapmode::colour_func_t colour_func);
void lock_mapmodes();
size_t get_mapmode_count() const;
Mapmode const* get_mapmode_by_index(Mapmode::index_t index) const;
Mapmode const* get_mapmode_by_identifier(std::string const& identifier) const;
+ static constexpr size_t MAPMODE_COLOUR_SIZE = 3;
return_t generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const;
return_t generate_province_buildings(BuildingManager const& manager);