From 58a4659c47bb16bdbaa0136109cce13b93cd7414 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Wed, 15 Sep 2021 18:33:16 +0300 Subject: [PATCH] Remove body::Shape enum, make npc use CapsulePrism --- common/src/comp/body.rs | 57 ++++++++++---------------------------- server/src/state_ext.rs | 21 ++------------ voxygen/src/scene/debug.rs | 1 + 3 files changed, 17 insertions(+), 62 deletions(-) diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index 653d64b028..acc747b49c 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -154,12 +154,6 @@ impl< // We can just determine shape form dimensions. // // But I want Dachshund in Veloren at least somewhere XD -enum Shape { - // Dachshund-like - Long, - // Cyclops-like - Wide, -} impl Body { pub fn is_humanoid(&self) -> bool { matches!(self, Body::Humanoid(_)) } @@ -403,26 +397,6 @@ impl Body { } } - fn shape(&self) -> Shape { - match self { - Body::BipedLarge(_) - | Body::BipedSmall(_) - | Body::Golem(_) - | Body::Humanoid(_) - | Body::Object(_) => Shape::Wide, - Body::BirdLarge(_) - | Body::BirdMedium(_) - | Body::Dragon(_) - | Body::FishMedium(_) - | Body::FishSmall(_) - | Body::QuadrupedLow(_) - | Body::QuadrupedMedium(_) - | Body::QuadrupedSmall(_) - | Body::Ship(_) - | Body::Theropod(_) => Shape::Long, - } - } - // Note: This is used for collisions, but it's not very accurate for shapes that // are very much not cylindrical. Eventually this ought to be replaced by more // accurate collision shapes. @@ -451,29 +425,26 @@ impl Body { // The width (shoulder to shoulder) and length (nose to tail) let (width, length) = (dim.x, dim.y); - match self.shape() { - Shape::Long => { - let radius = width / 2.0; + if length > width { + // Dachshund-like + let radius = width / 2.0; - let a = length - 2.0 * radius; - debug_assert!(a > 0.0); + let a = length - 2.0 * radius; - let p0 = Vec2::new(0.0, -a / 2.0); - let p1 = Vec2::new(0.0, a / 2.0); + let p0 = Vec2::new(0.0, -a / 2.0); + let p1 = Vec2::new(0.0, a / 2.0); - (p0, p1, radius) - }, - Shape::Wide => { - let radius = length / 2.0; + (p0, p1, radius) + } else { + // Cyclops-like + let radius = length / 2.0; - let a = width - 2.0 * radius; - debug_assert!(a > 0.0); + let a = width - 2.0 * radius; - let p0 = Vec2::new(-a / 2.0, 0.0); - let p1 = Vec2::new(a / 2.0, 0.0); + let p0 = Vec2::new(-a / 2.0, 0.0); + let p1 = Vec2::new(a / 2.0, 0.0); - (p0, p1, radius) - }, + (p0, p1, radius) } } diff --git a/server/src/state_ext.rs b/server/src/state_ext.rs index 78009fa908..c7e40f42dc 100644 --- a/server/src/state_ext.rs +++ b/server/src/state_ext.rs @@ -185,7 +185,6 @@ impl StateExt for State { inventory: comp::Inventory, body: comp::Body, ) -> EcsEntityBuilder { - use comp::body::{biped_large, quadruped_medium}; self.ecs_mut() .create_entity_synced() .with(pos) @@ -204,18 +203,7 @@ impl StateExt for State { comp::Body::Ship(ship) => comp::Collider::Voxel { id: ship.manifest_entry().to_string(), }, - body - @ - (comp::Body::QuadrupedMedium(quadruped_medium::Body { - species: quadruped_medium::Species::Camel, - .. - }) - | comp::Body::BipedLarge(biped_large::Body { - species: biped_large::Species::Cyclops, - .. - })) => { - // no Camel was hurt while doing this sausage - // can't say the same about Cyclops + _ => { let (p0, p1, radius) = body.sausage(); // TODO: @@ -228,12 +216,7 @@ impl StateExt for State { z_min: 0.0, z_max: body.height(), } - }, - _ => comp::Collider::Box { - radius: body.radius(), - z_min: 0.0, - z_max: body.height(), - }, + } }) .with(comp::Controller::default()) .with(body) diff --git a/voxygen/src/scene/debug.rs b/voxygen/src/scene/debug.rs index b4fbf2d0d4..f9042615b9 100644 --- a/voxygen/src/scene/debug.rs +++ b/voxygen/src/scene/debug.rs @@ -153,6 +153,7 @@ pub struct DebugShapeId(pub u64); pub struct Debug { next_shape_id: DebugShapeId, pending_shapes: HashMap, + #[allow(clippy::type_complexity)] pending_locals: HashMap, pending_deletes: HashSet, models: HashMap, Bound>)>,