diff options
| author | mat <git@matdoes.dev> | 2025-06-02 03:44:24 -0100 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-06-02 03:44:24 -0100 |
| commit | 3d121722d7b995de1346f9838df15386aea5acc8 (patch) | |
| tree | f970e92883a0530fa683a5b5aaf51355deb0158a /azalea/src/pathfinder | |
| parent | 99659bd9a33fad276c2a5ecfb68f094c4f544d48 (diff) | |
| download | azalea-drasl-3d121722d7b995de1346f9838df15386aea5acc8.tar.xz | |
several pathfinder fixes
Diffstat (limited to 'azalea/src/pathfinder')
| -rw-r--r-- | azalea/src/pathfinder/astar.rs | 23 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 21 |
2 files changed, 19 insertions, 25 deletions
diff --git a/azalea/src/pathfinder/astar.rs b/azalea/src/pathfinder/astar.rs index 9ae7ae20..8d23ed2e 100644 --- a/azalea/src/pathfinder/astar.rs +++ b/azalea/src/pathfinder/astar.rs @@ -285,26 +285,11 @@ pub struct WeightedNode { impl Ord for WeightedNode { #[inline] fn cmp(&self, other: &Self) -> cmp::Ordering { - // we compare bits instead of floats because it's faster. this is the same as - // f32::total_cmp as long as the numbers aren't negative - - debug_assert!(self.f_score >= 0.0); - debug_assert!(other.f_score >= 0.0); - debug_assert!(self.g_score >= 0.0); - debug_assert!(other.g_score >= 0.0); - - let self_f_score = self.f_score.to_bits() as i32; - let other_f_score = other.f_score.to_bits() as i32; - - if self_f_score == other_f_score { - let self_g_score = self.g_score.to_bits() as i32; - let other_g_score = other.g_score.to_bits() as i32; - - return self_g_score.cmp(&other_g_score); - } - // intentionally inverted to make the BinaryHeap a min-heap - other_f_score.cmp(&self_f_score) + match other.f_score.total_cmp(&self.f_score) { + cmp::Ordering::Equal => self.g_score.total_cmp(&other.g_score), + s => s, + } } } impl Eq for WeightedNode {} diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index dca0cc99..94d5bc69 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -861,9 +861,10 @@ pub fn check_for_path_obstruction( drop(custom_state_ref); warn!( - "path obstructed at index {obstructed_index} (starting at {:?}, path: {:?})", - executing_path.last_reached_node, executing_path.path + "path obstructed at index {obstructed_index} (starting at {:?})", + executing_path.last_reached_node, ); + debug!("obstructed path: {:?}", executing_path.path); // if it's near the end, don't bother recalculating a patch, just truncate and // mark it as partial if obstructed_index + 5 > executing_path.path.len() { @@ -1223,11 +1224,19 @@ where } } - if let Some(found_edge) = found_edge - && found_edge.cost <= edge.cost + current_position = movement_target; + // if found_edge is None or the cost increased, then return the index + if found_edge + .map(|found_edge| found_edge.cost > edge.cost) + .unwrap_or(true) { - current_position = found_edge.movement.target; - } else { + // if the node that we're currently executing was obstructed then it's often too + // late to change the path, so it's usually better to just ignore this case :/ + if i == 0 { + warn!("path obstructed at index 0, ignoring"); + continue; + } + return Some(i); } } |
