summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/path-search-dijkstra.cpp23
-rw-r--r--src/path-search.hpp2
-rw-r--r--test/dijkstra.cpp2
3 files changed, 18 insertions, 9 deletions
diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp
index fe0f2b70..5b43e5c9 100644
--- a/src/path-search-dijkstra.cpp
+++ b/src/path-search-dijkstra.cpp
@@ -168,8 +168,8 @@ size_t astar::edge_hash::operator()(const edge& e) const
#endif
}
-path_search_result astar::Dijkstra(world& w, point from_, point to_, object_id own_id, uint32_t max_dist,
- Vector2ub own_size, const pred& p)
+path_search_result astar::Dijkstra(world& w, point from_, point to_,object_id own_id, uint32_t max_dist,
+ Vector2ub own_size, int debug, const pred& p)
{
const auto [from, from_offset] = from_;
const auto [to, to_offset] = to_;
@@ -238,7 +238,11 @@ path_search_result astar::Dijkstra(world& w, point from_, point to_, object_id o
closest_path_len = n_dist;
}
- //Debug{} << "node" << id << "|" << node.coord.to_signed3() << node.offset << "|" << node.dist;
+ if (debug >= 2) [[unlikely]]
+ DBG_nospace << "node"
+ << " px:" << closest << " path:" << closest_path_len
+ << " pos:" << closest_pos.coord.to_signed()
+ << ";" << closest_pos.offset;
const auto bb0 = bbox_from_pos(Vector2(n_coord.local()), n_offset, own_size);
for (auto [vec, len] : directions)
@@ -284,16 +288,21 @@ path_search_result astar::Dijkstra(world& w, point from_, point to_, object_id o
}
}
- //Debug{} << (fresh ? " new" : " old") << new_idx << "|" << node.coord.to_signed3() << node.offset << "|" << node.dist;
+ if (debug >= 3) [[unlikely]]
+ DBG_nospace << (fresh ? "" : " old")
+ << " path:" << closest_path_len
+ << " pos:" << closest_pos.coord.to_signed()
+ << ";" << closest_pos.offset;
add_to_heap(new_idx);
}
}
fm_debug_assert(nodes.size() == indexes.size());
- DBG_nospace << "dijkstra: closest px:" << closest << " path:" << closest_path_len
- << " pos:" << closest_pos.coord.to_signed() << ";" << closest_pos.offset
- << " nodes:" << nodes.size() << " edges:" << edges.size();
+ if (debug)
+ DBG_nospace << "dijkstra: closest px:" << closest << " path:" << closest_path_len
+ << " pos:" << closest_pos.coord.to_signed() << ";" << closest_pos.offset
+ << " nodes:" << nodes.size() << " edges:" << edges.size();
// todo...
return result;
diff --git a/src/path-search.hpp b/src/path-search.hpp
index f705c251..35c00404 100644
--- a/src/path-search.hpp
+++ b/src/path-search.hpp
@@ -91,7 +91,7 @@ struct astar
// todo add simple bresenham short-circuit
path_search_result Dijkstra(world& w, point from, point to,
object_id own_id, uint32_t max_dist, Vector2ub own_size,
- const pred& p = path_search::never_continue());
+ int debug = 0, const pred& p = path_search::never_continue());
static constexpr auto div_factor = path_search::div_factor;
static constexpr auto initial_capacity = TILE_COUNT * 16 * div_factor*div_factor;
diff --git a/test/dijkstra.cpp b/test/dijkstra.cpp
index 7138db85..4163de2b 100644
--- a/test/dijkstra.cpp
+++ b/test/dijkstra.cpp
@@ -38,9 +38,9 @@ void test_app::test_dijkstra()
auto metal2 = tile_image_proto{loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked), 0};
auto& ch = w[chunk_coords_{0,0,0}];
+#if 0
ch[{4, 4}].wall_west() = metal2;
ch[{4, 4}].wall_north() = metal2;
-#if 1
ch[{8, 8}].wall_west() = metal2;
ch[{8, 8}].wall_north() = metal2;
ch[{9, 8}].wall_west() = metal2;