173a55e608
93 pub items (78 functions and methods, 14 constants, 1 struct) in horizon-client, horizon-world, horizon-core, horizon-friends and horizon-server-files had no caller anywhere in the repository: not in the crate, the other crates, the examples, the tests or the binaries. rustc can't flag them because horizon-client and the others are libraries, where a pub item counts as used. The imports and the private helpers only they used go with them (title.rs date_string, goals.rs flag_index). Also drops the #[allow(dead_code)]/#[allow(unused)] items that only hid dead code: chat_debug_fill, merchant_title and Goals::locked_by had no caller, and four stubs (_keep, _unused, _rule_kind, const _) existed only to keep an import used. LightTables::from_parts is used by its tests, so it is #[cfg(test)] instead of allowed. Protocol id tables and entity data serializer ids stay: they mirror vanilla's registries in full. The launcher's three unused items are left for a launcher PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
2.5 KiB
Rust
76 lines
2.5 KiB
Rust
//! Entity obstruction against a voxel shape. Entity storage, lifecycle and
|
|
//! vehicle-tree maintenance supply the immutable candidate snapshots here.
|
|
use horizon_core::geometry::{Aabb, ShapeError, ShapeOp, VoxelShape};
|
|
|
|
/// Object identity within the caller's entity snapshot, including its generation.
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub struct EntityIdentity(pub u64);
|
|
#[derive(Clone, Copy, Debug)]
|
|
pub struct ObstructionEntity {
|
|
pub identity: EntityIdentity,
|
|
pub root_vehicle: EntityIdentity,
|
|
pub bounds: Aabb,
|
|
pub removed: bool,
|
|
pub spectator: bool,
|
|
pub blocks_building: bool,
|
|
}
|
|
pub trait EntityObstructionWorld {
|
|
type Error;
|
|
/// Preserve native query order. Implementations may return a broad-phase
|
|
/// superset: exclusion, spectator and exact AABB filters are enforced below.
|
|
fn obstruction_candidates(
|
|
&mut self,
|
|
excluded: Option<EntityIdentity>,
|
|
bounds: Aabb,
|
|
) -> Result<Vec<ObstructionEntity>, Self::Error>;
|
|
}
|
|
#[derive(Debug)]
|
|
pub enum ObstructionError<E> {
|
|
World(E),
|
|
Shape(ShapeError),
|
|
}
|
|
impl<E: std::fmt::Display> std::fmt::Display for ObstructionError<E> {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::World(e) => e.fmt(f),
|
|
Self::Shape(e) => e.fmt(f),
|
|
}
|
|
}
|
|
}
|
|
impl<E: std::error::Error + 'static> std::error::Error for ObstructionError<E> {}
|
|
|
|
pub fn is_unobstructed<W: EntityObstructionWorld>(
|
|
world: &mut W,
|
|
excluded: Option<&ObstructionEntity>,
|
|
shape: &VoxelShape,
|
|
) -> Result<bool, ObstructionError<W::Error>> {
|
|
let Some(bounds) = shape.bounds() else {
|
|
return Ok(true);
|
|
};
|
|
let candidates = world
|
|
.obstruction_candidates(excluded.map(|e| e.identity), bounds)
|
|
.map_err(ObstructionError::World)?;
|
|
for entity in candidates {
|
|
if excluded.is_some_and(|e| e.identity == entity.identity)
|
|
|| entity.spectator
|
|
|| !entity.bounds.intersects(bounds)
|
|
{
|
|
continue;
|
|
}
|
|
if entity.removed
|
|
|| !entity.blocks_building
|
|
|| excluded.is_some_and(|e| e.root_vehicle == entity.root_vehicle)
|
|
{
|
|
continue;
|
|
}
|
|
let other = VoxelShape::from_box(entity.bounds).map_err(ObstructionError::Shape)?;
|
|
if shape
|
|
.join_is_not_empty(&other, ShapeOp::AND)
|
|
.map_err(ObstructionError::Shape)?
|
|
{
|
|
return Ok(false);
|
|
}
|
|
}
|
|
Ok(true)
|
|
}
|