From c2fb99159556e1d55552aac0a782dbc69be338f3 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 4 Oct 2023 19:49:30 -0500 Subject: BLAZINGLY FAST 🚀🚀🚀 pathfinding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- azalea/src/pathfinder/moves/basic.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'azalea/src/pathfinder/moves/basic.rs') 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 { - 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 { 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 { 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 { 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 { 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 { { continue; } - if !ctx.is_standable(&(pos + offset)) { + if !ctx.is_standable(pos + offset) { continue; } // +0.001 so it doesn't unnecessarily go diagonal sometimes -- cgit v1.2.3