Stop syncing health change timer updates

This commit is contained in:
Imbris 2019-12-01 16:54:21 -05:00 committed by Imbris
parent d341073a44
commit 8f7323f41b
6 changed files with 39 additions and 14 deletions

2
Cargo.lock generated
View File

@ -3062,7 +3062,7 @@ dependencies = [
[[package]]
name = "specs-idvs"
version = "0.1.0"
source = "git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15#55547cdf1358c667ac8a7d4c79857143bde2843c"
source = "git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15#f049bf725f2a690d01ea8a83da49c7ebf8d8ea2a"
dependencies = [
"hibitset 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", branch = "imbris/specs-15" }
specs = { version = "0.15.1", features = ["serde", "nightly"] }
specs = { version = "0.15.1", features = ["serde", "nightly", "storage-event-control"] }
vek = { version = "0.9.9", features = ["serde"] }
dot_vox = "4.0.0"
image = "0.22.3"

View File

@ -349,10 +349,13 @@ impl<'a> System<'a> for Sys {
&mut velocities,
&bodies,
!&mountings,
!&stickies, // Can't push stickies around
stickies.maybe(),
&mut physics_states,
)
.join()
.filter(|(_, _, _, _, _, _, sticky, physics)| {
sticky.is_none() || (physics.on_wall.is_none() && !physics.on_ground)
})
{
physics.touch_entity = None;

View File

@ -23,9 +23,25 @@ impl<'a> System<'a> for Sys {
) {
let mut server_event_emitter = server_event_bus.emitter();
// Increment last change timer
stats.set_event_emission(false); // avoid unnecessary syncing
for stat in (&mut stats).join() {
stat.health.last_change.0 += f64::from(dt.0);
}
stats.set_event_emission(true);
// Mutates all stats every tick causing the server to resend this component for every entity every tick
for (entity, mut stat) in (&entities, &mut stats).join() {
if stat.should_die() && !stat.is_dead {
for (entity, mut stats) in (&entities, &mut stats.restrict_mut()).join() {
let (set_dead, level_up) = {
let stat = stats.get_unchecked();
(
stat.should_die() && !stat.is_dead,
stat.exp.current() >= stat.exp.maximum(),
)
};
if set_dead {
let stat = stats.get_mut_unchecked();
server_event_emitter.emit(ServerEvent::Destroy {
entity,
cause: stat.health.last_change.1.cause,
@ -34,9 +50,8 @@ impl<'a> System<'a> for Sys {
stat.is_dead = true;
}
stat.health.last_change.0 += f64::from(dt.0);
if stat.exp.current() >= stat.exp.maximum() {
if level_up {
let stat = stats.get_mut_unchecked();
while stat.exp.current() >= stat.exp.maximum() {
stat.exp.change_by(-(stat.exp.maximum() as i64));
stat.exp.change_maximum_by(25);

View File

@ -36,8 +36,8 @@ use log::{debug, error};
use metrics::ServerMetrics;
use rand::Rng;
use specs::{
join::Join, world::EntityBuilder as EcsEntityBuilder, Builder, Entity as EcsEntity, SystemData,
WorldExt,
join::Join, world::EntityBuilder as EcsEntityBuilder, Builder, Entity as EcsEntity, RunNow,
SystemData, WorldExt,
};
use std::{
i32,
@ -831,7 +831,11 @@ impl Server {
// 3) Handle inputs from clients
frontend_events.append(&mut self.handle_new_connections()?);
// Run message recieving sys before the systems in common for decreased latency (e.g. run before controller system)
sys::message::Sys.run_now(&self.state.ecs());
let before_tick_4 = Instant::now();
// 4) Tick the server's LocalState.
self.state.tick(dt, sys::add_server_systems);
@ -897,11 +901,14 @@ impl Server {
self.metrics
.tick_time
.with_label_values(&["input"])
.set((before_tick_4 - before_tick_1).as_nanos() as i64);
.set((before_tick_4 - before_tick_1).as_nanos() as i64 - message_nanos);
self.metrics
.tick_time
.with_label_values(&["state tick"])
.set((before_handle_events - before_tick_4).as_nanos() as i64 - total_sys_nanos);
.set(
(before_handle_events - before_tick_4).as_nanos() as i64
- (total_sys_nanos - message_nanos),
);
self.metrics
.tick_time
.with_label_values(&["handle server events"])

View File

@ -21,9 +21,10 @@ const SENTINEL_SYS: &str = "sentinel_sys";
const SUBSCRIPTION_SYS: &str = "server_subscription_sys";
const TERRAIN_SYNC_SYS: &str = "server_terrain_sync_sys";
const TERRAIN_SYS: &str = "server_terrain_sys";
const MESSAGE_SYS: &str = "server_message_sys";
//const MESSAGE_SYS: &str = "server_message_sys";
pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) {
// TODO: makes some of these dependent on systems in common like the phys system
dispatch_builder.add(sentinel::Sys, SENTINEL_SYS, &[]);
dispatch_builder.add(subscription::Sys, SUBSCRIPTION_SYS, &[]);
dispatch_builder.add(
@ -33,7 +34,6 @@ pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) {
);
dispatch_builder.add(terrain_sync::Sys, TERRAIN_SYS, &[]);
dispatch_builder.add(terrain::Sys, TERRAIN_SYNC_SYS, &[TERRAIN_SYS]);
dispatch_builder.add(message::Sys, MESSAGE_SYS, &[]);
}
/// Used to keep track of how much time each system takes