Simplify code

Former-commit-id: c8bdf4199c913ab43ba08fdb19384bf7fcc6653d
This commit is contained in:
timokoesters 2019-04-17 20:06:06 +02:00
parent 932d43a2fc
commit a45d9db205
2 changed files with 11 additions and 17 deletions

View File

@ -169,12 +169,10 @@ impl Client {
// Update the server about the player's currently playing animation and the previous one // Update the server about the player's currently playing animation and the previous one
if let Some(animationHistory) = self.state.read_storage::<comp::AnimationHistory>().get(self.player).cloned() { if let Some(animationHistory) = self.state.read_storage::<comp::AnimationHistory>().get(self.player).cloned() {
if let Some(last) = animationHistory.last { if Some(animationHistory.current) != animationHistory.last {
if animationHistory.current != last {
self.postbox.send_message(ClientMsg::PlayerAnimation(animationHistory)); self.postbox.send_message(ClientMsg::PlayerAnimation(animationHistory));
} }
} }
}
// Request chunks from the server // Request chunks from the server
if let Some(pos) = self.state.read_storage::<comp::phys::Pos>().get(self.player) { if let Some(pos) = self.state.read_storage::<comp::phys::Pos>().get(self.player) {

View File

@ -374,9 +374,8 @@ impl Server {
&self.state.ecs().internal().read_storage::<Uid>(), &self.state.ecs().internal().read_storage::<Uid>(),
&self.state.ecs().internal().read_storage::<comp::AnimationHistory>(), &self.state.ecs().internal().read_storage::<comp::AnimationHistory>(),
).join() { ).join() {
if let Some(last) = animationHistory.last {
// Check if we need to sync // Check if we need to sync
if animationHistory.current == last { if Some(animationHistory.current) == animationHistory.last {
continue; continue;
} }
@ -385,16 +384,13 @@ impl Server {
animationHistory, animationHistory,
}); });
} }
}
// Update animation last/current state // Update animation last/current state
for (entity, mut animationHistory) in ( for (entity, mut animationHistory) in (
&self.state.ecs().internal().entities(), &self.state.ecs().internal().entities(),
&mut self.state.ecs().internal().write_storage::<comp::AnimationHistory>() &mut self.state.ecs().internal().write_storage::<comp::AnimationHistory>()
).join() { ).join() {
animationHistory.last = None; animationHistory.last = Some(animationHistory.current);
let mut new = animationHistory.clone();
new.last = Some(new.current);
} }
// Remove all force flags // Remove all force flags