From fe186fb44dfb5a1afce765aa65a41834bb93085d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20B=C3=B6klin?= Date: Thu, 20 May 2021 10:31:37 +0200 Subject: [PATCH] Code quality --- client/src/lib.rs | 9 +++++-- voxygen/src/session/mod.rs | 52 +++++++++++++------------------------- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index df73a2a780..22816cb656 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -931,6 +931,11 @@ impl Client { pub fn is_dead(&self) -> bool { self.current::().map_or(false, |h| h.is_dead) } + pub fn is_gliding(&self) -> bool { + self.current::() + .map_or(false, |cs| matches!(cs, comp::CharacterState::Glide(_))) + } + pub fn split_swap_slots(&mut self, a: comp::slot::Slot, b: comp::slot::Slot) { match (a, b) { (Slot::Equip(equip), slot) | (slot, Slot::Equip(equip)) => self.control_action( @@ -1234,7 +1239,7 @@ impl Client { } pub fn toggle_glide(&mut self) { - let is_gliding = self + let using_glider = self .state .ecs() .read_storage::() @@ -1246,7 +1251,7 @@ impl Client { ) }); - match is_gliding { + match using_glider { Some(true) => self.control_action(ControlAction::Unwield), Some(false) => self.control_action(ControlAction::GlideWield), None => warn!("Can't toggle glide, client entity doesn't have a `CharacterState`"), diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index 3a29fd8732..8d4bfecb5c 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -686,20 +686,8 @@ impl PlayState for SessionState { |b| hud.auto_walk(b), ); - if self - .client - .borrow() - .state() - .ecs() - .read_storage::() - .get(self.client.borrow().entity()) - .filter(|cs| matches!(cs, comp::CharacterState::Glide(_))) - .is_some() - { - self.key_state.auto_walk = false - } else { - self.key_state.auto_walk = self.auto_walk - } + self.key_state.auto_walk = + self.auto_walk && !self.client.borrow().is_gliding(); }, GameInput::CameraClamp => { let hud = &mut self.hud; @@ -764,30 +752,24 @@ impl PlayState for SessionState { } } - if let Some(dir) = self - .auto_walk - .then_some(( - self.client.borrow().state().ecs(), - self.client.borrow().entity(), - )) - .filter(|(ecs, entity)| { - ecs.read_storage::() - .get(*entity) - .map_or(false, |cs| matches!(cs, comp::CharacterState::Glide(_))) - }) - .and_then(|(ecs, entity)| { - ecs.read_storage::() + // If auto-gliding, point camera into the wind + if let Some(dir) = (self.auto_walk && self.client.borrow().is_gliding()) + .then_some(self.client.borrow()) + .and_then(|client| { + let ecs = client.state().ecs(); + let entity = client.entity(); + let fluid = ecs + .read_storage::() .get(entity)? - .in_fluid - .and_then(|fluid| { - Dir::from_unnormalized( - -fluid - .relative_flow(ecs.read_storage::().get(entity)?) - .0, - ) - }) + .in_fluid?; + let wind = ecs + .read_storage::() + .get(entity) + .map(|vel| -fluid.relative_flow(vel).0)?; + Dir::from_unnormalized(wind) }) { + self.key_state.auto_walk = false; self.inputs.look_dir = dir; } else if !self.free_look { self.walk_forward_dir = self.scene.camera().forward_xy();