From 93642428f2cfcb9ca8c69a011a0e845daa94a3a7 Mon Sep 17 00:00:00 2001 From: Snowram Date: Sat, 14 Nov 2020 23:05:35 +0100 Subject: [PATCH] Move eye sight and scale in body.rs, mounts tweaks --- common/src/comp/body.rs | 39 ++++++++++++++++++++++++--- common/src/comp/body/humanoid.rs | 25 ----------------- common/src/states/basic_beam.rs | 10 +++---- common/src/sys/agent.rs | 19 ++++--------- common/src/sys/mount.rs | 13 ++++++--- server/src/events/entity_creation.rs | 15 ++++++----- voxygen/src/anim/src/character/mod.rs | 2 +- voxygen/src/scene/mod.rs | 17 +++++------- 8 files changed, 68 insertions(+), 72 deletions(-) diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index d7a0b22119..317af58d3a 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -133,6 +133,8 @@ impl< } impl Body { + pub const DEFAULT_EYE_HEIGHT: f32 = 1.65; + pub fn is_humanoid(&self) -> bool { matches!(self, Body::Humanoid(_)) } // Note: this might need to be refined to something more complex for realistic @@ -140,7 +142,7 @@ impl Body { pub fn radius(&self) -> f32 { // TODO: Improve these values (some might be reliant on more info in inner type) match self { - Body::Humanoid(body) => 0.5 * body.scale(), + Body::Humanoid(_) => 0.5 * self.scale(), Body::QuadrupedSmall(_) => 0.4, Body::QuadrupedMedium(body) => match body.species { quadruped_medium::Species::Grolgar => 1.9, @@ -172,7 +174,7 @@ impl Body { pub fn height(&self) -> f32 { match self { - Body::Humanoid(body) => 1.9 * body.scale(), + Body::Humanoid(_) => 1.9 * self.scale(), Body::QuadrupedSmall(body) => match body.species { quadruped_small::Species::Dodarock => 1.5, quadruped_small::Species::Holladon => 1.5, @@ -199,7 +201,7 @@ impl Body { _ => 1.1, }, Body::FishMedium(_) => 1.1, - Body::Dragon(_) => 20.0, + Body::Dragon(_) => 16.0, Body::BirdSmall(_) => 1.1, Body::FishSmall(_) => 0.9, Body::BipedLarge(_) => 4.6, @@ -525,6 +527,37 @@ impl Body { } } + /// Returns the eye height for this humanoid. + pub fn eye_height(&self) -> f32 { Self::DEFAULT_EYE_HEIGHT * self.scale() } + + 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(_) => 2.5, + 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 { // TODO: Make this a manifest match self { diff --git a/common/src/comp/body/humanoid.rs b/common/src/comp/body/humanoid.rs index f00eefa529..c55973654f 100644 --- a/common/src/comp/body/humanoid.rs +++ b/common/src/comp/body/humanoid.rs @@ -63,33 +63,8 @@ impl Body { .accessory .min(self.species.num_accessories(self.body_type) - 1); } - - /// Returns a scale value relative to the average humanoid - pub fn scale(&self) -> f32 { - use BodyType::*; - use Species::*; - match (self.species, self.body_type) { - (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.696, - (Danari, Female) => 0.696, - } - } - - /// Returns the eye height for this humanoid. - pub fn eye_height(&self) -> f32 { DEFAULT_HUMANOID_EYE_HEIGHT * self.scale() } } -pub const DEFAULT_HUMANOID_EYE_HEIGHT: f32 = 1.65; - impl From for super::Body { fn from(body: Body) -> Self { super::Body::Humanoid(body) } } diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index bb254d704b..896c75b378 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -1,7 +1,5 @@ use crate::{ - comp::{ - beam, humanoid, Body, CharacterState, EnergyChange, EnergySource, Ori, Pos, StateUpdate, - }, + comp::{beam, CharacterState, EnergyChange, EnergySource, Ori, Pos, StateUpdate}, event::ServerEvent, states::utils::*, sync::Uid, @@ -91,10 +89,8 @@ impl CharacterBehavior for Data { timer: Duration::default(), }); // Gets offset - let eye_height = match data.body { - Body::Humanoid(body) => body.eye_height(), - _ => humanoid::DEFAULT_HUMANOID_EYE_HEIGHT, - }; + let eye_height = data.body.eye_height(); + // Build up update.character = CharacterState::BasicBeam(Data { timer: Duration::default(), diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index 9c3acf2a55..41768501de 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -343,20 +343,11 @@ impl<'a> System<'a> for Sys { ) { controller.actions.push(ControlAction::Wield); - let eye_offset = match body { - Some(body) => match body { - Body::Humanoid(body) => body.eye_height(), - _ => 0.4 * body.height(), - }, - _ => 0.0, - }; - let tgt_eye_offset = match bodies.get(*target) { - Some(body) => match body { - Body::Humanoid(body) => body.eye_height(), - _ => 0.4 * body.height(), - }, - _ => 0.0, - }; + let eye_offset = body.map_or(1.0, |b| b.eye_height()); + + let tgt_eye_offset = + bodies.get(*target).map_or(1.0, |b| b.eye_height()); + let distance_offset = match tactic { Tactic::Bow => 0.0004 * pos.0.distance_squared(tgt_pos.0), Tactic::Staff => 0.0015 * pos.0.distance_squared(tgt_pos.0), diff --git a/common/src/sys/mount.rs b/common/src/sys/mount.rs index 26c4fcac54..15de7f8e19 100644 --- a/common/src/sys/mount.rs +++ b/common/src/sys/mount.rs @@ -1,12 +1,12 @@ use crate::{ - comp::{Controller, MountState, Mounting, Ori, Pos, Vel}, + comp::{Body, Controller, MountState, Mounting, Ori, Pos, Vel}, metrics::SysMetrics, span, sync::UidAllocator, }; use specs::{ saveload::{Marker, MarkerAllocator}, - Entities, Join, Read, ReadExpect, System, WriteStorage, + Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage, }; use vek::*; @@ -18,6 +18,7 @@ impl<'a> System<'a> for Sys { Read<'a, UidAllocator>, ReadExpect<'a, SysMetrics>, Entities<'a>, + ReadStorage<'a, Body>, WriteStorage<'a, Controller>, WriteStorage<'a, MountState>, WriteStorage<'a, Mounting>, @@ -32,6 +33,7 @@ impl<'a> System<'a> for Sys { uid_allocator, sys_metrics, entities, + bodies, mut controllers, mut mount_state, mut mountings, @@ -43,7 +45,9 @@ impl<'a> System<'a> for Sys { let start_time = std::time::Instant::now(); span!(_guard, "run", "mount::Sys::run"); // Mounted entities. - for (entity, mut mount_states) in (&entities, &mut mount_state.restrict_mut()).join() { + for (entity, mut mount_states, body) in + (&entities, &mut mount_state.restrict_mut(), bodies.maybe()).join() + { match mount_states.get_unchecked() { MountState::Unmounted => {}, MountState::MountedBy(mounter_uid) => { @@ -61,8 +65,9 @@ impl<'a> System<'a> for Sys { let pos = positions.get(entity).copied(); let ori = orientations.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) { - let _ = positions.insert(mounter, Pos(pos.0 + Vec3::unit_z() * 1.0)); + let _ = positions.insert(mounter, Pos(pos.0 + Vec3::unit_z() * scale)); let _ = orientations.insert(mounter, ori); let _ = velocities.insert(mounter, vel); } diff --git a/server/src/events/entity_creation.rs b/server/src/events/entity_creation.rs index 6ecd41dd29..7824d45ec8 100644 --- a/server/src/events/entity_creation.rs +++ b/server/src/events/entity_creation.rs @@ -2,9 +2,8 @@ use crate::{sys, Server, StateExt}; use common::{ character::CharacterId, comp::{ - self, beam, humanoid::DEFAULT_HUMANOID_EYE_HEIGHT, shockwave, Agent, Alignment, Body, - Gravity, Health, Item, ItemDrop, LightEmitter, Loadout, Ori, Pos, Projectile, Scale, Stats, - Vel, WaypointArea, + self, beam, shockwave, Agent, Alignment, Body, Gravity, Health, Item, ItemDrop, + LightEmitter, Loadout, Ori, Pos, Projectile, Scale, Stats, Vel, WaypointArea, }, outcome::Outcome, util::Dir, @@ -115,10 +114,12 @@ pub fn handle_shoot( .write_resource::>() .push(Outcome::ProjectileShot { pos, body, vel }); - let eye_height = match state.ecs().read_storage::().get(entity) { - Some(comp::Body::Humanoid(body)) => body.eye_height(), - _ => DEFAULT_HUMANOID_EYE_HEIGHT, - }; + let eye_height = state + .ecs() + .read_storage::() + .get(entity) + .map(|b| b.scale()) + .unwrap_or(1.0); pos.z += eye_height; diff --git a/voxygen/src/anim/src/character/mod.rs b/voxygen/src/anim/src/character/mod.rs index 75cf450a24..49ec356792 100644 --- a/voxygen/src/anim/src/character/mod.rs +++ b/voxygen/src/anim/src/character/mod.rs @@ -197,7 +197,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { fn from(body: &'a Body) -> Self { use comp::humanoid::{BodyType::*, Species::*}; Self { - scaler: body.scale(), + scaler: comp::Body::Humanoid(*body).scale(), head_scale: match (body.species, body.body_type) { (Orc, Male) => 0.9, (Orc, Female) => 0.9, diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index f1f62cb339..40154f9139 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -26,7 +26,6 @@ use crate::{ use client::Client; use common::{ comp, - comp::humanoid::DEFAULT_HUMANOID_EYE_HEIGHT, outcome::Outcome, span, state::{DeltaTime, State}, @@ -468,25 +467,21 @@ impl Scene { .get(scene_data.player_entity) .map(|p| p.on_ground); - let player_scale = match scene_data + let player_scale = scene_data .state .ecs() .read_storage::() .get(scene_data.player_entity) - { - Some(comp::Body::Humanoid(body)) => body.scale(), - _ => 1_f32, - }; + .map(|b| b.scale()) + .unwrap_or(1.0); - let eye_height = match scene_data + let eye_height = scene_data .state .ecs() .read_storage::() .get(scene_data.player_entity) - { - Some(comp::Body::Humanoid(body)) => body.eye_height(), - _ => DEFAULT_HUMANOID_EYE_HEIGHT, - }; + .map(|b| b.eye_height()) + .unwrap_or(1.0); // Add the analog input to camera self.camera