diff --git a/common/src/comp/animation.rs b/common/src/comp/animation.rs index 72c8bc56c4..c31761424d 100644 --- a/common/src/comp/animation.rs +++ b/common/src/comp/animation.rs @@ -17,8 +17,8 @@ pub struct AnimationInfo { pub changed: bool, } -impl AnimationInfo { - pub fn new() -> Self { +impl Default for AnimationInfo { + fn default() -> Self { Self { animation: Animation::Idle, time: 0.0, diff --git a/common/src/sys/inputs.rs b/common/src/sys/inputs.rs index 6f0a4f267b..1f3c74abb3 100644 --- a/common/src/sys/inputs.rs +++ b/common/src/sys/inputs.rs @@ -127,7 +127,7 @@ impl<'a> System<'a> for Sys { let last = animation_infos .get_mut(entity) .cloned() - .unwrap_or(AnimationInfo::new()); + .unwrap_or(AnimationInfo::default()); let changed = last.animation != animation; animation_infos.insert( @@ -149,6 +149,7 @@ impl<'a> System<'a> for Sys { { // Check if it is a hit if entity != b + && !stat_b.is_dead() && pos.0.distance_squared(pos_b.0) < 50.0 && dir.0.angle_between(pos_b.0 - pos.0).to_degrees() < 70.0 { diff --git a/server/src/lib.rs b/server/src/lib.rs index 99f3d118b8..b9e3fb4ce9 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -139,6 +139,7 @@ impl Server { .with(comp::Control::default()) .with(comp::phys::Vel(Vec3::zero())) .with(comp::phys::Dir(Vec3::unit_y())) + .with(comp::AnimationInfo::default()) .with(comp::Actor::Character { name, body }) .with(comp::Stats::default()) } @@ -155,7 +156,7 @@ impl Server { state.write_component(entity, comp::Actor::Character { name, body }); state.write_component(entity, comp::Stats::default()); state.write_component(entity, comp::Control::default()); - state.write_component(entity, comp::AnimationInfo::new()); + state.write_component(entity, comp::AnimationInfo::default()); state.write_component(entity, comp::phys::Pos(spawn_point)); state.write_component(entity, comp::phys::Vel(Vec3::zero())); state.write_component(entity, comp::phys::Dir(Vec3::unit_y())); @@ -569,18 +570,35 @@ impl Server { // Save player metadata (for example the username). state.write_component(entity, player); - // Sync logical information other players have authority over, not the server. - for (other_entity, &uid, &animation_info) in ( + // Sync physics + for (entity, &uid, &pos, &vel, &dir) in ( &state.ecs().entities(), - &state.ecs().read_storage::(), + &state.ecs().read_storage::(), + &state.ecs().read_storage::(), + &state.ecs().read_storage::(), + &state.ecs().read_storage::(), + ) + .join() + { + client.notify(ServerMsg::EntityPhysics { + entity: uid.into(), + pos, + vel, + dir, + }); + } + + // Sync animations + for (entity, &uid, &animation_info) in ( + &state.ecs().entities(), + &state.ecs().read_storage::(), &state.ecs().read_storage::(), ) .join() { - // Animation client.notify(ServerMsg::EntityAnimation { entity: uid.into(), - animation_info: animation_info, + animation_info: animation_info.clone(), }); } @@ -594,7 +612,7 @@ impl Server { self.clients .notify_registered(ServerMsg::EcsSync(self.state.ecs_mut().next_sync_package())); - // Sync 'physical' state. + // Sync physics for (entity, &uid, &pos, &vel, &dir, force_update) in ( &self.state.ecs().entities(), &self.state.ecs().read_storage::(), @@ -616,27 +634,32 @@ impl Server { }; match force_update { - Some(_) => self.clients.notify_ingame(msg), - None => self.clients.notify_ingame_except(entity, msg), + Some(_) => self.clients.notify_registered(msg), + None => self.clients.notify_registered_except(entity, msg), } } - // Sync animation. - for (entity, &uid, &animation_info) in ( + // Sync animations + for (entity, &uid, &animation_info, force_update) in ( &self.state.ecs().entities(), &self.state.ecs().read_storage::(), &self.state.ecs().read_storage::(), + self.state + .ecs() + .read_storage::() + .maybe(), ) .join() { - if animation_info.changed { - self.clients.notify_ingame_except( - entity, - ServerMsg::EntityAnimation { - entity: uid.into(), - animation_info: animation_info.clone(), - }, - ); + if animation_info.changed || force_update.is_some() { + let msg = ServerMsg::EntityAnimation { + entity: uid.into(), + animation_info: animation_info.clone(), + }; + match force_update { + Some(_) => self.clients.notify_registered(msg), + None => self.clients.notify_registered_except(entity, msg), + } } } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 1599027ba6..032e214275 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -335,15 +335,10 @@ impl Hud { .resolution(100.0) .set(id, ui_widgets); } - for (pos, hp) in (&entities, &pos, &stats) + + for (entity, pos, stats) in (&entities, &pos, &stats) .join() - .filter_map(|(entity, pos, stats)| { - if entity != me { - Some((pos.0, stats.hp)) - } else { - None - } - }) + .filter(|(entity, _, stats)| *entity != me && !stats.is_dead()) { let back_id = health_back_id_walker.next( &mut self.ids.health_bar_backs, @@ -356,17 +351,20 @@ impl Hud { // Healh Bar Rectangle::fill_with([120.0, 8.0], Color::Rgba(0.3, 0.3, 0.3, 0.5)) .x_y(0.0, -25.0) - .position_ingame(pos + Vec3::new(0.0, 0.0, 3.0)) + .position_ingame(pos.0 + Vec3::new(0.0, 0.0, 3.0)) .resolution(100.0) .set(back_id, ui_widgets); // Filling Rectangle::fill_with( - [120.0 * (hp.current as f64 / hp.maximum as f64), 8.0], + [ + 120.0 * (stats.hp.current as f64 / stats.hp.maximum as f64), + 8.0, + ], HP_COLOR, ) .x_y(0.0, -25.0) - .position_ingame(pos + Vec3::new(0.0, 0.0, 3.0)) + .position_ingame(pos.0 + Vec3::new(0.0, 0.0, 3.0)) .resolution(100.0) .set(bar_id, ui_widgets); } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index e6ccc2707c..60bf43c0ad 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -461,15 +461,15 @@ impl FigureMgr { let tick = client.get_tick(); let ecs = client.state().ecs(); - for (entity, actor, stats) in ( + for (entity, actor, stat) in ( &ecs.entities(), &ecs.read_storage::(), &ecs.read_storage::(), // Just to make sure the entity is alive ) .join() { - if stats.is_dead() { - return; + if stat.is_dead() { + //return; } match actor { @@ -487,6 +487,8 @@ impl FigureMgr { let model = self.model_cache.get_or_create_model(renderer, *body, tick); renderer.render_figure(model, globals, locals, bone_consts); + } else { + panic!(); } } } diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index b3d1d6372a..1b51b9d4f0 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -156,10 +156,6 @@ impl PlayState for SessionState { // Maintain global state global_state.maintain(); - // Maintain the scene. - self.scene - .maintain(global_state.window.renderer_mut(), &self.client.borrow()); - // extract HUD events ensuring the client borrow gets dropped let hud_events = self.hud.maintain( &self.client.borrow(), @@ -201,7 +197,10 @@ impl PlayState for SessionState { } } } - {} + + // Maintain the scene. + self.scene + .maintain(global_state.window.renderer_mut(), &self.client.borrow()); // Render the session. self.render(global_state.window.renderer_mut());