Make falldamage local, don't use force update for local, cleanup

This commit is contained in:
timokoesters
2019-08-25 20:31:56 +02:00
parent eb34e5bb27
commit 05f2f168fd
4 changed files with 17 additions and 29 deletions

View File

@ -6,13 +6,10 @@ use vek::*;
pub enum LocalEvent { pub enum LocalEvent {
Jump(EcsEntity), Jump(EcsEntity),
LandOnGround { entity: EcsEntity, vel: Vec3<f32> },
} }
pub enum ServerEvent { pub enum ServerEvent {
LandOnGround {
entity: EcsEntity,
vel: Vec3<f32>,
},
Explosion { Explosion {
pos: Vec3<f32>, pos: Vec3<f32>,
radius: f32, radius: f32,

View File

@ -318,18 +318,22 @@ impl State {
// Process local events // Process local events
let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all(); let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all();
for event in events { for event in events {
{ let mut velocities = self.ecs.write_storage::<comp::Vel>();
let mut velocities = self.ecs.write_storage::<comp::Vel>(); match event {
let mut force_updates = self.ecs.write_storage::<comp::ForceUpdate>(); LocalEvent::LandOnGround { entity, vel } => {
if let Some(stats) = self.ecs.write_storage::<comp::Stats>().get_mut(entity) {
match event { let falldmg = (vel.z / 1.5 + 10.0) as i32;
LocalEvent::Jump(entity) => { if falldmg < 0 {
if let Some(vel) = velocities.get_mut(entity) { stats.health.change_by(falldmg, comp::HealthSource::World);
vel.0.z = HUMANOID_JUMP_ACCEL;
let _ = force_updates.insert(entity, comp::ForceUpdate);
} }
} }
} }
LocalEvent::Jump(entity) => {
if let Some(vel) = velocities.get_mut(entity) {
vel.0.z = HUMANOID_JUMP_ACCEL;
}
}
} }
} }
} }

View File

@ -1,7 +1,7 @@
use { use {
crate::{ crate::{
comp::{Body, MovementState::*, Ori, PhysicsState, Pos, Scale, Stats, Vel}, comp::{Body, MovementState::*, Ori, PhysicsState, Pos, Scale, Stats, Vel},
event::{EventBus, ServerEvent}, event::{EventBus, LocalEvent},
state::DeltaTime, state::DeltaTime,
terrain::TerrainMap, terrain::TerrainMap,
vol::{ReadVol, Vox}, vol::{ReadVol, Vox},
@ -34,7 +34,7 @@ impl<'a> System<'a> for Sys {
Entities<'a>, Entities<'a>,
ReadExpect<'a, TerrainMap>, ReadExpect<'a, TerrainMap>,
Read<'a, DeltaTime>, Read<'a, DeltaTime>,
Read<'a, EventBus<ServerEvent>>, Read<'a, EventBus<LocalEvent>>,
ReadStorage<'a, Scale>, ReadStorage<'a, Scale>,
ReadStorage<'a, Body>, ReadStorage<'a, Body>,
WriteStorage<'a, PhysicsState>, WriteStorage<'a, PhysicsState>,
@ -211,7 +211,7 @@ impl<'a> System<'a> for Sys {
on_ground = true; on_ground = true;
if !was_on_ground { if !was_on_ground {
event_emitter.emit(ServerEvent::LandOnGround { entity, vel: vel.0 }); event_emitter.emit(LocalEvent::LandOnGround { entity, vel: vel.0 });
} }
} }

View File

@ -243,19 +243,6 @@ impl Server {
let clients = &mut self.clients; let clients = &mut self.clients;
match event { match event {
ServerEvent::LandOnGround { entity, vel } => {
if let Some(stats) = state
.ecs_mut()
.write_storage::<comp::Stats>()
.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 } => { ServerEvent::Explosion { pos, radius } => {
const RAYS: usize = 500; const RAYS: usize = 500;