Merge branch 'olexorus/2021_cleanup' into 'master'

Simplifications made possible by the 2021 Edition

Closes #1447

See merge request veloren/veloren!3277
This commit is contained in:
Imbris 2022-03-15 21:05:53 +00:00
commit 1ff8fffa1d
5 changed files with 33 additions and 30 deletions

View File

@ -1972,13 +1972,13 @@ fn closest_points(n: LineSegment2<f32>, m: LineSegment2<f32>) -> (Vec2<f32>, Vec
// Check to see whether the lines are parallel
if !t.is_finite() || !u.is_finite() {
// TODO: can use postfix .into_iter() when switching to Rust 2021
IntoIterator::into_iter([
[
(n.projected_point(m.start), m.start),
(n.projected_point(m.end), m.end),
(n.start, m.projected_point(n.start)),
(n.end, m.projected_point(n.end)),
])
]
.into_iter()
.min_by_key(|(a, b)| ordered_float::OrderedFloat(a.distance_squared(*b)))
.expect("Lines had non-finite elements")
} else {

View File

@ -647,19 +647,23 @@ impl Renderer {
);
self.views = views;
// appease borrow check (TODO: remove after Rust 2021)
let device = &self.device;
let queue = &self.queue;
let views = &self.views;
let bloom_params = self
.views
.bloom_tgts
.as_ref()
.map(|tgts| locals::BloomParams {
locals: bloom_sizes.map(|size| {
Self::create_consts_inner(device, queue, &[bloom::Locals::new(size)])
Self::create_consts_inner(&self.device, &self.queue, &[bloom::Locals::new(
size,
)])
}),
src_views: [&views.tgt_color_pp, &tgts[1], &tgts[2], &tgts[3], &tgts[4]],
src_views: [
&self.views.tgt_color_pp,
&tgts[1],
&tgts[2],
&tgts[3],
&tgts[4],
],
final_tgt_view: &tgts[0],
});

View File

@ -181,19 +181,15 @@ impl GraphicCache {
return;
}
// TODO: remove with Rust 2021 edition
let cache_map = &mut self.cache_map;
let textures = &mut self.textures;
// Remove from caches
// Maybe make this more efficient if replace graphic is used more often
cache_map.retain(|&(key_id, _key_dims), details| {
self.cache_map.retain(|&(key_id, _key_dims), details| {
// If the entry does not reference id, or it does but we can successfully
// invalidate, retain the entry; otherwise, discard this entry completely.
key_id != id
|| details
.invalidate()
.map_err(|index| textures.remove(index))
.map_err(|index| self.textures.remove(index))
.is_ok()
});
}

View File

@ -125,13 +125,13 @@ impl ItemTooltipManager {
{
let mp_h = MOUSE_PAD_Y / self.logical_scale_factor;
let tooltip_ids = &mut self.tooltip_ids; // TODO: remove with Rust 2021
let mut id_walker = tooltip_ids.walk();
let mut id_walker = self.tooltip_ids.walk();
let tooltip = |transparency, mouse_pos: [f64; 2], ui: &mut UiCell| {
let mut prev_id = None;
for item in items {
let tooltip_id = id_walker.next(tooltip_ids, &mut ui.widget_id_generator());
let tooltip_id =
id_walker.next(&mut self.tooltip_ids, &mut ui.widget_id_generator());
// Fill in text and the potential image beforehand to get an accurate size for
// spacing
let tooltip = tooltip

View File

@ -2130,18 +2130,21 @@ impl WorldSim {
/// them spawning).
pub fn get_near_trees(&self, wpos: Vec2<i32>) -> impl Iterator<Item = TreeAttr> + '_ {
// Deterministic based on wpos
// TODO: can use postfix .into_iter() when switching to Rust 2021
let normal_trees = IntoIterator::into_iter(self.gen_ctx.structure_gen.get(wpos))
.filter_map(move |(wpos, seed)| {
let lottery = self.make_forest_lottery(wpos);
Some(TreeAttr {
pos: wpos,
seed,
scale: 1.0,
forest_kind: *lottery.choose_seeded(seed).as_ref()?,
inhabited: false,
})
});
let normal_trees =
self.gen_ctx
.structure_gen
.get(wpos)
.into_iter()
.filter_map(move |(wpos, seed)| {
let lottery = self.make_forest_lottery(wpos);
Some(TreeAttr {
pos: wpos,
seed,
scale: 1.0,
forest_kind: *lottery.choose_seeded(seed).as_ref()?,
inhabited: false,
})
});
// // For testing
// let giant_trees =