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)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
sample,path_duration_us,path_length,nodes_expanded,success
|
||||
# Summary
|
||||
# total_paths,0
|
||||
# failed_paths,0
|
||||
# failed_paths,1906
|
||||
|
||||
|
@@ -579,13 +579,24 @@ pub fn calculate_provisional_path(
|
||||
goal: IVec3,
|
||||
node_limit: usize,
|
||||
) -> Vec<Vec3> {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user