Fixed lantern position when mounting

This commit is contained in:
Joshua Barretto 2022-01-15 20:15:38 +00:00
parent b3e2d825ed
commit 537cc38b5e
7 changed files with 77 additions and 42 deletions

View File

@ -735,40 +735,40 @@ impl Body {
match self {
Body::QuadrupedMedium(quadruped_medium) => {
match (quadruped_medium.species, quadruped_medium.body_type) {
(quadruped_medium::Species::Grolgar, _) => [0.5, 0.5, 1.8],
(quadruped_medium::Species::Saber, _) => [0.3, 0.3, 1.3],
(quadruped_medium::Species::Tiger, _) => [0.2, 0.2, 1.4],
(quadruped_medium::Species::Tuskram, _) => [-0.5, -0.5, 1.5],
(quadruped_medium::Species::Lion, _) => [0.3, 0.3, 1.5],
(quadruped_medium::Species::Tarasque, _) => [0.6, 0.6, 2.0],
(quadruped_medium::Species::Wolf, _) => [0.5, 0.5, 1.3],
(quadruped_medium::Species::Frostfang, _) => [0.5, 0.5, 1.2],
(quadruped_medium::Species::Mouflon, _) => [0.3, 0.3, 1.2],
(quadruped_medium::Species::Grolgar, _) => [0.0, 0.5, 1.8],
(quadruped_medium::Species::Saber, _) => [0.0, 0.3, 1.3],
(quadruped_medium::Species::Tiger, _) => [0.0, 0.2, 1.4],
(quadruped_medium::Species::Tuskram, _) => [0.0, -0.5, 1.5],
(quadruped_medium::Species::Lion, _) => [0.0, 0.3, 1.5],
(quadruped_medium::Species::Tarasque, _) => [0.0, 0.6, 2.0],
(quadruped_medium::Species::Wolf, _) => [0.0, 0.5, 1.3],
(quadruped_medium::Species::Frostfang, _) => [0.0, 0.5, 1.2],
(quadruped_medium::Species::Mouflon, _) => [0.0, 0.3, 1.2],
(quadruped_medium::Species::Catoblepas, _) => [0.0, 0.0, 2.0],
(quadruped_medium::Species::Bonerattler, _) => [0.5, 0.5, 1.2],
(quadruped_medium::Species::Deer, _) => [0.2, 0.2, 1.3],
(quadruped_medium::Species::Bonerattler, _) => [0.0, 0.5, 1.2],
(quadruped_medium::Species::Deer, _) => [0.0, 0.2, 1.3],
(quadruped_medium::Species::Hirdrasil, _) => [0.0, 0.0, 1.4],
(quadruped_medium::Species::Roshwalr, _) => [0.5, 0.5, 1.8],
(quadruped_medium::Species::Donkey, _) => [0.5, 0.5, 1.5],
(quadruped_medium::Species::Camel, _) => [-0.1, -0.1, 2.8],
(quadruped_medium::Species::Zebra, _) => [0.5, 0.5, 1.8],
(quadruped_medium::Species::Antelope, _) => [0.3, 0.3, 1.4],
(quadruped_medium::Species::Kelpie, _) => [0.5, 0.5, 1.9],
(quadruped_medium::Species::Roshwalr, _) => [0.0, 0.5, 1.8],
(quadruped_medium::Species::Donkey, _) => [0.0, 0.5, 1.5],
(quadruped_medium::Species::Camel, _) => [0.0, -0.1, 2.8],
(quadruped_medium::Species::Zebra, _) => [0.0, 0.5, 1.8],
(quadruped_medium::Species::Antelope, _) => [0.0, 0.3, 1.4],
(quadruped_medium::Species::Kelpie, _) => [0.0, 0.5, 1.9],
(quadruped_medium::Species::Horse, _) => [0.0, 0.0, 2.0],
(quadruped_medium::Species::Barghest, _) => [0.5, 0.5, 2.2],
(quadruped_medium::Species::Barghest, _) => [0.0, 0.5, 2.2],
(quadruped_medium::Species::Cattle, quadruped_medium::BodyType::Male) => {
[0.5, 0.5, 2.6]
[0.0, 0.5, 2.6]
},
(quadruped_medium::Species::Cattle, quadruped_medium::BodyType::Female) => {
[0.7, 0.7, 2.2]
[0.0, 0.7, 2.2]
},
(quadruped_medium::Species::Darkhound, _) => [0.5, 0.5, 1.4],
(quadruped_medium::Species::Highland, _) => [0.5, 0.5, 2.3],
(quadruped_medium::Species::Darkhound, _) => [0.0, 0.5, 1.4],
(quadruped_medium::Species::Highland, _) => [0.0, 0.5, 2.3],
(quadruped_medium::Species::Yak, _) => [0.0, 0.0, 3.0],
(quadruped_medium::Species::Panda, _) => [-0.2, -0.2, 1.4],
(quadruped_medium::Species::Bear, _) => [-0.4, -0.4, 2.5],
(quadruped_medium::Species::Dreadhorn, _) => [0.2, 0.2, 3.5],
(quadruped_medium::Species::Moose, _) => [-0.6, -0.6, 2.1],
(quadruped_medium::Species::Panda, _) => [0.0, -0.2, 1.4],
(quadruped_medium::Species::Bear, _) => [0.0, -0.4, 2.5],
(quadruped_medium::Species::Dreadhorn, _) => [0.0, 0.2, 3.5],
(quadruped_medium::Species::Moose, _) => [0.0, -0.6, 2.1],
(quadruped_medium::Species::Snowleopard, _) => [-0.5, -0.5, 1.4],
(quadruped_medium::Species::Mammoth, _) => [0.0, 4.9, 7.2],
(quadruped_medium::Species::Ngoubou, _) => [0.0, 0.3, 2.0],

View File

@ -39,10 +39,13 @@ impl Link for Mounting {
let entity = |uid: Uid| uid_allocator
.retrieve_entity_internal(uid.into());
if let Some((mount, rider)) = entity(this.mount).zip(entity(this.rider)) {
if this.mount == this.rider {
// Forbid self-mounting
Err(())
} else if let Some((mount, rider)) = entity(this.mount).zip(entity(this.rider)) {
let can_mount_with = |entity| is_mounts.get(entity).is_none() && is_riders.get(entity).is_none();
// Ensure that neither mount or rider are already part of a mounting relationship
if can_mount_with(mount) && can_mount_with(rider) {
let _ = is_mounts.insert(mount, this.make_role());
let _ = is_riders.insert(rider, this.make_role());

View File

@ -158,7 +158,7 @@ impl Body {
Body::Humanoid(_) => 3.5,
Body::QuadrupedSmall(_) => 3.0,
Body::QuadrupedMedium(quadruped_medium) => match quadruped_medium.species {
quadruped_medium::Species::Mammoth => 2.2,
quadruped_medium::Species::Mammoth => 1.0,
_ => 2.8,
},
Body::BirdMedium(_) => 6.0,

View File

@ -1,5 +1,5 @@
use common::{
comp::{Body, Controller, Ori, Pos, Vel},
comp::{Body, Controller, Ori, Pos, Vel, ForceUpdate},
uid::UidAllocator,
mounting::{Mount, Rider},
link::Is,
@ -27,6 +27,7 @@ impl<'a> System<'a> for Sys {
WriteStorage<'a, Pos>,
WriteStorage<'a, Vel>,
WriteStorage<'a, Ori>,
ReadStorage<'a, ForceUpdate>,
ReadStorage<'a, Body>,
);
@ -46,6 +47,7 @@ impl<'a> System<'a> for Sys {
mut positions,
mut velocities,
mut orientations,
force_updates,
bodies,
): Self::SystemData,
) {

View File

@ -8,7 +8,8 @@
drain_filter,
never_type,
option_zip,
unwrap_infallible
unwrap_infallible,
let_else
)]
#![cfg_attr(not(feature = "worldgen"), feature(const_panic))]

View File

@ -13,11 +13,14 @@ use common::{
terrain::TerrainChunkSize,
uid::Uid,
vol::RectVolSize,
link::Is,
mounting::Rider,
uid::UidAllocator,
};
use common_ecs::{Job, Origin, Phase, System};
use common_net::{msg::ServerGeneral, sync::CompSyncPackage};
use itertools::Either;
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, Write, WriteStorage};
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, Write, WriteStorage, saveload::MarkerAllocator};
use vek::*;
/// This system will send physics updates to the client
@ -27,15 +30,15 @@ pub struct Sys;
impl<'a> System<'a> for Sys {
#[allow(clippy::type_complexity)]
type SystemData = (
Entities<'a>,
(Read<'a, UidAllocator>, Entities<'a>),
Read<'a, Tick>,
ReadExpect<'a, TimeOfDay>,
ReadExpect<'a, Calendar>,
ReadExpect<'a, RegionMap>,
ReadStorage<'a, Uid>,
ReadStorage<'a, Pos>,
ReadStorage<'a, Vel>,
ReadStorage<'a, Ori>,
WriteStorage<'a, Pos>,
WriteStorage<'a, Vel>,
WriteStorage<'a, Ori>,
ReadStorage<'a, Inventory>,
ReadStorage<'a, RegionSubscription>,
ReadStorage<'a, Presence>,
@ -49,6 +52,7 @@ impl<'a> System<'a> for Sys {
Write<'a, DeletedEntities>,
Write<'a, Vec<Outcome>>,
Read<'a, PlayerPhysicsSettings>,
ReadStorage<'a, Is<Rider>>,
ReadStorage<'a, Player>,
TrackedComps<'a>,
ReadTrackers<'a>,
@ -61,15 +65,15 @@ impl<'a> System<'a> for Sys {
fn run(
job: &mut Job<Self>,
(
entities,
(uid_allocator, entities),
tick,
time_of_day,
calendar,
region_map,
uids,
positions,
velocities,
orientations,
mut positions,
mut velocities,
mut orientations,
inventories,
subscriptions,
presences,
@ -83,6 +87,7 @@ impl<'a> System<'a> for Sys {
mut deleted_entities,
mut outcomes,
player_physics_settings,
is_rider,
players,
tracked_comps,
trackers,
@ -106,6 +111,24 @@ impl<'a> System<'a> for Sys {
// 5. Inform clients of the component changes for that entity
// - Throttle update rate base on distance to each client
// Propagate `ForceUpdate`s to mounts
let mut propagate_mounts = Vec::new();
for (entity, _, is_rider) in (
&entities,
&force_updates,
&is_rider,
).join() {
propagate_mounts.push((is_rider.mount, entity));
}
for (mount_uid, rider) in propagate_mounts {
let Some(mount) = uid_allocator
.retrieve_entity_internal(mount_uid.into())
else { continue };
positions.get(rider).copied().map(|pos| positions.insert(mount, pos));
velocities.get(rider).copied().map(|vel| velocities.insert(mount, vel));
orientations.get(rider).copied().map(|ori| orientations.insert(mount, ori));
}
// Sync physics and other components
// via iterating through regions (in parallel)

View File

@ -460,9 +460,11 @@ impl FigureMgr {
}
let dt = ecs.fetch::<DeltaTime>().0;
let updater = ecs.read_resource::<LazyUpdate>();
for (entity, light_emitter_opt, body, mut light_anim) in (
for (entity, light_emitter_opt, interpolated, pos, body, mut light_anim) in (
&ecs.entities(),
ecs.read_storage::<LightEmitter>().maybe(),
ecs.read_storage::<crate::ecs::comp::Interpolated>().maybe(),
&ecs.read_storage::<Pos>(),
ecs.read_storage::<Body>().maybe(),
&mut ecs.write_storage::<LightAnimation>(),
)
@ -485,7 +487,11 @@ impl FigureMgr {
};
if let Some(lantern_offset) = body
.and_then(|body| self.states.get_mut(body, &entity))
.and_then(|state| state.lantern_offset)
.and_then(|state| {
// Calculate the correct lantern position
let pos = anim::vek::Vec3::from(interpolated.map(|i| i.pos).unwrap_or(pos.0).into_array());
Some(state.mount_world_pos + state.mount_transform.orientation * anim::vek::Vec3::from(state.lantern_offset?.into_array()) - pos)
})
{
light_anim.offset = vek::Vec3::from(lantern_offset);
} else if let Some(body) = body {