mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Addressed more comments
This commit is contained in:
parent
dd58784336
commit
39479863f5
@ -133,16 +133,29 @@ impl<
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Body {
|
impl Body {
|
||||||
pub const DEFAULT_EYE_HEIGHT: f32 = 1.65;
|
|
||||||
|
|
||||||
pub fn is_humanoid(&self) -> bool { matches!(self, Body::Humanoid(_)) }
|
pub fn is_humanoid(&self) -> bool { matches!(self, Body::Humanoid(_)) }
|
||||||
|
|
||||||
// Note: this might need to be refined to something more complex for realistic
|
// Note: this might need to be refined to something more complex for realistic
|
||||||
// behavior with less cylindrical bodies (e.g. wolfs)
|
// behavior with less cylindrical bodies (e.g. wolfs)
|
||||||
|
#[allow(unreachable_patterns)]
|
||||||
pub fn radius(&self) -> f32 {
|
pub fn radius(&self) -> f32 {
|
||||||
// TODO: Improve these values (some might be reliant on more info in inner type)
|
// TODO: Improve these values (some might be reliant on more info in inner type)
|
||||||
match self {
|
match self {
|
||||||
Body::Humanoid(_) => 0.5 * self.scale(),
|
Body::Humanoid(humanoid) => match (humanoid.species, humanoid.body_type) {
|
||||||
|
(humanoid::Species::Orc, humanoid::BodyType::Male) => 0.57,
|
||||||
|
(humanoid::Species::Orc, humanoid::BodyType::Female) => 0.51,
|
||||||
|
(humanoid::Species::Human, humanoid::BodyType::Male) => 0.51,
|
||||||
|
(humanoid::Species::Human, humanoid::BodyType::Female) => 0.48,
|
||||||
|
(humanoid::Species::Elf, humanoid::BodyType::Male) => 0.51,
|
||||||
|
(humanoid::Species::Elf, humanoid::BodyType::Female) => 0.48,
|
||||||
|
(humanoid::Species::Dwarf, humanoid::BodyType::Male) => 0.42,
|
||||||
|
(humanoid::Species::Dwarf, humanoid::BodyType::Female) => 0.39,
|
||||||
|
(humanoid::Species::Undead, humanoid::BodyType::Male) => 0.48,
|
||||||
|
(humanoid::Species::Undead, humanoid::BodyType::Female) => 0.45,
|
||||||
|
(humanoid::Species::Danari, humanoid::BodyType::Male) => 0.348,
|
||||||
|
(humanoid::Species::Danari, humanoid::BodyType::Female) => 0.348,
|
||||||
|
_ => 0.5,
|
||||||
|
},
|
||||||
Body::QuadrupedSmall(_) => 0.4,
|
Body::QuadrupedSmall(_) => 0.4,
|
||||||
Body::QuadrupedMedium(body) => match body.species {
|
Body::QuadrupedMedium(body) => match body.species {
|
||||||
quadruped_medium::Species::Grolgar => 1.9,
|
quadruped_medium::Species::Grolgar => 1.9,
|
||||||
@ -174,7 +187,20 @@ impl Body {
|
|||||||
|
|
||||||
pub fn height(&self) -> f32 {
|
pub fn height(&self) -> f32 {
|
||||||
match self {
|
match self {
|
||||||
Body::Humanoid(_) => 1.9 * self.scale(),
|
Body::Humanoid(humanoid) => match (humanoid.species, humanoid.body_type) {
|
||||||
|
(humanoid::Species::Orc, humanoid::BodyType::Male) => 2.17,
|
||||||
|
(humanoid::Species::Orc, humanoid::BodyType::Female) => 1.94,
|
||||||
|
(humanoid::Species::Human, humanoid::BodyType::Male) => 1.94,
|
||||||
|
(humanoid::Species::Human, humanoid::BodyType::Female) => 1.82,
|
||||||
|
(humanoid::Species::Elf, humanoid::BodyType::Male) => 1.94,
|
||||||
|
(humanoid::Species::Elf, humanoid::BodyType::Female) => 1.82,
|
||||||
|
(humanoid::Species::Dwarf, humanoid::BodyType::Male) => 1.60,
|
||||||
|
(humanoid::Species::Dwarf, humanoid::BodyType::Female) => 1.48,
|
||||||
|
(humanoid::Species::Undead, humanoid::BodyType::Male) => 1.82,
|
||||||
|
(humanoid::Species::Undead, humanoid::BodyType::Female) => 1.71,
|
||||||
|
(humanoid::Species::Danari, humanoid::BodyType::Male) => 1.32,
|
||||||
|
(humanoid::Species::Danari, humanoid::BodyType::Female) => 1.32,
|
||||||
|
},
|
||||||
Body::QuadrupedSmall(body) => match body.species {
|
Body::QuadrupedSmall(body) => match body.species {
|
||||||
quadruped_small::Species::Dodarock => 1.5,
|
quadruped_small::Species::Dodarock => 1.5,
|
||||||
quadruped_small::Species::Holladon => 1.5,
|
quadruped_small::Species::Holladon => 1.5,
|
||||||
@ -528,39 +554,7 @@ impl Body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the eye height for this humanoid.
|
/// Returns the eye height for this humanoid.
|
||||||
pub fn eye_height(&self) -> f32 { Self::DEFAULT_EYE_HEIGHT * self.scale() }
|
pub fn eye_height(&self) -> f32 { self.height() * 0.9 }
|
||||||
|
|
||||||
pub fn scale(&self) -> f32 {
|
|
||||||
match self {
|
|
||||||
Body::Humanoid(humanoid) => match (humanoid.species, humanoid.body_type) {
|
|
||||||
(humanoid::Species::Orc, humanoid::BodyType::Male) => 1.14,
|
|
||||||
(humanoid::Species::Orc, humanoid::BodyType::Female) => 1.02,
|
|
||||||
(humanoid::Species::Human, humanoid::BodyType::Male) => 1.02,
|
|
||||||
(humanoid::Species::Human, humanoid::BodyType::Female) => 0.96,
|
|
||||||
(humanoid::Species::Elf, humanoid::BodyType::Male) => 1.02,
|
|
||||||
(humanoid::Species::Elf, humanoid::BodyType::Female) => 0.96,
|
|
||||||
(humanoid::Species::Dwarf, humanoid::BodyType::Male) => 0.84,
|
|
||||||
(humanoid::Species::Dwarf, humanoid::BodyType::Female) => 0.78,
|
|
||||||
(humanoid::Species::Undead, humanoid::BodyType::Male) => 0.96,
|
|
||||||
(humanoid::Species::Undead, humanoid::BodyType::Female) => 0.9,
|
|
||||||
(humanoid::Species::Danari, humanoid::BodyType::Male) => 0.696,
|
|
||||||
(humanoid::Species::Danari, humanoid::BodyType::Female) => 0.696,
|
|
||||||
},
|
|
||||||
Body::BipedLarge(biped_large) => match (biped_large.species, biped_large.body_type) {
|
|
||||||
(biped_large::Species::Occultsaurok, _) => 2.0,
|
|
||||||
(biped_large::Species::Slysaurok, _) => 2.0,
|
|
||||||
_ => 2.2,
|
|
||||||
},
|
|
||||||
Body::BirdMedium(_) => 0.7,
|
|
||||||
Body::Dragon(_) => 16.0,
|
|
||||||
Body::Golem(_) => 2.0,
|
|
||||||
Body::QuadrupedMedium(_) => 1.0,
|
|
||||||
Body::QuadrupedLow(_) => 0.9,
|
|
||||||
Body::QuadrupedSmall(_) => 0.5,
|
|
||||||
Body::Theropod(_) => 2.0,
|
|
||||||
_ => 1.0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn default_light_offset(&self) -> Vec3<f32> {
|
pub fn default_light_offset(&self) -> Vec3<f32> {
|
||||||
// TODO: Make this a manifest
|
// TODO: Make this a manifest
|
||||||
|
@ -89,15 +89,17 @@ impl CharacterBehavior for Data {
|
|||||||
timer: Duration::default(),
|
timer: Duration::default(),
|
||||||
});
|
});
|
||||||
// Gets offsets
|
// Gets offsets
|
||||||
let body_offsets =
|
let body_offsets = Vec3::new(
|
||||||
Vec3::new(data.body.radius() * 3.0, 0.0, data.body.eye_height());
|
data.body.radius() * 3.0 * data.inputs.look_dir.x,
|
||||||
|
data.body.radius() * 3.0 * data.inputs.look_dir.y,
|
||||||
|
data.body.eye_height(),
|
||||||
|
) * 0.55;
|
||||||
// Build up
|
// Build up
|
||||||
update.character = CharacterState::BasicBeam(Data {
|
update.character = CharacterState::BasicBeam(Data {
|
||||||
timer: Duration::default(),
|
timer: Duration::default(),
|
||||||
stage_section: StageSection::Cast,
|
stage_section: StageSection::Cast,
|
||||||
particle_ori: Some(*data.inputs.look_dir),
|
particle_ori: Some(*data.inputs.look_dir),
|
||||||
offset: body_offsets * 0.55,
|
offset: body_offsets,
|
||||||
..*self
|
..*self
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -134,8 +136,11 @@ impl CharacterBehavior for Data {
|
|||||||
owner: Some(*data.uid),
|
owner: Some(*data.uid),
|
||||||
};
|
};
|
||||||
// Gets offsets
|
// Gets offsets
|
||||||
let body_offsets =
|
let body_offsets = Vec3::new(
|
||||||
Vec3::new(data.body.radius() * 3.0, 0.0, data.body.eye_height());
|
data.body.radius() + 2.0 * data.inputs.look_dir.x,
|
||||||
|
data.body.radius() + 2.0 * data.inputs.look_dir.y,
|
||||||
|
data.body.eye_height(),
|
||||||
|
) * 0.55;
|
||||||
let pos = Pos(data.pos.0 + body_offsets);
|
let pos = Pos(data.pos.0 + body_offsets);
|
||||||
// Create beam segment
|
// Create beam segment
|
||||||
update.server_events.push_front(ServerEvent::BeamSegment {
|
update.server_events.push_front(ServerEvent::BeamSegment {
|
||||||
@ -149,6 +154,7 @@ impl CharacterBehavior for Data {
|
|||||||
.checked_add(Duration::from_secs_f32(data.dt.0))
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
particle_ori: Some(*data.inputs.look_dir),
|
particle_ori: Some(*data.inputs.look_dir),
|
||||||
|
offset: body_offsets,
|
||||||
..*self
|
..*self
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{Body, Controller, MountState, Mounting, Ori, Pos, Vel},
|
comp::{Controller, MountState, Mounting, Ori, Pos, Vel},
|
||||||
metrics::SysMetrics,
|
metrics::SysMetrics,
|
||||||
span,
|
span,
|
||||||
sync::UidAllocator,
|
sync::UidAllocator,
|
||||||
};
|
};
|
||||||
use specs::{
|
use specs::{
|
||||||
saveload::{Marker, MarkerAllocator},
|
saveload::{Marker, MarkerAllocator},
|
||||||
Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage,
|
Entities, Join, Read, ReadExpect, System, WriteStorage,
|
||||||
};
|
};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -18,7 +18,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
Read<'a, UidAllocator>,
|
Read<'a, UidAllocator>,
|
||||||
ReadExpect<'a, SysMetrics>,
|
ReadExpect<'a, SysMetrics>,
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
ReadStorage<'a, Body>,
|
|
||||||
WriteStorage<'a, Controller>,
|
WriteStorage<'a, Controller>,
|
||||||
WriteStorage<'a, MountState>,
|
WriteStorage<'a, MountState>,
|
||||||
WriteStorage<'a, Mounting>,
|
WriteStorage<'a, Mounting>,
|
||||||
@ -33,7 +32,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
uid_allocator,
|
uid_allocator,
|
||||||
sys_metrics,
|
sys_metrics,
|
||||||
entities,
|
entities,
|
||||||
bodies,
|
|
||||||
mut controllers,
|
mut controllers,
|
||||||
mut mount_state,
|
mut mount_state,
|
||||||
mut mountings,
|
mut mountings,
|
||||||
@ -45,9 +43,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
let start_time = std::time::Instant::now();
|
let start_time = std::time::Instant::now();
|
||||||
span!(_guard, "run", "mount::Sys::run");
|
span!(_guard, "run", "mount::Sys::run");
|
||||||
// Mounted entities.
|
// Mounted entities.
|
||||||
for (entity, mut mount_states, body) in
|
for (entity, mut mount_states) in (&entities, &mut mount_state.restrict_mut()).join() {
|
||||||
(&entities, &mut mount_state.restrict_mut(), bodies.maybe()).join()
|
|
||||||
{
|
|
||||||
match mount_states.get_unchecked() {
|
match mount_states.get_unchecked() {
|
||||||
MountState::Unmounted => {},
|
MountState::Unmounted => {},
|
||||||
MountState::MountedBy(mounter_uid) => {
|
MountState::MountedBy(mounter_uid) => {
|
||||||
@ -65,9 +61,8 @@ impl<'a> System<'a> for Sys {
|
|||||||
let pos = positions.get(entity).copied();
|
let pos = positions.get(entity).copied();
|
||||||
let ori = orientations.get(entity).copied();
|
let ori = orientations.get(entity).copied();
|
||||||
let vel = velocities.get(entity).copied();
|
let vel = velocities.get(entity).copied();
|
||||||
let scale = body.map_or(1.0, |b| b.scale());
|
|
||||||
if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) {
|
if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) {
|
||||||
let _ = positions.insert(mounter, Pos(pos.0 + Vec3::unit_z() * scale));
|
let _ = positions.insert(mounter, Pos(pos.0 + Vec3::unit_z() * 1.0));
|
||||||
let _ = orientations.insert(mounter, ori);
|
let _ = orientations.insert(mounter, ori);
|
||||||
let _ = velocities.insert(mounter, vel);
|
let _ = velocities.insert(mounter, vel);
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ pub fn handle_shoot(
|
|||||||
.ecs()
|
.ecs()
|
||||||
.read_storage::<comp::Body>()
|
.read_storage::<comp::Body>()
|
||||||
.get(entity)
|
.get(entity)
|
||||||
.map_or(0.0, |b| b.scale());
|
.map_or(0.0, |b| b.eye_height());
|
||||||
|
|
||||||
pos.z += eye_height;
|
pos.z += eye_height;
|
||||||
|
|
||||||
|
@ -197,7 +197,21 @@ impl<'a> From<&'a Body> for SkeletonAttr {
|
|||||||
fn from(body: &'a Body) -> Self {
|
fn from(body: &'a Body) -> Self {
|
||||||
use comp::humanoid::{BodyType::*, Species::*};
|
use comp::humanoid::{BodyType::*, Species::*};
|
||||||
Self {
|
Self {
|
||||||
scaler: comp::Body::Humanoid(*body).scale(),
|
scaler: match (body.species, body.body_type) {
|
||||||
|
// TODO : Derive scale from body proportions
|
||||||
|
(Orc, Male) => 1.14,
|
||||||
|
(Orc, Female) => 1.02,
|
||||||
|
(Human, Male) => 1.02,
|
||||||
|
(Human, Female) => 0.96,
|
||||||
|
(Elf, Male) => 1.02,
|
||||||
|
(Elf, Female) => 0.96,
|
||||||
|
(Dwarf, Male) => 0.84,
|
||||||
|
(Dwarf, Female) => 0.78,
|
||||||
|
(Undead, Male) => 0.96,
|
||||||
|
(Undead, Female) => 0.9,
|
||||||
|
(Danari, Male) => 0.70,
|
||||||
|
(Danari, Female) => 0.70,
|
||||||
|
},
|
||||||
head_scale: match (body.species, body.body_type) {
|
head_scale: match (body.species, body.body_type) {
|
||||||
(Orc, Male) => 0.9,
|
(Orc, Male) => 0.9,
|
||||||
(Orc, Female) => 0.9,
|
(Orc, Female) => 0.9,
|
||||||
|
@ -467,19 +467,12 @@ impl Scene {
|
|||||||
.get(scene_data.player_entity)
|
.get(scene_data.player_entity)
|
||||||
.map(|p| p.on_ground);
|
.map(|p| p.on_ground);
|
||||||
|
|
||||||
let player_scale = scene_data
|
let (player_height, player_eye_height) = scene_data
|
||||||
.state
|
.state
|
||||||
.ecs()
|
.ecs()
|
||||||
.read_storage::<comp::Body>()
|
.read_storage::<comp::Body>()
|
||||||
.get(scene_data.player_entity)
|
.get(scene_data.player_entity)
|
||||||
.map_or(1.0, |b| b.scale());
|
.map_or((1.0, 0.0), |b| (b.height(), b.eye_height()));
|
||||||
|
|
||||||
let eye_height = scene_data
|
|
||||||
.state
|
|
||||||
.ecs()
|
|
||||||
.read_storage::<comp::Body>()
|
|
||||||
.get(scene_data.player_entity)
|
|
||||||
.map_or(0.0, |b| b.eye_height());
|
|
||||||
|
|
||||||
// Add the analog input to camera
|
// Add the analog input to camera
|
||||||
self.camera
|
self.camera
|
||||||
@ -494,15 +487,15 @@ impl Scene {
|
|||||||
let up = match self.camera.get_mode() {
|
let up = match self.camera.get_mode() {
|
||||||
CameraMode::FirstPerson => {
|
CameraMode::FirstPerson => {
|
||||||
if player_rolling {
|
if player_rolling {
|
||||||
player_scale * 0.8
|
player_height * 0.42
|
||||||
} else if is_running && on_ground.unwrap_or(false) {
|
} else if is_running && on_ground.unwrap_or(false) {
|
||||||
eye_height + (scene_data.state.get_time() as f32 * 17.0).sin() * 0.05
|
player_eye_height + (scene_data.state.get_time() as f32 * 17.0).sin() * 0.05
|
||||||
} else {
|
} else {
|
||||||
eye_height
|
player_eye_height
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
CameraMode::ThirdPerson if scene_data.is_aiming => player_scale * 2.2,
|
CameraMode::ThirdPerson if scene_data.is_aiming => player_height * 1.16,
|
||||||
CameraMode::ThirdPerson => eye_height,
|
CameraMode::ThirdPerson => player_eye_height,
|
||||||
CameraMode::Freefly => 0.0,
|
CameraMode::Freefly => 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user