diff options
| author | mat <git@matdoes.dev> | 2024-12-28 02:10:05 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2024-12-28 02:10:05 +0000 |
| commit | 615d8f9d2ac56b3244d328587243301da253eafd (patch) | |
| tree | 3cf08428ddeb29bcb58dbce04fee7bbbe4d2814d /azalea/src | |
| parent | ebaf5128fbc87970b2ba1f6157e5da035ae379c8 (diff) | |
| download | azalea-drasl-615d8f9d2ac56b3244d328587243301da253eafd.tar.xz | |
bump minimum rust version and improve pathfinder docs
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/pathfinder/astar.rs | 31 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 13 | ||||
| -rw-r--r-- | azalea/src/pathfinder/world.rs | 5 |
3 files changed, 34 insertions, 15 deletions
diff --git a/azalea/src/pathfinder/astar.rs b/azalea/src/pathfinder/astar.rs index c36ea790..dbdc9836 100644 --- a/azalea/src/pathfinder/astar.rs +++ b/azalea/src/pathfinder/astar.rs @@ -25,19 +25,6 @@ const COEFFICIENTS: [f32; 7] = [1.5, 2., 2.5, 3., 4., 5., 10.]; const MIN_IMPROVEMENT: f32 = 0.01; -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum PathfinderTimeout { - /// Time out after a certain duration has passed. This is a good default so - /// you don't waste too much time calculating a path if you're on a slow - /// computer. - Time(Duration), - /// Time out after this many nodes have been considered. - /// - /// This is useful as an alternative to a time limit if you're doing - /// something like running tests where you want consistent results. - Nodes(usize), -} - type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>; // Sources: @@ -300,3 +287,21 @@ impl PartialOrd for WeightedNode { Some(self.cmp(other)) } } + +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum PathfinderTimeout { + /// Time out after a certain duration has passed. This is a good default so + /// you don't waste too much time calculating a path if you're on a slow + /// computer. + Time(Duration), + /// Time out after this many nodes have been considered. + /// + /// This is useful as an alternative to a time limit if you're doing + /// something like running tests where you want consistent results. + Nodes(usize), +} +impl Default for PathfinderTimeout { + fn default() -> Self { + Self::Time(Duration::from_secs(1)) + } +} diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 95982215..0c926d03 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -142,8 +142,21 @@ pub struct GotoEvent { /// Whether the bot is allowed to break blocks while pathfinding. pub allow_mining: bool, + /// The minimum amount of time that should pass before the A* pathfinder + /// function can return a timeout. It may take up to [`Self::max_timeout`] + /// if it can't immediately find a usable path. + /// + /// A good default value for this is + /// `PathfinderTimeout::Time(Duration::from_secs(1))`. + /// /// Also see [`PathfinderTimeout::Nodes`] pub min_timeout: PathfinderTimeout, + /// The absolute maximum amount of time that the pathfinder function can + /// take to find a path. If it takes this long, it means no usable path was + /// found (so it might be impossible). + /// + /// A good default value for this is + /// `PathfinderTimeout::Time(Duration::from_secs(5))`. pub max_timeout: PathfinderTimeout, } #[derive(Event, Clone, Debug)] diff --git a/azalea/src/pathfinder/world.rs b/azalea/src/pathfinder/world.rs index f518523f..c50791b8 100644 --- a/azalea/src/pathfinder/world.rs +++ b/azalea/src/pathfinder/world.rs @@ -262,8 +262,9 @@ impl CachedWorld { let cached_mining_costs = unsafe { &mut *self.cached_mining_costs.get() }; // 20 bits total: // 8 bits for x, 4 bits for y, 8 bits for z - let hash_index = - (pos.x as usize & 0xff) << 12 | (pos.y as usize & 0xf) << 8 | (pos.z as usize & 0xff); + let hash_index = ((pos.x as usize & 0xff) << 12) + | ((pos.y as usize & 0xf) << 8) + | (pos.z as usize & 0xff); debug_assert!(hash_index < 1048576); let &(cached_pos, potential_cost) = unsafe { cached_mining_costs.get_unchecked(hash_index) }; |
