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.
//
// 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)
}
}

View File

@ -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)

View File

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