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
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
4 changed files with 17 additions and 29 deletions

View File

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

View File

@ -318,18 +318,22 @@ impl State {
// Process local events
let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all();
for event in events {
{
let mut velocities = self.ecs.write_storage::<comp::Vel>();
let mut force_updates = self.ecs.write_storage::<comp::ForceUpdate>();
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::<comp::Vel>();
match event {
LocalEvent::LandOnGround { entity, vel } => {
if let Some(stats) = self.ecs.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);
}
}
}
LocalEvent::Jump(entity) => {
if let Some(vel) = velocities.get_mut(entity) {
vel.0.z = HUMANOID_JUMP_ACCEL;
}
}
}
}
}

View File

@ -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<ServerEvent>>,
Read<'a, EventBus<LocalEvent>>,
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 });
}
}

View File

@ -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::<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 } => {
const RAYS: usize = 500;