use interpolated pos and ori

This commit is contained in:
Isse 2023-04-23 17:45:28 +02:00
parent facea64a58
commit 192356f6c5
9 changed files with 67 additions and 65 deletions

View File

@ -257,7 +257,7 @@ pub mod figuredata {
let dyna = base_structure.vol.map_into(|cell| { let dyna = base_structure.vol.map_into(|cell| {
if let Some(i) = cell { if let Some(i) = cell {
let color = base_structure.palette[u8::from(i) as usize]; 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) block.to_block(color)
} else { } else {
Block::new(BlockKind::Misc, color) Block::new(BlockKind::Misc, color)

View File

@ -8,10 +8,8 @@ use crate::{
use hashbrown::HashSet; use hashbrown::HashSet;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use specs::{ use specs::{
saveload::MarkerAllocator, saveload::MarkerAllocator, storage::GenericWriteStorage, Component, DenseVecStorage, Entities,
storage::{GenericWriteStorage, MaskedStorage}, Entity, Read, ReadExpect, ReadStorage, Write, WriteStorage,
Component, DenseVecStorage, Entities, Read, ReadExpect, ReadStorage, Storage, Write,
WriteStorage,
}; };
use vek::*; use vek::*;
@ -197,8 +195,7 @@ impl VolumePos {
&self, &self,
terrain: &TerrainGrid, terrain: &TerrainGrid,
uid_allocator: &UidAllocator, uid_allocator: &UidAllocator,
positions: &Storage<comp::Pos, impl std::ops::Deref<Target = MaskedStorage<comp::Pos>>>, mut read_pos_and_ori: impl FnMut(Entity) -> Option<(comp::Pos, comp::Ori)>,
orientations: &Storage<comp::Ori, impl std::ops::Deref<Target = MaskedStorage<comp::Ori>>>,
colliders: &ReadStorage<comp::Collider>, colliders: &ReadStorage<comp::Collider>,
) -> Option<(Mat4<f32>, Block)> { ) -> Option<(Mat4<f32>, Block)> {
match self.kind { match self.kind {
@ -211,8 +208,7 @@ impl VolumePos {
.retrieve_entity_internal(uid.0) .retrieve_entity_internal(uid.0)
.and_then(|entity| { .and_then(|entity| {
let collider = colliders.get(entity)?; let collider = colliders.get(entity)?;
let pos = positions.get(entity)?; let (pos, ori) = read_pos_and_ori(entity)?;
let ori = orientations.get(entity)?;
let voxel_colliders_manifest = VOXEL_COLLIDER_MANIFEST.read(); let voxel_colliders_manifest = VOXEL_COLLIDER_MANIFEST.read();
let voxel_collider = collider.get_vol(&voxel_colliders_manifest)?; let voxel_collider = collider.get_vol(&voxel_colliders_manifest)?;

View File

@ -98,8 +98,7 @@ impl<'a> System<'a> for Sys {
if let Some((mut mat, _)) = is_volume_rider.pos.get_block_and_transform( if let Some((mut mat, _)) = is_volume_rider.pos.get_block_and_transform(
&terrain, &terrain,
&uid_allocator, &uid_allocator,
&positions, |e| positions.get(e).copied().zip(orientations.get(e).copied()),
&orientations,
&colliders, &colliders,
) { ) {
let Some((mount_offset, mount_dir)) = is_volume_rider.block.mount_offset() else { let Some((mount_offset, mount_dir)) = is_volume_rider.block.mount_offset() else {

View File

@ -144,11 +144,10 @@ pub fn handle_mount_volume(server: &mut Server, rider: EcsEntity, volume_pos: Vo
let state = server.state_mut(); let state = server.state_mut();
let block_transform = volume_pos.get_block_and_transform( let block_transform = volume_pos.get_block_and_transform(
&state.terrain(),
&state.ecs().read_resource(), &state.ecs().read_resource(),
&state.ecs().read_resource(), |e| state.read_storage().get(e).copied().zip(state.read_storage().get(e).copied()),
&state.ecs().read_storage(), &state.read_storage(),
&state.ecs().read_storage(),
&state.ecs().read_storage(),
); );
if let Some((mat, block)) = block_transform if let Some((mat, block)) = block_transform

View File

@ -754,11 +754,10 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
pos.get_block_and_transform( pos.get_block_and_transform(
&state.terrain(), &state.terrain(),
&state.ecs().read_resource(), &state.ecs().read_resource(),
&state.read_storage(), |e| state.read_storage().get(e).copied().zip(state.read_storage().get(e).copied()),
&state.read_storage(),
&state.read_storage(), &state.read_storage(),
) )
.map(|(transform, _)| transform.mul_point(Vec3::broadcast(0.5))) .map(|(mat, _)| mat.mul_point(Vec3::broadcast(0.5)))
}); });
if !in_range { if !in_range {
debug!( debug!(

View File

@ -2041,7 +2041,12 @@ impl Hud {
// Render overtime for an interactable block // Render overtime for an interactable block
if let Some(Interactable::Block(block, pos, interaction)) = interactable 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::<vcomp::Interpolated>().get(e).map(|interpolated| (comp::Pos(interpolated.pos), interpolated.ori)),
&ecs.read_storage(),
) {
let overitem_id = overitem_walker.next( let overitem_id = overitem_walker.next(
&mut self.ids.overitems, &mut self.ids.overitems,
&mut ui_widgets.widget_id_generator(), &mut ui_widgets.widget_id_generator(),
@ -4743,8 +4748,10 @@ impl Hud {
pos.get_block_and_transform( pos.get_block_and_transform(
&client.state().terrain(), &client.state().terrain(),
&client.state().ecs().read_resource(), &client.state().ecs().read_resource(),
&client.state().read_storage(), |e| {
&client.state().read_storage(), client.state().read_storage::<vcomp::Interpolated>().get(e)
.map(|interpolated| (comp::Pos(interpolated.pos), interpolated.ori))
},
&client.state().read_storage(), &client.state().read_storage(),
) )
.map_or(false, |(mat, block)| { .map_or(false, |(mat, block)| {

View File

@ -709,17 +709,22 @@ impl Scene {
lights.extend( lights.extend(
( (
&scene_data.state.ecs().entities(), &scene_data.state.ecs().entities(),
&scene_data.state.read_storage::<comp::Pos>(), &scene_data
&scene_data.state.read_storage::<comp::Ori>(), .state
.read_storage::<crate::ecs::comp::Interpolated>(),
&scene_data.state.read_storage::<comp::Body>(), &scene_data.state.read_storage::<comp::Body>(),
&scene_data.state.read_storage::<comp::Collider>(), &scene_data.state.read_storage::<comp::Collider>(),
) )
.join() .join()
.filter_map(|(entity, pos, ori, body, collider)| { .filter_map(|(entity, interpolated, body, collider)| {
let vol = collider.get_vol(&voxel_colliders_manifest)?; 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) let mat = Mat4::from(interpolated.ori.to_quat())
* Mat4::translation_3d(vol.translation); .translated_3d(interpolated.pos)
* Mat4::translation_3d(offset);
let p = mat.inverted().mul_point(viewpoint_pos); let p = mat.inverted().mul_point(viewpoint_pos);
let aabb = Aabb { let aabb = Aabb {
@ -727,23 +732,21 @@ impl Scene {
max: vol.volume().sz.as_(), max: vol.volume().sz.as_(),
}; };
if aabb.contains_point(p) || aabb.distance_to_point(p) < max_light_dist { if aabb.contains_point(p) || aabb.distance_to_point(p) < max_light_dist {
figure_mgr Some(
.get_blocks_of_interest(entity, body, Some(collider)) blocks_of_interest
.map(move |(blocks_of_interest, _)| { .lights
blocks_of_interest .iter()
.lights .map(move |(block_offset, level)| {
.iter() let wpos = mat.mul_point(block_offset.as_() + 0.5);
.map(move |(block_offset, level)| { (wpos, level)
let wpos = mat.mul_point(block_offset.as_() + 0.5); })
(wpos, level) .filter(move |(wpos, _)| {
}) wpos.distance_squared(viewpoint_pos) < max_light_dist
.filter(move |(wpos, _)| { })
wpos.distance_squared(viewpoint_pos) < max_light_dist .map(|(wpos, level)| {
}) Light::new(wpos, Rgb::white(), *level as f32 / 7.0)
.map(|(wpos, level)| { }),
Light::new(wpos, Rgb::white(), *level as f32 / 7.0) )
})
})
} else { } else {
None None
} }

View File

@ -1568,11 +1568,10 @@ impl ParticleMgr {
}); });
} }
for (entity, body, pos, ori, collider) in ( for (entity, body, interpolated, collider) in (
&ecs.entities(), &ecs.entities(),
&ecs.read_storage::<comp::Body>(), &ecs.read_storage::<comp::Body>(),
&ecs.read_storage::<comp::Pos>(), &ecs.read_storage::<crate::ecs::comp::Interpolated>(),
&ecs.read_storage::<comp::Ori>(),
ecs.read_storage::<comp::Collider>().maybe(), ecs.read_storage::<comp::Collider>().maybe(),
) )
.join() .join()
@ -1580,6 +1579,10 @@ impl ParticleMgr {
if let Some((blocks_of_interest, offset)) = if let Some((blocks_of_interest, offset)) =
figure_mgr.get_blocks_of_interest(entity, body, collider) 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 blocks = (particles.blocks)(blocks_of_interest);
let avg_particles = dt * blocks.len() as f32 * particles.rate; let avg_particles = dt * blocks.len() as f32 * particles.rate;
@ -1593,9 +1596,7 @@ impl ParticleMgr {
.copied() .copied()
.unwrap() .unwrap()
.map(|e: i32| e as f32 + rng.gen::<f32>()); // Can't fail .map(|e: i32| e as f32 + rng.gen::<f32>()); // Can't fail
let wpos = (Mat4::from(ori.to_quat()).translated_3d(pos.0) let wpos = mat.mul_point(rel_pos);
* (rel_pos + offset).with_w(1.0))
.xyz();
Particle::new( Particle::new(
Duration::from_secs_f32(particles.lifetime), Duration::from_secs_f32(particles.lifetime),

View File

@ -248,18 +248,21 @@ pub(super) fn select_interactable(
&ecs.entities(), &ecs.entities(),
&ecs.read_storage::<Uid>(), &ecs.read_storage::<Uid>(),
&ecs.read_storage::<comp::Body>(), &ecs.read_storage::<comp::Body>(),
&ecs.read_storage::<comp::Pos>(), &ecs.read_storage::<crate::ecs::comp::Interpolated>(),
&ecs.read_storage::<comp::Ori>(),
&ecs.read_storage::<comp::Collider>(), &ecs.read_storage::<comp::Collider>(),
); );
let volumes = volumes_data let volumes = volumes_data
.join() .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 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) let mat = Mat4::from(interpolated.ori.to_quat()).translated_3d(interpolated.pos)
* Mat4::translation_3d(vol.translation); * Mat4::translation_3d(offset);
let p = mat.inverted().mul_point(player_pos); let p = mat.inverted().mul_point(player_pos);
let aabb = Aabb { let aabb = Aabb {
@ -267,17 +270,12 @@ pub(super) fn select_interactable(
max: vol.volume().sz.as_(), max: vol.volume().sz.as_(),
}; };
if aabb.contains_point(p) || aabb.distance_to_point(p) < search_dist { if aabb.contains_point(p) || aabb.distance_to_point(p) < search_dist {
scene Some(blocks_of_interest.interactables.iter().map(
.figure_mgr() move |(block_offset, interaction)| {
.get_blocks_of_interest(entity, body, Some(collider)) let wpos = mat.mul_point(block_offset.as_() + 0.5);
.map(move |(blocks_of_interest, _)| { (wpos, VolumePos::entity(*block_offset, *uid), interaction)
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 { } else {
None None
} }