diff --git a/common/net/src/sync/packet.rs b/common/net/src/sync/packet.rs index e57bf03a2e..084f602581 100644 --- a/common/net/src/sync/packet.rs +++ b/common/net/src/sync/packet.rs @@ -101,26 +101,26 @@ pub enum CompUpdateKind { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct EntityPackage { - pub uid: u64, + pub uid: Uid, pub comps: Vec

, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct EntitySyncPackage { - pub created_entities: Vec, - pub deleted_entities: Vec, + pub created_entities: Vec, + pub deleted_entities: Vec, } impl EntitySyncPackage { pub fn new( uids: &ReadStorage<'_, Uid>, uid_tracker: &UpdateTracker, filter: impl Join + Copy, - deleted_entities: Vec, + deleted_entities: Vec, ) -> Self { // Add created and deleted entities let created_entities = (uids, filter, uid_tracker.inserted()) .join() - .map(|(uid, _, _)| (*uid).into()) + .map(|(uid, _, _)| *uid) .collect(); Self { diff --git a/common/net/src/sync/sync_ext.rs b/common/net/src/sync/sync_ext.rs index 7f4d8d5430..d0f842c224 100644 --- a/common/net/src/sync/sync_ext.rs +++ b/common/net/src/sync/sync_ext.rs @@ -146,8 +146,7 @@ impl WorldSyncExt for specs::World { // Private utilities // // Only used on the client. -fn create_entity_with_uid(specs_world: &mut specs::World, entity_uid: u64) -> specs::Entity { - let entity_uid = Uid::from(entity_uid); +fn create_entity_with_uid(specs_world: &mut specs::World, entity_uid: Uid) -> specs::Entity { let existing_entity = specs_world.read_resource::().uid_entity(entity_uid); // TODO: Are there any expected cases where there is an existing entity with diff --git a/common/src/region.rs b/common/src/region.rs index 84926fdc5b..d01b026268 100644 --- a/common/src/region.rs +++ b/common/src/region.rs @@ -7,6 +7,9 @@ use vek::*; pub enum Event { // Contains the key of the region the entity moved to + // TODO: We only actually use the info from this when the entity moves to another region and + // isn't deleted, but we still generate and process these events in the case where the entity + // was deleted. Left(u32, Option>), // Contains the key of the region the entity came from Entered(u32, Option>), @@ -147,7 +150,8 @@ impl RegionMap { // component) TODO: distribute this between ticks None => { // TODO: shouldn't there be a way to extract the bitset of entities with - // positions directly from specs? + // positions directly from specs? Yes, with `.mask()` on the component + // storage. entities_to_remove.push((i, id)); }, } diff --git a/server/src/sys/entity_sync.rs b/server/src/sys/entity_sync.rs index dd8cbe1f9d..aa93568117 100644 --- a/server/src/sys/entity_sync.rs +++ b/server/src/sys/entity_sync.rs @@ -8,7 +8,6 @@ use common::{ region::{Event as RegionEvent, RegionMap}, resources::{PlayerPhysicsSettings, Time, TimeOfDay, TimeScale}, terrain::TerrainChunkSize, - uid::Uid, vol::RectVolSize, }; use common_ecs::{Job, Origin, Phase, System}; @@ -192,7 +191,8 @@ impl<'a> System<'a> for Sys { .unwrap_or(true) { // TODO: I suspect it would be more efficient (in terms of - // bandwidth) to batch messages like this. + // bandwidth) to batch messages like this (same in + // subscription.rs). client.send_fallible(ServerGeneral::DeleteEntity(uid)); } } @@ -352,7 +352,7 @@ impl<'a> System<'a> for Sys { }) { for uid in &deleted { - client.send_fallible(ServerGeneral::DeleteEntity(Uid(*uid))); + client.send_fallible(ServerGeneral::DeleteEntity(*uid)); } } } diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index a73cbb96b5..1ac783a20d 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -80,7 +80,6 @@ macro_rules! trackers { vel: Option, ori: Option, ) -> EntityPackage { - let uid = uid.0; let mut comps = Vec::new(); // NOTE: we could potentially include a bitmap indicating which components are present instead of tagging // components with the type in order to save bandwidth @@ -208,7 +207,7 @@ macro_rules! trackers { &self, comps: &TrackedStorages, filter: impl Join + Copy, - deleted_entities: Vec, + deleted_entities: Vec, ) -> (EntitySyncPackage, CompSyncPackage) { let entity_sync_package = EntitySyncPackage::new(&comps.uid, &self.uid, filter, deleted_entities); @@ -280,7 +279,7 @@ common_net::synced_components!(trackers); /// Deleted entities grouped by region pub struct DeletedEntities { - map: HashMap, Vec>, + map: HashMap, Vec>, } impl Default for DeletedEntities { @@ -293,18 +292,18 @@ impl Default for DeletedEntities { impl DeletedEntities { pub fn record_deleted_entity(&mut self, uid: Uid, region_key: Vec2) { - self.map.entry(region_key).or_default().push(uid.into()); + self.map.entry(region_key).or_default().push(uid); } - pub fn take_deleted_in_region(&mut self, key: Vec2) -> Vec { + pub fn take_deleted_in_region(&mut self, key: Vec2) -> Vec { self.map.remove(&key).unwrap_or_default() } - pub fn get_deleted_in_region(&self, key: Vec2) -> &[u64] { + pub fn get_deleted_in_region(&self, key: Vec2) -> &[Uid] { self.map.get(&key).map_or(&[], |v| v.as_slice()) } - pub fn take_remaining_deleted(&mut self) -> impl Iterator, Vec)> + '_ { + pub fn take_remaining_deleted(&mut self) -> impl Iterator, Vec)> + '_ { self.map.drain() } } diff --git a/server/src/sys/subscription.rs b/server/src/sys/subscription.rs index 3b20bde524..1b585d6def 100644 --- a/server/src/sys/subscription.rs +++ b/server/src/sys/subscription.rs @@ -135,10 +135,10 @@ impl<'a> System<'a> for Sys { // TODO: consider changing system ordering?? for event in region.events() { match event { - RegionEvent::Entered(_, _) => {}, /* These don't need to be */ - // processed because this - // region is being thrown out - // anyway + RegionEvent::Entered(_, _) => { + // These don't need to be processed because + // this region is being thrown out anyway + }, RegionEvent::Left(id, maybe_key) => { // Lookup UID for entity // Doesn't overlap with entity deletion in sync packages @@ -147,7 +147,9 @@ impl<'a> System<'a> for Sys { if let Some(&uid) = uids.get(entities.entity(*id)) { if !maybe_key .as_ref() - // Don't need to check that this isn't also in the regions to remove since the entity will be removed when we get to that one + // Don't need to check that this isn't also in the + // regions to remove since the entity will be removed + // when we get to that one. .map(|key| subscription.regions.contains(key)) .unwrap_or(false) { @@ -162,10 +164,10 @@ impl<'a> System<'a> for Sys { client.send_fallible(ServerGeneral::DeleteEntity(uid)); } } - // Send deleted entities since they won't be processed for this client in entity - // sync + // Send deleted entities since they won't be processed for this client + // in entity sync for uid in deleted_entities.get_deleted_in_region(key).iter() { - client.send_fallible(ServerGeneral::DeleteEntity(Uid(*uid))); + client.send_fallible(ServerGeneral::DeleteEntity(*uid)); } } @@ -195,6 +197,7 @@ impl<'a> System<'a> for Sys { ori.copied(), ) }) + // TODO: batch this into a single message .for_each(|msg| { // Send message to create entity and tracked components and // physics components