From 610c86a3b99dacd248beec2e882d0ab9747b3c26 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Sat, 29 Jun 2019 20:52:20 +0200 Subject: [PATCH] Animation fixes --- common/src/comp/mod.rs | 4 +-- common/src/sys/action_state.rs | 19 +++++++++++--- common/src/sys/animation.rs | 45 ++++++++++++---------------------- common/src/sys/mod.rs | 8 ++++-- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/common/src/comp/mod.rs b/common/src/comp/mod.rs index d93cf4c579..fee0d63f16 100644 --- a/common/src/comp/mod.rs +++ b/common/src/comp/mod.rs @@ -1,3 +1,4 @@ +mod action_state; mod agent; mod animation; mod body; @@ -7,9 +8,9 @@ mod inventory; mod phys; mod player; mod stats; -mod action_state; // Reexports +pub use action_state::ActionState; pub use agent::Agent; pub use animation::{Animation, AnimationInfo}; pub use body::{humanoid, quadruped, quadruped_medium, Actor, Body}; @@ -19,4 +20,3 @@ pub use inventory::{item, Inventory}; pub use phys::{ForceUpdate, Ori, Pos, Vel}; pub use player::Player; pub use stats::{Dying, HealthSource, Stats}; -pub use action_state::ActionState; diff --git a/common/src/sys/action_state.rs b/common/src/sys/action_state.rs index b3c97a1b15..93dc4607e5 100644 --- a/common/src/sys/action_state.rs +++ b/common/src/sys/action_state.rs @@ -1,7 +1,7 @@ use crate::{ comp::{ - Animation, AnimationInfo, Attacking, ForceUpdate, Gliding, Jumping, OnGround, Ori, Pos, - Rolling, Vel, ActionState, + ActionState, Animation, AnimationInfo, Attacking, Controller, ForceUpdate, Gliding, + Jumping, OnGround, Ori, Pos, Rolling, Vel, }, state::DeltaTime, }; @@ -13,6 +13,7 @@ impl<'a> System<'a> for Sys { type SystemData = ( Entities<'a>, Read<'a, DeltaTime>, + ReadStorage<'a, Controller>, ReadStorage<'a, Vel>, ReadStorage<'a, OnGround>, ReadStorage<'a, Jumping>, @@ -27,6 +28,7 @@ impl<'a> System<'a> for Sys { ( entities, dt, + controllers, // To make sure it only runs on the single client and the server velocities, on_grounds, jumpings, @@ -36,9 +38,20 @@ impl<'a> System<'a> for Sys { mut action_states, ): Self::SystemData, ) { - for (entity, vel, on_ground, jumping, gliding, attacking, rolling, mut action_state) in ( + for ( + entity, + vel, + _controller, + on_ground, + jumping, + gliding, + attacking, + rolling, + mut action_state, + ) in ( &entities, &velocities, + &controllers, on_grounds.maybe(), jumpings.maybe(), glidings.maybe(), diff --git a/common/src/sys/animation.rs b/common/src/sys/animation.rs index 6b251a0311..cebb5dde07 100644 --- a/common/src/sys/animation.rs +++ b/common/src/sys/animation.rs @@ -1,7 +1,5 @@ use crate::{ - comp::{ - Animation, AnimationInfo, ForceUpdate, ActionState - }, + comp::{ActionState, Animation, AnimationInfo, ForceUpdate}, state::DeltaTime, }; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; @@ -16,33 +14,14 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, AnimationInfo>, ); - fn run( - &mut self, - ( - entities, - dt, - action_states, - mut animation_infos, - ): Self::SystemData, - ) { - for (entity, a) in ( - &entities, - &action_states, - ) - .join() - { + fn run(&mut self, (entities, dt, action_states, mut animation_infos): Self::SystemData) { + for (entity, a) in (&entities, &action_states).join() { fn impossible_animation(message: &str) -> Animation { warn!("{}", message); Animation::Idle } - let animation = match ( - a.on_ground, - a.moving, - a.attacking, - a.gliding, - a.rolling, - ) { + let animation = match (a.on_ground, a.moving, a.attacking, a.gliding, a.rolling) { (_, _, true, true, _) => impossible_animation("Attack while gliding"), (_, _, true, _, true) => impossible_animation("Roll while attacking"), (_, _, _, true, true) => impossible_animation("Roll while gliding"), @@ -55,12 +34,18 @@ impl<'a> System<'a> for Sys { (_, _, true, false, false) => Animation::Attack, }; - let new_time = animation_infos.get(entity).filter(|i| i.animation == animation).map(|i| i.time + dt.0 as f64); + let new_time = animation_infos + .get(entity) + .filter(|i| i.animation == animation) + .map(|i| i.time + dt.0 as f64); - animation_infos.insert(entity, AnimationInfo { - animation, - time: new_time.unwrap_or(0.0), - }); + animation_infos.insert( + entity, + AnimationInfo { + animation, + time: new_time.unwrap_or(0.0), + }, + ); } } } diff --git a/common/src/sys/mod.rs b/common/src/sys/mod.rs index 6bf0ddb162..6507c09f7e 100644 --- a/common/src/sys/mod.rs +++ b/common/src/sys/mod.rs @@ -1,10 +1,10 @@ +mod action_state; pub mod agent; pub mod animation; pub mod combat; pub mod controller; pub mod phys; mod stats; -mod action_state; // External use specs::DispatcherBuilder; @@ -22,7 +22,11 @@ pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { dispatch_builder.add(agent::Sys, AGENT_SYS, &[]); dispatch_builder.add(controller::Sys, CONTROLLER_SYS, &[AGENT_SYS]); dispatch_builder.add(phys::Sys, PHYS_SYS, &[CONTROLLER_SYS]); - dispatch_builder.add(action_state::Sys, ACTION_STATE_SYS, &[CONTROLLER_SYS, PHYS_SYS]); + dispatch_builder.add( + action_state::Sys, + ACTION_STATE_SYS, + &[CONTROLLER_SYS, PHYS_SYS], + ); dispatch_builder.add(combat::Sys, COMBAT_SYS, &[ACTION_STATE_SYS]); dispatch_builder.add(animation::Sys, ANIMATION_SYS, &[ACTION_STATE_SYS]); dispatch_builder.add(stats::Sys, STATS_SYS, &[COMBAT_SYS]);