mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
bump minimum rust version and improve pathfinder docs
This commit is contained in:
parent
ebaf5128fb
commit
615d8f9d2a
7 changed files with 46 additions and 28 deletions
|
@ -8,7 +8,7 @@ pub struct RgbColor {
|
|||
impl RgbColor {
|
||||
pub fn new(r: u8, g: u8, b: u8) -> Self {
|
||||
Self {
|
||||
value: (r as u32) << 16 | (g as u32) << 8 | b as u32,
|
||||
value: ((r as u32) << 16) | ((g as u32) << 8) | (b as u32),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ pub struct ArgbColor {
|
|||
impl ArgbColor {
|
||||
pub fn new(a: u8, r: u8, g: u8, b: u8) -> Self {
|
||||
Self {
|
||||
value: (a as u32) << 24 | (r as u32) << 16 | (g as u32) << 8 | b as u32,
|
||||
value: ((a as u32) << 24) | ((r as u32) << 16) | ((g as u32) << 8) | b as u32,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ impl AzaleaRead for BlockStateWithPosition {
|
|||
let state = BlockState::try_from(state)
|
||||
.map_err(|_| BufReadError::UnexpectedEnumVariant { id: state as i32 })?;
|
||||
let pos = ChunkSectionBlockPos {
|
||||
x: (position_part >> 8 & 15) as u8,
|
||||
x: ((position_part >> 8) & 15) as u8,
|
||||
y: (position_part & 15) as u8,
|
||||
z: (position_part >> 4 & 15) as u8,
|
||||
z: ((position_part >> 4) & 15) as u8,
|
||||
};
|
||||
Ok(BlockStateWithPosition { pos, state })
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ impl AzaleaRead for BlockStateWithPosition {
|
|||
|
||||
impl AzaleaWrite for BlockStateWithPosition {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
let data = (self.state.id as u64) << 12
|
||||
| (u64::from(self.pos.x) << 8 | u64::from(self.pos.z) << 4 | u64::from(self.pos.y));
|
||||
let data = ((self.state.id as u64) << 12)
|
||||
| ((u64::from(self.pos.x) << 8) | (u64::from(self.pos.z) << 4) | u64::from(self.pos.y));
|
||||
u64::azalea_write_var(&data, buf)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ impl BitStorage {
|
|||
let cell_index = self.cell_index(index as u64);
|
||||
let cell = &self.data[cell_index];
|
||||
let bit_index = (index - cell_index * self.values_per_long) * self.bits;
|
||||
cell >> bit_index & self.mask
|
||||
(cell >> bit_index) & self.mask
|
||||
}
|
||||
|
||||
pub fn get_and_set(&mut self, index: usize, value: u64) -> u64 {
|
||||
|
@ -190,8 +190,8 @@ impl BitStorage {
|
|||
let cell_index = self.cell_index(index as u64);
|
||||
let cell = &mut self.data[cell_index];
|
||||
let bit_index = (index - cell_index * self.values_per_long) * self.bits;
|
||||
let old_value = *cell >> (bit_index as u64) & self.mask;
|
||||
*cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
|
||||
let old_value = (*cell >> (bit_index as u64)) & self.mask;
|
||||
*cell = (*cell & !(self.mask << bit_index)) | ((value & self.mask) << bit_index);
|
||||
old_value
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ impl BitStorage {
|
|||
let cell_index = self.cell_index(index as u64);
|
||||
let cell = &mut self.data[cell_index];
|
||||
let bit_index = (index - cell_index * self.values_per_long) * self.bits;
|
||||
*cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
|
||||
*cell = (*cell & !(self.mask << bit_index)) | ((value & self.mask) << bit_index);
|
||||
}
|
||||
|
||||
/// The number of entries.
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
//! only have this on if the bot has operator permissions, otherwise it'll
|
||||
//! just spam the server console unnecessarily.
|
||||
|
||||
#![feature(async_closure)]
|
||||
#![feature(trivial_bounds)]
|
||||
|
||||
mod commands;
|
||||
|
@ -53,9 +52,9 @@ async fn main() {
|
|||
|
||||
for username_or_email in &args.accounts {
|
||||
let account = if username_or_email.contains('@') {
|
||||
Account::microsoft(&username_or_email).await.unwrap()
|
||||
Account::microsoft(username_or_email).await.unwrap()
|
||||
} else {
|
||||
Account::offline(&username_or_email)
|
||||
Account::offline(username_or_email)
|
||||
};
|
||||
|
||||
let mut commands = CommandDispatcher::new();
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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) };
|
||||
|
|
Loading…
Add table
Reference in a new issue