diff --git a/src/core/replication/replicated_clients.rs b/src/core/replication/replicated_clients.rs index 615d01c7..1f80a46d 100644 --- a/src/core/replication/replicated_clients.rs +++ b/src/core/replication/replicated_clients.rs @@ -345,7 +345,7 @@ impl ReplicatedClient { /// /// Internal cleanup happens lazily during the iteration. pub(crate) fn drain_lost_visibility(&mut self) -> impl Iterator + '_ { - self.visibility.drain_lost_visibility().inspect(|entity| { + self.visibility.drain_lost().inspect(|entity| { self.mutation_ticks.remove(entity); }) } diff --git a/src/core/replication/replicated_clients/client_visibility.rs b/src/core/replication/replicated_clients/client_visibility.rs index f8632fc0..02f30968 100644 --- a/src/core/replication/replicated_clients/client_visibility.rs +++ b/src/core/replication/replicated_clients/client_visibility.rs @@ -121,7 +121,7 @@ impl ClientVisibility { } /// Drains all entities for which visibility was lost during this tick. - pub(super) fn drain_lost_visibility(&mut self) -> impl Iterator + '_ { + pub(super) fn drain_lost(&mut self) -> impl Iterator + '_ { match &mut self.filter { VisibilityFilter::All { .. } => VisibilityLostIter::AllVisible, VisibilityFilter::Blacklist { added, .. } => VisibilityLostIter::Lost(added.drain()), @@ -219,14 +219,14 @@ impl ClientVisibility { /// Checks if a specific entity is visible. pub fn is_visible(&self, entity: Entity) -> bool { - match self.visibility_state(entity) { + match self.state(entity) { Visibility::Hidden => false, Visibility::Gained | Visibility::Visible => true, } } /// Returns visibility of a specific entity. - pub(crate) fn visibility_state(&self, entity: Entity) -> Visibility { + pub(crate) fn state(&self, entity: Entity) -> Visibility { match &self.filter { VisibilityFilter::All => Visibility::Visible, VisibilityFilter::Blacklist { list, .. } => match list.get(&entity) { diff --git a/src/server.rs b/src/server.rs index b94b9997..5c2750d0 100644 --- a/src/server.rs +++ b/src/server.rs @@ -420,8 +420,11 @@ fn collect_despawns( for entity in despawn_buffer.drain(..) { let entity_range = serialized.write_entity(entity)?; for ((message, _), client) in messages.iter_mut().zip(replicated_clients.iter_mut()) { + let visibility = client.visibility().state(entity); + if visibility != Visibility::Hidden { + message.add_despawn(entity_range.clone()); + } client.remove_despawned(entity); - message.add_despawn(entity_range.clone()); } } @@ -487,7 +490,7 @@ fn collect_changes( for ((change_message, mutate_message), client) in messages.iter_mut().zip(replicated_clients.iter()) { - let visibility = client.visibility().visibility_state(entity.id()); + let visibility = client.visibility().state(entity.id()); change_message.start_entity_changes(visibility); mutate_message.start_entity_mutations(); }