From e414b82d2fb8b8dc76ed9ccc56f884fcec330e95 Mon Sep 17 00:00:00 2001 From: Joshua Barretto <joshua.s.barretto@gmail.com> Date: Wed, 26 Jun 2019 01:27:41 +0100 Subject: [PATCH] fmt --- world/examples/city.rs | 9 +++++++-- world/examples/turb.rs | 15 +++++---------- world/src/column/mod.rs | 12 ++++++++---- world/src/sim/location.rs | 4 ++-- world/src/sim/mod.rs | 32 +++++++++++++++----------------- world/src/sim/settlement.rs | 29 +++++++++++------------------ 6 files changed, 48 insertions(+), 53 deletions(-) diff --git a/world/examples/city.rs b/world/examples/city.rs index 6bd9af95af..8774b3daf9 100644 --- a/world/examples/city.rs +++ b/world/examples/city.rs @@ -1,7 +1,7 @@ +use rand::thread_rng; use std::ops::{Add, Mul, Sub}; use vek::*; use veloren_world::sim::Settlement; -use rand::thread_rng; const W: usize = 640; const H: usize = 480; @@ -21,7 +21,12 @@ fn main() { let seed = settlement.get_at(pos).map(|b| b.seed).unwrap_or(0); - buf[j * W + i] = u32::from_le_bytes([(seed >> 0) as u8, (seed >> 8) as u8, (seed >> 16) as u8, (seed >> 24) as u8]); + buf[j * W + i] = u32::from_le_bytes([ + (seed >> 0) as u8, + (seed >> 8) as u8, + (seed >> 16) as u8, + (seed >> 24) as u8, + ]); } } diff --git a/world/examples/turb.rs b/world/examples/turb.rs index 419d70756e..6fa2f94a4b 100644 --- a/world/examples/turb.rs +++ b/world/examples/turb.rs @@ -1,15 +1,14 @@ +use noise::{NoiseFn, Seedable, SuperSimplex}; +use rand::thread_rng; use std::ops::{Add, Mul, Sub}; use vek::*; use veloren_world::sim::Settlement; -use rand::thread_rng; -use noise::{Seedable, NoiseFn, SuperSimplex}; const W: usize = 640; const H: usize = 640; fn main() { - let mut win = - minifb::Window::new("Turb", W, H, minifb::WindowOptions::default()).unwrap(); + let mut win = minifb::Window::new("Turb", W, H, minifb::WindowOptions::default()).unwrap(); let nz_x = SuperSimplex::new().set_seed(0); let nz_y = SuperSimplex::new().set_seed(1); @@ -24,13 +23,9 @@ fn main() { let pos = pos * 10.0; - let pos = (0..10) - .fold(pos, |pos, _| pos.map(|e| e.powf(3.0) - 1.0)); + let pos = (0..10).fold(pos, |pos, _| pos.map(|e| e.powf(3.0) - 1.0)); - let val = if pos - .map(|e| e.abs() < 0.5) - .reduce_and() - { + let val = if pos.map(|e| e.abs() < 0.5).reduce_and() { 1.0f32 } else { 0.0 diff --git a/world/src/column/mod.rs b/world/src/column/mod.rs index 82d59dbb4e..8baff7863a 100644 --- a/world/src/column/mod.rs +++ b/world/src/column/mod.rs @@ -139,7 +139,8 @@ impl<'a> Sampler for ColumnGen<'a> { let dist_to_path = match &sim_chunk.location { Some(loc) => { let this_loc = &sim.locations[loc.loc_idx]; - this_loc.neighbours + this_loc + .neighbours .iter() .map(|j| { let other_loc = &sim.locations[*j]; @@ -159,7 +160,7 @@ impl<'a> Sampler for ColumnGen<'a> { .filter(|x| x.is_finite()) .min_by(|a, b| a.partial_cmp(b).unwrap()) .unwrap_or(f32::INFINITY) - }, + } None => f32::INFINITY, }; @@ -178,11 +179,14 @@ impl<'a> Sampler for ColumnGen<'a> { let rpos = wposf.map2(loc.center, |a, b| a as f32 - b as f32) / 256.0 + 0.5; if rpos.map(|e| e >= 0.0 && e < 1.0).reduce_and() { - (loc.settlement.get_at(rpos).map(|b| b.seed % 20 + 10).unwrap_or(0)) as f32 + (loc.settlement + .get_at(rpos) + .map(|b| b.seed % 20 + 10) + .unwrap_or(0)) as f32 } else { 0.0 } - }, + } None => 0.0, }; diff --git a/world/src/sim/location.rs b/world/src/sim/location.rs index 916ffba554..240ddd03bf 100644 --- a/world/src/sim/location.rs +++ b/world/src/sim/location.rs @@ -1,7 +1,7 @@ +use super::Settlement; +use fxhash::FxHashSet; use rand::Rng; use vek::*; -use fxhash::FxHashSet; -use super::Settlement; #[derive(Clone, Debug)] pub struct Location { diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 5a237c6460..158a2d6aa8 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -160,14 +160,10 @@ impl WorldSim { loc_clone.sort_by_key(|(_, l)| l.distance_squared(pos)); - loc_clone - .iter() - .skip(1) - .take(2) - .for_each(|(j, _)| { - locations[i].neighbours.insert(*j); - locations[*j].neighbours.insert(i); - }); + loc_clone.iter().skip(1).take(2).for_each(|(j, _)| { + locations[i].neighbours.insert(*j); + locations[*j].neighbours.insert(i); + }); } // Simulate invasion! @@ -181,10 +177,8 @@ impl WorldSim { let loc = Vec2::new(i as i32 + R_COORDS[idx], j as i32 + R_COORDS[idx + 1]) .map(|e| e as usize); - loc_grid[j * grid_size.x + i] = loc_grid - .get(loc.y * grid_size.x + loc.x) - .cloned() - .flatten(); + loc_grid[j * grid_size.x + i] = + loc_grid.get(loc.y * grid_size.x + loc.x).cloned().flatten(); } } } @@ -195,7 +189,10 @@ impl WorldSim { for i in 0..WORLD_SIZE.x { for j in 0..WORLD_SIZE.y { let chunk_pos = Vec2::new(i as i32, j as i32); - let block_pos = Vec2::new(chunk_pos.x * TerrainChunkSize::SIZE.x as i32, chunk_pos.y * TerrainChunkSize::SIZE.y as i32); + let block_pos = Vec2::new( + chunk_pos.x * TerrainChunkSize::SIZE.x as i32, + chunk_pos.y * TerrainChunkSize::SIZE.y as i32, + ); let cell_pos = Vec2::new(i / cell_size, j / cell_size); // Find the distance to each region @@ -228,7 +225,10 @@ impl WorldSim { .unwrap() .location .as_ref() - .map(|l| locations[l.loc_idx].center.distance_squared(block_pos) < town_size * town_size) + .map(|l| { + locations[l.loc_idx].center.distance_squared(block_pos) + < town_size * town_size + }) .unwrap_or(false); if in_town { self.get_mut(chunk_pos).unwrap().spawn_rate = 0.0; @@ -471,9 +471,7 @@ impl SimChunk { pub fn get_name(&self, world: &WorldSim) -> Option<String> { if let Some(loc) = &self.location { - Some(world.locations[loc.loc_idx] - .name() - .to_string()) + Some(world.locations[loc.loc_idx].name().to_string()) } else { None } diff --git a/world/src/sim/settlement.rs b/world/src/sim/settlement.rs index 946193aef8..aadae70693 100644 --- a/world/src/sim/settlement.rs +++ b/world/src/sim/settlement.rs @@ -27,25 +27,16 @@ pub struct Building { enum Lot { None, One(Building), - Many { - split_x: bool, - lots: Vec<Lot>, - }, + Many { split_x: bool, lots: Vec<Lot> }, } impl Lot { pub fn generate(deep: usize, depth: f32, aspect: f32, rng: &mut impl Rng) -> Self { - let depth = if deep < 3 { - 8.0 - } else { - depth - }; + let depth = if deep < 3 { 8.0 } else { depth }; if (depth < 1.0 || deep > 6) && !(deep < 3 || deep % 2 == 1) { if rng.gen::<f32>() < 0.5 { - Lot::One(Building { - seed: rng.gen(), - }) + Lot::One(Building { seed: rng.gen() }) } else { Lot::None } @@ -76,11 +67,13 @@ impl Lot { pub fn get_at(&self, pos: Vec2<f32>) -> Option<&Building> { match self { Lot::None => None, - Lot::One(building) => if pos.map(|e| e > 0.1 && e < 0.9).reduce_and() { - Some(building) - } else { - None - }, + Lot::One(building) => { + if pos.map(|e| e > 0.1 && e < 0.9).reduce_and() { + Some(building) + } else { + None + } + } Lot::Many { split_x, lots } => { let split_dim = if *split_x { pos.x } else { pos.y }; let idx = (split_dim * lots.len() as f32).floor() as usize; @@ -89,7 +82,7 @@ impl Lot { } else { Vec2::new(pos.x, (pos.y * lots.len() as f32).fract()) }) - }, + } } } }