From ab7740f378f143ac9be9a4f6139631b43b715160 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 6 Oct 2019 16:50:35 -0400 Subject: [PATCH] Fix not not sending updates outside a certain range and not sending character state when it changes due to update throttling --- server/src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/server/src/lib.rs b/server/src/lib.rs index 606b24c6ad..caeefac861 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1589,7 +1589,8 @@ impl Server { entity: EcsEntity, pos: comp::Pos, force_update, - clients: &mut Clients| { + clients: &mut Clients, + throttle: bool| { for (index, _, client_entity, client_pos) in &subscribers { match force_update { None if client_entity == &entity => {} @@ -1597,18 +1598,18 @@ impl Server { let distance_sq = client_pos.0.distance_squared(pos.0); // Throttle update rate based on distance to player - let update = if distance_sq < 100.0f32.powi(2) { + let update = if !throttle || distance_sq < 100.0f32.powi(2) { true // Closer than 100.0 blocks } else if distance_sq < 150.0f32.powi(2) { - tick + entity.id() as u64 % 2 == 0 + (tick + entity.id() as u64) % 2 == 0 } else if distance_sq < 200.0f32.powi(2) { - tick + entity.id() as u64 % 4 == 0 + (tick + entity.id() as u64) % 4 == 0 } else if distance_sq < 250.0f32.powi(2) { - tick + entity.id() as u64 % 8 == 0 + (tick + entity.id() as u64) % 8 == 0 } else if distance_sq < 300.0f32.powi(2) { - tick + entity.id() as u64 % 8 == 0 + (tick + entity.id() as u64) % 16 == 0 } else { - tick + entity.id() as u64 % 16 == 0 + (tick + entity.id() as u64) % 32 == 0 }; if update { @@ -1648,6 +1649,7 @@ impl Server { pos, force_update, clients, + true, ); } @@ -1663,6 +1665,7 @@ impl Server { pos, force_update, clients, + true, ); } } @@ -1679,6 +1682,7 @@ impl Server { pos, force_update, clients, + true, ); } } @@ -1699,6 +1703,7 @@ impl Server { pos, force_update, clients, + false, ); } }