From 134d0f0c0426a8c46b44ece9d00b96c5bfb6fff3 Mon Sep 17 00:00:00 2001 From: Isse Date: Tue, 18 Apr 2023 13:55:29 +0200 Subject: [PATCH] varius fixes --- common/src/cmd.rs | 8 ++-- common/src/comp/body/ship.rs | 5 ++- common/src/consts.rs | 2 +- common/src/terrain/block.rs | 3 +- common/src/terrain/sprite.rs | 9 ++-- common/src/util/find_dist.rs | 4 +- server/src/cmd.rs | 13 +++--- server/src/events/interaction.rs | 4 +- server/src/events/inventory_manip.rs | 20 +++++++-- voxygen/src/hud/mod.rs | 2 +- voxygen/src/scene/figure/mod.rs | 41 +++++++++--------- voxygen/src/scene/figure/volume.rs | 5 ++- voxygen/src/scene/mod.rs | 62 ++++++++++++++++------------ voxygen/src/session/interactable.rs | 7 ++-- voxygen/src/session/mod.rs | 4 +- 15 files changed, 112 insertions(+), 77 deletions(-) diff --git a/common/src/cmd.rs b/common/src/cmd.rs index 62afb6beae..1e565d1c7b 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -737,9 +737,11 @@ impl ServerChatCommand { "Send messages to everyone on the server", None, ), - ServerChatCommand::MakeVolume => { - cmd(vec![Integer("size", 15, Optional)], "Create a volume (experimental)", Some(Admin)) - }, + ServerChatCommand::MakeVolume => cmd( + vec![Integer("size", 15, Optional)], + "Create a volume (experimental)", + Some(Admin), + ), ServerChatCommand::Location => { cmd(vec![Any("name", Required)], "Teleport to a location", None) }, diff --git a/common/src/comp/body/ship.rs b/common/src/comp/body/ship.rs index 47f3b9dd85..45f5c52e24 100644 --- a/common/src/comp/body/ship.rs +++ b/common/src/comp/body/ship.rs @@ -243,7 +243,10 @@ pub mod figuredata { AssetExt::load("common.manifests.ship_manifest")?; let mut colliders = HashMap::new(); for (_, spec) in (manifest.read().0).0.iter() { - for (index, bone) in [&spec.bone0, &spec.bone1, &spec.bone2, &spec.bone3].iter().enumerate() { + for (index, bone) in [&spec.bone0, &spec.bone1, &spec.bone2, &spec.bone3] + .iter() + .enumerate() + { // TODO: Currently both client and server load models and manifests from // "common.voxel.". In order to support CSG procedural airships, we probably // need to load them in the server and sync them as an ECS resource. diff --git a/common/src/consts.rs b/common/src/consts.rs index 41c4171a8e..033f743278 100644 --- a/common/src/consts.rs +++ b/common/src/consts.rs @@ -1,7 +1,7 @@ // The limit on distance between the entity and a collectible (squared) pub const MAX_PICKUP_RANGE: f32 = 5.0; pub const MAX_MOUNT_RANGE: f32 = 5.0; -pub const MAX_SPRITE_MOUNT_RANGE: f32 = 1.5; +pub const MAX_SPRITE_MOUNT_RANGE: f32 = 2.0; pub const MAX_TRADE_RANGE: f32 = 20.0; pub const GRAVITY: f32 = 25.0; diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index cacae32e9b..f68f2f66d5 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -436,7 +436,8 @@ impl Block { } pub fn is_controller(&self) -> bool { - self.get_sprite().map_or(false, |sprite| sprite.is_controller()) + self.get_sprite() + .map_or(false, |sprite| sprite.is_controller()) } #[inline] diff --git a/common/src/terrain/sprite.rs b/common/src/terrain/sprite.rs index 45e989ffe6..5de80dd6f1 100644 --- a/common/src/terrain/sprite.rs +++ b/common/src/terrain/sprite.rs @@ -506,13 +506,14 @@ impl SpriteKind { pub fn is_mountable(&self) -> bool { self.mount_offset().is_some() } #[inline] - pub fn is_controller(&self) -> bool { - matches!(self, SpriteKind::Helm) - } + pub fn is_controller(&self) -> bool { matches!(self, SpriteKind::Helm) } #[inline] pub fn is_door(&self) -> bool { - matches!(self, SpriteKind::Door | SpriteKind::DoorWide | SpriteKind::DoorDark) + matches!( + self, + SpriteKind::Door | SpriteKind::DoorWide | SpriteKind::DoorDark + ) } /// Which tool (if any) is needed to collect this sprite? diff --git a/common/src/util/find_dist.rs b/common/src/util/find_dist.rs index d27202c360..2bc023abaf 100644 --- a/common/src/util/find_dist.rs +++ b/common/src/util/find_dist.rs @@ -156,9 +156,7 @@ impl FindDist for Vec3 { } #[inline] - fn min_distance(self, other: Cylinder) -> f32 { - other.min_distance(self) - } + fn min_distance(self, other: Cylinder) -> f32 { other.min_distance(self) } } #[cfg(test)] diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 3f2a0f20b5..0b3c664922 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1699,8 +1699,8 @@ fn handle_make_volume( let pos = position(server, target, "target")?; let ship = comp::ship::Body::Volume; let sz = parse_cmd_args!(args, u32).unwrap_or(15); - if sz < 1 || sz > 127 { - return Err(format!("Size has to be between 1 and 127.")); + if !(1..=127).contains(&sz) { + return Err("Size has to be between 1 and 127.".to_string()); }; let sz = Vec3::broadcast(sz); let collider = { @@ -1715,9 +1715,12 @@ fn handle_make_volume( }; server .state - .create_ship(comp::Pos(pos.0 + Vec3::unit_z() * (50.0 + sz.z as f32 / 2.0)), comp::Ori::default(), ship, move |_| { - collider - }) + .create_ship( + comp::Pos(pos.0 + Vec3::unit_z() * (50.0 + sz.z as f32 / 2.0)), + comp::Ori::default(), + ship, + move |_| collider, + ) .build(); server.notify_client( diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index e8a0dbc0a9..3281559f9c 100644 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -151,9 +151,9 @@ pub fn handle_mount_volume(server: &mut Server, rider: EcsEntity, volume_pos: Vo &state.ecs().read_storage(), ); - if let Some((transform, block)) = block_transform + if let Some((mat, block)) = block_transform && let Some(mount_offset) = block.mount_offset() { - let mount_pos = (Mat4::from(transform) * mount_offset.0.with_w(1.0)).xyz(); + let mount_pos = (mat * mount_offset.0.with_w(1.0)).xyz(); let within_range = { let positions = state.ecs().read_storage::(); positions.get(rider).map_or(false, |pos| pos.0.distance_squared(mount_pos) < MAX_SPRITE_MOUNT_RANGE * MAX_SPRITE_MOUNT_RANGE) diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index 047390c6b3..80b9be97df 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -13,6 +13,7 @@ use common::{ InventoryUpdate, }, consts::MAX_PICKUP_RANGE, + mounting::VolumePos, recipe::{ self, default_component_recipe_book, default_recipe_book, default_repair_recipe_book, }, @@ -21,7 +22,7 @@ use common::{ trade::Trades, uid::Uid, util::find_dist::{self, FindDist}, - vol::ReadVol, mounting::VolumePos, + vol::ReadVol, }; use common_net::sync::WorldSyncExt; use common_state::State; @@ -750,7 +751,14 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv .filter(|pos| { let entity_cylinder = get_cylinder(state, entity); let in_range = within_pickup_range(entity_cylinder, || { - pos.get_block_and_transform(&state.terrain(), &state.ecs().read_resource(), &state.read_storage(), &state.read_storage(), &state.read_storage()).map(|(transform, _)| transform.mul_point(Vec3::broadcast(0.5))) + pos.get_block_and_transform( + &state.terrain(), + &state.ecs().read_resource(), + &state.read_storage(), + &state.read_storage(), + &state.read_storage(), + ) + .map(|(transform, _)| transform.mul_point(Vec3::broadcast(0.5))) }); if !in_range { debug!( @@ -762,7 +770,13 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv } in_range }) - .and_then(|pos| pos.get_block(&state.terrain(), &state.ecs().read_resource(), &state.read_storage())) + .and_then(|pos| { + pos.get_block( + &state.terrain(), + &state.ecs().read_resource(), + &state.read_storage(), + ) + }) .and_then(|block| block.get_sprite()) }; diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index d90e170f07..f835f11dd8 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -2040,7 +2040,7 @@ impl Hud { } // Render overtime for an interactable block - if let Some(Interactable::Block(block, pos, interaction)) = interactable + 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 overitem_id = overitem_walker.next( &mut self.ids.overitems, diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 5babe05dfc..65ed7f757e 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -38,9 +38,10 @@ use common::{ comp::{ inventory::slot::EquipSlot, item::{tool::AbilityContext, Hands, ItemKind, ToolKind}, - ship::{self, figuredata::VOXEL_COLLIDER_MANIFEST}, Body, CharacterActivity, CharacterState, Collider, Controller, Health, Inventory, - Item, ItemKey, Last, LightAnimation, LightEmitter, Ori, PhysicsState, PoiseState, Pos, - Scale, SkillSet, Stance, Vel, + ship::{self, figuredata::VOXEL_COLLIDER_MANIFEST}, + Body, CharacterActivity, CharacterState, Collider, Controller, Health, Inventory, Item, + ItemKey, Last, LightAnimation, LightEmitter, Ori, PhysicsState, PoiseState, Pos, Scale, + SkillSet, Stance, Vel, }, link::Is, mounting::{Rider, VolumeRider}, @@ -6104,7 +6105,7 @@ impl FigureMgr { pos.0.into(), ori.into_vec4().into(), vk, - Arc::clone(&vol), + Arc::clone(vol), tick, &slow_jobs, terrain, @@ -6346,23 +6347,25 @@ impl FigureMgr { if let Some((data, sprite_instances)) = self.get_sprite_instances(entity, body, collider) { - let dist = collider.and_then(|collider| { - let vol = collider.get_vol(&voxel_colliders_manifest)?; - - let mat = Mat4::from(ori.to_quat()).translated_3d(pos.0) - * Mat4::translation_3d(vol.translation); + let dist = collider + .and_then(|collider| { + let vol = collider.get_vol(&voxel_colliders_manifest)?; - let p = mat.inverted().mul_point(cam_pos); - let aabb = Aabb { - min: Vec3::zero(), - max: vol.volume().sz.as_(), - }; - Some(if aabb.contains_point(p) { - 0.0 - } else { - aabb.distance_to_point(p) + let mat = Mat4::from(ori.to_quat()).translated_3d(pos.0) + * Mat4::translation_3d(vol.translation); + + let p = mat.inverted().mul_point(cam_pos); + let aabb = Aabb { + min: Vec3::zero(), + max: vol.volume().sz.as_(), + }; + Some(if aabb.contains_point(p) { + 0.0 + } else { + aabb.distance_to_point(p) + }) }) - }).unwrap_or_else(|| pos.0.distance(cam_pos)); + .unwrap_or_else(|| pos.0.distance(cam_pos)); if dist < sprite_render_distance { let lod_level = if dist < sprite_high_detail_distance { diff --git a/voxygen/src/scene/figure/volume.rs b/voxygen/src/scene/figure/volume.rs index 380bb2e972..41bc3c927e 100644 --- a/voxygen/src/scene/figure/volume.rs +++ b/voxygen/src/scene/figure/volume.rs @@ -3,7 +3,10 @@ use super::{ load::{BodySpec, ShipBoneMeshes}, EcsEntity, }; -use common::{assets, comp::ship::{figuredata::VoxelCollider, AIRSHIP_SCALE}}; +use common::{ + assets, + comp::ship::figuredata::VoxelCollider, +}; use std::{convert::TryFrom, sync::Arc}; #[derive(Copy, Clone, PartialEq, Eq, Hash)] diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 0ad8e11b4f..878f23492a 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -690,8 +690,7 @@ impl Scene { .filter(|(pos, _, light_anim, h)| { light_anim.col != Rgb::zero() && light_anim.strength > 0.0 - && pos.0.distance_squared(viewpoint_pos) - < max_light_dist + && pos.0.distance_squared(viewpoint_pos) < max_light_dist && h.map_or(true, |h| !h.is_dead) }) .map(|(pos, interpolated, light_anim, _)| { @@ -714,33 +713,42 @@ impl Scene { &scene_data.state.read_storage::(), &scene_data.state.read_storage::(), &scene_data.state.read_storage::(), - ).join().filter_map(|(entity, pos, ori, body, collider)| { - let vol = collider.get_vol(&voxel_colliders_manifest)?; + ) + .join() + .filter_map(|(entity, pos, ori, body, collider)| { + let vol = collider.get_vol(&voxel_colliders_manifest)?; - let mat = Mat4::from(ori.to_quat()).translated_3d(pos.0) - * Mat4::translation_3d(vol.translation); + let mat = Mat4::from(ori.to_quat()).translated_3d(pos.0) + * Mat4::translation_3d(vol.translation); - let p = mat.inverted().mul_point(viewpoint_pos); - let aabb = Aabb { - min: Vec3::zero(), - 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, _)| { - blocks_of_interest.lights.iter().map( - move |(block_offset, level)| { - let wpos = mat.mul_point(block_offset.as_() + 0.5); - (wpos, level) - }, - ).filter(move |(wpos, _)| wpos.distance_squared(viewpoint_pos) < max_light_dist) - .map(|(wpos, level)| Light::new(wpos, Rgb::white(), *level as f32 / 7.0)) - }) - } else { - None - } - }).flatten() + let p = mat.inverted().mul_point(viewpoint_pos); + let aabb = Aabb { + min: Vec3::zero(), + 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, _)| { + blocks_of_interest + .lights + .iter() + .map(move |(block_offset, level)| { + let wpos = mat.mul_point(block_offset.as_() + 0.5); + (wpos, level) + }) + .filter(move |(wpos, _)| { + wpos.distance_squared(viewpoint_pos) < max_light_dist + }) + .map(|(wpos, level)| { + Light::new(wpos, Rgb::white(), *level as f32 / 7.0) + }) + }) + } else { + None + } + }) + .flatten(), ); lights.sort_by_key(|light| light.get_pos().distance_squared(viewpoint_pos) as i32); lights.truncate(MAX_LIGHT_COUNT); diff --git a/voxygen/src/session/interactable.rs b/voxygen/src/session/interactable.rs index 88050a61b9..2a40e85724 100644 --- a/voxygen/src/session/interactable.rs +++ b/voxygen/src/session/interactable.rs @@ -312,8 +312,9 @@ pub(super) fn select_interactable( .chain(volumes) .filter(|(wpos, volume_pos, interaction)| { match interaction { - Interaction::Mount => !is_volume_rider.contains(player_entity) && wpos.distance_squared(player_pos) < MAX_SPRITE_MOUNT_RANGE * MAX_SPRITE_MOUNT_RANGE && - is_volume_rider.join().find(|is_volume_rider| is_volume_rider.pos == *volume_pos).is_none(), + Interaction::Mount => !is_volume_rider.contains(player_entity) + && wpos.distance_squared(player_pos) < MAX_SPRITE_MOUNT_RANGE * MAX_SPRITE_MOUNT_RANGE + && !is_volume_rider.join().any(|is_volume_rider| is_volume_rider.pos == *volume_pos), _ => true, } }) @@ -333,7 +334,7 @@ pub(super) fn select_interactable( &ecs.read_resource::(), &ecs.read_storage(), block_pos, - interaction.clone(), + *interaction, ) }) .or_else(|| closest_interactable_entity.map(|(e, _)| Interactable::Entity(e))) diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index 52d44c7756..a330737c99 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -951,9 +951,7 @@ impl PlayState for SessionState { BlockInteraction::Craft(tab) => { self.hud.show.open_crafting_tab( *tab, - block - .get_sprite() - .map(|s| (*pos, s)), + block.get_sprite().map(|s| (*pos, s)), ) }, BlockInteraction::Mount => {