Fixed clippy warnings and fmt

This commit is contained in:
Joshua Barretto 2021-03-06 17:23:03 +00:00
parent 0cbdc2b1b7
commit 911acdd9db
20 changed files with 149 additions and 119 deletions

View File

@ -73,6 +73,8 @@ impl<T> Default for Store<T> {
} }
impl<T> Store<T> { impl<T> Store<T> {
pub fn is_empty(&self) -> bool { self.len == 0 }
pub fn len(&self) -> usize { self.len } pub fn len(&self) -> usize { self.len }
pub fn contains(&self, id: Id<T>) -> bool { pub fn contains(&self, id: Id<T>) -> bool {

View File

@ -570,7 +570,6 @@ impl<'a> Widget for Map<'a> {
SiteKind::Castle => self.imgs.mmap_site_castle, SiteKind::Castle => self.imgs.mmap_site_castle,
SiteKind::Cave => self.imgs.mmap_site_cave, SiteKind::Cave => self.imgs.mmap_site_cave,
SiteKind::Tree => self.imgs.mmap_site_tree, SiteKind::Tree => self.imgs.mmap_site_tree,
_ => self.imgs.mmap_site_excl,
}) })
.x_y_position_relative_to( .x_y_position_relative_to(
state.ids.grid, state.ids.grid,
@ -584,7 +583,6 @@ impl<'a> Widget for Map<'a> {
SiteKind::Castle => self.imgs.mmap_site_castle_hover, SiteKind::Castle => self.imgs.mmap_site_castle_hover,
SiteKind::Cave => self.imgs.mmap_site_cave_hover, SiteKind::Cave => self.imgs.mmap_site_cave_hover,
SiteKind::Tree => self.imgs.mmap_site_tree_hover, SiteKind::Tree => self.imgs.mmap_site_tree_hover,
_ => self.imgs.mmap_site_excl,
}) })
.image_color(UI_HIGHLIGHT_0) .image_color(UI_HIGHLIGHT_0)
.with_tooltip( .with_tooltip(
@ -605,7 +603,7 @@ impl<'a> Widget for Map<'a> {
_ => TEXT_COLOR, _ => TEXT_COLOR,
}, },
SiteKind::Cave => TEXT_COLOR, SiteKind::Cave => TEXT_COLOR,
_ => TEXT_COLOR, SiteKind::Tree => TEXT_COLOR,
}, },
); );
// Only display sites that are toggled on // Only display sites that are toggled on
@ -630,8 +628,10 @@ impl<'a> Widget for Map<'a> {
site_btn.set(state.ids.mmap_site_icons[i], ui); site_btn.set(state.ids.mmap_site_icons[i], ui);
} }
}, },
_ => { SiteKind::Tree => {
if show_trees {
site_btn.set(state.ids.mmap_site_icons[i], ui); site_btn.set(state.ids.mmap_site_icons[i], ui);
}
}, },
} }

View File

@ -304,7 +304,6 @@ impl<'a> Widget for MiniMap<'a> {
SiteKind::Castle => self.imgs.mmap_site_castle_bg, SiteKind::Castle => self.imgs.mmap_site_castle_bg,
SiteKind::Cave => self.imgs.mmap_site_cave_bg, SiteKind::Cave => self.imgs.mmap_site_cave_bg,
SiteKind::Tree => self.imgs.mmap_site_tree, SiteKind::Tree => self.imgs.mmap_site_tree,
_ => self.imgs.mmap_site_excl,
}) })
.x_y_position_relative_to( .x_y_position_relative_to(
state.ids.grid, state.ids.grid,
@ -335,7 +334,6 @@ impl<'a> Widget for MiniMap<'a> {
SiteKind::Castle => self.imgs.mmap_site_castle, SiteKind::Castle => self.imgs.mmap_site_castle,
SiteKind::Cave => self.imgs.mmap_site_cave, SiteKind::Cave => self.imgs.mmap_site_cave,
SiteKind::Tree => self.imgs.mmap_site_tree, SiteKind::Tree => self.imgs.mmap_site_tree,
_ => self.imgs.mmap_site_excl,
}) })
.middle_of(state.ids.mmap_site_icons_bgs[i]) .middle_of(state.ids.mmap_site_icons_bgs[i])
.w_h(20.0, 20.0) .w_h(20.0, 20.0)

View File

@ -515,7 +515,7 @@ impl<V: RectRasterableVol> Terrain<V> {
const AMBIANCE: f32 = 0.15; // 0-1, the proportion of light that should illuminate the rear of an object const AMBIANCE: f32 = 0.15; // 0-1, the proportion of light that should illuminate the rear of an object
let (bias, total, max) = Spiral2d::new() let (bias, total) = Spiral2d::new()
.take(9) .take(9)
.map(|rpos| { .map(|rpos| {
let chunk_pos = wpos_chunk + rpos; let chunk_pos = wpos_chunk + rpos;
@ -535,14 +535,13 @@ impl<V: RectRasterableVol> Terrain<V> {
}) })
.flatten() .flatten()
.fold( .fold(
(Vec3::broadcast(0.001), 0.0, 0.0f32), (Vec3::broadcast(0.001), 0.0),
|(bias, total, max), (lpos, level)| { |(bias, total), (lpos, level)| {
let rpos = lpos.map(|e| e as f32 + 0.5) - wpos; let rpos = lpos.map(|e| e as f32 + 0.5) - wpos;
let level = (*level as f32 - rpos.magnitude()).max(0.0) / SUNLIGHT as f32; let level = (*level as f32 - rpos.magnitude()).max(0.0) / SUNLIGHT as f32;
( (
bias + rpos.try_normalized().unwrap_or_else(Vec3::zero) * level, bias + rpos.try_normalized().unwrap_or_else(Vec3::zero) * level,
total + level, total + level,
max.max(level),
) )
}, },
); );
@ -643,7 +642,7 @@ impl<V: RectRasterableVol> Terrain<V> {
// be meshed // be meshed
span!(guard, "Add chunks with modified blocks to mesh todo list"); span!(guard, "Add chunks with modified blocks to mesh todo list");
// TODO: would be useful if modified blocks were grouped by chunk // TODO: would be useful if modified blocks were grouped by chunk
for (&pos, &block) in scene_data.state.terrain_changes().modified_blocks.iter() { for (&pos, &_block) in scene_data.state.terrain_changes().modified_blocks.iter() {
// TODO: Be cleverer about this to avoid remeshing all neighbours. There are a // TODO: Be cleverer about this to avoid remeshing all neighbours. There are a
// few things that can create an 'effect at a distance'. These are // few things that can create an 'effect at a distance'. These are
// as follows: // as follows:

View File

@ -1,4 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Benchmark, Criterion}; use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
use rand::prelude::*;
use veloren_world::layer::tree::{ProceduralTree, TreeConfig}; use veloren_world::layer::tree::{ProceduralTree, TreeConfig};
fn tree(c: &mut Criterion) { fn tree(c: &mut Criterion) {
@ -6,7 +7,10 @@ fn tree(c: &mut Criterion) {
let mut i = 0; let mut i = 0;
b.iter(|| { b.iter(|| {
i += 1; i += 1;
black_box(ProceduralTree::generate(TreeConfig::OAK, i)); black_box(ProceduralTree::generate(
TreeConfig::oak(&mut thread_rng(), 1.0),
&mut thread_rng(),
));
}); });
}); });
@ -15,7 +19,7 @@ fn tree(c: &mut Criterion) {
b.iter_batched( b.iter_batched(
|| { || {
i += 1; i += 1;
ProceduralTree::generate(TreeConfig::OAK, i) ProceduralTree::generate(TreeConfig::oak(&mut thread_rng(), 1.0), &mut thread_rng())
}, },
|tree| { |tree| {
let bounds = tree.get_bounds(); let bounds = tree.get_bounds();

View File

@ -1,4 +1,3 @@
use structopt::StructOpt;
use svg_fmt::*; use svg_fmt::*;
use veloren_world::site2::test_site; use veloren_world::site2::test_site;

View File

@ -68,7 +68,7 @@ impl<'a> Canvas<'a> {
.get(pos - self.wpos()) .get(pos - self.wpos())
.ok() .ok()
.copied() .copied()
.unwrap_or(Block::empty()) .unwrap_or_else(Block::empty)
} }
pub fn set(&mut self, pos: Vec3<i32>, block: Block) { pub fn set(&mut self, pos: Vec3<i32>, block: Block) {

View File

@ -108,7 +108,7 @@ impl Civs {
attempt(5, || { attempt(5, || {
let (kind, size) = match ctx.rng.gen_range(0..64) { let (kind, size) = match ctx.rng.gen_range(0..64) {
0..=4 => (SiteKind::Castle, 3), 0..=4 => (SiteKind::Castle, 3),
5..=28 => (SiteKind::Refactor, 6), // 5..=28 => (SiteKind::Refactor, 6),
29..=31 => (SiteKind::Tree, 4), 29..=31 => (SiteKind::Tree, 4),
_ => (SiteKind::Dungeon, 0), _ => (SiteKind::Dungeon, 0),
}; };

View File

@ -69,10 +69,10 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
let sim = &self.sim; let sim = &self.sim;
let turb = Vec2::new( // let turb = Vec2::new(
sim.gen_ctx.turb_x_nz.get((wposf.div(48.0)).into_array()) as f32, // sim.gen_ctx.turb_x_nz.get((wposf.div(48.0)).into_array()) as f32,
sim.gen_ctx.turb_y_nz.get((wposf.div(48.0)).into_array()) as f32, // sim.gen_ctx.turb_y_nz.get((wposf.div(48.0)).into_array()) as f32,
) * 12.0; // ) * 12.0;
let wposf_turb = wposf; // + turb.map(|e| e as f64); let wposf_turb = wposf; // + turb.map(|e| e as f64);
let chaos = sim.get_interpolated(wpos, |chunk| chunk.chaos)?; let chaos = sim.get_interpolated(wpos, |chunk| chunk.chaos)?;

View File

@ -333,7 +333,7 @@ impl TreeConfig {
} }
} }
pub fn giant(rng: &mut impl Rng, scale: f32, inhabited: bool) -> Self { pub fn giant(_rng: &mut impl Rng, scale: f32, inhabited: bool) -> Self {
let log_scale = 1.0 + scale.log2().max(0.0); let log_scale = 1.0 + scale.log2().max(0.0);
Self { Self {
@ -380,7 +380,6 @@ impl ProceduralTree {
0, 0,
None, None,
rng, rng,
true,
); );
this.trunk_idx = trunk_idx; this.trunk_idx = trunk_idx;
@ -391,6 +390,7 @@ impl ProceduralTree {
// returning the index and AABB of the branch. This AABB gets propagated // returning the index and AABB of the branch. This AABB gets propagated
// down to the parent and is used later during sampling to cull the branches to // down to the parent and is used later during sampling to cull the branches to
// be sampled. // be sampled.
#[allow(clippy::too_many_arguments)]
fn add_branch( fn add_branch(
&mut self, &mut self,
config: &TreeConfig, config: &TreeConfig,
@ -401,7 +401,6 @@ impl ProceduralTree {
depth: usize, depth: usize,
sibling_idx: Option<usize>, sibling_idx: Option<usize>,
rng: &mut impl Rng, rng: &mut impl Rng,
has_stairs: bool,
) -> (usize, Aabb<f32>) { ) -> (usize, Aabb<f32>) {
let end = start + dir * branch_len; let end = start + dir * branch_len;
let line = LineSegment3 { start, end }; let line = LineSegment3 { start, end };
@ -412,7 +411,10 @@ impl ProceduralTree {
0.0 0.0
}; };
let has_stairs = /*has_stairs &&*/ config.inhabited && depth < config.max_depth && branch_radius > 6.5 && start.xy().distance(end.xy()) < (start.z - end.z).abs() * 1.5; let has_stairs = config.inhabited
&& depth < config.max_depth
&& branch_radius > 6.5
&& start.xy().distance(end.xy()) < (start.z - end.z).abs() * 1.5;
let bark_radius = if has_stairs { 5.0 } else { 0.0 } + wood_radius * 0.25; let bark_radius = if has_stairs { 5.0 } else { 0.0 } + wood_radius * 0.25;
// The AABB that covers this branch, along with wood and leaves that eminate // The AABB that covers this branch, along with wood and leaves that eminate
@ -477,7 +479,6 @@ impl ProceduralTree {
depth + 1, depth + 1,
child_idx, child_idx,
rng, rng,
has_stairs,
); );
child_idx = Some(branch_idx); child_idx = Some(branch_idx);
// Parent branches AABBs include the AABBs of child branches to allow for // Parent branches AABBs include the AABBs of child branches to allow for
@ -523,7 +524,7 @@ impl ProceduralTree {
// within its AABB // within its AABB
if branch.aabb.contains_point(pos) { if branch.aabb.contains_point(pos) {
// Probe this branch // Probe this branch
let (this, d2) = branch.is_branch_or_leaves_at(pos, parent); let (this, _d2) = branch.is_branch_or_leaves_at(pos, parent);
let siblings = branch_or_leaves | Vec4::from(this); let siblings = branch_or_leaves | Vec4::from(this);

View File

@ -1,6 +1,10 @@
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
#![allow(clippy::option_map_unit_fn)] #![allow(
clippy::option_map_unit_fn,
clippy::blocks_in_if_conditions,
clippy::too_many_arguments
)]
#![deny(clippy::clone_on_ref_ptr)] #![deny(clippy::clone_on_ref_ptr)]
#![feature( #![feature(
arbitrary_enum_discriminant, arbitrary_enum_discriminant,

View File

@ -29,8 +29,8 @@ use crate::{
column::ColumnGen, column::ColumnGen,
site::Site, site::Site,
util::{ util::{
seed_expan, DHashSet, FastNoise, FastNoise2d, RandomField, RandomPerm, Sampler, seed_expan, DHashSet, FastNoise, FastNoise2d, RandomField, Sampler, StructureGen2d,
StructureGen2d, CARDINALS, LOCALITY, NEIGHBORS, CARDINALS, LOCALITY, NEIGHBORS,
}, },
IndexRef, CONFIG, IndexRef, CONFIG,
}; };
@ -1570,15 +1570,14 @@ impl WorldSim {
// Vec2::new(rng.gen_range(-16..17), rng.gen_range(-16..17)); } // Vec2::new(rng.gen_range(-16..17), rng.gen_range(-16..17)); }
for cliff in cliffs { for cliff in cliffs {
let alt = self.get(cliff).map_or(0.0, |c| c.alt);
Spiral2d::new() Spiral2d::new()
.take((4usize * 2 + 1).pow(2)) .take((4usize * 2 + 1).pow(2))
.for_each(|rpos| { .for_each(|rpos| {
let dist = rpos.map(|e| e as f32).magnitude(); let dist = rpos.map(|e| e as f32).magnitude();
if let Some(c) = self.get_mut(cliff + rpos) { if let Some(c) = self.get_mut(cliff + rpos) {
let warp = 1.0 / (1.0 + dist); let warp = 1.0 / (1.0 + dist);
c.tree_density *= (1.0 - warp); c.tree_density *= 1.0 - warp;
c.cliff_height = Lerp::lerp(44.0, 0.0, (-1.0 + dist / 3.5)); c.cliff_height = Lerp::lerp(44.0, 0.0, -1.0 + dist / 3.5);
} }
}); });
} }

View File

@ -12,12 +12,8 @@ pub use self::{
settlement::Settlement, tree::Tree, settlement::Settlement, tree::Tree,
}; };
use crate::{column::ColumnSample, site2, Canvas, IndexRef}; use crate::{column::ColumnSample, site2, Canvas};
use common::{ use common::generation::ChunkSupplement;
generation::ChunkSupplement,
terrain::Block,
vol::{BaseVol, ReadVol, RectSizedVol, WriteVol},
};
use rand::Rng; use rand::Rng;
use serde::Deserialize; use serde::Deserialize;
use vek::*; use vek::*;
@ -121,8 +117,8 @@ impl Site {
SiteKind::Settlement(s) => s.name(), SiteKind::Settlement(s) => s.name(),
SiteKind::Dungeon(d) => d.name(), SiteKind::Dungeon(d) => d.name(),
SiteKind::Castle(c) => c.name(), SiteKind::Castle(c) => c.name(),
SiteKind::Refactor(s) => "Town", SiteKind::Refactor(_) => "Town",
SiteKind::Tree(t) => "Tree", SiteKind::Tree(_) => "Giant Tree",
} }
} }

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
layer::tree::{ProceduralTree, TreeConfig}, layer::tree::{ProceduralTree, TreeConfig},
util::{FastNoise, Sampler},
site::SpawnRules, site::SpawnRules,
util::{FastNoise, Sampler},
Canvas, Land, Canvas, Land,
}; };
use common::terrain::{Block, BlockKind}; use common::terrain::{Block, BlockKind};
@ -38,7 +38,7 @@ impl Tree {
} }
} }
pub fn render(&self, canvas: &mut Canvas, dynamic_rng: &mut impl Rng) { pub fn render(&self, canvas: &mut Canvas, _dynamic_rng: &mut impl Rng) {
let nz = FastNoise::new(self.seed); let nz = FastNoise::new(self.seed);
canvas.foreach_col(|canvas, wpos2d, col| { canvas.foreach_col(|canvas, wpos2d, col| {
@ -50,19 +50,39 @@ impl Tree {
return; return;
} }
let mut above = true;
for z in (bounds.min.z..bounds.max.z + 1).rev() { for z in (bounds.min.z..bounds.max.z + 1).rev() {
let wpos = wpos2d.with_z(self.alt + z); let wpos = wpos2d.with_z(self.alt + z);
let rposf = (wpos - self.origin.with_z(self.alt)).map(|e| e as f32 + 0.5); let rposf = (wpos - self.origin.with_z(self.alt)).map(|e| e as f32 + 0.5);
let (branch, leaves, _, _) = self.tree.is_branch_or_leaves_at(rposf); let (branch, leaves, _, _) = self.tree.is_branch_or_leaves_at(rposf);
if branch || leaves {
if above && col.snow_cover {
canvas.set(
wpos + Vec3::unit_z(),
Block::new(BlockKind::Snow, Rgb::new(255, 255, 255)),
);
}
if leaves { if leaves {
let dark = Rgb::new(10, 70, 50).map(|e| e as f32); let dark = Rgb::new(10, 70, 50).map(|e| e as f32);
let light = Rgb::new(80, 140, 10).map(|e| e as f32); let light = Rgb::new(80, 140, 10).map(|e| e as f32);
let leaf_col = Lerp::lerp(dark, light, nz.get(rposf.map(|e| e as f64) * 0.05) * 0.5 + 0.5); let leaf_col = Lerp::lerp(
canvas.set(wpos, Block::new(BlockKind::Leaves, leaf_col.map(|e| e as u8))); dark,
light,
nz.get(rposf.map(|e| e as f64) * 0.05) * 0.5 + 0.5,
);
canvas.set(
wpos,
Block::new(BlockKind::Leaves, leaf_col.map(|e| e as u8)),
);
} else if branch { } else if branch {
canvas.set(wpos, Block::new(BlockKind::Wood, Rgb::new(80, 32, 0))); canvas.set(wpos, Block::new(BlockKind::Wood, Rgb::new(80, 32, 0)));
} }
above = true;
}
} }
}); });
} }

View File

@ -129,7 +129,7 @@ pub trait Structure {
fn render_collect(&self, site: &Site) -> (Store<Primitive>, Vec<(Id<Primitive>, Fill)>) { fn render_collect(&self, site: &Site) -> (Store<Primitive>, Vec<(Id<Primitive>, Fill)>) {
let mut tree = Store::default(); let mut tree = Store::default();
let mut fills = Vec::new(); let mut fills = Vec::new();
let root = self.render(site, |p| tree.insert(p), |p, f| fills.push((p, f))); self.render(site, |p| tree.insert(p), |p, f| fills.push((p, f)));
(tree, fills) (tree, fills)
} }
} }

View File

@ -5,18 +5,19 @@ mod tile;
use self::{ use self::{
gen::{Fill, Primitive, Structure}, gen::{Fill, Primitive, Structure},
plot::{Plot, PlotKind}, plot::{Plot, PlotKind},
tile::{HazardKind, Tile, TileGrid, TileKind, KeepKind, Ori, TILE_SIZE}, tile::{HazardKind, Ori, Tile, TileGrid, TileKind, TILE_SIZE},
}; };
use crate::{ use crate::{
site::SpawnRules, site::SpawnRules,
util::{attempt, DHashSet, Grid, CARDINALS, LOCALITY, SQUARE_4, SQUARE_9}, util::{attempt, DHashSet, Grid, CARDINALS, SQUARE_4, SQUARE_9},
Canvas, Land, Canvas, Land,
}; };
use common::{ use common::{
astar::Astar, astar::Astar,
lottery::Lottery, lottery::Lottery,
spiral::Spiral2d, spiral::Spiral2d,
store::{Id, Store}, terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize}, store::{Id, Store},
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
vol::RectVolSize, vol::RectVolSize,
}; };
use hashbrown::hash_map::DefaultHashBuilder; use hashbrown::hash_map::DefaultHashBuilder;
@ -62,7 +63,6 @@ impl Site {
self.wpos_tile(wpos + rpos * tile::TILE_SIZE as i32) self.wpos_tile(wpos + rpos * tile::TILE_SIZE as i32)
.is_empty() .is_empty()
}), }),
..SpawnRules::default()
} }
} }
@ -193,12 +193,10 @@ impl Site {
let search_pos = if rng.gen() { let search_pos = if rng.gen() {
self.plot(*self.plazas.choose(rng)?).root_tile self.plot(*self.plazas.choose(rng)?).root_tile
+ (dir * 4.0).map(|e: f32| e.round() as i32) + (dir * 4.0).map(|e: f32| e.round() as i32)
} else { } else if let PlotKind::Road(path) = &self.plot(*self.roads.choose(rng)?).kind {
if let PlotKind::Road(path) = &self.plot(*self.roads.choose(rng)?).kind {
*path.nodes().choose(rng)? + (dir * 1.0).map(|e: f32| e.round() as i32) *path.nodes().choose(rng)? + (dir * 1.0).map(|e: f32| e.round() as i32)
} else { } else {
unreachable!() unreachable!()
}
}; };
self.find_aabr(search_pos, area_range, min_dims) self.find_aabr(search_pos, area_range, min_dims)
@ -360,14 +358,11 @@ impl Site {
* rng.gen_range(16.0..48.0)) * rng.gen_range(16.0..48.0))
.map(|e| e as i32); .map(|e| e as i32);
if site.plazas.iter().all(|&p| { Some(tile).filter(|_| {
site.plazas.iter().all(|&p| {
site.plot(p).root_tile.distance_squared(tile) > 20i32.pow(2) site.plot(p).root_tile.distance_squared(tile) > 20i32.pow(2)
}) && rng.gen_range(0..48) > tile.map(|e| e.abs()).reduce_max() }) && rng.gen_range(0..48) > tile.map(|e| e.abs()).reduce_max()
{ })
Some(tile)
} else {
None
}
}) })
.unwrap_or_else(Vec2::zero); .unwrap_or_else(Vec2::zero);
@ -444,10 +439,22 @@ impl Site {
plot: Some(plot), plot: Some(plot),
}, },
); );
site.tiles.set(Vec2::new(aabr.center().x + 2, aabr.center().y + 2), tower.clone()); site.tiles.set(
site.tiles.set(Vec2::new(aabr.center().x + 2, aabr.center().y - 3), tower.clone()); Vec2::new(aabr.center().x + 2, aabr.center().y + 2),
site.tiles.set(Vec2::new(aabr.center().x - 3, aabr.center().y + 2), tower.clone()); tower.clone(),
site.tiles.set(Vec2::new(aabr.center().x - 3, aabr.center().y - 3), tower.clone()); );
site.tiles.set(
Vec2::new(aabr.center().x + 2, aabr.center().y - 3),
tower.clone(),
);
site.tiles.set(
Vec2::new(aabr.center().x - 3, aabr.center().y + 2),
tower.clone(),
);
site.tiles.set(
Vec2::new(aabr.center().x - 3, aabr.center().y - 3),
tower.clone(),
);
site.blit_aabr( site.blit_aabr(
Aabr { Aabr {
@ -486,7 +493,7 @@ impl Site {
self.origin + tile * tile::TILE_SIZE as i32 + tile::TILE_SIZE as i32 / 2 self.origin + tile * tile::TILE_SIZE as i32 + tile::TILE_SIZE as i32 / 2
} }
pub fn render_tile(&self, canvas: &mut Canvas, dynamic_rng: &mut impl Rng, tpos: Vec2<i32>) { pub fn render_tile(&self, canvas: &mut Canvas, _dynamic_rng: &mut impl Rng, tpos: Vec2<i32>) {
let tile = self.tiles.get(tpos); let tile = self.tiles.get(tpos);
let twpos = self.tile_wpos(tpos); let twpos = self.tile_wpos(tpos);
let border = TILE_SIZE as i32; let border = TILE_SIZE as i32;
@ -497,6 +504,7 @@ impl Site {
}) })
.flatten(); .flatten();
#[allow(clippy::single_match)]
match &tile.kind { match &tile.kind {
TileKind::Plaza => { TileKind::Plaza => {
let near_roads = CARDINALS.iter().filter_map(|rpos| { let near_roads = CARDINALS.iter().filter_map(|rpos| {
@ -510,7 +518,7 @@ impl Site {
} }
}); });
cols.for_each(|(wpos2d, offs)| { cols.for_each(|(wpos2d, _offs)| {
let wpos2df = wpos2d.map(|e| e as f32); let wpos2df = wpos2d.map(|e| e as f32);
let dist = near_roads let dist = near_roads
.clone() .clone()
@ -584,6 +592,7 @@ impl Site {
let tile = self.wpos_tile(wpos2d); let tile = self.wpos_tile(wpos2d);
let seed = tile.plot.map_or(0, |p| self.plot(p).seed); let seed = tile.plot.map_or(0, |p| self.plot(p).seed);
#[allow(clippy::single_match)]
match tile.kind { match tile.kind {
TileKind::Field /*| TileKind::Road*/ => (-4..5).for_each(|z| canvas.map( TileKind::Field /*| TileKind::Road*/ => (-4..5).for_each(|z| canvas.map(
Vec3::new(wpos2d.x, wpos2d.y, col.alt as i32 + z), Vec3::new(wpos2d.x, wpos2d.y, col.alt as i32 + z),

View File

@ -26,7 +26,6 @@ impl Plot {
} }
pub enum PlotKind { pub enum PlotKind {
Field,
House(House), House(House),
Plaza, Plaza,
Castle(Castle), Castle(Castle),

View File

@ -1,28 +1,28 @@
use super::*; use super::*;
use crate::{util::SQUARE_4, Land}; use crate::Land;
use common::terrain::{Block, BlockKind, SpriteKind}; use common::terrain::{Block, BlockKind};
use rand::prelude::*; use rand::prelude::*;
use vek::*; use vek::*;
pub struct Castle { pub struct Castle {
entrance_tile: Vec2<i32>, _entrance_tile: Vec2<i32>,
tile_aabr: Aabr<i32>, tile_aabr: Aabr<i32>,
bounds: Aabr<i32>, _bounds: Aabr<i32>,
alt: i32, alt: i32,
} }
impl Castle { impl Castle {
pub fn generate( pub fn generate(
land: &Land, land: &Land,
rng: &mut impl Rng, _rng: &mut impl Rng,
site: &Site, site: &Site,
entrance_tile: Vec2<i32>, entrance_tile: Vec2<i32>,
tile_aabr: Aabr<i32>, tile_aabr: Aabr<i32>,
) -> Self { ) -> Self {
Self { Self {
entrance_tile, _entrance_tile: entrance_tile,
tile_aabr, tile_aabr,
bounds: Aabr { _bounds: Aabr {
min: site.tile_wpos(tile_aabr.min), min: site.tile_wpos(tile_aabr.min),
max: site.tile_wpos(tile_aabr.max), max: site.tile_wpos(tile_aabr.max),
}, },
@ -39,20 +39,20 @@ impl Structure for Castle {
mut fill: G, mut fill: G,
) { ) {
let wall_height = 24; let wall_height = 24;
let thickness = 12; let _thickness = 12;
let parapet_height = 2; let parapet_height = 2;
let parapet_width = 1; let parapet_width = 1;
let downwards = 40; let _downwards = 40;
let tower_height = 12; let tower_height = 12;
let keep_levels = 3; let keep_levels = 3;
let keep_level_height = 8; let keep_level_height = 8;
let keep_height = wall_height + keep_levels * keep_level_height + 1; let _keep_height = wall_height + keep_levels * keep_level_height + 1;
for x in 0..self.tile_aabr.size().w { for x in 0..self.tile_aabr.size().w {
for y in 0..self.tile_aabr.size().h { for y in 0..self.tile_aabr.size().h {
let tile_pos = self.tile_aabr.min + Vec2::new(x, y); let tile_pos = self.tile_aabr.min + Vec2::new(x, y);
let wpos_center = site.tile_center_wpos(tile_pos); let _wpos_center = site.tile_center_wpos(tile_pos);
let wpos = site.tile_wpos(tile_pos); let wpos = site.tile_wpos(tile_pos);
let ori = if x == 0 || x == self.tile_aabr.size().w - 1 { let ori = if x == 0 || x == self.tile_aabr.size().w - 1 {
Vec2::new(1, 0) Vec2::new(1, 0)
@ -71,7 +71,7 @@ impl Structure for Castle {
}; };
let ori_tower = ori_tower_x + ori_tower_y; let ori_tower = ori_tower_x + ori_tower_y;
match site.tiles.get(tile_pos).kind.clone() { match site.tiles.get(tile_pos).kind.clone() {
TileKind::Wall(orientation) => { TileKind::Wall(_ori) => {
let wall = prim(Primitive::Aabb(Aabb { let wall = prim(Primitive::Aabb(Aabb {
min: wpos.with_z(self.alt), min: wpos.with_z(self.alt),
max: (wpos + 6).with_z(self.alt + wall_height + parapet_height), max: (wpos + 6).with_z(self.alt + wall_height + parapet_height),
@ -115,7 +115,7 @@ impl Structure for Castle {
})); }));
let tower_lower_inner_x = prim(Primitive::Aabb(Aabb { let tower_lower_inner_x = prim(Primitive::Aabb(Aabb {
min: Vec3::new( min: Vec3::new(
wpos.x + 1 * ori_tower.x, wpos.x + ori_tower.x,
wpos.y + parapet_width, wpos.y + parapet_width,
self.alt + wall_height, self.alt + wall_height,
), ),
@ -128,7 +128,7 @@ impl Structure for Castle {
let tower_lower_inner_y = prim(Primitive::Aabb(Aabb { let tower_lower_inner_y = prim(Primitive::Aabb(Aabb {
min: Vec3::new( min: Vec3::new(
wpos.x + parapet_width, wpos.x + parapet_width,
wpos.y + 1 * ori_tower.y, wpos.y + ori_tower.y,
self.alt + wall_height, self.alt + wall_height,
), ),
max: Vec3::new( max: Vec3::new(
@ -147,19 +147,19 @@ impl Structure for Castle {
min: Vec3::new( min: Vec3::new(
wpos.x - 1, wpos.x - 1,
wpos.y - 1, wpos.y - 1,
self.alt + wall_height + tower_height - 3 as i32, self.alt + wall_height + tower_height - 3i32,
), ),
max: Vec3::new( max: Vec3::new(
wpos.x + 7, wpos.x + 7,
wpos.y + 7, wpos.y + 7,
self.alt + wall_height + tower_height - 1 as i32, self.alt + wall_height + tower_height - 1i32,
), ),
})); }));
let tower_upper2 = prim(Primitive::Aabb(Aabb { let tower_upper2 = prim(Primitive::Aabb(Aabb {
min: Vec3::new( min: Vec3::new(
wpos.x - 2, wpos.x - 2,
wpos.y - 2, wpos.y - 2,
self.alt + wall_height + tower_height - 1 as i32, self.alt + wall_height + tower_height - 1i32,
), ),
max: Vec3::new( max: Vec3::new(
wpos.x + 8, wpos.x + 8,
@ -209,11 +209,11 @@ impl Structure for Castle {
} }
}, },
tile::KeepKind::Corner => {}, tile::KeepKind::Corner => {},
tile::KeepKind::Wall(orientation) => { tile::KeepKind::Wall(_ori) => {
for i in 0..keep_levels + 1 { for i in 0..keep_levels + 1 {
let height = keep_level_height * i; let _height = keep_level_height * i;
// TODO clamp value in case of big heights // TODO clamp value in case of big heights
let window_height = keep_level_height - 3; let _window_height = keep_level_height - 3;
} }
}, },
} }

View File

@ -1,11 +1,11 @@
use super::*; use super::*;
use crate::{util::SQUARE_4, Land}; use crate::Land;
use common::terrain::{Block, BlockKind, SpriteKind}; use common::terrain::{Block, BlockKind, SpriteKind};
use rand::prelude::*; use rand::prelude::*;
use vek::*; use vek::*;
pub struct House { pub struct House {
door_tile: Vec2<i32>, _door_tile: Vec2<i32>,
tile_aabr: Aabr<i32>, tile_aabr: Aabr<i32>,
bounds: Aabr<i32>, bounds: Aabr<i32>,
alt: i32, alt: i32,
@ -22,7 +22,7 @@ impl House {
tile_aabr: Aabr<i32>, tile_aabr: Aabr<i32>,
) -> Self { ) -> Self {
Self { Self {
door_tile, _door_tile: door_tile,
tile_aabr, tile_aabr,
bounds: Aabr { bounds: Aabr {
min: site.tile_wpos(tile_aabr.min), min: site.tile_wpos(tile_aabr.min),

View File

@ -7,6 +7,7 @@ pub const TILE_SIZE: u32 = 6;
pub const ZONE_SIZE: u32 = 16; pub const ZONE_SIZE: u32 = 16;
pub const ZONE_RADIUS: u32 = 16; pub const ZONE_RADIUS: u32 = 16;
pub const TILE_RADIUS: u32 = ZONE_SIZE * ZONE_RADIUS; pub const TILE_RADIUS: u32 = ZONE_SIZE * ZONE_RADIUS;
#[allow(dead_code)]
pub const MAX_BLOCK_RADIUS: u32 = TILE_SIZE * TILE_RADIUS; pub const MAX_BLOCK_RADIUS: u32 = TILE_SIZE * TILE_RADIUS;
pub struct TileGrid { pub struct TileGrid {
@ -48,7 +49,7 @@ impl TileGrid {
Grid::populate_from(Vec2::broadcast(ZONE_SIZE as i32), |_| None) Grid::populate_from(Vec2::broadcast(ZONE_SIZE as i32), |_| None)
}) })
.get_mut(tpos.map(|e| e.rem_euclid(ZONE_SIZE as i32))) .get_mut(tpos.map(|e| e.rem_euclid(ZONE_SIZE as i32)))
.map(|tile| tile.get_or_insert_with(|| Tile::empty())) .map(|tile| tile.get_or_insert_with(Tile::empty))
}) })
} }
@ -87,9 +88,8 @@ impl TileGrid {
let mut last_growth = 0; let mut last_growth = 0;
for i in 0..32 { for i in 0..32 {
if i - last_growth >= 4 { if i - last_growth >= 4
break; || aabr.size().product()
} else if aabr.size().product()
+ if i % 2 == 0 { + if i % 2 == 0 {
aabr.size().h aabr.size().h
} else { } else {