Fix rolling for the player

This commit is contained in:
timokoesters
2019-08-28 14:46:20 +02:00
committed by jshipsey
parent d84c07c1cb
commit 77a48c61a1
4 changed files with 27 additions and 17 deletions

View File

@ -286,17 +286,22 @@ impl Client {
{ {
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() {
let mut last_character_state = let mut last_character_states =
ecs.write_storage::<comp::Last<comp::CharacterState>>(); ecs.write_storage::<comp::Last<comp::CharacterState>>();
if let Some(client_character_state) = if let Some(client_character_state) =
ecs.read_storage::<comp::CharacterState>().get(entity) ecs.read_storage::<comp::CharacterState>().get(entity)
{ {
if last_character_state if last_character_states
.get(entity) .get(entity)
.map(|&l| l != *client_character_state) .map(|&l| {
std::mem::discriminant(&l.0.movement)
!= std::mem::discriminant(&client_character_state.movement)
|| std::mem::discriminant(&l.0.action)
!= std::mem::discriminant(&client_character_state.action)
})
.unwrap_or(true) .unwrap_or(true)
{ {
let _ = last_character_state let _ = last_character_states
.insert(entity, comp::Last(*client_character_state)); .insert(entity, comp::Last(*client_character_state));
} }
} }

View File

@ -7,9 +7,3 @@ pub struct Last<C: Component + PartialEq>(pub C);
impl<C: Component + Send + Sync + PartialEq> Component for Last<C> { impl<C: Component + Send + Sync + PartialEq> Component for Last<C> {
type Storage = VecStorage<Self>; type Storage = VecStorage<Self>;
} }
impl<C: Component + PartialEq> PartialEq<C> for Last<C> {
fn eq(&self, other: &C) -> bool {
self.0 == *other
}
}

View File

@ -1105,7 +1105,7 @@ impl Server {
if let Some(client_pos) = ecs.read_storage::<comp::Pos>().get(entity) { if let Some(client_pos) = ecs.read_storage::<comp::Pos>().get(entity) {
if last_pos if last_pos
.get(entity) .get(entity)
.map(|&l| l != *client_pos) .map(|&l| l.0 != *client_pos)
.unwrap_or(true) .unwrap_or(true)
{ {
let _ = last_pos.insert(entity, comp::Last(*client_pos)); let _ = last_pos.insert(entity, comp::Last(*client_pos));
@ -1123,7 +1123,7 @@ impl Server {
if let Some(client_vel) = ecs.read_storage::<comp::Vel>().get(entity) { if let Some(client_vel) = ecs.read_storage::<comp::Vel>().get(entity) {
if last_vel if last_vel
.get(entity) .get(entity)
.map(|&l| l != *client_vel) .map(|&l| l.0 != *client_vel)
.unwrap_or(true) .unwrap_or(true)
{ {
let _ = last_vel.insert(entity, comp::Last(*client_vel)); let _ = last_vel.insert(entity, comp::Last(*client_vel));
@ -1141,7 +1141,7 @@ impl Server {
if let Some(client_ori) = ecs.read_storage::<comp::Ori>().get(entity) { if let Some(client_ori) = ecs.read_storage::<comp::Ori>().get(entity) {
if last_ori if last_ori
.get(entity) .get(entity)
.map(|&l| l != *client_ori) .map(|&l| l.0 != *client_ori)
.unwrap_or(true) .unwrap_or(true)
{ {
let _ = last_ori.insert(entity, comp::Last(*client_ori)); let _ = last_ori.insert(entity, comp::Last(*client_ori));
@ -1161,7 +1161,13 @@ impl Server {
{ {
if last_character_state if last_character_state
.get(entity) .get(entity)
.map(|&l| l != *client_character_state) .map(|&l| {
// Check if enum item is the same without looking at the inner data
std::mem::discriminant(&l.0.movement)
!= std::mem::discriminant(&client_character_state.movement)
|| std::mem::discriminant(&l.0.action)
!= std::mem::discriminant(&client_character_state.action)
})
.unwrap_or(true) .unwrap_or(true)
{ {
let _ = let _ =

View File

@ -691,10 +691,15 @@ 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();
} }
if last_character.0.action != character.action {
if std::mem::discriminant(&last_character.0.action)
!= std::mem::discriminant(&character.action)
{
state.last_action_change = Instant::now(); state.last_action_change = Instant::now();
} }
@ -702,7 +707,7 @@ impl FigureMgr {
state.last_movement_change.elapsed().as_secs_f64(); state.last_movement_change.elapsed().as_secs_f64();
let time_since_action_change = state.last_action_change.elapsed().as_secs_f64(); let time_since_action_change = state.last_action_change.elapsed().as_secs_f64();
let target_base = match dbg!(&character).movement { let target_base = match &character.movement {
Stand => anim::character::StandAnimation::update_skeleton( Stand => anim::character::StandAnimation::update_skeleton(
&CharacterSkeleton::new(), &CharacterSkeleton::new(),
time, time,