diff options
| author | mat <git@matdoes.dev> | 2023-10-04 19:49:30 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-10-04 19:49:30 -0500 |
| commit | c2fb99159556e1d55552aac0a782dbc69be338f3 (patch) | |
| tree | 946aa44d8637335c05d3312eddfe6874b6c29f27 /azalea/src/pathfinder/moves/basic.rs | |
| parent | a060ffff93f84df2c419c6180d4ee916ace36ad9 (diff) | |
| download | azalea-drasl-c2fb99159556e1d55552aac0a782dbc69be338f3.tar.xz | |
BLAZINGLY FAST 🚀🚀🚀 pathfinding
Diffstat (limited to 'azalea/src/pathfinder/moves/basic.rs')
| -rw-r--r-- | azalea/src/pathfinder/moves/basic.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs index dfb90bd0..013b3c19 100644 --- a/azalea/src/pathfinder/moves/basic.rs +++ b/azalea/src/pathfinder/moves/basic.rs @@ -14,7 +14,7 @@ use crate::{ use super::{default_is_reached, Edge, ExecuteCtx, IsReachedCtx, MoveData, PathfinderCtx}; pub fn basic_move(ctx: &PathfinderCtx, node: BlockPos) -> Vec<Edge> { - let mut edges = Vec::new(); + let mut edges = Vec::with_capacity(8); edges.extend(forward_move(ctx, node)); edges.extend(ascend_move(ctx, node)); edges.extend(descend_move(ctx, node)); @@ -27,7 +27,7 @@ fn forward_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec<Edge> { for dir in CardinalDirection::iter() { let offset = BlockPos::new(dir.x(), 0, dir.z()); - if !ctx.is_standable(&(pos + offset)) { + if !ctx.is_standable(pos + offset) { continue; } @@ -73,10 +73,10 @@ fn ascend_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec<Edge> { for dir in CardinalDirection::iter() { let offset = BlockPos::new(dir.x(), 1, dir.z()); - if !ctx.is_block_passable(&pos.up(2)) { + if !ctx.is_block_passable(pos.up(2)) { continue; } - if !ctx.is_standable(&(pos + offset)) { + if !ctx.is_standable(pos + offset) { continue; } @@ -157,18 +157,18 @@ fn descend_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec<Edge> { for dir in CardinalDirection::iter() { let dir_delta = BlockPos::new(dir.x(), 0, dir.z()); let new_horizontal_position = pos + dir_delta; - let fall_distance = ctx.fall_distance(&new_horizontal_position); + let fall_distance = ctx.fall_distance(new_horizontal_position); if fall_distance == 0 || fall_distance > 3 { continue; } let new_position = new_horizontal_position.down(fall_distance as i32); // check whether 3 blocks vertically forward are passable - if !ctx.is_passable(&new_horizontal_position) { + if !ctx.is_passable(new_horizontal_position) { continue; } // check whether we can stand on the target position - if !ctx.is_standable(&new_position) { + if !ctx.is_standable(new_position) { continue; } @@ -266,8 +266,8 @@ fn diagonal_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec<Edge> { let right = dir.right(); let offset = BlockPos::new(dir.x() + right.x(), 0, dir.z() + right.z()); - if !ctx.is_passable(&BlockPos::new(pos.x + dir.x(), pos.y, pos.z + dir.z())) - && !ctx.is_passable(&BlockPos::new( + if !ctx.is_passable(BlockPos::new(pos.x + dir.x(), pos.y, pos.z + dir.z())) + && !ctx.is_passable(BlockPos::new( pos.x + dir.right().x(), pos.y, pos.z + dir.right().z(), @@ -275,7 +275,7 @@ fn diagonal_move(ctx: &PathfinderCtx, pos: BlockPos) -> Vec<Edge> { { continue; } - if !ctx.is_standable(&(pos + offset)) { + if !ctx.is_standable(pos + offset) { continue; } // +0.001 so it doesn't unnecessarily go diagonal sometimes |
