From 9379c7be03fed4cd08d57c6de0ea6cbeea3ac717 Mon Sep 17 00:00:00 2001 From: popertots Date: Wed, 18 Mar 2026 17:00:29 +0000 Subject: [PATCH] fix: add benchmark recording to calculate_provisional_path Provisional paths were not being recorded to benchmark stats, causing total_paths=0 while failed_paths accumulated. Now records: - path_calc_times_us (timing) - path_lengths (path length) - nodes_expanded (A* nodes visited) - failed_paths (when start/goal not standable) --- pathfinding_benchmark_current.csv | 2 +- src/entities/shared_systems/pathfinding.rs | 43 +++++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/pathfinding_benchmark_current.csv b/pathfinding_benchmark_current.csv index b4366c7..fe6f29b 100644 --- a/pathfinding_benchmark_current.csv +++ b/pathfinding_benchmark_current.csv @@ -1,4 +1,4 @@ sample,path_duration_us,path_length,nodes_expanded,success # Summary # total_paths,0 -# failed_paths,0 +# failed_paths,1906 diff --git a/src/entities/shared_systems/pathfinding.rs b/src/entities/shared_systems/pathfinding.rs index a8a47ab..b657751 100644 --- a/src/entities/shared_systems/pathfinding.rs +++ b/src/entities/shared_systems/pathfinding.rs @@ -579,13 +579,24 @@ pub fn calculate_provisional_path( goal: IVec3, node_limit: usize, ) -> Vec { + let timer = Instant::now(); + if !is_standable_tile(tilemap, start) { + LOCAL_FAILED_PATHS.with(|f| { + *f.borrow_mut() += 1; + }); + return Vec::new(); + } + if !is_standable_tile(tilemap, goal) { + LOCAL_FAILED_PATHS.with(|f| { + *f.borrow_mut() += 1; + }); return Vec::new(); } let estimated_tiles = octile_distance_3d(start, goal) / ITILE_SIZE; - SCRATCHPAD.with(|s| { + let result = SCRATCHPAD.with(|s| { let mut scratch = s.borrow_mut(); let capacity = ((estimated_tiles as usize).max(64)).min(4096); scratch.clear_and_reserve(capacity); @@ -613,11 +624,17 @@ pub fn calculate_provisional_path( } if current == goal { - return reconstruct_path(&scratch.came_from, current); + return ( + reconstruct_path(&scratch.came_from, current), + nodes_expanded, + ); } if nodes_expanded >= node_limit { - return reconstruct_path(&scratch.came_from, best_node); + return ( + reconstruct_path(&scratch.came_from, best_node), + nodes_expanded, + ); } scratch.closed_set.insert(current); @@ -651,8 +668,24 @@ pub fn calculate_provisional_path( } } - reconstruct_path(&scratch.came_from, best_node) - }) + ( + reconstruct_path(&scratch.came_from, best_node), + nodes_expanded, + ) + }); + + let elapsed = timer.elapsed().as_micros(); + LOCAL_PATH_TIMES.with(|t| { + t.borrow_mut().push(elapsed); + }); + LOCAL_PATH_LENGTHS.with(|l| { + l.borrow_mut().push(result.0.len()); + }); + LOCAL_NODES_EXPANDED.with(|n| { + n.borrow_mut().push(result.1); + }); + + result.0 } pub fn bench_report_system(