aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/pathfinder
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-10-02 19:57:13 -0500
committermat <git@matdoes.dev>2023-10-02 19:57:13 -0500
commit985327241d341caf2ce357955cb46657cfa303cb (patch)
tree285f7b4a1d07707c7de1e308b54d9fb2110aaf6a /azalea/src/pathfinder
parent7b10e5cd7e80be85f7b0517f941b175e733d3fc4 (diff)
downloadazalea-drasl-985327241d341caf2ce357955cb46657cfa303cb.tar.xz
yet another W for linear searches
Diffstat (limited to 'azalea/src/pathfinder')
-rw-r--r--azalea/src/pathfinder/mod.rs4
-rw-r--r--azalea/src/pathfinder/moves/mod.rs18
2 files changed, 14 insertions, 8 deletions
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index 831a5524..74b4342f 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -283,7 +283,7 @@ fn path_found_listener(
"Entity tried to pathfind but the entity isn't in a valid world",
);
let world = &world_lock.read().chunks;
- let ctx = PathfinderCtx::new(&world);
+ let ctx = PathfinderCtx::new(world);
let successors_fn: moves::SuccessorsFn = event.successors_fn;
let successors = |pos: BlockPos| successors_fn(&ctx, pos);
@@ -446,7 +446,7 @@ fn tick_execute_path(
{
// obstruction check (the path we're executing isn't possible anymore)
let world = &world_lock.read().chunks;
- let ctx = PathfinderCtx::new(&world);
+ let ctx = PathfinderCtx::new(world);
let successors = |pos: BlockPos| successors_fn(&ctx, pos);
if let Some(last_reached_node) = pathfinder.last_reached_node {
diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs
index 9eb6462b..907db4fc 100644
--- a/azalea/src/pathfinder/moves/mod.rs
+++ b/azalea/src/pathfinder/moves/mod.rs
@@ -9,10 +9,9 @@ use super::astar;
use azalea_block::BlockState;
use azalea_client::{StartSprintEvent, StartWalkEvent};
use azalea_core::position::{BlockPos, ChunkBlockPos, ChunkPos, Vec3};
-use azalea_physics::collision::{self, BlockWithShape};
+use azalea_physics::collision::BlockWithShape;
use azalea_world::ChunkStorage;
use bevy_ecs::{entity::Entity, event::EventWriter};
-use nohash_hasher::IntMap;
type Edge = astar::Edge<BlockPos, MoveData>;
@@ -36,7 +35,7 @@ impl Debug for MoveData {
pub struct PathfinderCtx<'a> {
world: &'a ChunkStorage,
- cached_chunks: RefCell<IntMap<ChunkPos, Vec<azalea_world::Section>>>,
+ cached_chunks: RefCell<Vec<(ChunkPos, Vec<azalea_world::Section>)>>,
}
impl<'a> PathfinderCtx<'a> {
@@ -51,7 +50,13 @@ impl<'a> PathfinderCtx<'a> {
let chunk_pos = ChunkPos::from(pos);
let mut cached_chunks = self.cached_chunks.borrow_mut();
- if let Some(sections) = cached_chunks.get(&chunk_pos) {
+ if let Some(sections) = cached_chunks.iter().find_map(|(pos, sections)| {
+ if *pos == chunk_pos {
+ Some(sections)
+ } else {
+ None
+ }
+ }) {
return azalea_world::chunk_storage::get_block_state_from_sections(
sections,
&ChunkBlockPos::from(pos),
@@ -62,11 +67,12 @@ impl<'a> PathfinderCtx<'a> {
let chunk = self.world.get(&chunk_pos)?;
let chunk = chunk.read();
- cached_chunks.insert(chunk_pos, chunk.sections.clone());
+ cached_chunks.push((chunk_pos, chunk.sections.clone()));
+ let chunk_block_pos = ChunkBlockPos::from(pos);
azalea_world::chunk_storage::get_block_state_from_sections(
&chunk.sections,
- &ChunkBlockPos::from(pos),
+ &chunk_block_pos,
self.world.min_y,
)
}