Now using the box iterator everywhere I can before writing a flood iterator.
This commit is contained in:
parent
547be19e68
commit
043c0d91df
2 changed files with 7 additions and 26 deletions
25
pathing.cpp
25
pathing.cpp
|
@ -5,22 +5,11 @@
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x, size_t w, size_t h) {
|
inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x) {
|
||||||
dbc::check(h == closed.size(), "given height and closed height don't match");
|
for(matrix::in_box it{closed, x, y, 1}; it.next();) {
|
||||||
dbc::check(w == closed[0].size(), "given width and closed width don't match");
|
if(closed[it.y][it.x] == 0) {
|
||||||
|
closed[it.y][it.x] = 1;
|
||||||
vector<int> rows{int(y) - 1, int(y), int(y) + 1};
|
neighbors.push_back({.x=it.x, .y=it.y});
|
||||||
vector<int> cols{int(x) - 1, int(x), int(x) + 1};
|
|
||||||
|
|
||||||
for(int row : rows) {
|
|
||||||
for(int col : cols) {
|
|
||||||
if(row < 0 || row >= int(h)) continue;
|
|
||||||
if(col < 0 || col >= int(w)) continue;
|
|
||||||
|
|
||||||
if(closed[row][col] == 0) {
|
|
||||||
closed[row][col] = 1;
|
|
||||||
neighbors.push_back({.x=size_t(col), .y=size_t(row)});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +45,7 @@ void Pathing::compute_paths(Matrix &walls) {
|
||||||
|
|
||||||
// Second pass: Add border to open
|
// Second pass: Add border to open
|
||||||
for(auto sp : starting_pixels) {
|
for(auto sp : starting_pixels) {
|
||||||
add_neighbors(open_pixels, closed, sp.y, sp.x, $width, $height);
|
add_neighbors(open_pixels, closed, sp.y, sp.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Third pass: Iterate filling in the open list
|
// Third pass: Iterate filling in the open list
|
||||||
|
@ -65,7 +54,7 @@ void Pathing::compute_paths(Matrix &walls) {
|
||||||
PointList next_open;
|
PointList next_open;
|
||||||
for(auto sp : open_pixels) {
|
for(auto sp : open_pixels) {
|
||||||
$paths[sp.y][sp.x] = counter;
|
$paths[sp.y][sp.x] = counter;
|
||||||
add_neighbors(next_open, closed, sp.y, sp.x, $width, $height);
|
add_neighbors(next_open, closed, sp.y, sp.x);
|
||||||
}
|
}
|
||||||
open_pixels = next_open;
|
open_pixels = next_open;
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,14 +217,6 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, const Matrix &light
|
||||||
pixel.foreground_color = Color::HSV(80, 100, light_value / 1.5);
|
pixel.foreground_color = Color::HSV(80, 100, light_value / 1.5);
|
||||||
pixel.background_color = Color::HSV(30, 20, light_value / 3);
|
pixel.background_color = Color::HSV(30, 20, light_value / 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
// swapped!
|
|
||||||
canvas.DrawText(x * 2, y * 4, tile, [light_value](auto &pixel) {
|
|
||||||
pixel.foreground_color = Color::HSV(30, 40, light_value);
|
|
||||||
pixel.background_color = Color::HSV(30, 20, light_value / 3);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue