From 05f2f168fd36ced5f26b9c865f69006d53fc2c15 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Sun, 25 Aug 2019 20:31:56 +0200 Subject: [PATCH] Make falldamage local, don't use force update for local, cleanup --- common/src/event.rs | 5 +---- common/src/state.rs | 22 +++++++++++++--------- common/src/sys/phys.rs | 6 +++--- server/src/lib.rs | 13 ------------- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/common/src/event.rs b/common/src/event.rs index b655b645bd..fc081c3e01 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -6,13 +6,10 @@ use vek::*; pub enum LocalEvent { Jump(EcsEntity), + LandOnGround { entity: EcsEntity, vel: Vec3 }, } pub enum ServerEvent { - LandOnGround { - entity: EcsEntity, - vel: Vec3, - }, Explosion { pos: Vec3, radius: f32, diff --git a/common/src/state.rs b/common/src/state.rs index f6d9084ee7..6d18e06fea 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -318,18 +318,22 @@ impl State { // Process local events let events = self.ecs.read_resource::>().recv_all(); for event in events { - { - let mut velocities = self.ecs.write_storage::(); - let mut force_updates = self.ecs.write_storage::(); - - match event { - LocalEvent::Jump(entity) => { - if let Some(vel) = velocities.get_mut(entity) { - vel.0.z = HUMANOID_JUMP_ACCEL; - let _ = force_updates.insert(entity, comp::ForceUpdate); + let mut velocities = self.ecs.write_storage::(); + match event { + LocalEvent::LandOnGround { entity, vel } => { + if let Some(stats) = self.ecs.write_storage::().get_mut(entity) { + let falldmg = (vel.z / 1.5 + 10.0) as i32; + if falldmg < 0 { + stats.health.change_by(falldmg, comp::HealthSource::World); } } } + + LocalEvent::Jump(entity) => { + if let Some(vel) = velocities.get_mut(entity) { + vel.0.z = HUMANOID_JUMP_ACCEL; + } + } } } } diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 1d379dbb4c..cd16ee87a3 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -1,7 +1,7 @@ use { crate::{ comp::{Body, MovementState::*, Ori, PhysicsState, Pos, Scale, Stats, Vel}, - event::{EventBus, ServerEvent}, + event::{EventBus, LocalEvent}, state::DeltaTime, terrain::TerrainMap, vol::{ReadVol, Vox}, @@ -34,7 +34,7 @@ impl<'a> System<'a> for Sys { Entities<'a>, ReadExpect<'a, TerrainMap>, Read<'a, DeltaTime>, - Read<'a, EventBus>, + Read<'a, EventBus>, ReadStorage<'a, Scale>, ReadStorage<'a, Body>, WriteStorage<'a, PhysicsState>, @@ -211,7 +211,7 @@ impl<'a> System<'a> for Sys { on_ground = true; if !was_on_ground { - event_emitter.emit(ServerEvent::LandOnGround { entity, vel: vel.0 }); + event_emitter.emit(LocalEvent::LandOnGround { entity, vel: vel.0 }); } } diff --git a/server/src/lib.rs b/server/src/lib.rs index 5cb1b69d43..2c4eaf6ef2 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -243,19 +243,6 @@ impl Server { let clients = &mut self.clients; match event { - ServerEvent::LandOnGround { entity, vel } => { - if let Some(stats) = state - .ecs_mut() - .write_storage::() - .get_mut(entity) - { - let falldmg = (vel.z / 1.5 + 10.0) as i32; - if falldmg < 0 { - stats.health.change_by(falldmg, comp::HealthSource::World); - } - } - } - ServerEvent::Explosion { pos, radius } => { const RAYS: usize = 500;