aboutsummaryrefslogtreecommitdiff
path: root/azalea/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-02 03:44:24 -0100
committermat <git@matdoes.dev>2025-06-02 03:44:24 -0100
commit3d121722d7b995de1346f9838df15386aea5acc8 (patch)
treef970e92883a0530fa683a5b5aaf51355deb0158a /azalea/src
parent99659bd9a33fad276c2a5ecfb68f094c4f544d48 (diff)
downloadazalea-drasl-3d121722d7b995de1346f9838df15386aea5acc8.tar.xz
several pathfinder fixes
Diffstat (limited to 'azalea/src')
-rw-r--r--azalea/src/pathfinder/astar.rs23
-rw-r--r--azalea/src/pathfinder/mod.rs21
-rw-r--r--azalea/src/swarm/mod.rs19
3 files changed, 30 insertions, 33 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);
}
}
diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs
index 170effc8..f4fb6f5d 100644
--- a/azalea/src/swarm/mod.rs
+++ b/azalea/src/swarm/mod.rs
@@ -32,7 +32,7 @@ use bevy_app::{App, PluginGroup, PluginGroupBuilder, Plugins, SubApp};
use bevy_ecs::prelude::*;
use futures::future::{BoxFuture, join_all};
use parking_lot::{Mutex, RwLock};
-use tokio::sync::mpsc;
+use tokio::{sync::mpsc, time::sleep};
use tracing::{debug, error, warn};
use crate::{BoxHandleFn, DefaultBotPlugins, HandleFn, JoinOpts, NoState, StartError};
@@ -495,9 +495,7 @@ where
for ((account, bot_join_opts), state) in accounts.iter().zip(states) {
let mut join_opts = default_join_opts.clone();
join_opts.update(bot_join_opts);
- swarm_clone
- .add_and_retry_forever_with_opts(account, state, &join_opts)
- .await;
+ let _ = swarm_clone.add_with_opts(account, state, &join_opts).await;
tokio::time::sleep(join_delay).await;
}
} else {
@@ -507,9 +505,9 @@ where
|((account, bot_join_opts), state)| async {
let mut join_opts = default_join_opts.clone();
join_opts.update(bot_join_opts);
- swarm_borrow
+ let _ = swarm_borrow
.clone()
- .add_and_retry_forever_with_opts(account, state, &join_opts)
+ .add_with_opts(account, state, &join_opts)
.await;
},
))
@@ -830,24 +828,29 @@ impl Swarm {
///
/// This does exponential backoff (though very limited), starting at 5
/// seconds and doubling up to 15 seconds.
+ #[deprecated(note = "azalea has auto-reconnect functionality built-in now, use `add` instead")]
pub async fn add_and_retry_forever<S: Component + Clone>(
&self,
account: &Account,
state: S,
) -> Client {
+ #[allow(deprecated)]
self.add_and_retry_forever_with_opts(account, state, &JoinOpts::default())
.await
}
/// Same as [`Self::add_and_retry_forever`], but allow passing custom join
/// options.
+ #[deprecated(
+ note = "azalea has auto-reconnect functionality built-in now, use `add_with_opts` instead"
+ )]
pub async fn add_and_retry_forever_with_opts<S: Component + Clone>(
&self,
account: &Account,
state: S,
opts: &JoinOpts,
) -> Client {
- let mut disconnects = 0;
+ let mut disconnects: u32 = 0;
loop {
match self.add_with_opts(account, state.clone(), opts).await {
Ok(bot) => return bot,
@@ -870,7 +873,7 @@ impl Swarm {
}
}
- tokio::time::sleep(delay).await;
+ sleep(delay).await;
}
}
}