From 687a042cfa3d1feb9f8a57e9e7a0318af89f115e Mon Sep 17 00:00:00 2001 From: telastrus <10052313+telastrus@users.noreply.github.com> Date: Tue, 6 Aug 2019 17:51:13 -0400 Subject: [PATCH 1/2] fall damage + velocity debug --- common/src/comp/mod.rs | 2 +- common/src/comp/stats.rs | 1 + common/src/sys/phys.rs | 12 +++++++++++- voxygen/src/hud/mod.rs | 17 +++++++++++++++-- voxygen/src/session.rs | 12 +++++++++++- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/common/src/comp/mod.rs b/common/src/comp/mod.rs index bee5458a2c..aed36d9585 100644 --- a/common/src/comp/mod.rs +++ b/common/src/comp/mod.rs @@ -8,7 +8,7 @@ mod inventory; mod last; mod phys; mod player; -mod stats; +pub mod stats; mod visual; // Reexports diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index 771a8d5b1c..87dbfa7412 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -6,6 +6,7 @@ use specs_idvs::IDVStorage; pub enum HealthSource { Attack { by: Uid }, // TODO: Implement weapon Suicide, + World, //ZA WARUDO! Revive, Command, LevelUp, diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 8d6a072ab6..b2267ebcdb 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -1,4 +1,5 @@ use crate::{ + comp::HealthSource, comp::{ ActionState, Body, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Scale, Stats, Vel, Wielding, @@ -41,6 +42,7 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, Pos>, WriteStorage<'a, Vel>, WriteStorage<'a, Ori>, + WriteStorage<'a, Stats>, ); fn run( @@ -56,10 +58,11 @@ impl<'a> System<'a> for Sys { mut positions, mut velocities, mut orientations, + mut stats, ): Self::SystemData, ) { // Apply movement inputs - for (entity, a, scale, _, mut pos, mut vel, mut ori) in ( + for (entity, a, scale, b, mut pos, mut vel, mut ori, mut stat) in ( &entities, &action_states, scales.maybe(), @@ -67,6 +70,7 @@ impl<'a> System<'a> for Sys { &mut positions, &mut velocities, &mut orientations, + &mut stats, ) .join() { @@ -206,6 +210,12 @@ impl<'a> System<'a> for Sys { // When the resolution direction is pointing upwards, we must be on the ground if resolve_dir.z > 0.0 && vel.0.z <= 0.0 { + //check for fall damage + let falldmg = (vel.0.z / 1.5 + 6.0) as i32; + if falldmg < 0 { + //println!("fall damage: {}", falldmg); + stat.health.change_by(falldmg, HealthSource::World); + } on_ground = true; } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 5251416430..f15e559b0d 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -82,6 +82,7 @@ widget_ids! { fps_counter, ping, coordinates, + velocity, loaded_distance, // Game Version @@ -127,6 +128,7 @@ pub struct DebugInfo { pub tps: f64, pub ping_ms: f64, pub coordinates: Option, + pub velocity: Option, } pub enum Event { @@ -498,7 +500,7 @@ impl Hud { .font_id(self.fonts.opensans) .font_size(14) .set(self.ids.ping, ui_widgets); - // Players position + // Player's position let coordinates_text = match debug_info.coordinates { Some(coordinates) => format!("Coordinates: {:.1}", coordinates.0), None => "Player has no Pos component".to_owned(), @@ -509,13 +511,24 @@ impl Hud { .font_id(self.fonts.opensans) .font_size(14) .set(self.ids.coordinates, ui_widgets); + //Player's velocity + let velocity_text = match debug_info.velocity { + Some(velocity) => format!("Velocity: {:.1}", velocity.0), + None => "Player has no Vel component".to_owned(), + }; + Text::new(&velocity_text) + .color(TEXT_COLOR) + .down_from(self.ids.coordinates, 5.0) + .font_id(self.fonts.opensans) + .font_size(14) + .set(self.ids.velocity, ui_widgets); // Loaded distance Text::new(&format!( "View distance: {} chunks", client.loaded_distance().unwrap_or(0) )) .color(TEXT_COLOR) - .down_from(self.ids.coordinates, 5.0) + .down_from(self.ids.velocity, 5.0) .font_id(self.fonts.opensans) .font_size(14) .set(self.ids.loaded_distance, ui_widgets); diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index f593086784..36cd3d995f 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -7,7 +7,9 @@ use crate::{ Direction, Error, GlobalState, PlayState, PlayStateResult, }; use client::{self, Client}; -use common::{clock::Clock, comp, comp::Pos, msg::ClientState, terrain::Block, vol::ReadVol}; +use common::{ + clock::Clock, comp, comp::Pos, comp::Vel, msg::ClientState, terrain::Block, vol::ReadVol, +}; use log::error; use specs::Join; use std::{cell::RefCell, rc::Rc, time::Duration}; @@ -287,6 +289,14 @@ impl PlayState for SessionState { .read_storage::() .get(self.client.borrow().entity()) .cloned(), + velocity: self + .client + .borrow() + .state() + .ecs() + .read_storage::() + .get(self.client.borrow().entity()) + .cloned(), }, &self.scene.camera(), ); From b05f99d80909852f17c9cce38cbd40415b443163 Mon Sep 17 00:00:00 2001 From: telastrus <4415544-telastrus@users.noreply.gitlab.com> Date: Tue, 6 Aug 2019 22:26:24 -0400 Subject: [PATCH 2/2] undo unnecessary pub mod fixed comments fixed other comment --- common/src/comp/mod.rs | 2 +- common/src/comp/stats.rs | 2 +- common/src/sys/phys.rs | 3 +-- voxygen/src/hud/mod.rs | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/common/src/comp/mod.rs b/common/src/comp/mod.rs index aed36d9585..bee5458a2c 100644 --- a/common/src/comp/mod.rs +++ b/common/src/comp/mod.rs @@ -8,7 +8,7 @@ mod inventory; mod last; mod phys; mod player; -pub mod stats; +mod stats; mod visual; // Reexports diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index 87dbfa7412..a6c5d189fc 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -6,7 +6,7 @@ use specs_idvs::IDVStorage; pub enum HealthSource { Attack { by: Uid }, // TODO: Implement weapon Suicide, - World, //ZA WARUDO! + World, Revive, Command, LevelUp, diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index b2267ebcdb..de3045b0a6 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -210,10 +210,9 @@ impl<'a> System<'a> for Sys { // When the resolution direction is pointing upwards, we must be on the ground if resolve_dir.z > 0.0 && vel.0.z <= 0.0 { - //check for fall damage + // Check for fall damage let falldmg = (vel.0.z / 1.5 + 6.0) as i32; if falldmg < 0 { - //println!("fall damage: {}", falldmg); stat.health.change_by(falldmg, HealthSource::World); } on_ground = true; diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index f15e559b0d..95ca203571 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -511,7 +511,7 @@ impl Hud { .font_id(self.fonts.opensans) .font_size(14) .set(self.ids.coordinates, ui_widgets); - //Player's velocity + // Player's velocity let velocity_text = match debug_info.velocity { Some(velocity) => format!("Velocity: {:.1}", velocity.0), None => "Player has no Vel component".to_owned(),