Rename retrieve_entity_internal to lookup_entity

This commit is contained in:
Imbris 2023-04-23 02:04:58 -04:00
parent ea725fffde
commit 3277d18265
25 changed files with 93 additions and 118 deletions

View File

@ -77,8 +77,7 @@ impl WorldSyncExt for specs::World {
/// Get an entity from a UID
fn entity_from_uid(&self, uid: Uid) -> Option<specs::Entity> {
self.read_resource::<UidAllocator>()
.retrieve_entity_internal(uid)
self.read_resource::<UidAllocator>().lookup_entity(uid)
}
fn apply_entity_package<P: CompPacket>(
@ -119,7 +118,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.into())
.lookup_entity(uid.into())
{
let force_update = player_entity == Some(entity);
match update {
@ -143,7 +142,7 @@ fn create_entity_with_uid(specs_world: &mut specs::World, entity_uid: u64) -> sp
let entity_uid = Uid::from(entity_uid);
let existing_entity = specs_world
.read_resource::<UidAllocator>()
.retrieve_entity_internal(entity_uid);
.lookup_entity(entity_uid);
match existing_entity {
Some(entity) => entity,

View File

@ -725,9 +725,7 @@ pub fn may_harm(
if let Some(Alignment::Owned(uid)) = alignment {
// return original entity
// if can't get owner
uid_allocator
.retrieve_entity_internal(uid)
.unwrap_or(entity)
uid_allocator.lookup_entity(uid).unwrap_or(entity)
} else {
entity
}

View File

@ -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);
let entity = |uid: Uid| uid_allocator.lookup_entity(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);
let entity = |uid: Uid| uid_allocator.lookup_entity(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);
let entity = |uid: Uid| uid_allocator.lookup_entity(uid);
let mount = entity(this.mount);
let rider = entity(this.rider);
@ -228,24 +228,22 @@ impl VolumePos {
comp::Ori::default(),
*terrain.get(self.pos).ok()?,
)),
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)?;
Volume::Entity(uid) => uid_allocator.lookup_entity(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::<f32>::translation_3d(local_translation);
let trans = Mat4::from(ori.to_quat()).translated_3d(pos.0)
* Mat4::<f32>::translation_3d(local_translation);
Some((trans, ori, block))
}),
Some((trans, ori, block))
}),
}
}
@ -258,18 +256,16 @@ impl VolumePos {
) -> Option<Block> {
match self.kind {
Volume::Terrain => Some(*terrain.get(self.pos).ok()?),
Volume::Entity(uid) => uid_allocator
.retrieve_entity_internal(uid)
.and_then(|entity| {
let collider = colliders.get(entity)?;
Volume::Entity(uid) => uid_allocator.lookup_entity(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)
}),
}
}
}
@ -330,7 +326,7 @@ impl Link for VolumeMounting {
colliders,
): &mut Self::CreateData<'_>,
) -> Result<(), Self::Error> {
let entity = |uid: Uid| uid_allocator.retrieve_entity_internal(uid.into());
let entity = |uid: Uid| uid_allocator.lookup_entity(uid);
let riders = match this.pos.kind {
Volume::Terrain => &mut *terrain_riders,
@ -375,7 +371,7 @@ impl Link for VolumeMounting {
colliders,
): &mut Self::PersistData<'_>,
) -> bool {
let entity = |uid: Uid| uid_allocator.retrieve_entity_internal(uid.into());
let entity = |uid: Uid| uid_allocator.lookup_entity(uid);
let is_alive =
|entity| entities.is_alive(entity) && healths.get(entity).map_or(true, |h| !h.is_dead);
let riders = match this.pos.kind {
@ -407,7 +403,7 @@ impl Link for VolumeMounting {
this: &LinkHandle<Self>,
(terrain_riders, volume_riders, is_rider, uid_allocator): &mut Self::DeleteData<'_>,
) {
let entity = |uid: Uid| uid_allocator.retrieve_entity_internal(uid.into());
let entity = |uid: Uid| uid_allocator.lookup_entity(uid);
let riders = match this.pos.kind {
Volume::Terrain => Some(&mut **terrain_riders),

View File

@ -55,9 +55,7 @@ impl UidAllocator {
id
}
pub fn retrieve_entity_internal(&self, id: Uid) -> Option<Entity> {
self.mapping.get(&id).copied()
}
pub fn lookup_entity(&self, id: Uid) -> Option<Entity> { self.mapping.get(&id).copied() }
}
#[cfg(not(target_arch = "wasm32"))]

View File

@ -238,9 +238,13 @@ fn retrieve_action(
EcsAccessError::EcsPointerNotAvailable,
))?
};
let player = world.uid_allocator.retrieve_entity_internal(e).ok_or(
RetrieveError::EcsAccessError(EcsAccessError::EcsEntityNotFound(e)),
)?;
let player =
world
.uid_allocator
.lookup_entity(e)
.ok_or(RetrieveError::EcsAccessError(
EcsAccessError::EcsEntityNotFound(e),
))?;
Ok(RetrieveResult::GetPlayerName(
world
@ -263,9 +267,13 @@ fn retrieve_action(
EcsAccessError::EcsPointerNotAvailable,
))?
};
let player = world.uid_allocator.retrieve_entity_internal(e).ok_or(
RetrieveError::EcsAccessError(EcsAccessError::EcsEntityNotFound(e)),
)?;
let player =
world
.uid_allocator
.lookup_entity(e)
.ok_or(RetrieveError::EcsAccessError(
EcsAccessError::EcsEntityNotFound(e),
))?;
Ok(RetrieveResult::GetEntityHealth(
world
.health

View File

@ -96,7 +96,7 @@ impl<'a> System<'a> for Sys {
let same_group = |uid: Uid| {
read_data
.uid_allocator
.retrieve_entity_internal(uid)
.lookup_entity(uid)
.and_then(|e| read_data.groups.get(e))
.map_or(false, |owner_group| {
Some(owner_group) == read_data.groups.get(target)
@ -166,9 +166,7 @@ fn activate_aura(
Alignment::Owned(uid) => Some(uid),
_ => None,
})
.and_then(|uid| {
read_data.uid_allocator.retrieve_entity_internal(*uid)
})
.and_then(|uid| read_data.uid_allocator.lookup_entity(*uid))
.and_then(|owner| read_data.char_states.get(owner))
.map_or(false, CharacterState::is_sitting))
},
@ -185,9 +183,7 @@ fn activate_aura(
// when we will add this.
let may_harm = || {
let owner = match source {
BuffSource::Character { by } => {
read_data.uid_allocator.retrieve_entity_internal(by)
},
BuffSource::Character { by } => read_data.uid_allocator.lookup_entity(by),
_ => None,
};
combat::may_harm(

View File

@ -97,7 +97,7 @@ impl<'a> System<'a> for Sys {
let beam_owner = beam_segment
.owner
.and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid));
.and_then(|uid| read_data.uid_allocator.lookup_entity(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

@ -275,29 +275,27 @@ impl<'a> System<'a> for Sys {
}
})
.for_each(|(buff_id, buff, uid, aura_key)| {
let replace = if let Some(aura_entity) = read_data
.uid_allocator
.retrieve_entity_internal((*uid).into())
{
if let Some(aura) = read_data
.auras
.get(aura_entity)
.and_then(|auras| auras.auras.get(*aura_key))
{
if let (Some(pos), Some(aura_pos)) = (
read_data.positions.get(entity),
read_data.positions.get(aura_entity),
) {
pos.0.distance_squared(aura_pos.0) > aura.radius.powi(2)
let replace =
if let Some(aura_entity) = read_data.uid_allocator.lookup_entity(*uid) {
if let Some(aura) = read_data
.auras
.get(aura_entity)
.and_then(|auras| auras.auras.get(*aura_key))
{
if let (Some(pos), Some(aura_pos)) = (
read_data.positions.get(entity),
read_data.positions.get(aura_entity),
) {
pos.0.distance_squared(aura_pos.0) > aura.radius.powi(2)
} else {
true
}
} else {
true
}
} else {
true
}
} else {
true
};
};
if replace {
expired_buffs.push(*buff_id);
server_emitter.emit(ServerEvent::Buff {
@ -504,12 +502,9 @@ fn execute_effect(
ModifierKind::Fractional => health.maximum() * amount,
};
let damage_contributor = by.and_then(|uid| {
read_data
.uid_allocator
.retrieve_entity_internal(uid)
.map(|entity| {
DamageContributor::new(uid, read_data.groups.get(entity).cloned())
})
read_data.uid_allocator.lookup_entity(uid).map(|entity| {
DamageContributor::new(uid, read_data.groups.get(entity).cloned())
})
});
server_emitter.emit(ServerEvent::HealthChange {
entity,

View File

@ -48,9 +48,8 @@ impl<'a> System<'a> for Sys {
for event in controller.events.drain(..) {
match event {
ControlEvent::Mount(mountee_uid) => {
if let Some(mountee_entity) = read_data
.uid_allocator
.retrieve_entity_internal(mountee_uid)
if let Some(mountee_entity) =
read_data.uid_allocator.lookup_entity(mountee_uid)
{
server_emitter.emit(ServerEvent::Mount(entity, mountee_entity));
}
@ -80,9 +79,7 @@ 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)
{
if let Some(npc_entity) = read_data.uid_allocator.lookup_entity(npc_uid) {
server_emitter
.emit(ServerEvent::NpcInteract(entity, npc_entity, subject));
}

View File

@ -54,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)
.lookup_entity(is_mount.rider)
.and_then(|rider| {
controllers
.get_mut(rider)
@ -138,7 +138,7 @@ impl<'a> System<'a> for Sys {
common::mounting::Volume::Terrain => Vec3::zero(),
common::mounting::Volume::Entity(uid) => {
if let Some(v) = uid_allocator
.retrieve_entity_internal(uid.into())
.lookup_entity(uid)
.and_then(|e| velocities.get(e))
{
v.0
@ -172,7 +172,7 @@ impl<'a> System<'a> for Sys {
match is_volume_rider.pos.kind {
common::mounting::Volume::Entity(uid) => {
if let Some(controller) = uid_allocator
.retrieve_entity_internal(uid.into())
.lookup_entity(uid)
.and_then(|e| controllers.get_mut(e))
{
controller.inputs = inputs;

View File

@ -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));
.and_then(|uid| read_data.uid_allocator.lookup_entity(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)
.lookup_entity(other)
.and_then(|e| read_data.groups.get(e))
);
@ -125,7 +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);
let entity_of = |uid: Uid| read_data.uid_allocator.lookup_entity(uid);
// Don't hit if there is terrain between the projectile and where the entity was
// supposed to be hit by it.

View File

@ -91,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));
.and_then(|uid| read_data.uid_allocator.lookup_entity(uid));
if rng.gen_bool(0.05) {
server_emitter.emit(ServerEvent::Sound {

View File

@ -65,7 +65,7 @@ pub fn aim_projectile(speed: f32, pos: Vec3<f32>, tgt: Vec3<f32>) -> Option<Dir>
}
pub fn get_entity_by_id(uid: Uid, read_data: &ReadData) -> Option<EcsEntity> {
read_data.uid_allocator.retrieve_entity_internal(uid)
read_data.uid_allocator.lookup_entity(uid)
}
/// Calculates whether the agent should continue chase or let the target escape.

View File

@ -246,7 +246,7 @@ fn position_mut<T>(
.state
.ecs()
.read_resource::<UidAllocator>()
.retrieve_entity_internal(is_rider.mount)
.lookup_entity(is_rider.mount)
})
.map(Ok)
.or_else(|| {
@ -263,7 +263,7 @@ fn position_mut<T>(
.state
.ecs()
.read_resource::<UidAllocator>()
.retrieve_entity_internal(uid.into())?),
.lookup_entity(uid)?),
})
})
})

View File

@ -569,7 +569,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, last_change: Healt
state
.ecs()
.read_resource::<UidAllocator>()
.retrieve_entity_internal((*entity_uid).into())
.lookup_entity(*entity_uid)
},
)
.and_then(|killer| state.entity_as_actor(killer)),
@ -742,10 +742,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
let settings = server.settings();
let server_eventbus = ecs.read_resource::<EventBus<ServerEvent>>();
let time = ecs.read_resource::<Time>();
let owner_entity = owner.and_then(|uid| {
ecs.read_resource::<UidAllocator>()
.retrieve_entity_internal(uid)
});
let owner_entity = owner.and_then(|uid| ecs.read_resource::<UidAllocator>().lookup_entity(uid));
let explosion_volume = 6.25 * explosion.radius;
let mut emitter = server_eventbus.emitter();

View File

@ -860,7 +860,7 @@ impl StateExt for State {
.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);
let entity_from_uid = |uid| uid_allocator.lookup_entity(uid);
if msg.chat_type.uid().map_or(true, |sender| {
entity_from_uid(sender).map_or(false, |e| {

View File

@ -102,17 +102,13 @@ impl<'a> System<'a> for Sys {
// The entity that is moving, if riding it's the mount, otherwise it's itself
let moving_entity = is_rider
.and_then(|is_rider| {
read_data
.uid_allocator
.retrieve_entity_internal(is_rider.mount)
})
.and_then(|is_rider| read_data.uid_allocator.lookup_entity(is_rider.mount))
.or_else(|| {
is_volume_rider.and_then(|is_volume_rider| {
match is_volume_rider.pos.kind {
Volume::Terrain => None,
Volume::Entity(uid) => {
read_data.uid_allocator.retrieve_entity_internal(uid.into())
read_data.uid_allocator.lookup_entity(uid)
},
}
})

View File

@ -244,11 +244,7 @@ fn target_if_attacked(bdata: &mut BehaviorData) -> bool {
&& health.last_change.amount < 0.0 =>
{
if let Some(by) = health.last_change.damage_by() {
if let Some(attacker) = bdata
.read_data
.uid_allocator
.retrieve_entity_internal(by.uid())
{
if let Some(attacker) = bdata.read_data.uid_allocator.lookup_entity(by.uid()) {
// If target is dead or invulnerable (for now, this only
// means safezone), untarget them and idle.
if is_dead_or_invulnerable(attacker, bdata.read_data) {

View File

@ -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)
.lookup_entity(uid)
.map_or(true, |entity| !entities.is_alive(entity)),
LootOwnerKind::Group(group) => group_manager.group_info(group).is_none(),
}

View File

@ -39,7 +39,7 @@ impl<'a> System<'a> for Sys {
})
.filter_map(|(pet_entity, pet_pos, owner_uid)| {
uid_allocator
.retrieve_entity_internal(owner_uid)
.lookup_entity(owner_uid)
.and_then(|owner_entity| {
match (positions.get(owner_entity), physics.get(owner_entity)) {
(Some(position), Some(physics)) => {

View File

@ -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);
let entity = uid_allocator.lookup_entity(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

@ -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);
let entity = uid_allocator.lookup_entity(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)
.lookup_entity(uid)
.and_then(|entity| stats.get(entity))
.map(|stats| stats.name.as_str())
})

View File

@ -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);
let entity = uid_allocator.lookup_entity(uid);
let member_pos = entity.and_then(|entity| member_pos.get(entity));
if let Some(member_pos) = member_pos {

View File

@ -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)?;
let mount = uid_allocator.lookup_entity(mount)?;
let body = *bodies.get(mount)?;
let meta = self.states.get_mut(&body, &mount)?;
Some((meta.mount_transform, meta.mount_world_pos))

View File

@ -288,8 +288,7 @@ impl ParticleMgr {
let ecs = scene_data.state.ecs();
if target
.and_then(|target| {
ecs.read_resource::<UidAllocator>()
.retrieve_entity_internal(target)
ecs.read_resource::<UidAllocator>().lookup_entity(target)
})
.and_then(|entity| {
ecs.read_storage::<Body>()