This commit is contained in:
2026-01-24 18:22:57 +01:00
parent 511816adea
commit 4465a756ef
5 changed files with 88 additions and 68 deletions
+8 -5
View File
@@ -49,7 +49,6 @@ static void astar_bench(benchmark::State& state) {
AStar::AStar<CoordinateType, false> pathFinder;
benchmark::DoNotOptimize(pathFinder);
pathFinder.setWorldSize({mapWidth, mapHeight});
pathFinder.setHeuristic(AStar::Heuristic::euclidean);
pathFinder.setDiagonalMovement(true);
@@ -62,15 +61,12 @@ static void astar_bench(benchmark::State& state) {
blocks[index] = 0;
} else {
blocks[index] = 1;
pathFinder.addObstacle({static_cast<int32_t>(x), static_cast<int32_t>(y)});
}
}
}
blocks[0] = 0;
pathFinder.removeObstacle({0, 0});
blocks[mapWidth * mapHeight - 1] = 0;
pathFinder.removeObstacle({mapWidth - 1, mapHeight - 1});
AStar::Vec2i source(0, 0);
AStar::Vec2i target(mapWidth - 1, mapHeight - 1);
@@ -78,8 +74,15 @@ static void astar_bench(benchmark::State& state) {
std::vector<AStar::Vec2i> path;
benchmark::DoNotOptimize(path);
std::function<bool(AStar::Vec2i)> isWalkable = [&blocks, mapWidth, mapHeight](AStar::Vec2i pos) {
if (pos.x < 0 || pos.x >= mapWidth || pos.y < 0 || pos.y >= mapHeight) {
return false;
}
return blocks[pos.x + pos.y * mapWidth] == 0;
};
for (auto _ : state) {
path = pathFinder.findPath(source, target);
path = pathFinder.findPath(source, target, {mapWidth, mapHeight}, isWalkable);
state.PauseTiming();
if (path.size() == 0) {
state.SkipWithError("No path found");