Skip to content

Commit 615d8f9

Browse files
committed
bump minimum rust version and improve pathfinder docs
1 parent ebaf512 commit 615d8f9

File tree

7 files changed

+46
-28
lines changed

7 files changed

+46
-28
lines changed

azalea-core/src/color.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct RgbColor {
88
impl RgbColor {
99
pub fn new(r: u8, g: u8, b: u8) -> Self {
1010
Self {
11-
value: (r as u32) << 16 | (g as u32) << 8 | b as u32,
11+
value: ((r as u32) << 16) | ((g as u32) << 8) | (b as u32),
1212
}
1313
}
1414

@@ -33,7 +33,7 @@ pub struct ArgbColor {
3333
impl ArgbColor {
3434
pub fn new(a: u8, r: u8, g: u8, b: u8) -> Self {
3535
Self {
36-
value: (a as u32) << 24 | (r as u32) << 16 | (g as u32) << 8 | b as u32,
36+
value: ((a as u32) << 24) | ((r as u32) << 16) | ((g as u32) << 8) | b as u32,
3737
}
3838
}
3939

azalea-protocol/src/packets/game/c_section_blocks_update.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ impl AzaleaRead for BlockStateWithPosition {
2525
let state = BlockState::try_from(state)
2626
.map_err(|_| BufReadError::UnexpectedEnumVariant { id: state as i32 })?;
2727
let pos = ChunkSectionBlockPos {
28-
x: (position_part >> 8 & 15) as u8,
28+
x: ((position_part >> 8) & 15) as u8,
2929
y: (position_part & 15) as u8,
30-
z: (position_part >> 4 & 15) as u8,
30+
z: ((position_part >> 4) & 15) as u8,
3131
};
3232
Ok(BlockStateWithPosition { pos, state })
3333
}
3434
}
3535

3636
impl AzaleaWrite for BlockStateWithPosition {
3737
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
38-
let data = (self.state.id as u64) << 12
39-
| (u64::from(self.pos.x) << 8 | u64::from(self.pos.z) << 4 | u64::from(self.pos.y));
38+
let data = ((self.state.id as u64) << 12)
39+
| ((u64::from(self.pos.x) << 8) | (u64::from(self.pos.z) << 4) | u64::from(self.pos.y));
4040
u64::azalea_write_var(&data, buf)?;
4141
Ok(())
4242
}

azalea-world/src/bit_storage.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl BitStorage {
176176
let cell_index = self.cell_index(index as u64);
177177
let cell = &self.data[cell_index];
178178
let bit_index = (index - cell_index * self.values_per_long) * self.bits;
179-
cell >> bit_index & self.mask
179+
(cell >> bit_index) & self.mask
180180
}
181181

182182
pub fn get_and_set(&mut self, index: usize, value: u64) -> u64 {
@@ -190,8 +190,8 @@ impl BitStorage {
190190
let cell_index = self.cell_index(index as u64);
191191
let cell = &mut self.data[cell_index];
192192
let bit_index = (index - cell_index * self.values_per_long) * self.bits;
193-
let old_value = *cell >> (bit_index as u64) & self.mask;
194-
*cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
193+
let old_value = (*cell >> (bit_index as u64)) & self.mask;
194+
*cell = (*cell & !(self.mask << bit_index)) | ((value & self.mask) << bit_index);
195195
old_value
196196
}
197197

@@ -206,7 +206,7 @@ impl BitStorage {
206206
let cell_index = self.cell_index(index as u64);
207207
let cell = &mut self.data[cell_index];
208208
let bit_index = (index - cell_index * self.values_per_long) * self.bits;
209-
*cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index;
209+
*cell = (*cell & !(self.mask << bit_index)) | ((value & self.mask) << bit_index);
210210
}
211211

212212
/// The number of entries.

azalea/examples/testbot/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
//! only have this on if the bot has operator permissions, otherwise it'll
2121
//! just spam the server console unnecessarily.
2222
23-
#![feature(async_closure)]
2423
#![feature(trivial_bounds)]
2524

2625
mod commands;
@@ -53,9 +52,9 @@ async fn main() {
5352

5453
for username_or_email in &args.accounts {
5554
let account = if username_or_email.contains('@') {
56-
Account::microsoft(&username_or_email).await.unwrap()
55+
Account::microsoft(username_or_email).await.unwrap()
5756
} else {
58-
Account::offline(&username_or_email)
57+
Account::offline(username_or_email)
5958
};
6059

6160
let mut commands = CommandDispatcher::new();

azalea/src/pathfinder/astar.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,6 @@ const COEFFICIENTS: [f32; 7] = [1.5, 2., 2.5, 3., 4., 5., 10.];
2525

2626
const MIN_IMPROVEMENT: f32 = 0.01;
2727

28-
#[derive(Debug, Clone, Copy, PartialEq)]
29-
pub enum PathfinderTimeout {
30-
/// Time out after a certain duration has passed. This is a good default so
31-
/// you don't waste too much time calculating a path if you're on a slow
32-
/// computer.
33-
Time(Duration),
34-
/// Time out after this many nodes have been considered.
35-
///
36-
/// This is useful as an alternative to a time limit if you're doing
37-
/// something like running tests where you want consistent results.
38-
Nodes(usize),
39-
}
40-
4128
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
4229

4330
// Sources:
@@ -300,3 +287,21 @@ impl PartialOrd for WeightedNode {
300287
Some(self.cmp(other))
301288
}
302289
}
290+
291+
#[derive(Debug, Clone, Copy, PartialEq)]
292+
pub enum PathfinderTimeout {
293+
/// Time out after a certain duration has passed. This is a good default so
294+
/// you don't waste too much time calculating a path if you're on a slow
295+
/// computer.
296+
Time(Duration),
297+
/// Time out after this many nodes have been considered.
298+
///
299+
/// This is useful as an alternative to a time limit if you're doing
300+
/// something like running tests where you want consistent results.
301+
Nodes(usize),
302+
}
303+
impl Default for PathfinderTimeout {
304+
fn default() -> Self {
305+
Self::Time(Duration::from_secs(1))
306+
}
307+
}

azalea/src/pathfinder/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,21 @@ pub struct GotoEvent {
142142
/// Whether the bot is allowed to break blocks while pathfinding.
143143
pub allow_mining: bool,
144144

145+
/// The minimum amount of time that should pass before the A* pathfinder
146+
/// function can return a timeout. It may take up to [`Self::max_timeout`]
147+
/// if it can't immediately find a usable path.
148+
///
149+
/// A good default value for this is
150+
/// `PathfinderTimeout::Time(Duration::from_secs(1))`.
151+
///
145152
/// Also see [`PathfinderTimeout::Nodes`]
146153
pub min_timeout: PathfinderTimeout,
154+
/// The absolute maximum amount of time that the pathfinder function can
155+
/// take to find a path. If it takes this long, it means no usable path was
156+
/// found (so it might be impossible).
157+
///
158+
/// A good default value for this is
159+
/// `PathfinderTimeout::Time(Duration::from_secs(5))`.
147160
pub max_timeout: PathfinderTimeout,
148161
}
149162
#[derive(Event, Clone, Debug)]

azalea/src/pathfinder/world.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,9 @@ impl CachedWorld {
262262
let cached_mining_costs = unsafe { &mut *self.cached_mining_costs.get() };
263263
// 20 bits total:
264264
// 8 bits for x, 4 bits for y, 8 bits for z
265-
let hash_index =
266-
(pos.x as usize & 0xff) << 12 | (pos.y as usize & 0xf) << 8 | (pos.z as usize & 0xff);
265+
let hash_index = ((pos.x as usize & 0xff) << 12)
266+
| ((pos.y as usize & 0xf) << 8)
267+
| (pos.z as usize & 0xff);
267268
debug_assert!(hash_index < 1048576);
268269
let &(cached_pos, potential_cost) =
269270
unsafe { cached_mining_costs.get_unchecked(hash_index) };

0 commit comments

Comments
 (0)