mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
Add more derives to the pathfinder goals for flexibility (#183)
This commit is contained in:
parent
0902edb244
commit
3cf17cb896
3 changed files with 28 additions and 20 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -222,6 +222,7 @@ dependencies = [
|
||||||
"priority-queue",
|
"priority-queue",
|
||||||
"rand",
|
"rand",
|
||||||
"rustc-hash 2.0.0",
|
"rustc-hash 2.0.0",
|
||||||
|
"serde",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
|
@ -8,51 +8,53 @@ version = "0.10.3+mc1.21.1"
|
||||||
|
|
||||||
[package.metadata.release]
|
[package.metadata.release]
|
||||||
pre-release-replacements = [
|
pre-release-replacements = [
|
||||||
{ file = "README.md", search = "`azalea = \"[a-z0-9\\.-]+\"`", replace = "`azalea = \"{{version}}\"`" },
|
{ file = "README.md", search = "`azalea = \"[a-z0-9\\.-]+\"`", replace = "`azalea = \"{{version}}\"`" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "^1.0.86"
|
anyhow = "^1.0.86"
|
||||||
async-trait = "0.1.80"
|
async-trait = "0.1.80"
|
||||||
|
azalea-auth = { version = "0.10.0", path = "../azalea-auth" }
|
||||||
azalea-block = { version = "0.10.0", path = "../azalea-block" }
|
azalea-block = { version = "0.10.0", path = "../azalea-block" }
|
||||||
|
azalea-brigadier = { version = "0.10.0", path = "../azalea-brigadier" }
|
||||||
|
azalea-buf = { version = "0.10.0", path = "../azalea-buf" }
|
||||||
azalea-chat = { version = "0.10.0", path = "../azalea-chat" }
|
azalea-chat = { version = "0.10.0", path = "../azalea-chat" }
|
||||||
azalea-client = { version = "0.10.0", path = "../azalea-client", default-features = false }
|
azalea-client = { version = "0.10.0", path = "../azalea-client", default-features = false }
|
||||||
azalea-core = { version = "0.10.0", path = "../azalea-core" }
|
azalea-core = { version = "0.10.0", path = "../azalea-core" }
|
||||||
|
azalea-entity = { version = "0.10.0", path = "../azalea-entity" }
|
||||||
|
azalea-inventory = { version = "0.10.0", path = "../azalea-inventory" }
|
||||||
azalea-physics = { version = "0.10.0", path = "../azalea-physics" }
|
azalea-physics = { version = "0.10.0", path = "../azalea-physics" }
|
||||||
azalea-protocol = { version = "0.10.0", path = "../azalea-protocol" }
|
azalea-protocol = { version = "0.10.0", path = "../azalea-protocol" }
|
||||||
azalea-registry = { version = "0.10.0", path = "../azalea-registry" }
|
azalea-registry = { version = "0.10.0", path = "../azalea-registry" }
|
||||||
azalea-world = { version = "0.10.0", path = "../azalea-world" }
|
azalea-world = { version = "0.10.0", path = "../azalea-world" }
|
||||||
azalea-auth = { version = "0.10.0", path = "../azalea-auth" }
|
|
||||||
azalea-brigadier = { version = "0.10.0", path = "../azalea-brigadier" }
|
|
||||||
azalea-buf = { version = "0.10.0", path = "../azalea-buf" }
|
|
||||||
bevy_app = "0.13.0"
|
bevy_app = "0.13.0"
|
||||||
bevy_ecs = "0.13.0"
|
bevy_ecs = "0.13.0"
|
||||||
|
bevy_log = "0.13.0"
|
||||||
bevy_tasks = { version = "0.13.0", features = ["multi-threaded"] }
|
bevy_tasks = { version = "0.13.0", features = ["multi-threaded"] }
|
||||||
|
bevy_time = "0.13.0"
|
||||||
derive_more = { version = "0.99.18", features = ["deref", "deref_mut"] }
|
derive_more = { version = "0.99.18", features = ["deref", "deref_mut"] }
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
futures-lite = "2.3.0"
|
futures-lite = "2.3.0"
|
||||||
tracing = "0.1.40"
|
|
||||||
nohash-hasher = "0.2.0"
|
nohash-hasher = "0.2.0"
|
||||||
num-traits = "0.2.19"
|
num-traits = "0.2.19"
|
||||||
parking_lot = { version = "^0.12.3", features = ["deadlock_detection"] }
|
parking_lot = { version = "^0.12.3", features = ["deadlock_detection"] }
|
||||||
priority-queue = "2.0.3"
|
priority-queue = "2.0.3"
|
||||||
|
rustc-hash = "2.0.0"
|
||||||
|
serde = { version = "1", optional = true }
|
||||||
thiserror = "^1.0.61"
|
thiserror = "^1.0.61"
|
||||||
tokio = "^1.38.0"
|
tokio = "^1.38.0"
|
||||||
|
tracing = "0.1.40"
|
||||||
uuid = "1.9.1"
|
uuid = "1.9.1"
|
||||||
bevy_log = "0.13.0"
|
|
||||||
bevy_time = "0.13.0"
|
|
||||||
rustc-hash = "2.0.0"
|
|
||||||
azalea-inventory = { version = "0.10.0", path = "../azalea-inventory" }
|
|
||||||
azalea-entity = { version = "0.10.0", path = "../azalea-entity" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.5.1"
|
criterion = "0.5.1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["log"]
|
default = ["log", "serde"]
|
||||||
# enables bevy_log::LogPlugin by default
|
# enables bevy_log::LogPlugin by default
|
||||||
log = ["azalea-client/log"]
|
log = ["azalea-client/log"]
|
||||||
|
serde = ["dep:serde"]
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "pathfinder"
|
name = "pathfinder"
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
//! The goals that a pathfinder can try to reach.
|
//! The goals that a pathfinder can try to reach.
|
||||||
|
|
||||||
use std::f32::consts::SQRT_2;
|
|
||||||
|
|
||||||
use azalea_core::position::{BlockPos, Vec3};
|
use azalea_core::position::{BlockPos, Vec3};
|
||||||
use azalea_world::ChunkStorage;
|
use azalea_world::ChunkStorage;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::f32::consts::SQRT_2;
|
||||||
|
|
||||||
use super::costs::{COST_HEURISTIC, FALL_N_BLOCKS_COST, JUMP_ONE_BLOCK_COST};
|
use super::costs::{COST_HEURISTIC, FALL_N_BLOCKS_COST, JUMP_ONE_BLOCK_COST};
|
||||||
|
|
||||||
|
@ -15,7 +16,8 @@ pub trait Goal {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Move to the given block position.
|
/// Move to the given block position.
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
pub struct BlockPosGoal(pub BlockPos);
|
pub struct BlockPosGoal(pub BlockPos);
|
||||||
impl Goal for BlockPosGoal {
|
impl Goal for BlockPosGoal {
|
||||||
fn heuristic(&self, n: BlockPos) -> f32 {
|
fn heuristic(&self, n: BlockPos) -> f32 {
|
||||||
|
@ -48,8 +50,9 @@ fn xz_heuristic(dx: f32, dz: f32) -> f32 {
|
||||||
(diagonal * SQRT_2 + straight) * COST_HEURISTIC
|
(diagonal * SQRT_2 + straight) * COST_HEURISTIC
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Move to the given block position, ignoring the y axis.
|
/// Move to the given block position, ignoring the y-axis.
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
pub struct XZGoal {
|
pub struct XZGoal {
|
||||||
pub x: i32,
|
pub x: i32,
|
||||||
pub z: i32,
|
pub z: i32,
|
||||||
|
@ -74,7 +77,8 @@ fn y_heuristic(dy: f32) -> f32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Move to the given y coordinate.
|
/// Move to the given y coordinate.
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
pub struct YGoal {
|
pub struct YGoal {
|
||||||
pub y: i32,
|
pub y: i32,
|
||||||
}
|
}
|
||||||
|
@ -89,7 +93,8 @@ impl Goal for YGoal {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get within the given radius of the given position.
|
/// Get within the given radius of the given position.
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
pub struct RadiusGoal {
|
pub struct RadiusGoal {
|
||||||
pub pos: Vec3,
|
pub pos: Vec3,
|
||||||
pub radius: f32,
|
pub radius: f32,
|
||||||
|
@ -163,7 +168,7 @@ impl<T: Goal, U: Goal> Goal for AndGoal<T, U> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to reach all of the given goals.
|
/// Try to reach all the given goals.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AndGoals<T: Goal>(pub Vec<T>);
|
pub struct AndGoals<T: Goal>(pub Vec<T>);
|
||||||
impl<T: Goal> Goal for AndGoals<T> {
|
impl<T: Goal> Goal for AndGoals<T> {
|
||||||
|
@ -180,7 +185,7 @@ impl<T: Goal> Goal for AndGoals<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Move to a position where we can reach the given block.
|
/// Move to a position where we can reach the given block.
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ReachBlockPosGoal {
|
pub struct ReachBlockPosGoal {
|
||||||
pub pos: BlockPos,
|
pub pos: BlockPos,
|
||||||
pub chunk_storage: ChunkStorage,
|
pub chunk_storage: ChunkStorage,
|
||||||
|
|
Loading…
Add table
Reference in a new issue