From b16d1613e5c4de120b20f539f3b7792ab7304ccc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 26 Feb 2024 19:36:16 +0100 Subject: try to fix region bad fill order --- src/chunk-region.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/chunk-region.cpp b/src/chunk-region.cpp index 5b15b7e2..22c97eed 100644 --- a/src/chunk-region.cpp +++ b/src/chunk-region.cpp @@ -46,7 +46,7 @@ constexpr bbox bbox_from_pos2(Vector2i pt, Vector2i from) constexpr bbox make_pos(Vector2i ij, Vector2i from) { auto pos = div_min + div_size * ij; - auto pos0 = pos + from*div_size; + auto pos0 = pos - from*div_size; return bbox_from_pos2(pos, pos0); } @@ -145,22 +145,25 @@ auto chunk::make_pass_region(const pred& f, bool debug) -> pass_region auto& tmp = get_tmp(); const auto nbs = _world->neighbors(_coord); - constexpr Vector2i fours[4] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} }; + constexpr Vector2i fours[4] = { + {-1, 0}, {1, 0}, + {0, -1}, {0, 1}, + }; //if (Vector2i pos{0, 0}; check_pos(*c, nbs, pos, fours[1])) tmp.append(pos, 1); // top - constexpr auto get_positions = [](int i) { - constexpr auto last = div_count - Vector2i{1}; - return std::array {{ - {i, last.y()}, // bottom - {i, 0}, // top - {last.x(), i}, // right - {0, i}, // left - }}; - }; - for (int i = 0; i < div_count.x(); i++) { + constexpr auto get_positions = [](int i) { + constexpr auto last = div_count - Vector2i{1}; + return std::array {{ + {0, i}, // left + {last.x(), i}, // right + {i, 0}, // top + {i, last.y()}, // bottom + }}; + }; + auto positions = get_positions(i); for (auto i = 0u; i < 4; i++) if (check_pos(*this, nbs, positions[i], fours[i], f)) @@ -173,7 +176,7 @@ auto chunk::make_pass_region(const pred& f, bool debug) -> pass_region arrayRemoveSuffix(tmp.stack); for (int i = 0; i < 4; i++) { - Vector2i from = fours[i], pos{p - from}; + Vector2i from = fours[i], pos{p + from}; if ((uint32_t)pos.x() >= div_count.x() || (uint32_t)pos.y() >= div_count.y()) [[unlikely]] continue; if (tmp.check_visited(ret.bits, pos, i) && check_pos(*this, nbs, pos, from, f)) -- cgit v1.2.3