From 1b768743426b1466db579bd5355687e679285caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Wed, 11 May 2022 21:50:14 +0200 Subject: [PATCH] renamings and using unstable sort according to a code review --- server/src/chunk_serialize.rs | 2 +- server/src/client.rs | 4 +++- server/src/lib.rs | 2 +- server/src/sys/chunk_serialize.rs | 8 ++++---- server/src/sys/msg/terrain.rs | 6 +++--- server/src/sys/terrain.rs | 6 +++--- server/src/sys/terrain_sync.rs | 6 +++--- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/server/src/chunk_serialize.rs b/server/src/chunk_serialize.rs index 9929f056fa..4986bd0f49 100644 --- a/server/src/chunk_serialize.rs +++ b/server/src/chunk_serialize.rs @@ -14,7 +14,7 @@ use vek::Vec2; /// send to MULTIPLE clients /// TODO: store a urgent flag and seperate even more, 5 ticks vs 5 seconds #[derive(Debug, PartialEq)] -pub struct ChunkSendQueue { +pub struct ChunkSendEntry { pub(crate) entity: Entity, pub(crate) chunk_key: Vec2, } diff --git a/server/src/client.rs b/server/src/client.rs index 3187fd0cc4..202790ad08 100644 --- a/server/src/client.rs +++ b/server/src/client.rs @@ -218,7 +218,9 @@ impl Client { pub(crate) fn terrain_params(&self) -> StreamParams { self.terrain_stream_params.clone() } - pub(crate) fn prepare_terrain( + /// Only used for Serialize Chunks in a SlowJob. + /// TODO: find a more elegant version for this invariant + pub(crate) fn prepare_chunk_update_msg( terrain_chunk_update: ServerGeneral, params: &StreamParams, ) -> PreparedMsg { diff --git a/server/src/lib.rs b/server/src/lib.rs index 852767f29a..aa702a788c 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -249,7 +249,7 @@ impl Server { state.ecs_mut().insert(Vec::::new()); state .ecs_mut() - .insert(EventBus::::default()); + .insert(EventBus::::default()); state.ecs_mut().insert(Locations::default()); state.ecs_mut().insert(LoginProvider::new( settings.auth_server_address.clone(), diff --git a/server/src/sys/chunk_serialize.rs b/server/src/sys/chunk_serialize.rs index 2325c31b3a..aa97fcb5b2 100644 --- a/server/src/sys/chunk_serialize.rs +++ b/server/src/sys/chunk_serialize.rs @@ -1,5 +1,5 @@ use crate::{ - chunk_serialize::{ChunkSendQueue, SerializedChunk}, + chunk_serialize::{ChunkSendEntry, SerializedChunk}, client::Client, metrics::NetworkRequestMetrics, presence::Presence, @@ -23,7 +23,7 @@ impl<'a> System<'a> for Sys { Read<'a, Tick>, ReadStorage<'a, Client>, ReadStorage<'a, Presence>, - ReadExpect<'a, EventBus>, + ReadExpect<'a, EventBus>, ReadExpect<'a, NetworkRequestMetrics>, ReadExpect<'a, SlowJobPool>, ReadExpect<'a, TerrainGrid>, @@ -119,7 +119,7 @@ impl<'a> System<'a> for Sys { let chunk_sender = chunk_sender.clone(); slow_jobs.spawn("CHUNK_SERIALIZER", move || { for (chunk, chunk_key, mut meta) in chunks { - let msg = Client::prepare_terrain( + let msg = Client::prepare_chunk_update_msg( ServerGeneral::TerrainChunkUpdate { key: chunk_key, chunk: Ok(SerializedTerrainChunk::via_heuristic( @@ -129,7 +129,7 @@ impl<'a> System<'a> for Sys { }, &meta.params, ); - meta.recipients.sort(); + meta.recipients.sort_unstable(); meta.recipients.dedup(); if let Err(e) = chunk_sender.send(SerializedChunk { lossy_compression: meta.lossy_compression, diff --git a/server/src/sys/msg/terrain.rs b/server/src/sys/msg/terrain.rs index 3fef026079..af91135db6 100644 --- a/server/src/sys/msg/terrain.rs +++ b/server/src/sys/msg/terrain.rs @@ -1,5 +1,5 @@ use crate::{ - chunk_serialize::ChunkSendQueue, client::Client, lod::Lod, metrics::NetworkRequestMetrics, + chunk_serialize::ChunkSendEntry, client::Client, lod::Lod, metrics::NetworkRequestMetrics, presence::Presence, ChunkRequest, }; use common::{ @@ -22,7 +22,7 @@ impl<'a> System<'a> for Sys { type SystemData = ( Entities<'a>, Read<'a, EventBus>, - ReadExpect<'a, EventBus>, + ReadExpect<'a, EventBus>, ReadExpect<'a, TerrainGrid>, ReadExpect<'a, Lod>, ReadExpect<'a, NetworkRequestMetrics>, @@ -86,7 +86,7 @@ impl<'a> System<'a> for Sys { if in_vd { if terrain.get_key_arc(key).is_some() { network_metrics.chunks_served_from_memory.inc(); - chunk_send_emitter.emit(ChunkSendQueue { + chunk_send_emitter.emit(ChunkSendEntry { chunk_key: key, entity, }); diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index c53cc4159c..967c20c2e5 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -7,7 +7,7 @@ use world::{IndexOwned, World}; use crate::{ chunk_generator::ChunkGenerator, - chunk_serialize::ChunkSendQueue, + chunk_serialize::ChunkSendEntry, client::Client, presence::{Presence, RepositionOnChunkLoad}, rtsim::RtSim, @@ -63,7 +63,7 @@ impl<'a> System<'a> for Sys { ReadExpect<'a, SlowJobPool>, ReadExpect<'a, IndexOwned>, ReadExpect<'a, Arc>, - ReadExpect<'a, EventBus>, + ReadExpect<'a, EventBus>, WriteExpect<'a, ChunkGenerator>, WriteExpect<'a, TerrainGrid>, Write<'a, TerrainChanges>, @@ -268,7 +268,7 @@ impl<'a> System<'a> for Sys { .magnitude_squared(); if adjusted_dist_sqr <= presence.view_distance.pow(2) { - chunk_send_emitter.emit(ChunkSendQueue { + chunk_send_emitter.emit(ChunkSendEntry { entity, chunk_key: key, }); diff --git a/server/src/sys/terrain_sync.rs b/server/src/sys/terrain_sync.rs index ad1bd95659..a12302b393 100644 --- a/server/src/sys/terrain_sync.rs +++ b/server/src/sys/terrain_sync.rs @@ -1,4 +1,4 @@ -use crate::{chunk_serialize::ChunkSendQueue, client::Client, presence::Presence}; +use crate::{chunk_serialize::ChunkSendEntry, client::Client, presence::Presence}; use common::{comp::Pos, event::EventBus, terrain::TerrainGrid}; use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::{CompressedData, ServerGeneral}; @@ -14,7 +14,7 @@ impl<'a> System<'a> for Sys { Entities<'a>, ReadExpect<'a, TerrainGrid>, Read<'a, TerrainChanges>, - ReadExpect<'a, EventBus>, + ReadExpect<'a, EventBus>, ReadStorage<'a, Pos>, ReadStorage<'a, Presence>, ReadStorage<'a, Client>, @@ -35,7 +35,7 @@ impl<'a> System<'a> for Sys { for (entity, presence, pos) in (&entities, &presences, &positions).join() { if super::terrain::chunk_in_vd(pos.0, *chunk_key, &terrain, presence.view_distance) { - chunk_send_emitter.emit(ChunkSendQueue { + chunk_send_emitter.emit(ChunkSendEntry { entity, chunk_key: *chunk_key, });