mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
clippy is a thing
This commit is contained in:
parent
f20b5f0b49
commit
51f38df169
@ -59,8 +59,8 @@ use crate::{
|
||||
render::UiDrawer,
|
||||
scene::camera::{self, Camera},
|
||||
session::{
|
||||
settings_change::{Chat as ChatChange, Interface as InterfaceChange, SettingsChange},
|
||||
interactable::Interactable,
|
||||
settings_change::{Chat as ChatChange, Interface as InterfaceChange, SettingsChange},
|
||||
},
|
||||
settings::chat::ChatFilter,
|
||||
ui::{
|
||||
|
@ -2,6 +2,7 @@ use ordered_float::OrderedFloat;
|
||||
use specs::{Join, WorldExt};
|
||||
use vek::*;
|
||||
|
||||
use super::target::Target;
|
||||
use client::{self, Client};
|
||||
use common::{
|
||||
comp,
|
||||
@ -11,7 +12,6 @@ use common::{
|
||||
vol::ReadVol,
|
||||
};
|
||||
use common_base::span;
|
||||
use super::target::Target;
|
||||
|
||||
use crate::scene::{terrain::Interaction, Scene};
|
||||
|
||||
|
@ -21,7 +21,7 @@ use common::{
|
||||
item::{tool::ToolKind, ItemDef, ItemDesc},
|
||||
ChatMsg, ChatType, InputKind, InventoryUpdateEvent, Pos, Stats, UtteranceKind, Vel,
|
||||
},
|
||||
consts::{MAX_MOUNT_RANGE},
|
||||
consts::MAX_MOUNT_RANGE,
|
||||
outcome::Outcome,
|
||||
terrain::{Block, BlockKind},
|
||||
trade::TradeResult,
|
||||
@ -48,9 +48,9 @@ use crate::{
|
||||
Direction, GlobalState, PlayState, PlayStateResult,
|
||||
};
|
||||
use hashbrown::HashMap;
|
||||
use interactable::{select_interactable, Interactable};
|
||||
use settings_change::Language::ChangeLanguage;
|
||||
use interactable::{Interactable, select_interactable};
|
||||
use target::{Target, targets_under_cursor};
|
||||
use target::{targets_under_cursor, Target};
|
||||
#[cfg(feature = "egui-ui")]
|
||||
use voxygen_egui::EguiDebugInfo;
|
||||
|
||||
@ -415,7 +415,13 @@ impl PlayState for SessionState {
|
||||
|
||||
// Check to see whether we're aiming at anything
|
||||
let (build_target, collect_target, entity_target, mine_target, shortest_dist) =
|
||||
targets_under_cursor(&self.client.borrow(), cam_pos, cam_dir, can_build, is_mining);
|
||||
targets_under_cursor(
|
||||
&self.client.borrow(),
|
||||
cam_pos,
|
||||
cam_dir,
|
||||
can_build,
|
||||
is_mining,
|
||||
);
|
||||
|
||||
self.interactable = select_interactable(
|
||||
&self.client.borrow(),
|
||||
@ -426,7 +432,9 @@ impl PlayState for SessionState {
|
||||
);
|
||||
|
||||
let is_nearest_target = |target: Option<Target>| {
|
||||
target.map(|t| (t.distance() == shortest_dist)).unwrap_or(false)
|
||||
target
|
||||
.map(|t| (t.distance() <= shortest_dist))
|
||||
.unwrap_or(false)
|
||||
};
|
||||
|
||||
// Only highlight terrain blocks which can be interacted with
|
||||
@ -451,7 +459,7 @@ impl PlayState for SessionState {
|
||||
self.inputs.select_pos,
|
||||
entity_target.map(Target::entity).unwrap_or(None),
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Handle window events.
|
||||
@ -490,7 +498,10 @@ impl PlayState for SessionState {
|
||||
if let Some(build_target) = build_target {
|
||||
self.inputs.select_pos = Some(build_target.position());
|
||||
let mut client = self.client.borrow_mut();
|
||||
client.place_block(build_target.position_int(), self.selected_block);
|
||||
client.place_block(
|
||||
build_target.position_int(),
|
||||
self.selected_block,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
entity_event_handler!(InputKind::Secondary, state);
|
||||
@ -511,7 +522,8 @@ impl PlayState for SessionState {
|
||||
.ok()
|
||||
.copied()
|
||||
}) {
|
||||
self.inputs.select_pos = build_target.map(Target::position);
|
||||
self.inputs.select_pos =
|
||||
build_target.map(Target::position);
|
||||
self.selected_block = block;
|
||||
}
|
||||
}
|
||||
@ -670,7 +682,8 @@ impl PlayState for SessionState {
|
||||
match interaction {
|
||||
Some(Interaction::Collect) => {
|
||||
if block.is_collectible() {
|
||||
self.inputs.select_pos = collect_target.map(Target::position);
|
||||
self.inputs.select_pos = collect_target
|
||||
.map(Target::position);
|
||||
client.collect_block(pos);
|
||||
}
|
||||
},
|
||||
|
@ -8,16 +8,16 @@ use common::{
|
||||
terrain::{Block, TerrainChunk},
|
||||
util::find_dist::{Cylinder, FindDist},
|
||||
vol::ReadVol,
|
||||
volumes::vol_grid_2d::{VolGrid2dError},
|
||||
volumes::vol_grid_2d::VolGrid2dError,
|
||||
};
|
||||
use common_base::span;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Target {
|
||||
Build(Vec3<f32>, Vec3<f32>, f32), // (solid_pos, build_pos, dist)
|
||||
Collectable(Vec3<f32>, f32), // (pos, dist)
|
||||
Entity(specs::Entity, Vec3<f32>, f32), // (e, pos, dist)
|
||||
Mine(Vec3<f32>, f32), // (pos, dist)
|
||||
Collectable(Vec3<f32>, f32), // (pos, dist)
|
||||
Entity(specs::Entity, Vec3<f32>, f32), // (e, pos, dist)
|
||||
Mine(Vec3<f32>, f32), // (pos, dist)
|
||||
}
|
||||
|
||||
impl Target {
|
||||
@ -46,9 +46,7 @@ impl Target {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn position_int(self) -> Vec3<i32> {
|
||||
self.position().map(|p| p.floor() as i32)
|
||||
}
|
||||
pub fn position_int(self) -> Vec3<i32> { self.position().map(|p| p.floor() as i32) }
|
||||
}
|
||||
|
||||
/// Max distance an entity can be "targeted"
|
||||
@ -88,19 +86,28 @@ pub(super) fn targets_under_cursor(
|
||||
char_states.get(player_entity),
|
||||
);
|
||||
|
||||
fn curry_find_pos <'a> (
|
||||
client: &'a Client, cam_pos: &'a Vec3<f32>, cam_dir: &'a Vec3<f32>, player_cylinder: &'a Cylinder
|
||||
) -> impl FnMut(fn(Block)->bool) -> (Option<Vec3<f32>>, Option<Vec3<f32>>, (f32, Result<Option<Block>, VolGrid2dError<TerrainChunk>>)) + 'a {
|
||||
fn curry_find_pos<'a>(
|
||||
client: &'a Client,
|
||||
cam_pos: &'a Vec3<f32>,
|
||||
cam_dir: &'a Vec3<f32>,
|
||||
player_cylinder: &'a Cylinder,
|
||||
) -> impl FnMut(
|
||||
fn(Block) -> bool,
|
||||
) -> (
|
||||
Option<Vec3<f32>>,
|
||||
Option<Vec3<f32>>,
|
||||
(f32, Result<Option<Block>, VolGrid2dError<TerrainChunk>>),
|
||||
) + 'a {
|
||||
let terrain = client.state().terrain();
|
||||
|
||||
move |hit: fn(Block)->bool| {
|
||||
move |hit: fn(Block) -> bool| {
|
||||
let cam_ray = terrain
|
||||
.ray(*cam_pos, *cam_pos + *cam_dir * 100.0)
|
||||
.until(|block| hit(*block))
|
||||
.cast();
|
||||
let cam_ray = (cam_ray.0, cam_ray.1.map(|x| x.copied()));
|
||||
let cam_dist = cam_ray.0;
|
||||
|
||||
|
||||
if matches!(
|
||||
cam_ray.1,
|
||||
Ok(Some(_)) if player_cylinder.min_distance(*cam_pos + *cam_dir * (cam_dist + 0.01)) <= MAX_PICKUP_RANGE
|
||||
@ -108,28 +115,35 @@ pub(super) fn targets_under_cursor(
|
||||
(
|
||||
Some(*cam_pos + *cam_dir * cam_dist),
|
||||
Some(*cam_pos + *cam_dir * (cam_dist - 0.01)),
|
||||
cam_ray
|
||||
cam_ray,
|
||||
)
|
||||
} else { (None, None, cam_ray) }
|
||||
} else {
|
||||
(None, None, cam_ray)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut find_pos = curry_find_pos(&client, &cam_pos, &cam_dir, &player_cylinder);
|
||||
let mut find_pos = curry_find_pos(client, &cam_pos, &cam_dir, &player_cylinder);
|
||||
|
||||
let (collect_pos, _, cam_ray_0) = find_pos(|b: Block| { b.is_collectible() });
|
||||
let (mine_pos, _, cam_ray_1) = find_pos(|b: Block| { b.mine_tool().is_some() });
|
||||
let (collect_pos, _, cam_ray_0) = find_pos(|b: Block| b.is_collectible());
|
||||
let (mine_pos, _, cam_ray_1) = find_pos(|b: Block| b.mine_tool().is_some());
|
||||
// FIXME: the `solid_pos` is used in the remove_block(). is this correct?
|
||||
let (solid_pos, build_pos, cam_ray_2) = find_pos(|b: Block| { b.is_solid() });
|
||||
let (solid_pos, build_pos, cam_ray_2) = find_pos(|b: Block| b.is_solid());
|
||||
|
||||
// collectables can be in the Air. so using solely solid_pos is not correct.
|
||||
// so, use a minimum distance of all 3
|
||||
let mut cam_rays = vec![&cam_ray_0, &cam_ray_2];
|
||||
if is_mining { cam_rays.push(&cam_ray_1); }
|
||||
let cam_dist = cam_rays.iter().filter_map(|x| match **x {
|
||||
(d, Ok(Some(_))) => Some(d),
|
||||
_ => None,
|
||||
}).min_by(|d1, d2| d1.partial_cmp(d2).unwrap())
|
||||
.unwrap_or(MAX_PICKUP_RANGE);
|
||||
if is_mining {
|
||||
cam_rays.push(&cam_ray_1);
|
||||
}
|
||||
let cam_dist = cam_rays
|
||||
.iter()
|
||||
.filter_map(|x| match **x {
|
||||
(d, Ok(Some(_))) => Some(d),
|
||||
_ => None,
|
||||
})
|
||||
.min_by(|d1, d2| d1.partial_cmp(d2).unwrap())
|
||||
.unwrap_or(MAX_PICKUP_RANGE);
|
||||
|
||||
// See if ray hits entities
|
||||
// Currently treated as spheres
|
||||
@ -200,11 +214,15 @@ pub(super) fn targets_under_cursor(
|
||||
|
||||
let build_target = if can_build {
|
||||
solid_pos.map(|p| Target::Build(p, build_pos.unwrap(), cam_ray_2.0))
|
||||
} else { None };
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mine_target = if is_mining {
|
||||
mine_pos.map(|p| Target::Mine(p, cam_ray_1.0))
|
||||
} else { None };
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let shortest_distance = cam_dist;
|
||||
|
||||
@ -215,6 +233,6 @@ pub(super) fn targets_under_cursor(
|
||||
collect_pos.map(|p| Target::Collectable(p, cam_ray_0.0)),
|
||||
entity_target,
|
||||
mine_target,
|
||||
shortest_distance
|
||||
shortest_distance,
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user