From 431b2ae07b2db109b6feafe3a32b1aab1708a839 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 20 Apr 2020 17:30:39 +0100 Subject: [PATCH] Fixed window mask layering, fmt --- common/src/path.rs | 4 +- common/src/terrain/block.rs | 7 +- voxygen/src/mesh/terrain.rs | 16 +++-- voxygen/src/render/mesh.rs | 23 +++---- voxygen/src/scene/terrain.rs | 4 +- world/src/civ/mod.rs | 18 +++-- world/src/column/mod.rs | 6 +- world/src/sim/mod.rs | 69 ++++++++++--------- world/src/sim/path.rs | 3 +- .../settlement/building/archetype/house.rs | 41 +++++++---- world/src/site/settlement/building/mod.rs | 11 +-- world/src/site/settlement/mod.rs | 10 +-- 12 files changed, 122 insertions(+), 90 deletions(-) diff --git a/common/src/path.rs b/common/src/path.rs index f152ed9668..ec30217a23 100644 --- a/common/src/path.rs +++ b/common/src/path.rs @@ -39,9 +39,7 @@ impl Path { pub fn end(&self) -> Option<&T> { self.nodes.last() } - pub fn nodes(&self) -> &[T] { - &self.nodes - } + pub fn nodes(&self) -> &[T] { &self.nodes } } // Route: A path that can be progressed along diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index 0a3e40d00a..e91e75e706 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -287,10 +287,9 @@ impl Block { pub fn get_ori(&self) -> Option { match self.kind { - BlockKind::Window1 - | BlockKind::Window2 - | BlockKind::Window3 - | BlockKind::Window4 => Some(self.color[0] & 0b111), + BlockKind::Window1 | BlockKind::Window2 | BlockKind::Window3 | BlockKind::Window4 => { + Some(self.color[0] & 0b111) + }, _ => None, } } diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 116210d37b..59e9be7aef 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -298,9 +298,10 @@ impl + ReadVol + Debug> Meshable + ReadVol + Debug> Meshable { verts: Vec, } -impl Clone for Mesh

where P::Vertex: Clone { +impl Clone for Mesh

+where + P::Vertex: Clone, +{ fn clone(&self) -> Self { - Self { verts: self.verts.clone() } + Self { + verts: self.verts.clone(), + } } } @@ -61,22 +66,16 @@ impl Mesh

{ } } - pub fn verts(&self) -> &[P::Vertex] { - &self.verts - } + pub fn verts(&self) -> &[P::Vertex] { &self.verts } - pub fn iter(&self) -> std::slice::Iter { - self.verts.iter() - } + pub fn iter(&self) -> std::slice::Iter { self.verts.iter() } } impl IntoIterator for Mesh

{ - type Item = P::Vertex; type IntoIter = std::vec::IntoIter; + type Item = P::Vertex; - fn into_iter(self) -> Self::IntoIter { - self.verts.into_iter() - } + fn into_iter(self) -> Self::IntoIter { self.verts.into_iter() } } /// Represents a triangle stored on the CPU. diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index dfbf48f669..856797b3fa 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -268,9 +268,7 @@ fn mesh_worker + RectRasterableVol + ReadVol + Debug>( let seed = wpos.x as u64 * 3 + wpos.y as u64 * 7 + wpos.x as u64 * wpos.y as u64; // Awful PRNG - let ori = block - .get_ori() - .unwrap_or((seed % 8) as u8); + let ori = block.get_ori().unwrap_or((seed % 8) as u8); let instance = SpriteInstance::new( Mat4::identity() diff --git a/world/src/civ/mod.rs b/world/src/civ/mod.rs index f25318b6e8..1504b6dd7c 100644 --- a/world/src/civ/mod.rs +++ b/world/src/civ/mod.rs @@ -3,7 +3,7 @@ mod econ; use crate::{ sim::{SimChunk, WorldSim}, site::{Dungeon, Settlement, Site as WorldSite}, - util::{attempt, seed_expan, NEIGHBORS, CARDINALS}, + util::{attempt, seed_expan, CARDINALS, NEIGHBORS}, }; use common::{ astar::Astar, @@ -108,9 +108,7 @@ impl Civs { .0; let mut chunk = ctx.sim.get_mut(locs[1]).unwrap(); - chunk.path.neighbors |= - (1 << (to_prev_idx as u8)) | - (1 << (to_next_idx as u8)); + chunk.path.neighbors |= (1 << (to_prev_idx as u8)) | (1 << (to_next_idx as u8)); chunk.path.offset = Vec2::new( ctx.rng.gen_range(-16.0, 16.0), ctx.rng.gen_range(-16.0, 16.0), @@ -164,7 +162,11 @@ impl Civs { // Place sites in world for site in this.sites.iter() { - let wpos = site.center.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| e * sz as i32 + sz as i32 / 2); + let wpos = site + .center + .map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| { + e * sz as i32 + sz as i32 / 2 + }); let world_site = match &site.kind { SiteKind::Settlement => { @@ -491,7 +493,11 @@ fn walk_in_dir(sim: &WorldSim, a: Vec2, dir: Vec2) -> Option { if loc_suitable_for_walking(sim, a) && loc_suitable_for_walking(sim, a + dir) { let a_alt = sim.get(a)?.alt; let b_alt = sim.get(a + dir)?.alt; - let water_cost = if sim.get(a + dir)?.river.near_water() { 25.0 } else { 0.0 }; + let water_cost = if sim.get(a + dir)?.river.near_water() { + 25.0 + } else { + 0.0 + }; Some((b_alt - a_alt).abs() / 2.5) } else { None diff --git a/world/src/column/mod.rs b/world/src/column/mod.rs index 0c350d3097..c5ec89e2b1 100644 --- a/world/src/column/mod.rs +++ b/world/src/column/mod.rs @@ -1119,7 +1119,11 @@ impl<'a> Sampler<'a> for ColumnGen<'a> { }; const PATH_WIDTH: f32 = 5.0; - let path_dist_factor = sim.get_nearest_path(wpos).map(|(dist, _)| dist / PATH_WIDTH).unwrap_or(1.0).min(1.0); + let path_dist_factor = sim + .get_nearest_path(wpos) + .map(|(dist, _)| dist / PATH_WIDTH) + .unwrap_or(1.0) + .min(1.0); let ground = Lerp::lerp( sub_surface_color, ground, diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 89a56f47ec..78e2074dfc 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -2,8 +2,8 @@ mod diffusion; mod erosion; mod location; mod map; -mod util; mod path; +mod util; // Reexports use self::erosion::Compute; @@ -15,12 +15,12 @@ pub use self::{ }, location::Location, map::{MapConfig, MapDebug}, + path::PathData, util::{ cdf_irwin_hall, downhill, get_oceans, local_cells, map_edge_factor, neighbors, uniform_idx_as_vec2, uniform_noise, uphill, vec2_as_uniform_idx, InverseCdf, ScaleBias, NEIGHBOR_DELTA, }, - path::PathData, }; use crate::{ @@ -29,7 +29,10 @@ use crate::{ civ::Place, column::ColumnGen, site::{Settlement, Site}, - util::{seed_expan, FastNoise, RandomField, Sampler, StructureGen2d, LOCALITY, CARDINAL_LOCALITY, NEIGHBORS}, + util::{ + seed_expan, FastNoise, RandomField, Sampler, StructureGen2d, CARDINAL_LOCALITY, LOCALITY, + NEIGHBORS, + }, CONFIG, }; use common::{ @@ -1777,15 +1780,18 @@ impl WorldSim { let chunk_pos = wpos.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| { e.div_euclid(sz as i32) }); - let get_chunk_centre = |chunk_pos: Vec2| chunk_pos.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| { - e * sz as i32 + sz as i32 / 2 - }); + let get_chunk_centre = |chunk_pos: Vec2| { + chunk_pos.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| { + e * sz as i32 + sz as i32 / 2 + }) + }; LOCALITY .iter() .filter_map(|ctrl| { let chunk = self.get(chunk_pos + *ctrl)?; - let ctrl_pos = get_chunk_centre(chunk_pos + *ctrl).map(|e| e as f32) + chunk.path.offset; + let ctrl_pos = + get_chunk_centre(chunk_pos + *ctrl).map(|e| e as f32) + chunk.path.offset; let chunk_connections = chunk.path.neighbors.count_ones(); if chunk_connections == 0 { @@ -1803,35 +1809,36 @@ impl WorldSim { .unwrap(); let start_pos_chunk = chunk_pos + *ctrl + start_rpos; ( - get_chunk_centre(start_pos_chunk).map(|e| e as f32) + self.get(start_pos_chunk)?.path.offset, + get_chunk_centre(start_pos_chunk).map(|e| e as f32) + + self.get(start_pos_chunk)?.path.offset, Some(start_idx), ) }; - Some(NEIGHBORS - .iter() - .enumerate() - .filter(move |(i, _)| chunk.path.neighbors & (1 << *i as u8) != 0) - .filter_map(move |(i, end_rpos)| { - let end_pos_chunk = chunk_pos + *ctrl + end_rpos; - let end_pos = get_chunk_centre(end_pos_chunk).map(|e| e as f32) + self.get(end_pos_chunk)?.path.offset; + Some( + NEIGHBORS + .iter() + .enumerate() + .filter(move |(i, _)| chunk.path.neighbors & (1 << *i as u8) != 0) + .filter_map(move |(i, end_rpos)| { + let end_pos_chunk = chunk_pos + *ctrl + end_rpos; + let end_pos = get_chunk_centre(end_pos_chunk).map(|e| e as f32) + + self.get(end_pos_chunk)?.path.offset; - let bez = QuadraticBezier2 { - start: (start_pos + ctrl_pos) / 2.0, - ctrl: ctrl_pos, - end: (end_pos + ctrl_pos) / 2.0, - }; - let nearest_interval = bez - .binary_search_point_by_steps( - wpos.map(|e| e as f32), - 6, - 0.01, - ) - .0.clamped(0.0, 1.0); - let pos = bez.evaluate(nearest_interval); - let dist_sqrd = pos.distance_squared(wpos.map(|e| e as f32)); - Some((dist_sqrd, pos.map(|e| e.floor() as i32))) - })) + let bez = QuadraticBezier2 { + start: (start_pos + ctrl_pos) / 2.0, + ctrl: ctrl_pos, + end: (end_pos + ctrl_pos) / 2.0, + }; + let nearest_interval = bez + .binary_search_point_by_steps(wpos.map(|e| e as f32), 6, 0.01) + .0 + .clamped(0.0, 1.0); + let pos = bez.evaluate(nearest_interval); + let dist_sqrd = pos.distance_squared(wpos.map(|e| e as f32)); + Some((dist_sqrd, pos.map(|e| e.floor() as i32))) + }), + ) }) .flatten() .min_by_key(|(dist_sqrd, _)| (dist_sqrd * 1024.0) as i32) diff --git a/world/src/sim/path.rs b/world/src/sim/path.rs index 25563669d2..ea4f24df42 100644 --- a/world/src/sim/path.rs +++ b/world/src/sim/path.rs @@ -2,7 +2,8 @@ use vek::*; #[derive(Debug)] pub struct PathData { - pub offset: Vec2, // Offset from centre of chunk: must not be more than half chunk width in any direction + pub offset: Vec2, /* Offset from centre of chunk: must not be more than half chunk + * width in any direction */ pub neighbors: u8, // One bit for each neighbor } diff --git a/world/src/site/settlement/building/archetype/house.rs b/world/src/site/settlement/building/archetype/house.rs index d78016d66c..fb86d4f494 100644 --- a/world/src/site/settlement/building/archetype/house.rs +++ b/world/src/site/settlement/building/archetype/house.rs @@ -171,10 +171,14 @@ impl Archetype for House { let profile = Vec2::new(bound_offset.x, z); let make_meta = |ori| { - Rgb::new(match ori { - Ori::East => 0, - Ori::North => 2, - }, 0, 0) + Rgb::new( + match ori { + Ori::East => 0, + Ori::North => 2, + }, + 0, + 0, + ) }; let make_block = |r, g, b| { @@ -204,7 +208,10 @@ impl Archetype for House { .with_priority(facade_layer); let empty = BlockMask::nothing(); let internal = BlockMask::new(Block::empty(), structural_layer); - let end_window = BlockMask::new(Block::new(BlockKind::Window1, make_meta(ori.flip())), facade_layer); + let end_window = BlockMask::new( + Block::new(BlockKind::Window1, make_meta(ori.flip())), + structural_layer, + ); let fire = BlockMask::new(Block::new(BlockKind::Ember, Rgb::white()), foundation_layer); let ceil_height = 6; @@ -311,15 +318,21 @@ impl Archetype for House { return Some(empty); } else { let (frame_bounds, frame_borders) = if profile.y >= ceil_height { - (Aabr { - min: Vec2::new(-1, ceil_height + 2), - max: Vec2::new(1, ceil_height + 5), - }, Vec2::new(1, 1)) + ( + Aabr { + min: Vec2::new(-1, ceil_height + 2), + max: Vec2::new(1, ceil_height + 5), + }, + Vec2::new(1, 1), + ) } else { - (Aabr { - min: Vec2::new(2, foundation_height + 2), - max: Vec2::new(width - 2, ceil_height - 2), - }, Vec2::new(1, 0)) + ( + Aabr { + min: Vec2::new(2, foundation_height + 2), + max: Vec2::new(width - 2, ceil_height - 2), + }, + Vec2::new(1, 0), + ) }; let window_bounds = Aabr { min: (frame_bounds.min + frame_borders) @@ -335,7 +348,7 @@ impl Archetype for House { if window_bounds.contains_point(surface_pos) { return Some(end_window); } else if frame_bounds.contains_point(surface_pos) { - return Some(log.with_priority(facade_layer)); + return Some(log.with_priority(structural_layer)); }; } diff --git a/world/src/site/settlement/building/mod.rs b/world/src/site/settlement/building/mod.rs index cc37d4acc5..97087a4af7 100644 --- a/world/src/site/settlement/building/mod.rs +++ b/world/src/site/settlement/building/mod.rs @@ -50,10 +50,13 @@ impl Building { pub fn sample(&self, pos: Vec3) -> Option { let rpos = pos - self.origin; self.skel - .sample_closest(rpos.into(), |dist, bound_offset, center_offset, ori, branch| { - self.archetype - .draw(dist, bound_offset, center_offset, rpos.z, ori, branch) - }) + .sample_closest( + rpos.into(), + |dist, bound_offset, center_offset, ori, branch| { + self.archetype + .draw(dist, bound_offset, center_offset, rpos.z, ori, branch) + }, + ) .finish() } } diff --git a/world/src/site/settlement/mod.rs b/world/src/site/settlement/mod.rs index 5e0ebbe689..79152914e8 100644 --- a/world/src/site/settlement/mod.rs +++ b/world/src/site/settlement/mod.rs @@ -611,10 +611,12 @@ impl Settlement { Crop::Sunflower => Some(BlockKind::Sunflower), _ => None, } - .or_else(|| if roll(9, 256) == 0 { - Some(BlockKind::Scarecrow) - } else { - None + .or_else(|| { + if roll(9, 256) == 0 { + Some(BlockKind::Scarecrow) + } else { + None + } }) .map(|kind| Block::new(kind, Rgb::white())); }