aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map/Map.cpp
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-09-19 14:09:19 +0200
committer zaaarf <zaaarf@proton.me>2023-09-19 17:33:15 +0200
commit3017b6338ca67c0c18f404cf8e162918e36e94e7 (patch)
tree688d961ebddd6efdf910e90601c0ed5ce2740e48 /src/openvic-simulation/map/Map.cpp
parent5ece48b0bf738a14a4464d09f29468b9dffdbe05 (diff)
fix: adjacency algorithm optimisiations and fixes
Diffstat (limited to 'src/openvic-simulation/map/Map.cpp')
-rw-r--r--src/openvic-simulation/map/Map.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp
index 6ccaee0..e2ad1de 100644
--- a/src/openvic-simulation/map/Map.cpp
+++ b/src/openvic-simulation/map/Map.cpp
@@ -504,9 +504,9 @@ bool Map::load_region_file(ast::NodeCPtr root) {
bool Map::_generate_province_adjacencies() {
bool changed = false;
- auto generate_adjacency = [&] (shape_pixel_t cur, int32_t x, int32_t y) -> bool {
- int32_t idx = x + y * width;
- if (idx >= 0 && idx < province_shape_image.size()) {
+ auto generate_adjacency = [&] (shape_pixel_t cur, size_t x, size_t y) -> bool {
+ if (x < width && y < height) {
+ size_t idx = x + y * width;
shape_pixel_t neighbour_pixel = province_shape_image[idx];
if (cur.index != neighbour_pixel.index) {
Province* cur_province = get_province_by_index(cur.index);
@@ -516,8 +516,8 @@ bool Map::_generate_province_adjacencies() {
else if (neighbour == nullptr)
Logger::error("No known province with index ", neighbour_pixel.index, ": cannot create adjacency for it!");
else { //TODO: distance logic and flags
- cur_province->add_adjacency(neighbour->index, 0, 0);
- neighbour->add_adjacency(cur_province->index, 0, 0);
+ cur_province->add_adjacency(neighbour, 0, 0);
+ neighbour->add_adjacency(cur_province, 0, 0);
return true;
}
}
@@ -525,12 +525,10 @@ bool Map::_generate_province_adjacencies() {
return false;
};
- for (int32_t y = 0; y < height; ++y) {
- for (int32_t x = 0; x < width; ++x) {
+ for (size_t y = 0; y < height; ++y) {
+ for (size_t x = 0; x < width; ++x) {
shape_pixel_t cur = province_shape_image[x + y * width];
changed |= generate_adjacency(cur, x + 1, y);
- changed |= generate_adjacency(cur, x, y - 1);
- changed |= generate_adjacency(cur, x - 1, y);
changed |= generate_adjacency(cur, x, y + 1);
}
}