From 8a8a5526f14e95496cfdb05f0e345a2deac39fe3 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 24 May 2023 21:09:42 +0100 Subject: [PATCH] Added carriage --- assets/common/manifests/ship_manifest.ron | 36 ++++++++++++++++++++++ assets/common/voxel/carriage/prop.vox | 3 ++ assets/common/voxel/carriage/rudder.vox | 3 ++ assets/common/voxel/carriage/structure.vox | 3 ++ common/src/comp/body.rs | 1 + common/src/comp/body/ship.rs | 8 +++-- common/src/comp/phys.rs | 1 + common/src/states/behavior.rs | 5 ++- common/src/states/utils.rs | 12 +++++++- common/systems/src/character_behavior.rs | 7 +++-- common/systems/src/phys.rs | 4 +++ voxygen/anim/src/ship/mod.rs | 4 +++ 12 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 assets/common/voxel/carriage/prop.vox create mode 100644 assets/common/voxel/carriage/rudder.vox create mode 100644 assets/common/voxel/carriage/structure.vox diff --git a/assets/common/manifests/ship_manifest.ron b/assets/common/manifests/ship_manifest.ron index 148aae98bd..98d8a1ca48 100644 --- a/assets/common/manifests/ship_manifest.ron +++ b/assets/common/manifests/ship_manifest.ron @@ -179,6 +179,42 @@ central: ("submarine.rudder"), ), + custom_indices: { + 1: Air(ChairSingle, 4), + 2: Air(Helm, 0), + 3: Air(Door, 4), + 4: Air(Door, 0), + 9: Air(CraftingBench, 0), + 10: Air(Window1, 0), + 11: Air(RepairBench, 0), + 12: Air(DismantlingBench, 4), + 13: Air(Window1, 2), + 14: Air(Crate, 0), + 15: Air(Cauldron, 2), + 16: Air(Tent, 0), + 17: Air(CookingPot, 0), + 18: Air(WallLampSmall, 4), + 19: Air(Lantern, 4), + }, + ), + Carriage: ( + bone0: ( + offset: (-4.5, -6.5, -0.5), + central: ("carriage.structure"), + ), + bone1: ( + offset: (0.0, 0.0, 0.0), + central: ("empty"), + ), + bone2: ( + offset: (0.0, 0.0, 0.0), + central: ("empty"), + ), + bone3: ( + offset: (0.0, 0.0, 0.0), + central: ("empty"), + ), + custom_indices: { 1: Air(ChairSingle, 4), 2: Air(Helm, 0), diff --git a/assets/common/voxel/carriage/prop.vox b/assets/common/voxel/carriage/prop.vox new file mode 100644 index 0000000000..e3747c02c9 --- /dev/null +++ b/assets/common/voxel/carriage/prop.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd4854e224023f76d93bc5f595bcf81940061b797f8d5ef6e9bd2af687a7899d +size 1200 diff --git a/assets/common/voxel/carriage/rudder.vox b/assets/common/voxel/carriage/rudder.vox new file mode 100644 index 0000000000..bf59b76a74 --- /dev/null +++ b/assets/common/voxel/carriage/rudder.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6019cd971b4cd79445f23be0e53b2d5d71b1993cd5fcb7b16fc09fa520167de8 +size 1240 diff --git a/assets/common/voxel/carriage/structure.vox b/assets/common/voxel/carriage/structure.vox new file mode 100644 index 0000000000..789196c384 --- /dev/null +++ b/assets/common/voxel/carriage/structure.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0423d5cc73724125279ca1adb3335c8a84bbcfe3da42f2bd3a285a13a50e4364 +size 2276 diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index 36fc4b22e7..62e6b5954f 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -1099,6 +1099,7 @@ impl Body { ship::Body::Galleon => [-2.0, -5.0, 4.0], ship::Body::Skiff => [1.0, -2.0, 2.0], ship::Body::Submarine => [1.0, -2.0, 2.0], + ship::Body::Carriage => [1.0, -2.0, 2.0], ship::Body::Volume => [0.0, 0.0, 0.0], }, _ => [0.0, 0.0, 0.0], diff --git a/common/src/comp/body/ship.rs b/common/src/comp/body/ship.rs index 2a24fda024..a75d672e8e 100644 --- a/common/src/comp/body/ship.rs +++ b/common/src/comp/body/ship.rs @@ -19,7 +19,7 @@ pub const ALL_BODIES: [Body; 6] = [ ]; pub const ALL_AIRSHIPS: [Body; 2] = [Body::DefaultAirship, Body::AirBalloon]; -pub const ALL_SHIPS: [Body; 4] = [Body::SailBoat, Body::Galleon, Body::Skiff, Body::Submarine]; +pub const ALL_SHIPS: [Body; 5] = [Body::SailBoat, Body::Galleon, Body::Skiff, Body::Submarine, Body::Carriage]; make_case_elim!( body, @@ -33,6 +33,7 @@ make_case_elim!( Volume = 4, Skiff = 5, Submarine = 6, + Carriage = 7, } ); @@ -64,6 +65,7 @@ impl Body { Body::Galleon => Some("galleon.structure"), Body::Skiff => Some("skiff.structure"), Body::Submarine => Some("submarine.structure"), + Body::Carriage => Some("carriage.structure"), Body::Volume => None, } } @@ -76,6 +78,7 @@ impl Body { Body::Galleon => Vec3::new(14.0, 48.0, 10.0), Body::Skiff => Vec3::new(7.0, 15.0, 10.0), Body::Submarine => Vec3::new(2.0, 15.0, 8.0), + Body::Carriage => Vec3::new(2.0, 15.0, 8.0), } } @@ -109,6 +112,7 @@ impl Body { match self { Body::DefaultAirship | Body::AirBalloon | Body::Volume => Density(AIR_DENSITY), Body::Submarine => Density(WATER_DENSITY), // Neutrally buoyant + Body::Carriage => Density(WATER_DENSITY * 0.5), _ => Density(AIR_DENSITY * 0.95 + WATER_DENSITY * 0.05), /* Most boats should be very * buoyant */ } @@ -123,7 +127,7 @@ impl Body { pub fn flying_height(&self) -> f32 { if self.can_fly() { 200.0 } else { 0.0 } } pub fn has_water_thrust(&self) -> bool { - !self.can_fly() // TODO: Differentiate this more carefully + !self.can_fly() && !matches!(self, Body::Carriage) // TODO: Differentiate this more carefully } pub fn make_collider(&self) -> Collider { diff --git a/common/src/comp/phys.rs b/common/src/comp/phys.rs index 31282be1f9..4257d04301 100644 --- a/common/src/comp/phys.rs +++ b/common/src/comp/phys.rs @@ -63,6 +63,7 @@ pub struct PreviousPhysCache { pub origins: Option<(Vec2, Vec2)>, pub pos: Option, pub ori: Quaternion, + pub pos_interp: Option, } impl Component for PreviousPhysCache { diff --git a/common/src/states/behavior.rs b/common/src/states/behavior.rs index 8bc65b4030..a309be7607 100644 --- a/common/src/states/behavior.rs +++ b/common/src/states/behavior.rs @@ -6,7 +6,7 @@ use crate::{ ActiveAbilities, Beam, Body, CharacterActivity, CharacterState, Combo, ControlAction, Controller, ControllerInputs, Density, Energy, Health, InputAttr, InputKind, Inventory, InventoryAction, Mass, Melee, Ori, PhysicsState, Pos, Scale, SkillSet, Stance, StateUpdate, - Stats, Vel, + Stats, Vel, PreviousPhysCache, }, link::Is, mounting::{Rider, VolumeRider}, @@ -149,6 +149,7 @@ pub struct JoinData<'a> { pub mount_data: Option<&'a Is>, pub volume_mount_data: Option<&'a Is>, pub stance: Option<&'a Stance>, + pub previous_physics: Option<&'a PreviousPhysCache>, } pub struct JoinStruct<'a> { @@ -179,6 +180,7 @@ pub struct JoinStruct<'a> { pub mount_data: Option<&'a Is>, pub volume_mount_data: Option<&'a Is>, pub stance: Option<&'a Stance>, + pub previous_physics: Option<&'a PreviousPhysCache>, } impl<'a> JoinData<'a> { @@ -223,6 +225,7 @@ impl<'a> JoinData<'a> { mount_data: j.mount_data, volume_mount_data: j.volume_mount_data, stance: j.stance, + previous_physics: j.previous_physics, } } } diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index de16597c23..b6b18d2c05 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -146,6 +146,7 @@ impl Body { quadruped_low::Species::Deadwood => 140.0, quadruped_low::Species::Mossdrake => 100.0, }, + Body::Ship(ship::Body::Carriage) => 250.0, Body::Ship(_) => 0.0, Body::Arthropod(arthropod) => match arthropod.species { arthropod::Species::Tarantula => 135.0, @@ -220,6 +221,7 @@ impl Body { quadruped_low::Species::Mossdrake => 1.7, _ => 2.0, }, + Body::Ship(ship::Body::Carriage) => 0.6, Body::Ship(ship) if ship.has_water_thrust() => 5.0 / self.dimensions().y, Body::Ship(_) => 6.0 / self.dimensions().y, Body::Arthropod(_) => 3.5, @@ -587,6 +589,13 @@ pub fn handle_orientation( (a.to_quat().into_vec4() - b.to_quat().into_vec4()).reduce(|a, b| a.abs() + b.abs()) } + let pitch = if matches!(data.body, Body::Ship(ship::Body::Carriage)) { + let change = (data.pos.0 - data.previous_physics.and_then(|p| p.pos_interp).unwrap_or(*data.pos).0) / data.dt.0; + change.z / change.xy().magnitude().max(1.0) + } else { + 0.0 + }; + // Direction is set to the override if one is provided, else if entity is // strafing or attacking the horiontal component of the look direction is used, // else the current horizontal movement direction is used @@ -601,7 +610,8 @@ pub fn handle_orientation( } else { Dir::from_unnormalized(data.inputs.move_dir.into()) .map_or_else(|| to_horizontal_fast(data.ori), |dir| dir.into()) - }; + } + .pitched_up(pitch); // unit is multiples of 180° let half_turns_per_tick = data.body.base_ori_rate() / data.scale.map_or(1.0, |s| s.0.sqrt()) * efficiency diff --git a/common/systems/src/character_behavior.rs b/common/systems/src/character_behavior.rs index 59099305b7..8e0b2ea878 100644 --- a/common/systems/src/character_behavior.rs +++ b/common/systems/src/character_behavior.rs @@ -10,7 +10,7 @@ use common::{ inventory::item::{tool::AbilityMap, MaterialStatManifest}, ActiveAbilities, Beam, Body, CharacterActivity, CharacterState, Combo, Controller, Density, Energy, Health, Inventory, InventoryManip, Mass, Melee, Ori, PhysicsState, Poise, Pos, - Scale, SkillSet, Stance, StateUpdate, Stats, Vel, + Scale, SkillSet, Stance, StateUpdate, Stats, Vel, PreviousPhysCache, }, event::{EventBus, LocalEvent, ServerEvent}, link::Is, @@ -54,6 +54,7 @@ pub struct ReadData<'a> { terrain: ReadExpect<'a, TerrainGrid>, inventories: ReadStorage<'a, Inventory>, stances: ReadStorage<'a, Stance>, + previous_physics: ReadStorage<'a, PreviousPhysCache>, } /// ## Character Behavior System @@ -120,7 +121,7 @@ impl<'a> System<'a> for Sys { controller, health, body, - (physics, scale, stat, skill_set, active_abilities, is_rider), + (physics, scale, stat, skill_set, active_abilities, previous_physics, is_rider), combo, ) in ( &read_data.entities, @@ -143,6 +144,7 @@ impl<'a> System<'a> for Sys { &read_data.stats, &read_data.skill_sets, read_data.active_abilities.maybe(), + read_data.previous_physics.maybe(), read_data.is_riders.maybe(), ), read_data.combos.maybe(), @@ -210,6 +212,7 @@ impl<'a> System<'a> for Sys { mount_data: read_data.is_riders.get(entity), volume_mount_data: read_data.is_volume_riders.get(entity), stance: read_data.stances.get(entity), + previous_physics, }; for action in actions { diff --git a/common/systems/src/phys.rs b/common/systems/src/phys.rs index c2ee9305dd..83142d2e92 100644 --- a/common/systems/src/phys.rs +++ b/common/systems/src/phys.rs @@ -218,6 +218,7 @@ impl<'a> PhysicsData<'a> { origins: None, pos: None, ori: Quaternion::identity(), + pos_interp: None, }); } @@ -744,6 +745,9 @@ impl<'a> PhysicsData<'a> { // it did not work (investigate root cause?) previous_phys_cache.pos = Some(*pos); previous_phys_cache.ori = ori.to_quat(); + previous_phys_cache.pos_interp = Some(Pos( + previous_phys_cache.pos_interp.unwrap_or(*pos).0 * 0.85 + pos.0 * 0.15, + )); } drop(guard); } diff --git a/voxygen/anim/src/ship/mod.rs b/voxygen/anim/src/ship/mod.rs index 2073be87c6..70bcbe2d2d 100644 --- a/voxygen/anim/src/ship/mod.rs +++ b/voxygen/anim/src/ship/mod.rs @@ -109,6 +109,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { Galleon => (0.0, 0.0, 0.0), Skiff => (0.0, 0.0, 0.0), Submarine => (0.0, 0.0, 0.0), + Carriage => (0.0, 0.0, 0.0), Volume => (0.0, 0.0, 0.0), }, bone1: match body { @@ -118,6 +119,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { Galleon => (0.0, 0.0, 0.0), Skiff => (0.0, 0.0, 0.0), Submarine => (0.0, -15.0, 3.5), + Carriage => (0.0, 0.0, 0.0), Volume => (0.0, 0.0, 0.0), }, bone2: match body { @@ -127,6 +129,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { Galleon => (0.0, 0.0, 0.0), Skiff => (0.0, 0.0, 0.0), Submarine => (0.0, 0.0, 0.0), + Carriage => (0.0, 0.0, 0.0), Volume => (0.0, 0.0, 0.0), }, bone3: match body { @@ -136,6 +139,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { Galleon => (0.0, 0.0, 0.0), Skiff => (0.0, 0.0, 0.0), Submarine => (0.0, -18.0, 3.5), + Carriage => (0.0, 0.0, 0.0), Volume => (0.0, 0.0, 0.0), }, bone1_prop_trail_offset: match body {