Fix interpolation for possession, and make the mount point of airships above their deck.

This commit is contained in:
Avi Weinstock 2021-03-14 20:07:54 -04:00
parent be9476a1ca
commit 546ee48073
6 changed files with 28 additions and 8 deletions

View File

@ -1460,6 +1460,7 @@ impl Client {
ServerGeneral::SetPlayerEntity(uid) => { 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.0) {
self.entity = entity; self.entity = entity;
*self.state.ecs_mut().write_resource() = PlayerEntity(Some(entity));
} else { } else {
return Err(Error::Other("Failed to find entity from uid.".to_owned())); return Err(Error::Other("Failed to find entity from uid.".to_owned()));
} }

View File

@ -15,6 +15,7 @@ default = ["simd"]
[dependencies] [dependencies]
common-base = { package = "veloren-common-base", path = "base" } common-base = { package = "veloren-common-base", path = "base" }
#inline_tweak = "1.0.2"
# Serde # Serde
serde = { version = "1.0.110", features = ["derive", "rc"] } serde = { version = "1.0.110", features = ["derive", "rc"] }

View File

@ -12,6 +12,7 @@ default = ["simd"]
[dependencies] [dependencies]
common = {package = "veloren-common", path = "../../common"} common = {package = "veloren-common", path = "../../common"}
#inline_tweak = "1.0.2"
sum_type = "0.2.0" sum_type = "0.2.0"
vek = { version = "=0.14.1", features = ["serde"] } vek = { version = "=0.14.1", features = ["serde"] }

View File

@ -32,8 +32,8 @@ impl<T: 'static + Send + Sync> Component for InterpBuffer<T> {
// 0 is pure physics, 1 is pure extrapolation // 0 is pure physics, 1 is pure extrapolation
const PHYSICS_VS_EXTRAPOLATION_FACTOR: f32 = 0.2; const PHYSICS_VS_EXTRAPOLATION_FACTOR: f32 = 0.2;
const POSITION_INTERP_SANITY: f32 = 1000.0; const POSITION_INTERP_SANITY: Option<f32> = None;
const VELOCITY_INTERP_SANITY: f32 = 1000.0; const VELOCITY_INTERP_SANITY: Option<f32> = None;
const ENABLE_POSITION_HERMITE: bool = false; const ENABLE_POSITION_HERMITE: bool = false;
impl InterpolatableComponent for Pos { impl InterpolatableComponent for Pos {
@ -52,7 +52,9 @@ impl InterpolatableComponent for Pos {
if (t1 - t0).abs() < f64::EPSILON { if (t1 - t0).abs() < f64::EPSILON {
return self; return self;
} }
if p0.0.distance_squared(p1.0) > POSITION_INTERP_SANITY.powf(2.0) { if POSITION_INTERP_SANITY
.map_or(false, |limit| p0.0.distance_squared(p1.0) > limit.powf(2.0))
{
warn!("position delta exceeded sanity check, clamping"); warn!("position delta exceeded sanity check, clamping");
return p1; return p1;
} }
@ -103,7 +105,9 @@ impl InterpolatableComponent for Vel {
if (t1 - t0).abs() < f64::EPSILON { if (t1 - t0).abs() < f64::EPSILON {
return self; return self;
} }
if p0.0.distance_squared(p1.0) > VELOCITY_INTERP_SANITY.powf(2.0) { if VELOCITY_INTERP_SANITY
.map_or(false, |limit| p0.0.distance_squared(p1.0) > limit.powf(2.0))
{
warn!("velocity delta exceeded sanity check, clamping"); warn!("velocity delta exceeded sanity check, clamping");
return p1; return p1;
} }

View File

@ -573,6 +573,13 @@ impl Body {
Body::Humanoid(_) | Body::BipedSmall(_) | Body::BipedLarge(_) Body::Humanoid(_) | Body::BipedSmall(_) | Body::BipedLarge(_)
) )
} }
pub fn mounting_offset(&self) -> Vec3<f32> {
match self {
Body::Ship(ship::Body::DefaultAirship) => Vec3::from([0.0, 0.0, 10.0]),
_ => Vec3::unit_z(),
}
}
} }
impl Component for Body { impl Component for Body {

View File

@ -1,11 +1,11 @@
use common::{ use common::{
comp::{Controller, MountState, Mounting, Ori, Pos, Vel}, comp::{Body, Controller, MountState, Mounting, Ori, Pos, Vel},
uid::UidAllocator, uid::UidAllocator,
}; };
use common_ecs::{Job, Origin, Phase, System}; use common_ecs::{Job, Origin, Phase, System};
use specs::{ use specs::{
saveload::{Marker, MarkerAllocator}, saveload::{Marker, MarkerAllocator},
Entities, Join, Read, WriteStorage, Entities, Join, Read, ReadStorage, WriteStorage,
}; };
use vek::*; use vek::*;
@ -23,6 +23,7 @@ impl<'a> System<'a> for Sys {
WriteStorage<'a, Pos>, WriteStorage<'a, Pos>,
WriteStorage<'a, Vel>, WriteStorage<'a, Vel>,
WriteStorage<'a, Ori>, WriteStorage<'a, Ori>,
ReadStorage<'a, Body>,
); );
const NAME: &'static str = "mount"; const NAME: &'static str = "mount";
@ -40,10 +41,13 @@ impl<'a> System<'a> for Sys {
mut positions, mut positions,
mut velocities, mut velocities,
mut orientations, mut orientations,
bodies,
): Self::SystemData, ): Self::SystemData,
) { ) {
// Mounted entities. // Mounted entities.
for (entity, mut mount_states) in (&entities, &mut mount_state.restrict_mut()).join() { for (entity, mut mount_states, body) in
(&entities, &mut mount_state.restrict_mut(), bodies.maybe()).join()
{
match mount_states.get_unchecked() { match mount_states.get_unchecked() {
MountState::Unmounted => {}, MountState::Unmounted => {},
MountState::MountedBy(mounter_uid) => { MountState::MountedBy(mounter_uid) => {
@ -62,7 +66,9 @@ impl<'a> System<'a> for Sys {
let ori = orientations.get(entity).copied(); let ori = orientations.get(entity).copied();
let vel = velocities.get(entity).copied(); let vel = velocities.get(entity).copied();
if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) { if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) {
let _ = positions.insert(mounter, Pos(pos.0 + Vec3::unit_z() * 1.0)); let mounting_offset =
body.map_or(Vec3::unit_z(), Body::mounting_offset);
let _ = positions.insert(mounter, Pos(pos.0 + mounting_offset));
let _ = orientations.insert(mounter, ori); let _ = orientations.insert(mounter, ori);
let _ = velocities.insert(mounter, vel); let _ = velocities.insert(mounter, vel);
} }