aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2/map/Map.cpp
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-04-29 21:00:44 +0200
committer Hop311 <hop3114@gmail.com>2023-04-29 21:00:44 +0200
commit7e2700514652212e50a006ad525e7c7ca8e7840c (patch)
tree681431640bca4f25f5e383cc7960e5ff228b47cc /extension/src/openvic2/map/Map.cpp
parent1f8545facd248bbf4ea0cd551fea5f7d9b0efdce (diff)
Terrain textures + province colour alpha channel
Diffstat (limited to 'extension/src/openvic2/map/Map.cpp')
-rw-r--r--extension/src/openvic2/map/Map.cpp49
1 files changed, 33 insertions, 16 deletions
diff --git a/extension/src/openvic2/map/Map.cpp b/extension/src/openvic2/map/Map.cpp
index 4e7c0bb..ab035ad 100644
--- a/extension/src/openvic2/map/Map.cpp
+++ b/extension/src/openvic2/map/Map.cpp
@@ -1,9 +1,9 @@
-#include "openvic2/map/Map.hpp"
+#include "Map.hpp"
#include <cassert>
#include <unordered_set>
-#include "openvic2/Logger.hpp"
+#include "../Logger.hpp"
using namespace OpenVic2;
@@ -31,7 +31,7 @@ return_t Map::add_province(std::string const& identifier, colour_t colour) {
Logger::error("Invalid province identifier - empty!");
return FAILURE;
}
- if (colour == NULL_COLOUR || colour > MAX_COLOUR) {
+ if (colour == NULL_COLOUR || colour > MAX_COLOUR_RGB) {
Logger::error("Invalid province colour: ", Province::colour_to_hex_string(colour));
return FAILURE;
}
@@ -175,7 +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_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data) {
+return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data,
+ uint8_t const* terrain_data, terrain_variant_map_t const& terrain_variant_map) {
if (!province_shape_image.empty()) {
Logger::error("Province index image has already been generated!");
return FAILURE;
@@ -192,47 +193,62 @@ return_t Map::generate_province_shape_image(size_t new_width, size_t new_height,
Logger::error("Province colour data pointer is null!");
return FAILURE;
}
+ if (terrain_data == nullptr) {
+ Logger::error("Province terrain data pointer is null!");
+ return FAILURE;
+ }
width = new_width;
height = new_height;
province_shape_image.resize(width * height);
std::vector<bool> province_checklist(provinces.get_item_count());
return_t ret = SUCCESS;
- std::unordered_set<colour_t> unrecognised_colours;
+ std::unordered_set<colour_t> unrecognised_province_colours, unrecognised_terrain_colours;
for (int32_t y = 0; y < height; ++y) {
for (int32_t x = 0; x < width; ++x) {
const int32_t idx = x + y * width;
- const colour_t colour = colour_at(colour_data, idx);
+
+ const colour_t terrain_colour = colour_at(terrain_data, idx);
+ const terrain_variant_map_t::const_iterator it = terrain_variant_map.find(terrain_colour);
+ if (it != terrain_variant_map.end()) province_shape_image[idx].terrain = it->second;
+ else {
+ if (unrecognised_terrain_colours.find(terrain_colour) == unrecognised_terrain_colours.end()) {
+ unrecognised_terrain_colours.insert(terrain_colour);
+ Logger::error("Unrecognised terrain colour ", Province::colour_to_hex_string(terrain_colour), " at (", x, ", ", y, ")");
+ ret = FAILURE;
+ }
+ province_shape_image[idx].terrain = 0;
+ }
+
+ const colour_t province_colour = colour_at(colour_data, idx);
if (x > 0) {
const int32_t jdx = idx - 1;
- if (colour_at(colour_data, jdx) == colour) {
- province_shape_image[idx] = province_shape_image[jdx];
+ if (colour_at(colour_data, jdx) == province_colour) {
+ province_shape_image[idx].index = province_shape_image[jdx].index;
continue;
}
}
if (y > 0) {
const int32_t jdx = idx - width;
- if (colour_at(colour_data, jdx) == colour) {
- province_shape_image[idx] = province_shape_image[jdx];
+ if (colour_at(colour_data, jdx) == province_colour) {
+ province_shape_image[idx].index = province_shape_image[jdx].index;
continue;
}
}
- Province const* province = get_province_by_colour(colour);
+ Province const* province = get_province_by_colour(province_colour);
if (province != nullptr) {
const index_t index = province->get_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()) {
- unrecognised_colours.insert(colour);
- Logger::error("Unrecognised province colour ", Province::colour_to_hex_string(colour), " at (", x, ", ", y, ")");
+ if (unrecognised_province_colours.find(province_colour) == unrecognised_province_colours.end()) {
+ unrecognised_province_colours.insert(province_colour);
+ Logger::error("Unrecognised province colour ", Province::colour_to_hex_string(province_colour), " at (", x, ", ", y, ")");
ret = FAILURE;
}
province_shape_image[idx].index = NULL_INDEX;
- province_shape_image[idx].terrain = 0;
}
}
@@ -303,6 +319,7 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target)
*target++ = (colour >> 16) & 0xFF;
*target++ = (colour >> 8) & 0xFF;
*target++ = colour & 0xFF;
+ *target++ = (colour >> 24) & 0xFF;
}
return SUCCESS;
}