From 043c0d91df003e5119fece3964a63fef137d211e Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 16 Dec 2024 01:17:11 -0500 Subject: [PATCH] Now using the box iterator everywhere I can before writing a flood iterator. --- pathing.cpp | 25 +++++++------------------ systems.cpp | 8 -------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/pathing.cpp b/pathing.cpp index 189108c..d59e448 100644 --- a/pathing.cpp +++ b/pathing.cpp @@ -5,22 +5,11 @@ using std::vector; -inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x, size_t w, size_t h) { - dbc::check(h == closed.size(), "given height and closed height don't match"); - dbc::check(w == closed[0].size(), "given width and closed width don't match"); - - vector rows{int(y) - 1, int(y), int(y) + 1}; - vector 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)}); - } +inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x) { + for(matrix::in_box it{closed, x, y, 1}; it.next();) { + if(closed[it.y][it.x] == 0) { + closed[it.y][it.x] = 1; + neighbors.push_back({.x=it.x, .y=it.y}); } } } @@ -56,7 +45,7 @@ void Pathing::compute_paths(Matrix &walls) { // Second pass: Add border to open 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 @@ -65,7 +54,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, $width, $height); + add_neighbors(next_open, closed, sp.y, sp.x); } open_pixels = next_open; } diff --git a/systems.cpp b/systems.cpp index 2203ef9..21d975c 100644 --- a/systems.cpp +++ b/systems.cpp @@ -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.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); - }); - */ } } }