diff --git a/client/src/lib.rs b/client/src/lib.rs index 2e4101f924..dedfd21a87 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1460,6 +1460,7 @@ impl Client { ServerGeneral::SetPlayerEntity(uid) => { if let Some(entity) = self.state.ecs().entity_from_uid(uid.0) { self.entity = entity; + *self.state.ecs_mut().write_resource() = PlayerEntity(Some(entity)); } else { return Err(Error::Other("Failed to find entity from uid.".to_owned())); } diff --git a/common/Cargo.toml b/common/Cargo.toml index 9001b753b1..ae126f3ed1 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -15,6 +15,7 @@ default = ["simd"] [dependencies] common-base = { package = "veloren-common-base", path = "base" } +#inline_tweak = "1.0.2" # Serde serde = { version = "1.0.110", features = ["derive", "rc"] } diff --git a/common/net/Cargo.toml b/common/net/Cargo.toml index b01fd9fc5e..5d8773a164 100644 --- a/common/net/Cargo.toml +++ b/common/net/Cargo.toml @@ -12,6 +12,7 @@ default = ["simd"] [dependencies] common = {package = "veloren-common", path = "../../common"} +#inline_tweak = "1.0.2" sum_type = "0.2.0" vek = { version = "=0.14.1", features = ["serde"] } diff --git a/common/net/src/sync/interpolation.rs b/common/net/src/sync/interpolation.rs index 143c516b9e..16e004d30a 100644 --- a/common/net/src/sync/interpolation.rs +++ b/common/net/src/sync/interpolation.rs @@ -32,8 +32,8 @@ impl Component for InterpBuffer { // 0 is pure physics, 1 is pure extrapolation const PHYSICS_VS_EXTRAPOLATION_FACTOR: f32 = 0.2; -const POSITION_INTERP_SANITY: f32 = 1000.0; -const VELOCITY_INTERP_SANITY: f32 = 1000.0; +const POSITION_INTERP_SANITY: Option = None; +const VELOCITY_INTERP_SANITY: Option = None; const ENABLE_POSITION_HERMITE: bool = false; impl InterpolatableComponent for Pos { @@ -52,7 +52,9 @@ impl InterpolatableComponent for Pos { if (t1 - t0).abs() < f64::EPSILON { 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"); return p1; } @@ -103,7 +105,9 @@ impl InterpolatableComponent for Vel { if (t1 - t0).abs() < f64::EPSILON { 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"); return p1; } diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index 9993e6a0c8..a56ea27528 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -573,6 +573,13 @@ impl Body { Body::Humanoid(_) | Body::BipedSmall(_) | Body::BipedLarge(_) ) } + + pub fn mounting_offset(&self) -> Vec3 { + match self { + Body::Ship(ship::Body::DefaultAirship) => Vec3::from([0.0, 0.0, 10.0]), + _ => Vec3::unit_z(), + } + } } impl Component for Body { diff --git a/common/sys/src/mount.rs b/common/sys/src/mount.rs index db36b178e8..28b714bd17 100644 --- a/common/sys/src/mount.rs +++ b/common/sys/src/mount.rs @@ -1,11 +1,11 @@ use common::{ - comp::{Controller, MountState, Mounting, Ori, Pos, Vel}, + comp::{Body, Controller, MountState, Mounting, Ori, Pos, Vel}, uid::UidAllocator, }; use common_ecs::{Job, Origin, Phase, System}; use specs::{ saveload::{Marker, MarkerAllocator}, - Entities, Join, Read, WriteStorage, + Entities, Join, Read, ReadStorage, WriteStorage, }; use vek::*; @@ -23,6 +23,7 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, Pos>, WriteStorage<'a, Vel>, WriteStorage<'a, Ori>, + ReadStorage<'a, Body>, ); const NAME: &'static str = "mount"; @@ -40,10 +41,13 @@ impl<'a> System<'a> for Sys { mut positions, mut velocities, mut orientations, + bodies, ): Self::SystemData, ) { // 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() { MountState::Unmounted => {}, MountState::MountedBy(mounter_uid) => { @@ -62,7 +66,9 @@ impl<'a> System<'a> for Sys { let ori = orientations.get(entity).copied(); let vel = velocities.get(entity).copied(); 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 _ = velocities.insert(mounter, vel); }