Remove potential for client to delete its own entity.

Also:
* Fix some clippy warnings
* Remove unused clippy allow
* Document semantics of `DeletedEntities`
This commit is contained in:
Imbris 2023-06-03 14:24:04 -04:00
parent 65efa779b5
commit b8af76deff
4 changed files with 18 additions and 7 deletions

View File

@ -2251,9 +2251,10 @@ impl Client {
self.dt_adjustment = dt_adjustment * time_scale.0;
},
ServerGeneral::EntitySync(entity_sync_package) => {
let uid = self.uid();
self.state
.ecs_mut()
.apply_entity_sync_package(entity_sync_package);
.apply_entity_sync_package(entity_sync_package, uid);
},
ServerGeneral::CompSync(comp_sync_package, force_counter) => {
self.force_update_counter = force_counter;
@ -2739,7 +2740,6 @@ impl Client {
let client_uid = self
.uid()
.map(|u| u.into())
.expect("Client doesn't have a Uid!!!");
// Clear ecs of all entities

View File

@ -25,7 +25,7 @@ pub trait WorldSyncExt {
&mut self,
entity_package: EntityPackage<P>,
) -> specs::Entity;
fn apply_entity_sync_package(&mut self, package: EntitySyncPackage);
fn apply_entity_sync_package(&mut self, package: EntitySyncPackage, client_uid: Option<Uid>);
fn apply_comp_sync_package<P: CompPacket>(&mut self, package: CompSyncPackage<P>);
}
@ -103,7 +103,7 @@ impl WorldSyncExt for specs::World {
entity
}
fn apply_entity_sync_package(&mut self, package: EntitySyncPackage) {
fn apply_entity_sync_package(&mut self, package: EntitySyncPackage, client_uid: Option<Uid>) {
// Take ownership of the fields
let EntitySyncPackage {
created_entities,
@ -117,7 +117,13 @@ impl WorldSyncExt for specs::World {
// Attempt to delete entities that were marked for deletion
deleted_entities.into_iter().for_each(|uid| {
self.delete_entity_and_clear_from_id_maps(uid.into());
// Skip deleting the client's own entity. It will appear here when exiting
// "in-game" and the client already handles cleaning things up
// there. Although the client might not get this anyway since it
// should no longer be subscribed to any regions.
if client_uid != Some(uid) {
self.delete_entity_and_clear_from_id_maps(uid);
}
});
}

View File

@ -311,6 +311,8 @@ impl<'a> System<'a> for Sys {
}
}
// TODO: force update counter only needs to be sent with updates specifically
// for a client's own entity. We can save bandwidth here.
client.send_fallible(ServerGeneral::CompSync(
comp_sync_package,
force_updates.get(*client_entity).map_or(0, |f| f.counter()),

View File

@ -1,4 +1,3 @@
#![allow(clippy::large_enum_variant)]
use common::{
comp::{
item::{tool::AbilityMap, MaterialStatManifest},
@ -277,7 +276,11 @@ use common_net::synced_components::*;
// of components. This will declare the types defined in the macro above.
common_net::synced_components!(trackers);
/// Deleted entities grouped by region
/// Deleted entities grouped by region.
///
/// Note, this is primarily for syncing purposes and can include the Uid of
/// clients that have left "in-game" to return to the character screen (even
/// though there is still an entity with this Uid!).
pub struct DeletedEntities {
map: HashMap<Vec2<i32>, Vec<Uid>>,
}