diff --git a/client/src/lib.rs b/client/src/lib.rs index 0e2dc2c0f4..422bbdc6cd 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -10,9 +10,7 @@ pub use crate::error::Error; pub use authc::AuthClientError; pub use common_net::msg::ServerInfo; pub use specs::{ - join::Join, - saveload::{Marker, MarkerAllocator}, - Builder, DispatcherBuilder, Entity as EcsEntity, ReadStorage, World, WorldExt, + join::Join, Builder, DispatcherBuilder, Entity as EcsEntity, ReadStorage, World, WorldExt, }; use crate::addr::ConnectionArgs; @@ -2203,7 +2201,7 @@ impl Client { self.chat_mode = m; }, ServerGeneral::SetPlayerEntity(uid) => { - if let Some(entity) = self.state.ecs().entity_from_uid(uid.0) { + if let Some(entity) = self.state.ecs().entity_from_uid(uid) { let old_player_entity = mem::replace( &mut *self.state.ecs_mut().write_resource(), PlayerEntity(Some(entity)), @@ -2265,11 +2263,11 @@ impl Client { ServerGeneral::CreateEntity(entity_package) => { self.state.ecs_mut().apply_entity_package(entity_package); }, - ServerGeneral::DeleteEntity(entity) => { - if self.uid() != Some(entity) { + ServerGeneral::DeleteEntity(entity_uid) => { + if self.uid() != Some(entity_uid) { self.state .ecs_mut() - .delete_entity_and_clear_from_uid_allocator(entity.0); + .delete_entity_and_clear_from_uid_allocator(entity_uid); } }, ServerGeneral::Notification(n) => { diff --git a/common/net/src/sync/sync_ext.rs b/common/net/src/sync/sync_ext.rs index d32b4b049c..eed9032157 100644 --- a/common/net/src/sync/sync_ext.rs +++ b/common/net/src/sync/sync_ext.rs @@ -6,11 +6,7 @@ use common::{ resources::PlayerEntity, uid::{Uid, UidAllocator}, }; -use specs::{ - saveload::{MarkedBuilder, MarkerAllocator}, - world::Builder, - WorldExt, -}; +use specs::{world::Builder, WorldExt}; use tracing::error; pub trait WorldSyncExt { @@ -22,9 +18,9 @@ pub trait WorldSyncExt { where C::Storage: Default + specs::storage::Tracked; fn create_entity_synced(&mut self) -> specs::EntityBuilder; - fn delete_entity_and_clear_from_uid_allocator(&mut self, uid: u64); + fn delete_entity_and_clear_from_uid_allocator(&mut self, uid: Uid); fn uid_from_entity(&self, entity: specs::Entity) -> Option; - fn entity_from_uid(&self, uid: u64) -> Option; + fn entity_from_uid(&self, uid: Uid) -> Option; fn apply_entity_package( &mut self, entity_package: EntityPackage

, @@ -56,10 +52,15 @@ impl WorldSyncExt for specs::World { } fn create_entity_synced(&mut self) -> specs::EntityBuilder { - self.create_entity().marked::() + let builder = self.create_entity(); + let uid = builder + .world + .write_resource::() + .allocate(builder.entity, None); + builder.with(uid) } - fn delete_entity_and_clear_from_uid_allocator(&mut self, uid: u64) { + fn delete_entity_and_clear_from_uid_allocator(&mut self, uid: Uid) { // Clear from uid allocator let maybe_entity = self.write_resource::().remove_entity(uid); if let Some(entity) = maybe_entity { @@ -75,7 +76,7 @@ impl WorldSyncExt for specs::World { } /// Get an entity from a UID - fn entity_from_uid(&self, uid: u64) -> Option { + fn entity_from_uid(&self, uid: Uid) -> Option { self.read_resource::() .retrieve_entity_internal(uid) } @@ -108,7 +109,7 @@ 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_uid_allocator(uid); + self.delete_entity_and_clear_from_uid_allocator(uid.into()); }); } @@ -118,7 +119,7 @@ impl WorldSyncExt for specs::World { package.comp_updates.into_iter().for_each(|(uid, update)| { if let Some(entity) = self .read_resource::() - .retrieve_entity_internal(uid) + .retrieve_entity_internal(uid.into()) { let force_update = player_entity == Some(entity); match update { @@ -139,6 +140,7 @@ impl WorldSyncExt for specs::World { // Private utilities fn create_entity_with_uid(specs_world: &mut specs::World, entity_uid: u64) -> specs::Entity { + let entity_uid = Uid::from(entity_uid); let existing_entity = specs_world .read_resource::() .retrieve_entity_internal(entity_uid); diff --git a/common/src/combat.rs b/common/src/combat.rs index bec5f2a492..a04964d7c4 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -29,7 +29,7 @@ use crate::{comp::Group, resources::Time}; #[cfg(not(target_arch = "wasm32"))] use { rand::Rng, - specs::{saveload::MarkerAllocator, Entity as EcsEntity, ReadStorage}, + specs::{Entity as EcsEntity, ReadStorage}, std::ops::{Mul, MulAssign}, vek::*, }; @@ -726,7 +726,7 @@ pub fn may_harm( // return original entity // if can't get owner uid_allocator - .retrieve_entity_internal(uid.into()) + .retrieve_entity_internal(uid) .unwrap_or(entity) } else { entity diff --git a/common/src/mounting.rs b/common/src/mounting.rs index 0cb1e812c5..a65ff8a71f 100644 --- a/common/src/mounting.rs +++ b/common/src/mounting.rs @@ -8,8 +8,8 @@ use crate::{ use hashbrown::HashSet; use serde::{Deserialize, Serialize}; use specs::{ - saveload::MarkerAllocator, storage::GenericWriteStorage, Component, DenseVecStorage, Entities, - Entity, Read, ReadExpect, ReadStorage, Write, WriteStorage, + storage::GenericWriteStorage, Component, DenseVecStorage, Entities, Entity, Read, ReadExpect, + ReadStorage, Write, WriteStorage, }; use vek::*; @@ -69,7 +69,7 @@ impl Link for Mounting { this: &LinkHandle, (uid_allocator, is_mounts, is_riders, is_volume_rider): &mut Self::CreateData<'_>, ) -> Result<(), Self::Error> { - let entity = |uid: Uid| uid_allocator.retrieve_entity_internal(uid.into()); + let entity = |uid: Uid| uid_allocator.retrieve_entity_internal(uid); if this.mount == this.rider { // Forbid self-mounting @@ -99,7 +99,7 @@ impl Link for Mounting { this: &LinkHandle, (uid_allocator, entities, healths, bodies, is_mounts, is_riders, character_states): &mut Self::PersistData<'_>, ) -> bool { - let entity = |uid: Uid| uid_allocator.retrieve_entity_internal(uid.into()); + let entity = |uid: Uid| uid_allocator.retrieve_entity_internal(uid); if let Some((mount, rider)) = entity(this.mount).zip(entity(this.rider)) { let is_alive = |entity| { @@ -128,7 +128,7 @@ impl Link for Mounting { this: &LinkHandle, (uid_allocator, is_mounts, is_riders, positions, force_update, terrain): &mut Self::DeleteData<'_>, ) { - let entity = |uid: Uid| uid_allocator.retrieve_entity_internal(uid.into()); + let entity = |uid: Uid| uid_allocator.retrieve_entity_internal(uid); let mount = entity(this.mount); let rider = entity(this.rider); @@ -228,26 +228,24 @@ impl VolumePos { comp::Ori::default(), *terrain.get(self.pos).ok()?, )), - Volume::Entity(uid) => { - uid_allocator - .retrieve_entity_internal(uid.0) - .and_then(|entity| { - let collider = colliders.get(entity)?; - let (pos, ori) = read_pos_and_ori(entity)?; + Volume::Entity(uid) => uid_allocator + .retrieve_entity_internal(uid) + .and_then(|entity| { + let collider = colliders.get(entity)?; + let (pos, ori) = read_pos_and_ori(entity)?; - let voxel_colliders_manifest = VOXEL_COLLIDER_MANIFEST.read(); - let voxel_collider = collider.get_vol(&voxel_colliders_manifest)?; + let voxel_colliders_manifest = VOXEL_COLLIDER_MANIFEST.read(); + let voxel_collider = collider.get_vol(&voxel_colliders_manifest)?; - let block = *voxel_collider.volume().get(self.pos).ok()?; + let block = *voxel_collider.volume().get(self.pos).ok()?; - let local_translation = voxel_collider.translation + self.pos.as_(); + let local_translation = voxel_collider.translation + self.pos.as_(); - let trans = Mat4::from(ori.to_quat()).translated_3d(pos.0) - * Mat4::::translation_3d(local_translation); + let trans = Mat4::from(ori.to_quat()).translated_3d(pos.0) + * Mat4::::translation_3d(local_translation); - Some((trans, ori, block)) - }) - }, + Some((trans, ori, block)) + }), } } @@ -260,20 +258,18 @@ impl VolumePos { ) -> Option { match self.kind { Volume::Terrain => Some(*terrain.get(self.pos).ok()?), - Volume::Entity(uid) => { - uid_allocator - .retrieve_entity_internal(uid.0) - .and_then(|entity| { - let collider = colliders.get(entity)?; + Volume::Entity(uid) => uid_allocator + .retrieve_entity_internal(uid) + .and_then(|entity| { + let collider = colliders.get(entity)?; - let voxel_colliders_manifest = VOXEL_COLLIDER_MANIFEST.read(); - let voxel_collider = collider.get_vol(&voxel_colliders_manifest)?; + let voxel_colliders_manifest = VOXEL_COLLIDER_MANIFEST.read(); + let voxel_collider = collider.get_vol(&voxel_colliders_manifest)?; - let block = *voxel_collider.volume().get(self.pos).ok()?; + let block = *voxel_collider.volume().get(self.pos).ok()?; - Some(block) - }) - }, + Some(block) + }), } } } diff --git a/common/src/uid.rs b/common/src/uid.rs index 83b8ec9b4d..864fb9b4c2 100644 --- a/common/src/uid.rs +++ b/common/src/uid.rs @@ -2,11 +2,7 @@ use hashbrown::HashMap; use serde::{Deserialize, Serialize}; #[cfg(not(target_arch = "wasm32"))] -use specs::{ - saveload::{Marker, MarkerAllocator}, - world::EntitiesRes, - Component, Entity, FlaggedStorage, Join, ReadStorage, VecStorage, -}; +use specs::{Component, Entity, FlaggedStorage, VecStorage}; use std::{fmt, u64}; #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] @@ -29,62 +25,42 @@ impl Component for Uid { type Storage = FlaggedStorage>; } -#[cfg(not(target_arch = "wasm32"))] -impl Marker for Uid { - type Allocator = UidAllocator; - type Identifier = u64; - - fn id(&self) -> u64 { self.0 } - - fn update(&mut self, update: Self) { - assert_eq!(self.0, update.0); - } -} - #[cfg(not(target_arch = "wasm32"))] #[derive(Debug)] pub struct UidAllocator { - index: u64, - mapping: HashMap, + next_id: u64, + mapping: HashMap, } #[cfg(not(target_arch = "wasm32"))] impl UidAllocator { pub fn new() -> Self { Self { - index: 0, + next_id: 0, mapping: HashMap::new(), } } // Useful for when a single entity is deleted because it doesn't reconstruct the // entire hashmap - pub fn remove_entity(&mut self, id: u64) -> Option { self.mapping.remove(&id) } + pub fn remove_entity(&mut self, id: Uid) -> Option { self.mapping.remove(&id) } + + pub fn allocate(&mut self, entity: Entity, id: Option) -> Uid { + let id = id.unwrap_or_else(|| { + let id = self.next_id; + self.next_id += 1; + Uid(id) + }); + self.mapping.insert(id, entity); + id + } + + pub fn retrieve_entity_internal(&self, id: Uid) -> Option { + self.mapping.get(&id).copied() + } } #[cfg(not(target_arch = "wasm32"))] impl Default for UidAllocator { fn default() -> Self { Self::new() } } - -#[cfg(not(target_arch = "wasm32"))] -impl MarkerAllocator for UidAllocator { - fn allocate(&mut self, entity: Entity, id: Option) -> Uid { - let id = id.unwrap_or_else(|| { - let id = self.index; - self.index += 1; - id - }); - self.mapping.insert(id, entity); - Uid(id) - } - - fn retrieve_entity_internal(&self, id: u64) -> Option { self.mapping.get(&id).copied() } - - fn maintain(&mut self, entities: &EntitiesRes, storage: &ReadStorage) { - self.mapping = (entities, storage) - .join() - .map(|(e, m)| (m.id(), e)) - .collect(); - } -} diff --git a/common/state/src/plugin/module.rs b/common/state/src/plugin/module.rs index f104f2a1a3..edc2d17630 100644 --- a/common/state/src/plugin/module.rs +++ b/common/state/src/plugin/module.rs @@ -5,7 +5,6 @@ use std::{ sync::{Arc, Mutex}, }; -use specs::saveload::MarkerAllocator; use wasmer::{imports, Cranelift, Function, Instance, Memory, Module, Store, Universal, Value}; use super::{ @@ -239,7 +238,7 @@ fn retrieve_action( EcsAccessError::EcsPointerNotAvailable, ))? }; - let player = world.uid_allocator.retrieve_entity_internal(e.0).ok_or( + let player = world.uid_allocator.retrieve_entity_internal(e).ok_or( RetrieveError::EcsAccessError(EcsAccessError::EcsEntityNotFound(e)), )?; @@ -264,7 +263,7 @@ fn retrieve_action( EcsAccessError::EcsPointerNotAvailable, ))? }; - let player = world.uid_allocator.retrieve_entity_internal(e.0).ok_or( + let player = world.uid_allocator.retrieve_entity_internal(e).ok_or( RetrieveError::EcsAccessError(EcsAccessError::EcsEntityNotFound(e)), )?; Ok(RetrieveResult::GetEntityHealth( diff --git a/common/systems/src/aura.rs b/common/systems/src/aura.rs index 8037c693ac..f83a558805 100644 --- a/common/systems/src/aura.rs +++ b/common/systems/src/aura.rs @@ -12,8 +12,7 @@ use common::{ }; use common_ecs::{Job, Origin, Phase, System}; use specs::{ - saveload::MarkerAllocator, shred::ResourceId, Entities, Entity as EcsEntity, Join, Read, - ReadStorage, SystemData, World, + shred::ResourceId, Entities, Entity as EcsEntity, Join, Read, ReadStorage, SystemData, World, }; #[derive(SystemData)] @@ -97,7 +96,7 @@ impl<'a> System<'a> for Sys { let same_group = |uid: Uid| { read_data .uid_allocator - .retrieve_entity_internal(uid.into()) + .retrieve_entity_internal(uid) .and_then(|e| read_data.groups.get(e)) .map_or(false, |owner_group| { Some(owner_group) == read_data.groups.get(target) @@ -168,9 +167,7 @@ fn activate_aura( _ => None, }) .and_then(|uid| { - read_data - .uid_allocator - .retrieve_entity_internal((*uid).into()) + read_data.uid_allocator.retrieve_entity_internal(*uid) }) .and_then(|owner| read_data.char_states.get(owner)) .map_or(false, CharacterState::is_sitting)) @@ -189,7 +186,7 @@ fn activate_aura( let may_harm = || { let owner = match source { BuffSource::Character { by } => { - read_data.uid_allocator.retrieve_entity_internal(by.into()) + read_data.uid_allocator.retrieve_entity_internal(by) }, _ => None, }; diff --git a/common/systems/src/beam.rs b/common/systems/src/beam.rs index 86ef024169..fc3c22d434 100644 --- a/common/systems/src/beam.rs +++ b/common/systems/src/beam.rs @@ -17,8 +17,8 @@ use common_ecs::{Job, Origin, ParMode, Phase, System}; use rand::Rng; use rayon::iter::ParallelIterator; use specs::{ - saveload::MarkerAllocator, shred::ResourceId, Entities, Join, ParJoin, Read, ReadExpect, - ReadStorage, SystemData, World, WriteStorage, + shred::ResourceId, Entities, Join, ParJoin, Read, ReadExpect, ReadStorage, SystemData, World, + WriteStorage, }; use std::time::Duration; use vek::*; @@ -95,9 +95,9 @@ impl<'a> System<'a> for Sys { }; let end_time = creation_time + beam_segment.duration.as_secs_f64(); - let beam_owner = beam_segment.owner.and_then(|uid| { - read_data.uid_allocator.retrieve_entity_internal(uid.into()) - }); + let beam_owner = beam_segment + .owner + .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid)); // Note: rayon makes it difficult to hold onto a thread-local RNG, if grabbing // this becomes a bottleneck we can look into alternatives. diff --git a/common/systems/src/buff.rs b/common/systems/src/buff.rs index 4b6e5f33f4..3ac880c1b1 100644 --- a/common/systems/src/buff.rs +++ b/common/systems/src/buff.rs @@ -22,8 +22,8 @@ use common_base::prof_span; use common_ecs::{Job, Origin, ParMode, Phase, System}; use rayon::iter::ParallelIterator; use specs::{ - saveload::MarkerAllocator, shred::ResourceId, Entities, Entity, Join, ParJoin, Read, - ReadExpect, ReadStorage, SystemData, World, WriteStorage, + shred::ResourceId, Entities, Entity, Join, ParJoin, Read, ReadExpect, ReadStorage, SystemData, + World, WriteStorage, }; #[derive(SystemData)] @@ -506,7 +506,7 @@ fn execute_effect( let damage_contributor = by.and_then(|uid| { read_data .uid_allocator - .retrieve_entity_internal(uid.0) + .retrieve_entity_internal(uid) .map(|entity| { DamageContributor::new(uid, read_data.groups.get(entity).cloned()) }) diff --git a/common/systems/src/controller.rs b/common/systems/src/controller.rs index 434fc7df8c..04ef434874 100644 --- a/common/systems/src/controller.rs +++ b/common/systems/src/controller.rs @@ -10,9 +10,8 @@ use common::{ }; use common_ecs::{Job, Origin, Phase, System}; use specs::{ - saveload::{Marker, MarkerAllocator}, - shred::ResourceId, - Entities, Join, Read, ReadExpect, ReadStorage, SystemData, World, WriteStorage, + shred::ResourceId, Entities, Join, Read, ReadExpect, ReadStorage, SystemData, World, + WriteStorage, }; use vek::*; @@ -51,7 +50,7 @@ impl<'a> System<'a> for Sys { ControlEvent::Mount(mountee_uid) => { if let Some(mountee_entity) = read_data .uid_allocator - .retrieve_entity_internal(mountee_uid.id()) + .retrieve_entity_internal(mountee_uid) { server_emitter.emit(ServerEvent::Mount(entity, mountee_entity)); } @@ -81,9 +80,8 @@ impl<'a> System<'a> for Sys { server_emitter.emit(ServerEvent::DisableLantern(entity)) }, ControlEvent::Interact(npc_uid, subject) => { - if let Some(npc_entity) = read_data - .uid_allocator - .retrieve_entity_internal(npc_uid.id()) + if let Some(npc_entity) = + read_data.uid_allocator.retrieve_entity_internal(npc_uid) { server_emitter .emit(ServerEvent::NpcInteract(entity, npc_entity, subject)); diff --git a/common/systems/src/mount.rs b/common/systems/src/mount.rs index 08ed26ebcb..72c26042cf 100644 --- a/common/systems/src/mount.rs +++ b/common/systems/src/mount.rs @@ -6,10 +6,7 @@ use common::{ uid::UidAllocator, }; use common_ecs::{Job, Origin, Phase, System}; -use specs::{ - saveload::{Marker, MarkerAllocator}, - Entities, Join, Read, ReadExpect, ReadStorage, WriteStorage, -}; +use specs::{Entities, Join, Read, ReadExpect, ReadStorage, WriteStorage}; use tracing::error; use vek::*; @@ -57,7 +54,7 @@ impl<'a> System<'a> for Sys { for (entity, is_mount, body) in (&entities, &is_mounts, bodies.maybe()).join() { // ...find the rider... let Some((inputs_and_actions, rider)) = uid_allocator - .retrieve_entity_internal(is_mount.rider.id()) + .retrieve_entity_internal(is_mount.rider) .and_then(|rider| { controllers .get_mut(rider) diff --git a/common/systems/src/projectile.rs b/common/systems/src/projectile.rs index a713ebe1ae..0f9ead3945 100644 --- a/common/systems/src/projectile.rs +++ b/common/systems/src/projectile.rs @@ -17,8 +17,8 @@ use common::vol::ReadVol; use common_ecs::{Job, Origin, Phase, System}; use rand::Rng; use specs::{ - saveload::MarkerAllocator, shred::ResourceId, Entities, Entity as EcsEntity, Join, Read, - ReadExpect, ReadStorage, SystemData, World, WriteStorage, + shred::ResourceId, Entities, Entity as EcsEntity, Join, Read, ReadExpect, ReadStorage, + SystemData, World, WriteStorage, }; use std::time::Duration; use vek::*; @@ -85,7 +85,7 @@ impl<'a> System<'a> for Sys { { let projectile_owner = projectile .owner - .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); + .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid)); if physics.on_surface().is_none() && rng.gen_bool(0.05) { server_emitter.emit(ServerEvent::Sound { @@ -104,7 +104,7 @@ impl<'a> System<'a> for Sys { .and_then(|e| read_data.groups.get(e)) .map_or(false, |owner_group| Some(owner_group) == read_data.uid_allocator - .retrieve_entity_internal(other.into()) + .retrieve_entity_internal(other) .and_then(|e| read_data.groups.get(e)) ); @@ -125,8 +125,7 @@ impl<'a> System<'a> for Sys { let projectile = &mut *projectile; - let entity_of = - |uid: Uid| read_data.uid_allocator.retrieve_entity_internal(uid.into()); + let entity_of = |uid: Uid| read_data.uid_allocator.retrieve_entity_internal(uid); // Don't hit if there is terrain between the projectile and where the entity was // supposed to be hit by it. diff --git a/common/systems/src/shockwave.rs b/common/systems/src/shockwave.rs index 696ea49372..6571cb05ff 100644 --- a/common/systems/src/shockwave.rs +++ b/common/systems/src/shockwave.rs @@ -15,8 +15,7 @@ use common::{ use common_ecs::{Job, Origin, Phase, System}; use rand::Rng; use specs::{ - saveload::MarkerAllocator, shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, - World, WriteStorage, + shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage, }; use vek::*; @@ -92,7 +91,7 @@ impl<'a> System<'a> for Sys { let shockwave_owner = shockwave .owner - .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); + .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid)); if rng.gen_bool(0.05) { server_emitter.emit(ServerEvent::Sound { diff --git a/server/agent/src/action_nodes.rs b/server/agent/src/action_nodes.rs index 1ca7e37dd8..a511d52b19 100644 --- a/server/agent/src/action_nodes.rs +++ b/server/agent/src/action_nodes.rs @@ -39,7 +39,7 @@ use common::{ }; use itertools::Itertools; use rand::{thread_rng, Rng}; -use specs::{saveload::Marker, Entity as EcsEntity}; +use specs::Entity as EcsEntity; use vek::*; #[cfg(feature = "use-dyn-lib")] @@ -397,7 +397,7 @@ impl<'a> AgentData<'a> { break 'activity; } } else if let Some(Alignment::Owned(owner_uid)) = self.alignment - && let Some(owner) = get_entity_by_id(owner_uid.id(), read_data) + && let Some(owner) = get_entity_by_id(*owner_uid, read_data) && let Some(pos) = read_data.positions.get(owner) && pos.0.distance_squared(self.pos.0) < MAX_MOUNT_RANGE.powi(2) && rng.gen_bool(0.01) @@ -455,7 +455,7 @@ impl<'a> AgentData<'a> { if let Some(patrol_origin) = agent.patrol_origin // Use owner as patrol origin otherwise .or_else(|| if let Some(Alignment::Owned(owner_uid)) = self.alignment - && let Some(owner) = get_entity_by_id(owner_uid.id(), read_data) + && let Some(owner) = get_entity_by_id(*owner_uid, read_data) && let Some(pos) = read_data.positions.get(owner) { Some(pos.0) @@ -1613,7 +1613,7 @@ impl<'a> AgentData<'a> { if let Some(Target { target, .. }) = agent.target { if let Some(tgt_health) = read_data.healths.get(target) { if let Some(by) = tgt_health.last_change.damage_by() { - if let Some(attacker) = get_entity_by_id(by.uid().0, read_data) { + if let Some(attacker) = get_entity_by_id(by.uid(), read_data) { if agent.target.is_none() { controller.push_utterance(UtteranceKind::Angry); } diff --git a/server/agent/src/util.rs b/server/agent/src/util.rs index e486ed2207..1e010c3dcb 100644 --- a/server/agent/src/util.rs +++ b/server/agent/src/util.rs @@ -9,15 +9,13 @@ use common::{ }, consts::GRAVITY, terrain::Block, + uid::Uid, util::Dir, vol::ReadVol, }; use core::f32::consts::PI; use rand::Rng; -use specs::{ - saveload::{Marker, MarkerAllocator}, - Entity as EcsEntity, -}; +use specs::Entity as EcsEntity; use vek::*; pub fn is_dead_or_invulnerable(entity: EcsEntity, read_data: &ReadData) -> bool { @@ -43,8 +41,8 @@ pub fn try_owner_alignment<'a>( alignment: Option<&'a Alignment>, read_data: &'a ReadData, ) -> Option<&'a Alignment> { - if let Some(Alignment::Owned(owner_uid)) = alignment { - if let Some(owner) = get_entity_by_id(owner_uid.id(), read_data) { + if let Some(&Alignment::Owned(owner_uid)) = alignment { + if let Some(owner) = get_entity_by_id(owner_uid, read_data) { return read_data.alignments.get(owner); } } @@ -66,8 +64,8 @@ pub fn aim_projectile(speed: f32, pos: Vec3, tgt: Vec3) -> Option

Dir::from_unnormalized(to_tgt) } -pub fn get_entity_by_id(id: u64, read_data: &ReadData) -> Option { - read_data.uid_allocator.retrieve_entity_internal(id) +pub fn get_entity_by_id(uid: Uid, read_data: &ReadData) -> Option { + read_data.uid_allocator.retrieve_entity_internal(uid) } /// Calculates whether the agent should continue chase or let the target escape. @@ -198,7 +196,7 @@ pub fn get_attacker(entity: EcsEntity, read_data: &ReadData) -> Option AgentData<'a> { diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 6d53e28c94..316dba2106 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -60,9 +60,7 @@ use core::{cmp::Ordering, convert::TryFrom}; use hashbrown::{HashMap, HashSet}; use humantime::Duration as HumanDuration; use rand::{thread_rng, Rng}; -use specs::{ - saveload::MarkerAllocator, storage::StorageEntry, Builder, Entity as EcsEntity, Join, WorldExt, -}; +use specs::{storage::StorageEntry, Builder, Entity as EcsEntity, Join, WorldExt}; use std::{fmt::Write, ops::DerefMut, str::FromStr, sync::Arc}; use vek::*; use wiring::{Circuit, Wire, WireNode, WiringAction, WiringActionEffect, WiringElement}; @@ -248,7 +246,7 @@ fn position_mut( .state .ecs() .read_resource::() - .retrieve_entity_internal(is_rider.mount.into()) + .retrieve_entity_internal(is_rider.mount) }) .map(Ok) .or_else(|| { @@ -2279,7 +2277,7 @@ fn handle_kill_npcs( .filter_map(|(entity, _health, (), alignment, pos)| { let should_kill = kill_pets || if let Some(Alignment::Owned(owned)) = alignment { - ecs.entity_from_uid(owned.0) + ecs.entity_from_uid(*owned) .map_or(true, |owner| !players.contains(owner)) } else { true diff --git a/server/src/events/entity_creation.rs b/server/src/events/entity_creation.rs index 86d9f11abd..151d7b37c8 100644 --- a/server/src/events/entity_creation.rs +++ b/server/src/events/entity_creation.rs @@ -154,7 +154,7 @@ pub fn handle_create_npc(server: &mut Server, pos: Pos, mut npc: NpcBuilder) -> let clients = state.ecs().read_storage::(); let uids = state.ecs().read_storage::(); let mut group_manager = state.ecs().write_resource::(); - if let Some(owner) = state.ecs().entity_from_uid(owner_uid.into()) { + if let Some(owner) = state.ecs().entity_from_uid(owner_uid) { let map_markers = state.ecs().read_storage::(); group_manager.new_pet( new_entity, diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index c3086f5be2..9bdc98a379 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -41,9 +41,7 @@ use common_net::{msg::ServerGeneral, sync::WorldSyncExt}; use common_state::{AreasContainer, BlockChange, NoDurabilityArea}; use hashbrown::HashSet; use rand::Rng; -use specs::{ - join::Join, saveload::MarkerAllocator, Builder, Entity as EcsEntity, Entity, WorldExt, -}; +use specs::{join::Join, Builder, Entity as EcsEntity, Entity, WorldExt}; use std::{collections::HashMap, iter, sync::Arc, time::Duration}; use tracing::{debug, error}; use vek::{Vec2, Vec3}; @@ -143,7 +141,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, last_change: Healt let get_attacker_name = |cause_of_death: KillType, by: Uid| -> KillSource { // Get attacker entity - if let Some(char_entity) = state.ecs().entity_from_uid(by.into()) { + if let Some(char_entity) = state.ecs().entity_from_uid(by) { // Check if attacker is another player or entity with stats (npc) if state .ecs() @@ -259,7 +257,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, last_change: Healt for (damage_contributor, damage) in entity_health.damage_contributions() { match damage_contributor { DamageContributor::Solo(uid) => { - if let Some(attacker) = state.ecs().entity_from_uid(uid.0) { + if let Some(attacker) = state.ecs().entity_from_uid(*uid) { damage_contributors.insert(DamageContrib::Solo(attacker), (*damage, 0.0)); } else { // An entity who was not in a group contributed damage but is now either @@ -746,7 +744,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3, explosion: Explosion, o let time = ecs.read_resource::