From 192356f6c51d38f14f3aa122f37743e725245af8 Mon Sep 17 00:00:00 2001 From: Isse Date: Sun, 23 Apr 2023 17:45:28 +0200 Subject: [PATCH] use interpolated pos and ori --- common/src/comp/body/ship.rs | 2 +- common/src/mounting.rs | 12 +++---- common/systems/src/mount.rs | 3 +- server/src/events/interaction.rs | 7 ++--- server/src/events/inventory_manip.rs | 5 ++- voxygen/src/hud/mod.rs | 13 ++++++-- voxygen/src/scene/mod.rs | 47 +++++++++++++++------------- voxygen/src/scene/particle.rs | 13 ++++---- voxygen/src/session/interactable.rs | 30 +++++++++--------- 9 files changed, 67 insertions(+), 65 deletions(-) diff --git a/common/src/comp/body/ship.rs b/common/src/comp/body/ship.rs index aa458c4547..788dc2238e 100644 --- a/common/src/comp/body/ship.rs +++ b/common/src/comp/body/ship.rs @@ -257,7 +257,7 @@ pub mod figuredata { let dyna = base_structure.vol.map_into(|cell| { if let Some(i) = cell { let color = base_structure.palette[u8::from(i) as usize]; - if let Some(block) = spec.custom_indices.get(&i.into()) && index == 0 { + if let Some(block) = spec.custom_indices.get(&i.get()) && index == 0 { block.to_block(color) } else { Block::new(BlockKind::Misc, color) diff --git a/common/src/mounting.rs b/common/src/mounting.rs index 0a087fa693..51410c66ed 100644 --- a/common/src/mounting.rs +++ b/common/src/mounting.rs @@ -8,10 +8,8 @@ use crate::{ use hashbrown::HashSet; use serde::{Deserialize, Serialize}; use specs::{ - saveload::MarkerAllocator, - storage::{GenericWriteStorage, MaskedStorage}, - Component, DenseVecStorage, Entities, Read, ReadExpect, ReadStorage, Storage, Write, - WriteStorage, + saveload::MarkerAllocator, storage::GenericWriteStorage, Component, DenseVecStorage, Entities, + Entity, Read, ReadExpect, ReadStorage, Write, WriteStorage, }; use vek::*; @@ -197,8 +195,7 @@ impl VolumePos { &self, terrain: &TerrainGrid, uid_allocator: &UidAllocator, - positions: &Storage>>, - orientations: &Storage>>, + mut read_pos_and_ori: impl FnMut(Entity) -> Option<(comp::Pos, comp::Ori)>, colliders: &ReadStorage, ) -> Option<(Mat4, Block)> { match self.kind { @@ -211,8 +208,7 @@ impl VolumePos { .retrieve_entity_internal(uid.0) .and_then(|entity| { let collider = colliders.get(entity)?; - let pos = positions.get(entity)?; - let ori = orientations.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)?; diff --git a/common/systems/src/mount.rs b/common/systems/src/mount.rs index eaa060641a..9aa56983d5 100644 --- a/common/systems/src/mount.rs +++ b/common/systems/src/mount.rs @@ -98,8 +98,7 @@ impl<'a> System<'a> for Sys { if let Some((mut mat, _)) = is_volume_rider.pos.get_block_and_transform( &terrain, &uid_allocator, - &positions, - &orientations, + |e| positions.get(e).copied().zip(orientations.get(e).copied()), &colliders, ) { let Some((mount_offset, mount_dir)) = is_volume_rider.block.mount_offset() else { diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index 3281559f9c..d498161a4e 100644 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -144,11 +144,10 @@ pub fn handle_mount_volume(server: &mut Server, rider: EcsEntity, volume_pos: Vo let state = server.state_mut(); let block_transform = volume_pos.get_block_and_transform( + &state.terrain(), &state.ecs().read_resource(), - &state.ecs().read_resource(), - &state.ecs().read_storage(), - &state.ecs().read_storage(), - &state.ecs().read_storage(), + |e| state.read_storage().get(e).copied().zip(state.read_storage().get(e).copied()), + &state.read_storage(), ); if let Some((mat, block)) = block_transform diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index 80b9be97df..fd452681d5 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -754,11 +754,10 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv pos.get_block_and_transform( &state.terrain(), &state.ecs().read_resource(), - &state.read_storage(), - &state.read_storage(), + |e| state.read_storage().get(e).copied().zip(state.read_storage().get(e).copied()), &state.read_storage(), ) - .map(|(transform, _)| transform.mul_point(Vec3::broadcast(0.5))) + .map(|(mat, _)| mat.mul_point(Vec3::broadcast(0.5))) }); if !in_range { debug!( diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index f835f11dd8..8bae2a789d 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -2041,7 +2041,12 @@ impl Hud { // Render overtime for an interactable block if let Some(Interactable::Block(block, pos, interaction)) = interactable - && let Some((mat, _)) = pos.get_block_and_transform(&ecs.read_resource(), &ecs.read_resource(), &ecs.read_storage(), &ecs.read_storage(), &ecs.read_storage()) { + && let Some((mat, _)) = pos.get_block_and_transform( + &ecs.read_resource(), + &ecs.read_resource(), + |e| ecs.read_storage::().get(e).map(|interpolated| (comp::Pos(interpolated.pos), interpolated.ori)), + &ecs.read_storage(), + ) { let overitem_id = overitem_walker.next( &mut self.ids.overitems, &mut ui_widgets.widget_id_generator(), @@ -4743,8 +4748,10 @@ impl Hud { pos.get_block_and_transform( &client.state().terrain(), &client.state().ecs().read_resource(), - &client.state().read_storage(), - &client.state().read_storage(), + |e| { + client.state().read_storage::().get(e) + .map(|interpolated| (comp::Pos(interpolated.pos), interpolated.ori)) + }, &client.state().read_storage(), ) .map_or(false, |(mat, block)| { diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 878f23492a..540c62ba8b 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -709,17 +709,22 @@ impl Scene { lights.extend( ( &scene_data.state.ecs().entities(), - &scene_data.state.read_storage::(), - &scene_data.state.read_storage::(), + &scene_data + .state + .read_storage::(), &scene_data.state.read_storage::(), &scene_data.state.read_storage::(), ) .join() - .filter_map(|(entity, pos, ori, body, collider)| { + .filter_map(|(entity, interpolated, body, collider)| { let vol = collider.get_vol(&voxel_colliders_manifest)?; + let (blocks_of_interest, offset) = + figure_mgr + .get_blocks_of_interest(entity, body, Some(collider))?; - let mat = Mat4::from(ori.to_quat()).translated_3d(pos.0) - * Mat4::translation_3d(vol.translation); + let mat = Mat4::from(interpolated.ori.to_quat()) + .translated_3d(interpolated.pos) + * Mat4::translation_3d(offset); let p = mat.inverted().mul_point(viewpoint_pos); let aabb = Aabb { @@ -727,23 +732,21 @@ impl Scene { max: vol.volume().sz.as_(), }; if aabb.contains_point(p) || aabb.distance_to_point(p) < max_light_dist { - figure_mgr - .get_blocks_of_interest(entity, body, Some(collider)) - .map(move |(blocks_of_interest, _)| { - blocks_of_interest - .lights - .iter() - .map(move |(block_offset, level)| { - let wpos = mat.mul_point(block_offset.as_() + 0.5); - (wpos, level) - }) - .filter(move |(wpos, _)| { - wpos.distance_squared(viewpoint_pos) < max_light_dist - }) - .map(|(wpos, level)| { - Light::new(wpos, Rgb::white(), *level as f32 / 7.0) - }) - }) + Some( + blocks_of_interest + .lights + .iter() + .map(move |(block_offset, level)| { + let wpos = mat.mul_point(block_offset.as_() + 0.5); + (wpos, level) + }) + .filter(move |(wpos, _)| { + wpos.distance_squared(viewpoint_pos) < max_light_dist + }) + .map(|(wpos, level)| { + Light::new(wpos, Rgb::white(), *level as f32 / 7.0) + }), + ) } else { None } diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index 7e54b207b6..8fa1436428 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -1568,11 +1568,10 @@ impl ParticleMgr { }); } - for (entity, body, pos, ori, collider) in ( + for (entity, body, interpolated, collider) in ( &ecs.entities(), &ecs.read_storage::(), - &ecs.read_storage::(), - &ecs.read_storage::(), + &ecs.read_storage::(), ecs.read_storage::().maybe(), ) .join() @@ -1580,6 +1579,10 @@ impl ParticleMgr { if let Some((blocks_of_interest, offset)) = figure_mgr.get_blocks_of_interest(entity, body, collider) { + let mat = Mat4::from(interpolated.ori.to_quat()) + .translated_3d(interpolated.pos) + * Mat4::translation_3d(offset); + let blocks = (particles.blocks)(blocks_of_interest); let avg_particles = dt * blocks.len() as f32 * particles.rate; @@ -1593,9 +1596,7 @@ impl ParticleMgr { .copied() .unwrap() .map(|e: i32| e as f32 + rng.gen::()); // Can't fail - let wpos = (Mat4::from(ori.to_quat()).translated_3d(pos.0) - * (rel_pos + offset).with_w(1.0)) - .xyz(); + let wpos = mat.mul_point(rel_pos); Particle::new( Duration::from_secs_f32(particles.lifetime), diff --git a/voxygen/src/session/interactable.rs b/voxygen/src/session/interactable.rs index 2a40e85724..840a8b0d50 100644 --- a/voxygen/src/session/interactable.rs +++ b/voxygen/src/session/interactable.rs @@ -248,18 +248,21 @@ pub(super) fn select_interactable( &ecs.entities(), &ecs.read_storage::(), &ecs.read_storage::(), - &ecs.read_storage::(), - &ecs.read_storage::(), + &ecs.read_storage::(), &ecs.read_storage::(), ); let volumes = volumes_data .join() - .filter_map(|(entity, uid, body, pos, ori, collider)| { + .filter_map(|(entity, uid, body, interpolated, collider)| { let vol = collider.get_vol(&voxel_colliders_manifest)?; + let (blocks_of_interest, offset) = + scene + .figure_mgr() + .get_blocks_of_interest(entity, body, Some(collider))?; - let mat = Mat4::from(ori.to_quat()).translated_3d(pos.0) - * Mat4::translation_3d(vol.translation); + let mat = Mat4::from(interpolated.ori.to_quat()).translated_3d(interpolated.pos) + * Mat4::translation_3d(offset); let p = mat.inverted().mul_point(player_pos); let aabb = Aabb { @@ -267,17 +270,12 @@ pub(super) fn select_interactable( max: vol.volume().sz.as_(), }; if aabb.contains_point(p) || aabb.distance_to_point(p) < search_dist { - scene - .figure_mgr() - .get_blocks_of_interest(entity, body, Some(collider)) - .map(move |(blocks_of_interest, _)| { - blocks_of_interest.interactables.iter().map( - move |(block_offset, interaction)| { - let wpos = mat.mul_point(block_offset.as_() + 0.5); - (wpos, VolumePos::entity(*block_offset, *uid), interaction) - }, - ) - }) + Some(blocks_of_interest.interactables.iter().map( + move |(block_offset, interaction)| { + let wpos = mat.mul_point(block_offset.as_() + 0.5); + (wpos, VolumePos::entity(*block_offset, *uid), interaction) + }, + )) } else { None }