Animation fixes

This commit is contained in:
timokoesters 2019-06-29 20:52:20 +02:00
parent 9f83533741
commit 610c86a3b9
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
4 changed files with 39 additions and 37 deletions

View File

@ -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;

View File

@ -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(),

View File

@ -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),
},
);
}
}
}

View File

@ -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]);