|
|
|
@ -5,9 +5,7 @@ |
|
|
|
|
|
|
|
|
|
using std::vector; |
|
|
|
|
|
|
|
|
|
inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x) { |
|
|
|
|
size_t h = closed.size(); |
|
|
|
|
size_t w = closed[0].size(); |
|
|
|
|
inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x, size_t w, size_t h) { |
|
|
|
|
vector<size_t> rows{y - 1, y, y + 1}; |
|
|
|
|
vector<size_t> cols{x - 1, x, x + 1}; |
|
|
|
|
|
|
|
|
@ -17,7 +15,6 @@ inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t |
|
|
|
|
(0 <= col && col < w) && |
|
|
|
|
closed[row][col] == 0) |
|
|
|
|
{ |
|
|
|
|
// BUG: maybe value here?
|
|
|
|
|
closed[row][col] = 1; |
|
|
|
|
neighbors.push_back({.x=col, .y=row}); |
|
|
|
|
} |
|
|
|
@ -39,18 +36,18 @@ void Pathing::compute_paths(Matrix &walls) { |
|
|
|
|
|
|
|
|
|
// First pass: Add starting pixels and put them in closed
|
|
|
|
|
for(size_t counter = 0; counter < $height * $width; counter++) { |
|
|
|
|
size_t x = counter % $width; // BUG: is this right?
|
|
|
|
|
size_t x = counter % $width; |
|
|
|
|
size_t y = counter / $width; |
|
|
|
|
if($input[y][x] == 0) { |
|
|
|
|
$paths[y][x] = 0; |
|
|
|
|
closed[y][x] = 1; // BUG: value here?
|
|
|
|
|
closed[y][x] = 1; |
|
|
|
|
starting_pixels.push_back({x,y}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Second pass: Add border to open
|
|
|
|
|
for(auto sp : starting_pixels) { |
|
|
|
|
add_neighbors(open_pixels, closed, sp.y, sp.x); |
|
|
|
|
add_neighbors(open_pixels, closed, sp.y, sp.x, $width, $height); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Third pass: Iterate filling in the open list
|
|
|
|
@ -59,7 +56,7 @@ void Pathing::compute_paths(Matrix &walls) { |
|
|
|
|
PointList next_open; |
|
|
|
|
for(auto sp : open_pixels) { |
|
|
|
|
$paths[sp.y][sp.x] = counter; |
|
|
|
|
add_neighbors(next_open, closed, sp.y, sp.x); |
|
|
|
|
add_neighbors(next_open, closed, sp.y, sp.x, $width, $height); |
|
|
|
|
} |
|
|
|
|
open_pixels = next_open; |
|
|
|
|
} |
|
|
|
@ -71,8 +68,8 @@ void Pathing::compute_paths(Matrix &walls) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Pathing::set_target(const Point &at, int value) { |
|
|
|
|
// BUG: not using value here but it can be < 0 for deeper slopes
|
|
|
|
|
$input[at.y][at.x] = 0; |
|
|
|
|
// FUTURE: I'll eventually allow setting this to negatives for priority
|
|
|
|
|
$input[at.y][at.x] = value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Pathing::clear_target(const Point &at) { |
|
|
|
|