From 7b09070fc88997c00d2dacb2257630ffbafd2960 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 16 May 2019 20:23:45 +0100 Subject: [PATCH] fmt Former-commit-id: 8f0bc964e00bfd9461f752622862de5335678e5b --- client/src/lib.rs | 3 +- common/src/comp/actor.rs | 4 +- common/src/sys/control.rs | 12 ++++- voxygen/src/anim/character/gliding.rs | 10 ++-- voxygen/src/anim/character/mod.rs | 5 +- voxygen/src/anim/quadruped/idle.rs | 6 +-- voxygen/src/anim/quadruped/jump.rs | 3 +- voxygen/src/anim/quadruped/mod.rs | 7 +-- voxygen/src/anim/quadruped/run.rs | 19 ++++--- voxygen/src/menu/char_selection/mod.rs | 6 +-- voxygen/src/menu/char_selection/scene.rs | 8 ++- voxygen/src/scene/figure.rs | 66 +++++++++++++----------- 12 files changed, 83 insertions(+), 66 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 740f9edc4b..11c4266974 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -202,7 +202,8 @@ impl Client { self.state.terrain().iter().for_each(|(key, _)| { if (Vec2::from(chunk_pos) - Vec2::from(key)) .map(|e: i32| e.abs()) - .reduce_max() > 10 + .reduce_max() + > 10 { chunks_to_remove.push(key); } diff --git a/common/src/comp/actor.rs b/common/src/comp/actor.rs index eca896ee17..885f53381e 100644 --- a/common/src/comp/actor.rs +++ b/common/src/comp/actor.rs @@ -155,7 +155,8 @@ const ALL_QRACES: [Race; 6] = [ Race::Elf, Race::Human, Race::Orc, - Race::Undead,]; + Race::Undead, +]; const ALL_QBODY_TYPES: [BodyType; 3] = [BodyType::Female, BodyType::Male, BodyType::Unspecified]; const ALL_QHEADS: [Pighead; 1] = [Pighead::Default]; const ALL_QCHESTS: [Pigchest; 1] = [Pigchest::Default]; @@ -170,7 +171,6 @@ pub struct QuadrupedBody { pub pigchest: Pigchest, pub pigleg_l: Pigleg_l, pub pigleg_r: Pigleg_r, - } impl QuadrupedBody { diff --git a/common/src/sys/control.rs b/common/src/sys/control.rs index c01ab474fc..375d26cbfb 100644 --- a/common/src/sys/control.rs +++ b/common/src/sys/control.rs @@ -59,7 +59,8 @@ impl<'a> System<'a> for Sys { if control.gliding && vel.0.z < 0.0 { // TODO: Don't hard-code this let anti_grav = 9.81 * 3.95 + vel.0.z.powf(2.0) * 0.2; - vel.0.z += dt.0 * anti_grav * Vec2::::from(vel.0 * 0.15).magnitude().min(1.0); + vel.0.z += + dt.0 * anti_grav * Vec2::::from(vel.0 * 0.15).magnitude().min(1.0); (true, 0.008) } else { @@ -68,7 +69,14 @@ impl<'a> System<'a> for Sys { }; // Friction - vel.0 -= Vec2::broadcast(dt.0) * 50.0 * vel.0.map(|e| (e.abs() * friction * (vel.0.magnitude() * 0.1 + 0.5)).min(e.abs()).copysign(e)) * Vec3::new(1.0, 1.0, 0.0); + vel.0 -= Vec2::broadcast(dt.0) + * 50.0 + * vel.0.map(|e| { + (e.abs() * friction * (vel.0.magnitude() * 0.1 + 0.5)) + .min(e.abs()) + .copysign(e) + }) + * Vec3::new(1.0, 1.0, 0.0); if vel.0.magnitude_squared() != 0.0 { dir.0 = vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0); diff --git a/voxygen/src/anim/character/gliding.rs b/voxygen/src/anim/character/gliding.rs index 19ebfbece8..be2102670d 100644 --- a/voxygen/src/anim/character/gliding.rs +++ b/voxygen/src/anim/character/gliding.rs @@ -33,7 +33,6 @@ impl Animation for GlidingAnimation { let waveveryslowalt = (anim_time as f32 * 2.5).sin(); let waveveryslowcos = (anim_time as f32 * 3.0).cos(); - let wave_slowtest = (anim_time as f32).min(PI / 2.0).sin(); let head_look = Vec2::new( @@ -49,7 +48,8 @@ impl Animation for GlidingAnimation { * 0.25, ); next.head.offset = Vec3::new(5.5, 2.0, 12.0); - next.head.ori = Quaternion::rotation_x(0.35 - waveveryslow * 0.10 + head_look.y) * Quaternion::rotation_z(head_look.x + waveveryslowcos * 0.15); + next.head.ori = Quaternion::rotation_x(0.35 - waveveryslow * 0.10 + head_look.y) + * Quaternion::rotation_z(head_look.x + waveveryslowcos * 0.15); next.head.scale = Vec3::one(); next.chest.offset = Vec3::new(5.5, 0.0, 8.0); @@ -73,11 +73,13 @@ impl Animation for GlidingAnimation { next.r_hand.scale = Vec3::one(); next.l_foot.offset = Vec3::new(-3.4, 1.0, 8.0); - next.l_foot.ori = Quaternion::rotation_x(wave_stop * -0.7 - wavecos_slow * -0.21 + waveveryslow * 0.19); + next.l_foot.ori = + Quaternion::rotation_x(wave_stop * -0.7 - wavecos_slow * -0.21 + waveveryslow * 0.19); next.l_foot.scale = Vec3::one(); next.r_foot.offset = Vec3::new(3.4, 1.0, 8.0); - next.r_foot.ori = Quaternion::rotation_x(wave_stop * -0.8 + waveslow * -0.25 + waveveryslowalt * 0.13); + next.r_foot.ori = + Quaternion::rotation_x(wave_stop * -0.8 + waveslow * -0.25 + waveveryslowalt * 0.13); next.r_foot.scale = Vec3::one(); next.weapon.offset = Vec3::new(-5.0, -6.0, 19.0); diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index 3605286cfc..d1054716a5 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -1,14 +1,13 @@ +pub mod gliding; pub mod idle; pub mod jump; pub mod run; -pub mod gliding; - // Reexports +pub use self::gliding::GlidingAnimation; pub use self::idle::IdleAnimation; pub use self::jump::JumpAnimation; pub use self::run::RunAnimation; -pub use self::gliding::GlidingAnimation; // Crate use crate::render::FigureBoneData; diff --git a/voxygen/src/anim/quadruped/idle.rs b/voxygen/src/anim/quadruped/idle.rs index 0b8c576c51..0a281c2e19 100644 --- a/voxygen/src/anim/quadruped/idle.rs +++ b/voxygen/src/anim/quadruped/idle.rs @@ -44,7 +44,8 @@ impl Animation for IdleAnimation { ); next.pighead.offset = Vec3::new(0.0, -2.0, -1.5 + wave * 0.2) / 11.0; - next.pighead.ori = Quaternion::rotation_z(pighead_look.x) * Quaternion::rotation_x(pighead_look.y + wavecos_slow * 0.03); + next.pighead.ori = Quaternion::rotation_z(pighead_look.x) + * Quaternion::rotation_x(pighead_look.y + wavecos_slow * 0.03); next.pighead.scale = Vec3::one() / 10.5; next.pigchest.offset = Vec3::new(wave_slow * 0.05, -9.0, 1.5 + wavecos_slow * 0.4) / 11.0; @@ -67,9 +68,6 @@ impl Animation for IdleAnimation { next.pigrb_leg.ori = Quaternion::rotation_x(wave_slow * 0.08); next.pigrb_leg.scale = Vec3::one() / 11.0; - - - next } } diff --git a/voxygen/src/anim/quadruped/jump.rs b/voxygen/src/anim/quadruped/jump.rs index 9d25f69d3e..0567e3c558 100644 --- a/voxygen/src/anim/quadruped/jump.rs +++ b/voxygen/src/anim/quadruped/jump.rs @@ -29,8 +29,7 @@ impl Animation for JumpAnimation { let wave_dip = (wave_slow.abs() - 0.5).abs(); let wave_stop = (anim_time as f32 * 4.5).min(PI / 2.0).sin(); - - next.pighead.offset = Vec3::new(0.0, 0.0, -1.5 ) / 11.0; + next.pighead.offset = Vec3::new(0.0, 0.0, -1.5) / 11.0; next.pighead.ori = Quaternion::rotation_x(wave_stop * 0.4); next.pighead.scale = Vec3::one() / 10.5; diff --git a/voxygen/src/anim/quadruped/mod.rs b/voxygen/src/anim/quadruped/mod.rs index a6b7e4474c..5115133cf2 100644 --- a/voxygen/src/anim/quadruped/mod.rs +++ b/voxygen/src/anim/quadruped/mod.rs @@ -1,13 +1,11 @@ - -pub mod run; pub mod idle; pub mod jump; - +pub mod run; // Reexports -pub use self::run::RunAnimation; pub use self::idle::IdleAnimation; pub use self::jump::JumpAnimation; +pub use self::run::RunAnimation; // Crate use crate::render::FigureBoneData; @@ -25,7 +23,6 @@ pub struct QuadrupedSkeleton { pigrf_leg: Bone, piglb_leg: Bone, pigrb_leg: Bone, - } impl QuadrupedSkeleton { diff --git a/voxygen/src/anim/quadruped/run.rs b/voxygen/src/anim/quadruped/run.rs index d817a52741..21e1fdafc3 100644 --- a/voxygen/src/anim/quadruped/run.rs +++ b/voxygen/src/anim/quadruped/run.rs @@ -31,27 +31,32 @@ impl Animation for RunAnimation { let wave_dip = (wave_slow.abs() - 0.5).abs(); next.pighead.offset = Vec3::new(0.0, 0.0, -1.5 + wave * 1.5) / 11.0; - next.pighead.ori = Quaternion::rotation_x(0.2 + wave * 0.05) * Quaternion::rotation_y(wavecos * 0.03); + next.pighead.ori = + Quaternion::rotation_x(0.2 + wave * 0.05) * Quaternion::rotation_y(wavecos * 0.03); next.pighead.scale = Vec3::one() / 10.5; next.pigchest.offset = Vec3::new(0.0, -9.0, 1.5 + wavecos * 1.2) / 11.0; next.pigchest.ori = Quaternion::rotation_x(wave * 0.1); next.pigchest.scale = Vec3::one() / 11.0; - next.piglf_leg.offset = Vec3::new(-4.5, 2.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0; - next.piglf_leg.ori = Quaternion::rotation_x(wavequick * 0.3); + next.piglf_leg.offset = + Vec3::new(-4.5, 2.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0; + next.piglf_leg.ori = Quaternion::rotation_x(wavequick * 0.3); next.piglf_leg.scale = Vec3::one() / 11.0; - next.pigrf_leg.offset = Vec3::new(2.5, 2.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0; + next.pigrf_leg.offset = + Vec3::new(2.5, 2.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0; next.pigrf_leg.ori = Quaternion::rotation_x(wavequickcos * -0.3); next.pigrf_leg.scale = Vec3::one() / 11.0; - next.piglb_leg.offset = Vec3::new(-4.5, -3.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0; + next.piglb_leg.offset = + Vec3::new(-4.5, -3.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0; next.piglb_leg.ori = Quaternion::rotation_x(wavequickcos * -0.3); next.piglb_leg.scale = Vec3::one() / 11.0; - next.pigrb_leg.offset = Vec3::new(2.5, -3.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0; - next.pigrb_leg.ori = Quaternion::rotation_x(wavequick * 0.3); + next.pigrb_leg.offset = + Vec3::new(2.5, -3.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0; + next.pigrb_leg.ori = Quaternion::rotation_x(wavequick * 0.3); next.pigrb_leg.scale = Vec3::one() / 11.0; next diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index e1b86311da..0bc18f324f 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -7,11 +7,7 @@ use crate::{ Direction, GlobalState, PlayState, PlayStateResult, }; use client::{self, Client}; -use common::{ - comp, - clock::Clock, - msg::ClientMsg, -}; +use common::{clock::Clock, comp, msg::ClientMsg}; use scene::Scene; use std::{cell::RefCell, rc::Rc, time::Duration}; use ui::CharSelectionUi; diff --git a/voxygen/src/menu/char_selection/scene.rs b/voxygen/src/menu/char_selection/scene.rs index 7ff104e41f..d29a50d127 100644 --- a/voxygen/src/menu/char_selection/scene.rs +++ b/voxygen/src/menu/char_selection/scene.rs @@ -99,8 +99,12 @@ impl Scene { ); self.figure_state.skeleton_mut().interpolate(&tgt_skeleton); - self.figure_state - .update(renderer, Vec3::zero(), -Vec3::unit_y(), Rgba::broadcast(1.0)); + self.figure_state.update( + renderer, + Vec3::zero(), + -Vec3::unit_y(), + Rgba::broadcast(1.0), + ); } pub fn render(&mut self, renderer: &mut Renderer, client: &Client) { diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 3c771579dc..39ddc2790e 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -15,8 +15,11 @@ use common::{ assets, comp::{ self, - actor::{Belt, Chest, Foot, Hand, Head, Pants, Shoulder, Weapon, Draw, Pighead, Pigchest, Pigleg_l, Pigleg_r}, - Body, HumanoidBody, QuadrupedBody + actor::{ + Belt, Chest, Draw, Foot, Hand, Head, Pants, Pigchest, Pighead, Pigleg_l, Pigleg_r, + Shoulder, Weapon, + }, + Body, HumanoidBody, QuadrupedBody, }, figure::Segment, msg, @@ -230,11 +233,8 @@ impl FigureModelCache { Self::load_mesh( match draw { Draw::Default => "glider.vox", - }, - Vec3::new(-26.0, -26.0, -5.0) - - + Vec3::new(-26.0, -26.0, -5.0), ) } @@ -293,7 +293,6 @@ impl FigureModelCache { } } - pub struct FigureMgr { model_cache: FigureModelCache, character_states: HashMap>, @@ -350,17 +349,19 @@ impl FigureMgr { time, animation_history.time, ), - comp::Animation::Gliding => character::GlidingAnimation::update_skeleton( - state.skeleton_mut(), - time, - animation_history.time, - ), + comp::Animation::Gliding => { + character::GlidingAnimation::update_skeleton( + state.skeleton_mut(), + time, + animation_history.time, + ) + } }; state.skeleton.interpolate(&target_skeleton); state.update(renderer, pos.0, dir.0, Rgba::white()); - }, + } Body::Quadruped(body) => { let state = self.quadruped_states.entry(entity).or_insert_with(|| { FigureState::new(renderer, QuadrupedSkeleton::new()) @@ -392,21 +393,21 @@ impl FigureMgr { // Change in health as color! let col = stats .and_then(|stats| stats.hp.last_change) - .map(|(change_by, change_time)| { - Rgba::new(1.0, 0.7, 0.7, 1.0) - }) + .map(|(change_by, change_time)| Rgba::new(1.0, 0.7, 0.7, 1.0)) .unwrap_or(Rgba::broadcast(1.0)); state.update(renderer, pos.0, dir.0, col); - }, + } }, // TODO: Non-character actors } } // Clear states that have dead entities - self.character_states.retain(|entity, _| ecs.entities().is_alive(*entity)); - self.quadruped_states.retain(|entity, _| ecs.entities().is_alive(*entity)); + self.character_states + .retain(|entity, _| ecs.entities().is_alive(*entity)); + self.quadruped_states + .retain(|entity, _| ecs.entities().is_alive(*entity)); } pub fn render( @@ -422,19 +423,20 @@ impl FigureMgr { match actor { comp::Actor::Character { body, .. } => { if let Some((locals, bone_consts)) = match body { - Body::Humanoid(_) => self.character_states.get(&entity).map(|state| (state.locals(), state.bone_consts())), - Body::Quadruped(_) => self.quadruped_states.get(&entity).map(|state| (state.locals(), state.bone_consts())), + Body::Humanoid(_) => self + .character_states + .get(&entity) + .map(|state| (state.locals(), state.bone_consts())), + Body::Quadruped(_) => self + .quadruped_states + .get(&entity) + .map(|state| (state.locals(), state.bone_consts())), } { let model = self.model_cache.get_or_create_model(renderer, *body, tick); - renderer.render_figure( - model, - globals, - locals, - bone_consts, - ); + renderer.render_figure(model, globals, locals, bone_consts); } - }, + } } } } @@ -457,7 +459,13 @@ impl FigureState { } } - pub fn update(&mut self, renderer: &mut Renderer, pos: Vec3, dir: Vec3, col: Rgba) { + pub fn update( + &mut self, + renderer: &mut Renderer, + pos: Vec3, + dir: Vec3, + col: Rgba, + ) { let mat = Mat4::::identity() * Mat4::translation_3d(pos) * Mat4::rotation_z(-dir.x.atan2(dir.y)); // + f32::consts::PI / 2.0);