Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not send despawns for hidden entities #366

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/replication/replicated_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ impl ReplicatedClient {
///
/// Internal cleanup happens lazily during the iteration.
pub(crate) fn drain_lost_visibility(&mut self) -> impl Iterator<Item = Entity> + '_ {
self.visibility.drain_lost_visibility().inspect(|entity| {
self.visibility.drain_lost().inspect(|entity| {
self.mutation_ticks.remove(entity);
})
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/replication/replicated_clients/client_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = Entity> + '_ {
pub(super) fn drain_lost(&mut self) -> impl Iterator<Item = Entity> + '_ {
match &mut self.filter {
VisibilityFilter::All { .. } => VisibilityLostIter::AllVisible,
VisibilityFilter::Blacklist { added, .. } => VisibilityLostIter::Lost(added.drain()),
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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();
}
Expand Down