A bit of late night work designing the little iterators.

This commit is contained in:
Zed A. Shaw 2024-12-14 11:00:52 -05:00
parent da0b941dfd
commit 8e470df554
11 changed files with 115 additions and 235 deletions

View file

@ -28,7 +28,7 @@ inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t
void Pathing::compute_paths(Matrix &walls) {
INVARIANT();
// Initialize the new array with every pixel at limit distance
matrix_assign($paths, WALL_PATH_LIMIT);
matrix::assign($paths, WALL_PATH_LIMIT);
Matrix closed = walls;
PointList starting_pixels;
@ -77,19 +77,13 @@ void Pathing::clear_target(const Point &at) {
}
void Pathing::random_flood(const Point from, std::function<void(Point at, int dnum)> cb) {
int from_x = from.x;
int from_y = from.y;
int dnum = $paths[from.y][from.x];
cb(from, dnum);
// quick hack to try the idea
matrix::each_cell it{$paths};
it.x = from.x;
it.y = from.y;
for(int y = from_y - 1; y <= from_y + 1; y++) {
if(y < 0 || y >= int($height)) continue;
for(int x = from_x - 1; x <= from_x + 1; x++) {
if(x >= 0 && x <= int($width)) {
dnum = $paths[y][x];
cb({size_t(x), size_t(y)}, dnum);
}
}
while(it.next()) {
cb({it.x, it.y}, $paths[it.y][it.x]);
}
}