summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-24 18:56:48 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-24 18:58:01 +0100
commitfdd9a4b31ff4f90388c1496bc5626bc2a5319064 (patch)
tree541dd08bc5b23b316387b69c2432a2086ef46889
parentd6f796666255d797444affe96fe8de3a92648a22 (diff)
clean up region stuff a bit
-rw-r--r--src/chunk-region.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/chunk-region.cpp b/src/chunk-region.cpp
index 2a7f0849..79114219 100644
--- a/src/chunk-region.cpp
+++ b/src/chunk-region.cpp
@@ -1,6 +1,7 @@
#include "chunk-region.hpp"
#include "path-search-bbox.hpp"
#include "world.hpp"
+#include <array>
#include <Corrade/Containers/GrowableArray.h>
#include <Magnum/Math/Functions.h>
@@ -151,15 +152,25 @@ void chunk::make_pass_region(pass_region& ret)
const auto nbs = _world->neighbors(_coord);
constexpr Vector2i fours[4] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
- constexpr auto last = div_count - Vector2i{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<Vector2i, 4> {{
+ {i, last.y()}, // bottom
+ {i, 0}, // top
+ {last.x(), i}, // right
+ {0, i}, // left
+ }};
+ };
+
for (int i = 0; i < div_count.x(); i++)
{
- if (Vector2i pos{i, last.y()}; check_pos(*this, nbs, pos, fours[0])) tmp.append(ret.bits, pos); // bottom
- if (Vector2i pos{i, 0}; check_pos(*this, nbs, pos, fours[1])) tmp.append(ret.bits, pos); // top
- if (Vector2i pos{last.x(), i}; check_pos(*this, nbs, pos, fours[2])) tmp.append(ret.bits, pos); // right
- if (Vector2i pos{0, i}; check_pos(*this, nbs, pos, fours[3])) tmp.append(ret.bits, pos); // left
+ auto positions = get_positions(i);
+ for (auto i = 0u; i < 4; i++)
+ if (check_pos(*this, nbs, positions[i], fours[i]))
+ tmp.append(ret.bits, positions[i]);
}
while (!tmp.stack.isEmpty())