diff options
author | zaaarf <zaaarf@proton.me> | 2023-09-18 23:30:45 +0200 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-09-19 17:33:15 +0200 |
commit | 5ece48b0bf738a14a4464d09f29468b9dffdbe05 (patch) | |
tree | 3739fd58c8cee39377887568b5e78875e5fb4bed | |
parent | a5ed46fd6770d7a72b4fd2d6aea9711520fecdf2 (diff) |
feat: make adjacency generator returns false if nothing changed
-rw-r--r-- | src/openvic-simulation/map/Map.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp index 5d160b7..6ccaee0 100644 --- a/src/openvic-simulation/map/Map.cpp +++ b/src/openvic-simulation/map/Map.cpp @@ -502,7 +502,9 @@ bool Map::load_region_file(ast::NodeCPtr root) { } bool Map::_generate_province_adjacencies() { - auto generate_adjacency = [&] (shape_pixel_t cur, int32_t x, int32_t y) { + 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()) { shape_pixel_t neighbour_pixel = province_shape_image[idx]; @@ -516,20 +518,22 @@ bool Map::_generate_province_adjacencies() { else { //TODO: distance logic and flags cur_province->add_adjacency(neighbour->index, 0, 0); neighbour->add_adjacency(cur_province->index, 0, 0); + return true; } } } + return false; }; for (int32_t y = 0; y < height; ++y) { for (int32_t x = 0; x < width; ++x) { shape_pixel_t cur = province_shape_image[x + y * width]; - generate_adjacency(cur, x + 1, y); - generate_adjacency(cur, x, y - 1); - generate_adjacency(cur, x - 1, y); - generate_adjacency(cur, x, y + 1); + 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); } } - return true; + return changed; } |