diff --git a/common/src/sys/anim.rs b/common/src/sys/anim.rs new file mode 100644 index 0000000000..1cc8415cc7 --- /dev/null +++ b/common/src/sys/anim.rs @@ -0,0 +1,25 @@ +// Library +use specs::{Join, Read, ReadStorage, System, WriteStorage}; +use vek::*; + +// Crate +use crate::{ + comp::{phys::Pos, AnimationHistory, Control}, + state::DeltaTime, +}; + +// Basic ECS AI agent system +pub struct Sys; + +impl<'a> System<'a> for Sys { + type SystemData = ( + Read<'a, DeltaTime>, + WriteStorage<'a, AnimationHistory>, + ); + + fn run(&mut self, (dt, mut anim_history): Self::SystemData) { + for (mut anim_history) in (&mut anim_history).join() { + anim_history.time += dt.0 as f64; + } + } +} diff --git a/common/src/sys/control.rs b/common/src/sys/control.rs index 0b3667322e..c8ddf2d2cc 100644 --- a/common/src/sys/control.rs +++ b/common/src/sys/control.rs @@ -71,7 +71,7 @@ impl<'a> System<'a> for Sys { let time = if let Some((true, time)) = last_history.map(|last| (last.current == animation, last.time)) { - time + dt.0 as f64 + time } else { 0.0 }; diff --git a/common/src/sys/mod.rs b/common/src/sys/mod.rs index 968fe2aa79..df4b9567d1 100644 --- a/common/src/sys/mod.rs +++ b/common/src/sys/mod.rs @@ -1,6 +1,7 @@ pub mod agent; pub mod control; pub mod phys; +pub mod anim; // External use specs::DispatcherBuilder; @@ -9,9 +10,11 @@ use specs::DispatcherBuilder; const AGENT_SYS: &str = "agent_sys"; const CONTROL_SYS: &str = "control_sys"; const MOVEMENT_SYS: &str = "movement_sys"; +const ANIM_SYS: &str = "anim_sys"; pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { dispatch_builder.add(agent::Sys, AGENT_SYS, &[]); dispatch_builder.add(control::Sys, CONTROL_SYS, &[]); dispatch_builder.add(phys::Sys, MOVEMENT_SYS, &[]); + dispatch_builder.add(anim::Sys, ANIM_SYS, &[]); } diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index bb76bd62de..90412242c6 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -29,8 +29,8 @@ impl Animation for IdleAnimation { let wave_dip = (wave_slow.abs() - 0.5).abs(); let head_look = Vec2::new( - (global_time as f32 / 5.0).floor().mul(7331.0).sin() * 0.5, - (global_time as f32 / 5.0).floor().mul(1337.0).sin() * 0.25, + ((global_time + anim_time) as f32 / 5.0).floor().mul(7331.0).sin() * 0.5, + ((global_time + anim_time) as f32 / 5.0).floor().mul(1337.0).sin() * 0.25, ); next.head.offset = Vec3::new(5.5, 2.0, 11.5 + waveultra_slow * 0.4); next.head.ori = Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y);