Cleanup UidAllocator and Uid a bit:

* Remove unnecessary Marker/MarkAllocator trait implementations.
* Delete excess functions
* Change some methods to take Uid instead of u64
This commit is contained in:
Imbris 2023-04-23 01:58:29 -04:00
parent d90926e4a3
commit ea725fffde
37 changed files with 194 additions and 256 deletions

View File

@ -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) => {

View File

@ -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<Uid>;
fn entity_from_uid(&self, uid: u64) -> Option<specs::Entity>;
fn entity_from_uid(&self, uid: Uid) -> Option<specs::Entity>;
fn apply_entity_package<P: CompPacket>(
&mut self,
entity_package: EntityPackage<P>,
@ -56,10 +52,15 @@ impl WorldSyncExt for specs::World {
}
fn create_entity_synced(&mut self) -> specs::EntityBuilder {
self.create_entity().marked::<Uid>()
let builder = self.create_entity();
let uid = builder
.world
.write_resource::<UidAllocator>()
.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::<UidAllocator>().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<specs::Entity> {
fn entity_from_uid(&self, uid: Uid) -> Option<specs::Entity> {
self.read_resource::<UidAllocator>()
.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::<UidAllocator>()
.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::<UidAllocator>()
.retrieve_entity_internal(entity_uid);

View File

@ -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

View File

@ -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<Self>,
(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<Self>,
(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<Self>,
(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,9 +228,8 @@ impl VolumePos {
comp::Ori::default(),
*terrain.get(self.pos).ok()?,
)),
Volume::Entity(uid) => {
uid_allocator
.retrieve_entity_internal(uid.0)
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)?;
@ -246,8 +245,7 @@ impl VolumePos {
* Mat4::<f32>::translation_3d(local_translation);
Some((trans, ori, block))
})
},
}),
}
}
@ -260,9 +258,8 @@ impl VolumePos {
) -> Option<Block> {
match self.kind {
Volume::Terrain => Some(*terrain.get(self.pos).ok()?),
Volume::Entity(uid) => {
uid_allocator
.retrieve_entity_internal(uid.0)
Volume::Entity(uid) => uid_allocator
.retrieve_entity_internal(uid)
.and_then(|entity| {
let collider = colliders.get(entity)?;
@ -272,8 +269,7 @@ impl VolumePos {
let block = *voxel_collider.volume().get(self.pos).ok()?;
Some(block)
})
},
}),
}
}
}

View File

@ -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<Self, VecStorage<Self>>;
}
#[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<u64, Entity>,
next_id: u64,
mapping: HashMap<Uid, Entity>,
}
#[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<Entity> { self.mapping.remove(&id) }
pub fn remove_entity(&mut self, id: Uid) -> Option<Entity> { self.mapping.remove(&id) }
pub fn allocate(&mut self, entity: Entity, id: Option<Uid>) -> 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<Entity> {
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<Uid> for UidAllocator {
fn allocate(&mut self, entity: Entity, id: Option<u64>) -> 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<Entity> { self.mapping.get(&id).copied() }
fn maintain(&mut self, entities: &EntitiesRes, storage: &ReadStorage<Uid>) {
self.mapping = (entities, storage)
.join()
.map(|(e, m)| (m.id(), e))
.collect();
}
}

View File

@ -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(

View File

@ -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,
};

View File

@ -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.

View File

@ -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())
})

View File

@ -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));

View File

@ -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)

View File

@ -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.

View File

@ -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 {

View File

@ -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);
}

View File

@ -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<f32>, tgt: Vec3<f32>) -> Option<Dir>
Dir::from_unnormalized(to_tgt)
}
pub fn get_entity_by_id(id: u64, read_data: &ReadData) -> Option<EcsEntity> {
read_data.uid_allocator.retrieve_entity_internal(id)
pub fn get_entity_by_id(uid: Uid, read_data: &ReadData) -> Option<EcsEntity> {
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<EcsEntity
.get(entity)
.filter(|health| health.last_change.amount < 0.0)
.and_then(|health| health.last_change.damage_by())
.and_then(|damage_contributor| get_entity_by_id(damage_contributor.uid().0, read_data))
.and_then(|damage_contributor| get_entity_by_id(damage_contributor.uid(), read_data))
}
impl<'a> AgentData<'a> {

View File

@ -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<T>(
.state
.ecs()
.read_resource::<UidAllocator>()
.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

View File

@ -154,7 +154,7 @@ pub fn handle_create_npc(server: &mut Server, pos: Pos, mut npc: NpcBuilder) ->
let clients = state.ecs().read_storage::<Client>();
let uids = state.ecs().read_storage::<Uid>();
let mut group_manager = state.ecs().write_resource::<comp::group::GroupManager>();
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::<comp::MapMarker>();
group_manager.new_pet(
new_entity,

View File

@ -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<f32>, explosion: Explosion, o
let time = ecs.read_resource::<Time>();
let owner_entity = owner.and_then(|uid| {
ecs.read_resource::<UidAllocator>()
.retrieve_entity_internal(uid.into())
.retrieve_entity_internal(uid)
});
let explosion_volume = 6.25 * explosion.radius;
@ -1421,7 +1419,7 @@ pub fn handle_teleport_to(server: &Server, entity: EcsEntity, target: Uid, max_r
let mut positions = ecs.write_storage::<Pos>();
let target_pos = ecs
.entity_from_uid(target.into())
.entity_from_uid(target)
.and_then(|e| positions.get(e))
.copied();
@ -1493,7 +1491,7 @@ pub fn handle_entity_attacked_hook(server: &Server, entity: EcsEntity) {
if let Some(trade) = trades.entity_trades.get(uid).copied() {
trades
.decline_trade(trade, *uid)
.and_then(|uid| ecs.entity_from_uid(uid.0))
.and_then(|uid| ecs.entity_from_uid(uid))
.map(|entity_b| {
// Notify both parties that the trade ended
let clients = ecs.read_storage::<Client>();

View File

@ -148,7 +148,7 @@ pub fn handle_group(server: &mut Server, entity: Entity, manip: GroupManip) {
let uids = state.ecs().read_storage::<Uid>();
let alignments = state.ecs().read_storage::<comp::Alignment>();
let target = match state.ecs().entity_from_uid(uid.into()) {
let target = match state.ecs().entity_from_uid(uid) {
Some(t) => t,
None => {
// Inform of failure
@ -254,7 +254,7 @@ pub fn handle_group(server: &mut Server, entity: Entity, manip: GroupManip) {
let state = server.state_mut();
let clients = state.ecs().read_storage::<Client>();
let uids = state.ecs().read_storage::<Uid>();
let target = match state.ecs().entity_from_uid(uid.into()) {
let target = match state.ecs().entity_from_uid(uid) {
Some(t) => t,
None => {
// Inform of failure

View File

@ -120,8 +120,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
match manip {
comp::InventoryManip::Pickup(pickup_uid) => {
let item_entity =
if let Some(item_entity) = state.ecs().entity_from_uid(pickup_uid.into()) {
let item_entity = if let Some(item_entity) = state.ecs().entity_from_uid(pickup_uid) {
item_entity
} else {
// Item entity could not be found - most likely because the entity

View File

@ -30,7 +30,7 @@ pub fn handle_invite(server: &mut Server, inviter: Entity, invitee_uid: Uid, kin
let max_group_size = server.settings().max_player_group_size;
let state = server.state_mut();
let clients = state.ecs().read_storage::<Client>();
let invitee = match state.ecs().entity_from_uid(invitee_uid.into()) {
let invitee = match state.ecs().entity_from_uid(invitee_uid) {
Some(t) => t,
None => {
// Inform of failure
@ -85,7 +85,7 @@ pub fn handle_invite(server: &mut Server, inviter: Entity, invitee_uid: Uid, kin
if let Some(active_trade) = trades.entity_trades.get(&inviter_uid).copied() {
trades
.decline_trade(active_trade, inviter_uid)
.and_then(|u| state.ecs().entity_from_uid(u.0))
.and_then(|u| state.ecs().entity_from_uid(u))
.map(|e| {
if let Some(client) = clients.get(e) {
client
@ -309,7 +309,7 @@ fn handle_invite_answer(
if let Some(active_trade) = trades.entity_trades.get(&invitee_uid).copied() {
trades
.decline_trade(active_trade, invitee_uid)
.and_then(|u| state.ecs().entity_from_uid(u.0))
.and_then(|u| state.ecs().entity_from_uid(u))
.map(|e| {
if let Some(client) = clients.get(e) {
client

View File

@ -13,7 +13,7 @@ use common::{
use common_base::span;
use common_net::msg::{PlayerListUpdate, ServerGeneral};
use common_state::State;
use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, Join, WorldExt};
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
use tracing::{debug, error, trace, warn, Instrument};
pub fn handle_character_delete(
@ -331,8 +331,8 @@ pub fn handle_possess(server: &mut Server, possessor_uid: Uid, possessee_uid: Ui
let mut delete_entity = None;
if let (Some(possessor), Some(possessee)) = (
state.ecs().entity_from_uid(possessor_uid.into()),
state.ecs().entity_from_uid(possessee_uid.into()),
state.ecs().entity_from_uid(possessor_uid),
state.ecs().entity_from_uid(possessee_uid),
) {
// In this section we check various invariants and can return early if any of
// them are not met.

View File

@ -64,7 +64,7 @@ pub(super) fn handle_process_trade_action(
if let TradeAction::Decline = action {
let to_notify = trades.decline_trade(trade_id, uid);
to_notify
.and_then(|u| server.state.ecs().entity_from_uid(u.0))
.and_then(|u| server.state.ecs().entity_from_uid(u))
.map(|e| {
server.notify_client(e, ServerGeneral::FinishedTrade(TradeResult::Declined));
notify_agent_simple(
@ -78,7 +78,7 @@ pub(super) fn handle_process_trade_action(
let ecs = server.state.ecs();
let inventories = ecs.read_component::<Inventory>();
let get_inventory = |uid: Uid| {
if let Some(entity) = ecs.entity_from_uid(uid.0) {
if let Some(entity) = ecs.entity_from_uid(uid) {
inventories.get(entity)
} else {
None
@ -92,7 +92,7 @@ pub(super) fn handle_process_trade_action(
let result = commit_trade(server.state.ecs(), entry.get());
entry.remove();
for party in parties.iter() {
if let Some(e) = server.state.ecs().entity_from_uid(party.0) {
if let Some(e) = server.state.ecs().entity_from_uid(*party) {
server.notify_client(e, ServerGeneral::FinishedTrade(result.clone()));
notify_agent_simple(
server.state.ecs().write_storage::<Agent>(),
@ -110,7 +110,7 @@ pub(super) fn handle_process_trade_action(
// sadly there is no map and collect on arrays
for i in 0..2 {
// parties.len()) {
entities[i] = server.state.ecs().entity_from_uid(parties[i].0);
entities[i] = server.state.ecs().entity_from_uid(parties[i]);
if let Some(e) = entities[i] {
inventories[i] = server
.state
@ -180,7 +180,7 @@ pub(crate) fn cancel_trades_for(state: &mut common_state::State, entity: EcsEnti
};
let to_notify = trades.decline_trade(active_trade, uid);
to_notify.and_then(|u| ecs.entity_from_uid(u.0)).map(|e| {
to_notify.and_then(|u| ecs.entity_from_uid(u)).map(|e| {
if let Some(c) = ecs.read_storage::<crate::Client>().get(e) {
c.send_fallible(ServerGeneral::FinishedTrade(TradeResult::Declined));
}
@ -198,7 +198,7 @@ pub(crate) fn cancel_trades_for(state: &mut common_state::State, entity: EcsEnti
fn commit_trade(ecs: &specs::World, trade: &PendingTrade) -> TradeResult {
let mut entities = Vec::new();
for party in trade.parties.iter() {
match ecs.entity_from_uid(party.0) {
match ecs.entity_from_uid(*party) {
Some(entity) => entities.push(entity),
None => return TradeResult::Declined,
}

View File

@ -36,10 +36,7 @@ use common_net::{
};
use common_state::State;
use rand::prelude::*;
use specs::{
saveload::MarkerAllocator, Builder, Entity as EcsEntity, EntityBuilder as EcsEntityBuilder,
Join, WorldExt,
};
use specs::{Builder, Entity as EcsEntity, EntityBuilder as EcsEntityBuilder, Join, WorldExt};
use std::time::{Duration, Instant};
use tracing::{trace, warn};
use vek::*;
@ -169,7 +166,7 @@ impl StateExt for State {
let groups = self.ecs().read_storage::<Group>();
let damage_contributor = source.and_then(|uid| {
self.ecs().entity_from_uid(uid.0).map(|attacker_entity| {
self.ecs().entity_from_uid(uid).map(|attacker_entity| {
DamageContributor::new(uid, groups.get(attacker_entity).cloned())
})
});
@ -214,7 +211,7 @@ impl StateExt for State {
if !character_state.is_stunned() {
let groups = self.ecs().read_storage::<Group>();
let damage_contributor = source.and_then(|uid| {
self.ecs().entity_from_uid(uid.0).map(|attacker_entity| {
self.ecs().entity_from_uid(uid).map(|attacker_entity| {
DamageContributor::new(uid, groups.get(attacker_entity).cloned())
})
});
@ -862,10 +859,11 @@ impl StateExt for State {
.clone()
.map_group(|_| group_info.map_or_else(|| "???".to_string(), |i| i.name.clone()));
let uid_allocator = ecs.read_resource::<UidAllocator>();
let entity_from_uid = |uid| uid_allocator.retrieve_entity_internal(uid);
if msg.chat_type.uid().map_or(true, |sender| {
(*ecs.read_resource::<UidAllocator>())
.retrieve_entity_internal(sender.0)
.map_or(false, |e| {
entity_from_uid(sender).map_or(false, |e| {
self.validate_chat_msg(
e,
&msg.chat_type,
@ -911,8 +909,7 @@ impl StateExt for State {
.unwrap_or_default()
{
// Send kill message to the dead player's group
let killed_entity =
(*ecs.read_resource::<UidAllocator>()).retrieve_entity_internal(uid.0);
let killed_entity = entity_from_uid(*uid);
let groups = ecs.read_storage::<Group>();
let killed_group = killed_entity.and_then(|e| groups.get(e));
if let Some(g) = &killed_group {
@ -947,8 +944,7 @@ impl StateExt for State {
}
},
comp::ChatType::Say(uid) => {
let entity_opt =
(*ecs.read_resource::<UidAllocator>()).retrieve_entity_internal(uid.0);
let entity_opt = entity_from_uid(*uid);
let positions = ecs.read_storage::<comp::Pos>();
if let Some(speaker_pos) = entity_opt.and_then(|e| positions.get(e)) {
@ -960,8 +956,7 @@ impl StateExt for State {
}
},
comp::ChatType::Region(uid) => {
let entity_opt =
(*ecs.read_resource::<UidAllocator>()).retrieve_entity_internal(uid.0);
let entity_opt = entity_from_uid(*uid);
let positions = ecs.read_storage::<comp::Pos>();
if let Some(speaker_pos) = entity_opt.and_then(|e| positions.get(e)) {
@ -973,8 +968,7 @@ impl StateExt for State {
}
},
comp::ChatType::Npc(uid) => {
let entity_opt =
(*ecs.read_resource::<UidAllocator>()).retrieve_entity_internal(uid.0);
let entity_opt = entity_from_uid(*uid);
let positions = ecs.read_storage::<comp::Pos>();
if let Some(speaker_pos) = entity_opt.and_then(|e| positions.get(e)) {
@ -986,8 +980,7 @@ impl StateExt for State {
}
},
comp::ChatType::NpcSay(uid) => {
let entity_opt =
(*ecs.read_resource::<UidAllocator>()).retrieve_entity_internal(uid.0);
let entity_opt = entity_from_uid(*uid);
let positions = ecs.read_storage::<comp::Pos>();
if let Some(speaker_pos) = entity_opt.and_then(|e| positions.get(e)) {

View File

@ -19,7 +19,7 @@ use common_base::prof_span;
use common_ecs::{Job, Origin, ParMode, Phase, System};
use rand::thread_rng;
use rayon::iter::ParallelIterator;
use specs::{saveload::MarkerAllocator, Join, ParJoin, Read, WriteStorage};
use specs::{Join, ParJoin, Read, WriteStorage};
/// This system will allow NPCs to modify their controller
#[derive(Default)]
@ -105,7 +105,7 @@ impl<'a> System<'a> for Sys {
.and_then(|is_rider| {
read_data
.uid_allocator
.retrieve_entity_internal(is_rider.mount.into())
.retrieve_entity_internal(is_rider.mount)
})
.or_else(|| {
is_volume_rider.and_then(|is_volume_rider| {

View File

@ -13,10 +13,7 @@ use common::{
rtsim::{NpcAction, RtSimEntity},
};
use rand::{prelude::ThreadRng, thread_rng, Rng};
use specs::{
saveload::{Marker, MarkerAllocator},
Entity as EcsEntity,
};
use specs::Entity as EcsEntity;
use vek::{Vec2, Vec3};
use self::interaction::{
@ -250,7 +247,7 @@ fn target_if_attacked(bdata: &mut BehaviorData) -> bool {
if let Some(attacker) = bdata
.read_data
.uid_allocator
.retrieve_entity_internal(by.uid().0)
.retrieve_entity_internal(by.uid())
{
// If target is dead or invulnerable (for now, this only
// means safezone), untarget them and idle.
@ -460,7 +457,7 @@ fn set_owner_if_no_target(bdata: &mut BehaviorData) -> bool {
if bdata.agent.target.is_none() && small_chance {
if let Some(Alignment::Owned(owner)) = bdata.agent_data.alignment {
if let Some(owner) = get_entity_by_id(owner.id(), bdata.read_data) {
if let Some(owner) = get_entity_by_id(*owner, bdata.read_data) {
let owner_pos = bdata.read_data.positions.get(owner).map(|pos| pos.0);
bdata.agent.target = Some(Target::new(

View File

@ -14,7 +14,6 @@ use common::{
trade::{TradeAction, TradePhase, TradeResult},
};
use rand::{thread_rng, Rng};
use specs::saveload::Marker;
use crate::sys::agent::util::get_entity_by_id;
@ -87,7 +86,7 @@ pub fn handle_inbox_talk(bdata: &mut BehaviorData) -> bool {
}
if let Some(AgentEvent::Talk(by, subject)) = agent.inbox.pop_front() {
let by_entity = get_entity_by_id(by.id(), read_data);
let by_entity = get_entity_by_id(by, read_data);
if let Some(rtsim_outbox) = &mut agent.rtsim_outbox {
if let Subject::Regular
@ -297,7 +296,7 @@ pub fn handle_inbox_trade_invite(bdata: &mut BehaviorData) -> bool {
// stand still and looking towards the trading player
controller.push_action(ControlAction::Stand);
controller.push_action(ControlAction::Talk);
if let Some(target) = get_entity_by_id(with.id(), read_data) {
if let Some(target) = get_entity_by_id(with, read_data) {
let target_pos = read_data.positions.get(target).map(|pos| pos.0);
agent.target = Some(Target::new(
@ -344,7 +343,7 @@ pub fn handle_inbox_trade_accepted(bdata: &mut BehaviorData) -> bool {
if let Some(AgentEvent::TradeAccepted(with)) = agent.inbox.pop_front() {
if !agent.behavior.is(BehaviorState::TRADING) {
if let Some(target) = get_entity_by_id(with.id(), read_data) {
if let Some(target) = get_entity_by_id(with, read_data) {
let target_pos = read_data.positions.get(target).map(|pos| pos.0);
agent.target = Some(Target::new(
@ -561,7 +560,7 @@ pub fn handle_inbox_cancel_interactions(bdata: &mut BehaviorData) -> bool {
let used = match msg {
AgentEvent::Talk(by, _) | AgentEvent::TradeAccepted(by) => {
if let (Some(target), Some(speaker)) =
(agent.target, get_entity_by_id(by.id(), bdata.read_data))
(agent.target, get_entity_by_id(*by, bdata.read_data))
{
// in combat, speak to players that aren't the current target
if !target.hostile || target.target != speaker {
@ -578,7 +577,7 @@ pub fn handle_inbox_cancel_interactions(bdata: &mut BehaviorData) -> bool {
AgentEvent::TradeInvite(by) => {
controller.push_invite_response(InviteResponse::Decline);
if let (Some(target), Some(speaker)) =
(agent.target, get_entity_by_id(by.id(), bdata.read_data))
(agent.target, get_entity_by_id(*by, bdata.read_data))
{
// in combat, speak to players that aren't the current target
if !target.hostile || target.target != speaker {

View File

@ -3,7 +3,7 @@ use common::{
uid::UidAllocator,
};
use common_ecs::{Job, Origin, Phase, System};
use specs::{saveload::MarkerAllocator, Entities, Entity, Join, Read, WriteStorage};
use specs::{Entities, Entity, Join, Read, WriteStorage};
use tracing::debug;
// This system manages loot that exists in the world
@ -33,7 +33,7 @@ impl<'a> System<'a> for Sys {
loot_owner.expired()
|| match loot_owner.owner() {
LootOwnerKind::Player(uid) => uid_allocator
.retrieve_entity_internal(uid.into())
.retrieve_entity_internal(uid)
.map_or(true, |entity| !entities.is_alive(entity)),
LootOwnerKind::Group(group) => group_manager.group_info(group).is_none(),
}

View File

@ -4,9 +4,7 @@ use common::{
uid::UidAllocator,
};
use common_ecs::{Job, Origin, Phase, System};
use specs::{
saveload::MarkerAllocator, Entities, Entity, Join, Read, ReadExpect, ReadStorage, WriteStorage,
};
use specs::{Entities, Entity, Join, Read, ReadExpect, ReadStorage, WriteStorage};
/// This system is responsible for handling pets
#[derive(Default)]
@ -36,12 +34,12 @@ impl<'a> System<'a> for Sys {
let lost_pets: Vec<(Entity, Pos)> = (&entities, &positions, &alignments, &pets)
.join()
.filter_map(|(entity, pos, alignment, _)| match alignment {
Alignment::Owned(owner_uid) => Some((entity, pos, owner_uid)),
Alignment::Owned(owner_uid) => Some((entity, pos, *owner_uid)),
_ => None,
})
.filter_map(|(pet_entity, pet_pos, owner_uid)| {
uid_allocator
.retrieve_entity_internal(owner_uid.0)
.retrieve_entity_internal(owner_uid)
.and_then(|owner_entity| {
match (positions.get(owner_entity), physics.get(owner_entity)) {
(Some(position), Some(physics)) => {

View File

@ -28,7 +28,7 @@ use conrod_core::{
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
};
use i18n::Localization;
use specs::{saveload::MarkerAllocator, WorldExt};
use specs::WorldExt;
widget_ids! {
pub struct Ids {
@ -202,7 +202,7 @@ impl<'a> Widget for Group<'a> {
None => client
.state()
.ecs()
.entity_from_uid(uid.0)
.entity_from_uid(uid)
.and_then(|entity| {
client
.state()
@ -382,7 +382,7 @@ impl<'a> Widget for Group<'a> {
let mut total_buff_count = 0;
for (i, &uid) in group_members.iter().copied().enumerate() {
self.show.group = true;
let entity = uid_allocator.retrieve_entity_internal(uid.into());
let entity = uid_allocator.retrieve_entity_internal(uid);
let stats = entity.and_then(|entity| stats.get(entity));
let skill_set = entity.and_then(|entity| skill_sets.get(entity));
let health = entity.and_then(|entity| healths.get(entity));

View File

@ -27,7 +27,7 @@ use conrod_core::{
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, UiCell, Widget, WidgetCommon,
};
use i18n::Localization;
use specs::{saveload::MarkerAllocator, WorldExt};
use specs::WorldExt;
use std::borrow::Cow;
use vek::*;
use winit::event::MouseButton;
@ -1251,7 +1251,7 @@ impl<'a> Widget for Map<'a> {
})
};
for (i, &uid) in group_members.iter().copied().enumerate() {
let entity = uid_allocator.retrieve_entity_internal(uid.into());
let entity = uid_allocator.retrieve_entity_internal(uid);
let member_pos = entity.and_then(|entity| member_pos.get(entity));
let stats = entity.and_then(|entity| stats.get(entity));
let name = if let Some(stats) = stats {
@ -1324,7 +1324,7 @@ impl<'a> Widget for Map<'a> {
.map(|info| info.player_alias.as_str())
.or_else(|| {
uid_allocator
.retrieve_entity_internal(uid.into())
.retrieve_entity_internal(uid)
.and_then(|entity| stats.get(entity))
.map(|stats| stats.name.as_str())
})

View File

@ -28,7 +28,7 @@ use conrod_core::{
};
use hashbrown::HashMap;
use image::{DynamicImage, RgbaImage};
use specs::{saveload::MarkerAllocator, WorldExt};
use specs::WorldExt;
use std::sync::Arc;
use vek::*;
@ -773,7 +773,7 @@ impl<'a> Widget for MiniMap<'a> {
})
};
for (i, &uid) in group_members.iter().copied().enumerate() {
let entity = uid_allocator.retrieve_entity_internal(uid.into());
let entity = uid_allocator.retrieve_entity_internal(uid);
let member_pos = entity.and_then(|entity| member_pos.get(entity));
if let Some(member_pos) = member_pos {

View File

@ -1247,8 +1247,7 @@ impl HudCollectFailedReason {
CollectFailedReason::LootOwned { owner, expiry_secs } => {
let owner = match owner {
LootOwnerKind::Player(owner_uid) => {
let maybe_owner_name =
ecs.entity_from_uid((*owner_uid).into()).and_then(|entity| {
let maybe_owner_name = ecs.entity_from_uid(*owner_uid).and_then(|entity| {
ecs.read_storage::<comp::Stats>()
.get(entity)
.map(|stats| stats.name.clone())
@ -4056,7 +4055,7 @@ impl Hud {
let ecs = client.state().ecs();
let inventories = ecs.read_component::<comp::Inventory>();
let get_inventory = |uid: Uid| {
if let Some(entity) = ecs.entity_from_uid(uid.0) {
if let Some(entity) = ecs.entity_from_uid(uid) {
inventories.get(entity)
} else {
None
@ -4914,7 +4913,7 @@ impl Hud {
let me = client.entity();
let my_uid = uids.get(me);
if let Some(entity) = ecs.entity_from_uid(info.target.0) {
if let Some(entity) = ecs.entity_from_uid(info.target) {
if let Some(floater_list) = hp_floater_lists.get_mut(entity) {
let hit_me = my_uid.map_or(false, |&uid| {
(info.target == uid) && global_state.settings.interface.sct_inc_dmg

View File

@ -204,7 +204,7 @@ impl<'a> Trade<'a> {
let inventories = self.client.inventories();
let check_if_us = |who: usize| -> Option<_> {
let uid = trade.parties[who];
let entity = self.client.state().ecs().entity_from_uid(uid.0)?;
let entity = self.client.state().ecs().entity_from_uid(uid)?;
let is_ours = entity == self.client.entity();
Some(((who, uid, entity), is_ours))
};

View File

@ -62,7 +62,7 @@ use core::{
};
use guillotiere::AtlasAllocator;
use hashbrown::HashMap;
use specs::{saveload::MarkerAllocator, Entity as EcsEntity, Join, LazyUpdate, WorldExt};
use specs::{Entity as EcsEntity, Join, LazyUpdate, WorldExt};
use std::sync::Arc;
use treeculler::{BVol, BoundingSphere};
use vek::*;
@ -1055,7 +1055,7 @@ impl FigureMgr {
let mount_transform_pos = (|| -> Option<_> {
if let Some(is_rider) = is_rider {
let mount = is_rider.mount;
let mount = uid_allocator.retrieve_entity_internal(mount.into())?;
let mount = uid_allocator.retrieve_entity_internal(mount)?;
let body = *bodies.get(mount)?;
let meta = self.states.get_mut(&body, &mount)?;
Some((meta.mount_transform, meta.mount_world_pos))

View File

@ -26,7 +26,7 @@ use common::{
use common_base::span;
use hashbrown::HashMap;
use rand::prelude::*;
use specs::{saveload::MarkerAllocator, Join, WorldExt};
use specs::{Join, WorldExt};
use std::{
f32::consts::{PI, TAU},
time::Duration,
@ -289,7 +289,7 @@ impl ParticleMgr {
if target
.and_then(|target| {
ecs.read_resource::<UidAllocator>()
.retrieve_entity_internal(target.0)
.retrieve_entity_internal(target)
})
.and_then(|entity| {
ecs.read_storage::<Body>()

View File

@ -294,7 +294,7 @@ impl SessionState {
};
let target_name = match client.player_list().get(&target) {
Some(info) => info.player_alias.clone(),
None => match client.state().ecs().entity_from_uid(target.0) {
None => match client.state().ecs().entity_from_uid(target) {
Some(entity) => {
let stats = client.state().read_storage::<Stats>();
stats
@ -362,9 +362,7 @@ impl SessionState {
entity: uid,
reason,
} => {
if let Some(entity) =
client.state().ecs().entity_from_uid(uid.into())
{
if let Some(entity) = client.state().ecs().entity_from_uid(uid) {
self.hud.add_failed_entity_pickup(
entity,
HudCollectFailedReason::from_server_reason(