Remove body::Shape enum, make npc use CapsulePrism

This commit is contained in:
juliancoffee 2021-09-15 18:33:16 +03:00
parent 6c3b61dc25
commit d86c9f2678
3 changed files with 17 additions and 62 deletions

View File

@ -154,12 +154,6 @@ impl<
// We can just determine shape form dimensions. // We can just determine shape form dimensions.
// //
// But I want Dachshund in Veloren at least somewhere XD // But I want Dachshund in Veloren at least somewhere XD
enum Shape {
// Dachshund-like
Long,
// Cyclops-like
Wide,
}
impl Body { impl Body {
pub fn is_humanoid(&self) -> bool { matches!(self, Body::Humanoid(_)) } 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 // 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 // are very much not cylindrical. Eventually this ought to be replaced by more
// accurate collision shapes. // accurate collision shapes.
@ -451,29 +425,26 @@ impl Body {
// The width (shoulder to shoulder) and length (nose to tail) // The width (shoulder to shoulder) and length (nose to tail)
let (width, length) = (dim.x, dim.y); let (width, length) = (dim.x, dim.y);
match self.shape() { if length > width {
Shape::Long => { // Dachshund-like
let radius = width / 2.0; let radius = width / 2.0;
let a = length - 2.0 * radius; let a = length - 2.0 * radius;
debug_assert!(a > 0.0);
let p0 = 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); let p1 = Vec2::new(0.0, a / 2.0);
(p0, p1, radius) (p0, p1, radius)
}, } else {
Shape::Wide => { // Cyclops-like
let radius = length / 2.0; let radius = length / 2.0;
let a = width - 2.0 * radius; let a = width - 2.0 * radius;
debug_assert!(a > 0.0);
let p0 = 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); let p1 = Vec2::new(a / 2.0, 0.0);
(p0, p1, radius) (p0, p1, radius)
},
} }
} }

View File

@ -185,7 +185,6 @@ impl StateExt for State {
inventory: comp::Inventory, inventory: comp::Inventory,
body: comp::Body, body: comp::Body,
) -> EcsEntityBuilder { ) -> EcsEntityBuilder {
use comp::body::{biped_large, quadruped_medium};
self.ecs_mut() self.ecs_mut()
.create_entity_synced() .create_entity_synced()
.with(pos) .with(pos)
@ -204,18 +203,7 @@ impl StateExt for State {
comp::Body::Ship(ship) => comp::Collider::Voxel { comp::Body::Ship(ship) => comp::Collider::Voxel {
id: ship.manifest_entry().to_string(), 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(); let (p0, p1, radius) = body.sausage();
// TODO: // TODO:
@ -228,12 +216,7 @@ impl StateExt for State {
z_min: 0.0, z_min: 0.0,
z_max: body.height(), z_max: body.height(),
} }
}, }
_ => comp::Collider::Box {
radius: body.radius(),
z_min: 0.0,
z_max: body.height(),
},
}) })
.with(comp::Controller::default()) .with(comp::Controller::default())
.with(body) .with(body)

View File

@ -153,6 +153,7 @@ pub struct DebugShapeId(pub u64);
pub struct Debug { pub struct Debug {
next_shape_id: DebugShapeId, next_shape_id: DebugShapeId,
pending_shapes: HashMap<DebugShapeId, DebugShape>, pending_shapes: HashMap<DebugShapeId, DebugShape>,
#[allow(clippy::type_complexity)]
pending_locals: HashMap<DebugShapeId, ([f32; 4], [f32; 4], [f32; 4])>, pending_locals: HashMap<DebugShapeId, ([f32; 4], [f32; 4], [f32; 4])>,
pending_deletes: HashSet<DebugShapeId>, pending_deletes: HashSet<DebugShapeId>,
models: HashMap<DebugShapeId, (Model<DebugVertex>, Bound<Consts<DebugLocals>>)>, models: HashMap<DebugShapeId, (Model<DebugVertex>, Bound<Consts<DebugLocals>>)>,