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

View File

@ -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<comp::Pos, impl std::ops::Deref<Target = MaskedStorage<comp::Pos>>>,
orientations: &Storage<comp::Ori, impl std::ops::Deref<Target = MaskedStorage<comp::Ori>>>,
mut read_pos_and_ori: impl FnMut(Entity) -> Option<(comp::Pos, comp::Ori)>,
colliders: &ReadStorage<comp::Collider>,
) -> Option<(Mat4<f32>, 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)?;

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(
&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 {

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

View File

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

View File

@ -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::<vcomp::Interpolated>().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::<vcomp::Interpolated>().get(e)
.map(|interpolated| (comp::Pos(interpolated.pos), interpolated.ori))
},
&client.state().read_storage(),
)
.map_or(false, |(mat, block)| {

View File

@ -709,17 +709,22 @@ impl Scene {
lights.extend(
(
&scene_data.state.ecs().entities(),
&scene_data.state.read_storage::<comp::Pos>(),
&scene_data.state.read_storage::<comp::Ori>(),
&scene_data
.state
.read_storage::<crate::ecs::comp::Interpolated>(),
&scene_data.state.read_storage::<comp::Body>(),
&scene_data.state.read_storage::<comp::Collider>(),
)
.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,9 +732,7 @@ 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, _)| {
Some(
blocks_of_interest
.lights
.iter()
@ -742,8 +745,8 @@ impl Scene {
})
.map(|(wpos, level)| {
Light::new(wpos, Rgb::white(), *level as f32 / 7.0)
})
})
}),
)
} else {
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.read_storage::<comp::Body>(),
&ecs.read_storage::<comp::Pos>(),
&ecs.read_storage::<comp::Ori>(),
&ecs.read_storage::<crate::ecs::comp::Interpolated>(),
ecs.read_storage::<comp::Collider>().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::<f32>()); // 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),

View File

@ -248,18 +248,21 @@ pub(super) fn select_interactable(
&ecs.entities(),
&ecs.read_storage::<Uid>(),
&ecs.read_storage::<comp::Body>(),
&ecs.read_storage::<comp::Pos>(),
&ecs.read_storage::<comp::Ori>(),
&ecs.read_storage::<crate::ecs::comp::Interpolated>(),
&ecs.read_storage::<comp::Collider>(),
);
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(
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
}