mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Make npcs roll correctly
This commit is contained in:
parent
77a48c61a1
commit
b99bac87db
@ -279,10 +279,7 @@ impl Client {
|
|||||||
// 2) Build up a list of events for this frame, to be passed to the frontend.
|
// 2) Build up a list of events for this frame, to be passed to the frontend.
|
||||||
let mut frontend_events = Vec::new();
|
let mut frontend_events = Vec::new();
|
||||||
|
|
||||||
// Handle new messages from the server.
|
// Prepare for new events
|
||||||
frontend_events.append(&mut self.handle_new_messages()?);
|
|
||||||
|
|
||||||
// 3) Update client local data
|
|
||||||
{
|
{
|
||||||
let ecs = self.state.ecs_mut();
|
let ecs = self.state.ecs_mut();
|
||||||
for (entity, _) in (&ecs.entities(), &ecs.read_storage::<comp::Body>()).join() {
|
for (entity, _) in (&ecs.entities(), &ecs.read_storage::<comp::Body>()).join() {
|
||||||
@ -307,6 +304,10 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Handle new messages from the server.
|
||||||
|
frontend_events.append(&mut self.handle_new_messages()?);
|
||||||
|
|
||||||
|
// 3) Update client local data
|
||||||
|
|
||||||
// 4) Tick the client's LocalState
|
// 4) Tick the client's LocalState
|
||||||
self.state.tick(dt);
|
self.state.tick(dt);
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
comp::{
|
|
||||||
ActionState::*, Animation, AnimationInfo, CharacterState, MovementState::*, PhysicsState,
|
|
||||||
Stats,
|
|
||||||
},
|
|
||||||
state::DeltaTime,
|
|
||||||
};
|
|
||||||
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
|
||||||
use std::fmt::Debug;
|
|
||||||
|
|
||||||
/// This system will apply the animation that fits best to the users actions
|
|
||||||
pub struct Sys;
|
|
||||||
impl<'a> System<'a> for Sys {
|
|
||||||
type SystemData = (
|
|
||||||
Entities<'a>,
|
|
||||||
Read<'a, DeltaTime>,
|
|
||||||
ReadStorage<'a, Stats>,
|
|
||||||
ReadStorage<'a, CharacterState>,
|
|
||||||
ReadStorage<'a, PhysicsState>,
|
|
||||||
WriteStorage<'a, AnimationInfo>,
|
|
||||||
);
|
|
||||||
|
|
||||||
fn run(
|
|
||||||
&mut self,
|
|
||||||
(entities, dt, stats, character_states, physics_states, mut animation_infos): Self::SystemData,
|
|
||||||
) {
|
|
||||||
for (entity, stats, character, physics) in
|
|
||||||
(&entities, &stats, &character_states, &physics_states).join()
|
|
||||||
{
|
|
||||||
if stats.is_dead {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let animation = match (physics.on_ground, &character.movement, &character.action) {
|
|
||||||
//(_, Roll { .. }, _) => Animation::Roll,
|
|
||||||
//(true, Stand, _) => Animation::Stand, //if standing still, legs still
|
|
||||||
//(true, Stand, Idle) => Animation::Idle, //if standing still and not acting, idle the body
|
|
||||||
//(true, Run, _) => Animation::Run, //if running, legs run
|
|
||||||
//(true, Run, Idle) => Animation::Lean, //if running and not acting, lean the body
|
|
||||||
//(false, Jump, Idle) => Animation::Jump,
|
|
||||||
//(true, Stand, Wield { .. }) => Animation::Cidle,
|
|
||||||
//(true, Run, Wield { .. }) => Animation::Crun,
|
|
||||||
//(false, Jump, Wield { .. }) => Animation::Cjump,
|
|
||||||
//(_, Glide, Idle) => Animation::Gliding,
|
|
||||||
//(_, _, Attack { .. }) => Animation::Attack,
|
|
||||||
//(_, _, Block { .. }) => Animation::Block,
|
|
||||||
// Impossible animation (Caused by missing animations or syncing delays)
|
|
||||||
_ => Animation::Gliding,
|
|
||||||
};
|
|
||||||
|
|
||||||
let new_time = animation_infos
|
|
||||||
.get(entity)
|
|
||||||
.filter(|i| i.animation == animation)
|
|
||||||
.map(|i| i.time + f64::from(dt.0));
|
|
||||||
|
|
||||||
let _ = animation_infos.insert(
|
|
||||||
entity,
|
|
||||||
AnimationInfo {
|
|
||||||
animation,
|
|
||||||
time: new_time.unwrap_or(0.0),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
pub mod agent;
|
pub mod agent;
|
||||||
pub mod animation;
|
|
||||||
mod cleanup;
|
mod cleanup;
|
||||||
pub mod combat;
|
pub mod combat;
|
||||||
pub mod controller;
|
pub mod controller;
|
||||||
@ -16,7 +15,6 @@ const CONTROLLER_SYS: &str = "controller_sys";
|
|||||||
const PHYS_SYS: &str = "phys_sys";
|
const PHYS_SYS: &str = "phys_sys";
|
||||||
const MOVEMENT_SYS: &str = "movement_sys";
|
const MOVEMENT_SYS: &str = "movement_sys";
|
||||||
const COMBAT_SYS: &str = "combat_sys";
|
const COMBAT_SYS: &str = "combat_sys";
|
||||||
const ANIMATION_SYS: &str = "animation_sys";
|
|
||||||
const STATS_SYS: &str = "stats_sys";
|
const STATS_SYS: &str = "stats_sys";
|
||||||
const CLEANUP_SYS: &str = "cleanup_sys";
|
const CLEANUP_SYS: &str = "cleanup_sys";
|
||||||
|
|
||||||
@ -26,7 +24,6 @@ pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) {
|
|||||||
dispatch_builder.add(phys::Sys, PHYS_SYS, &[CONTROLLER_SYS]);
|
dispatch_builder.add(phys::Sys, PHYS_SYS, &[CONTROLLER_SYS]);
|
||||||
dispatch_builder.add(movement::Sys, MOVEMENT_SYS, &[PHYS_SYS]);
|
dispatch_builder.add(movement::Sys, MOVEMENT_SYS, &[PHYS_SYS]);
|
||||||
dispatch_builder.add(combat::Sys, COMBAT_SYS, &[CONTROLLER_SYS]);
|
dispatch_builder.add(combat::Sys, COMBAT_SYS, &[CONTROLLER_SYS]);
|
||||||
dispatch_builder.add(animation::Sys, ANIMATION_SYS, &[MOVEMENT_SYS]);
|
|
||||||
dispatch_builder.add(stats::Sys, STATS_SYS, &[COMBAT_SYS]);
|
dispatch_builder.add(stats::Sys, STATS_SYS, &[COMBAT_SYS]);
|
||||||
dispatch_builder.add(cleanup::Sys, CLEANUP_SYS, &[STATS_SYS, ANIMATION_SYS]);
|
dispatch_builder.add(cleanup::Sys, CLEANUP_SYS, &[STATS_SYS, MOVEMENT_SYS]);
|
||||||
}
|
}
|
||||||
|
@ -782,7 +782,9 @@ impl FigureMgr {
|
|||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
if last_character.0.movement != character.movement {
|
if std::mem::discriminant(&last_character.0.movement)
|
||||||
|
!= std::mem::discriminant(&character.movement)
|
||||||
|
{
|
||||||
state.last_movement_change = Instant::now();
|
state.last_movement_change = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -829,7 +831,9 @@ impl FigureMgr {
|
|||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
if last_character.0.movement != character.movement {
|
if std::mem::discriminant(&last_character.0.movement)
|
||||||
|
!= std::mem::discriminant(&character.movement)
|
||||||
|
{
|
||||||
state.last_movement_change = Instant::now();
|
state.last_movement_change = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user