More cemetary work

This commit is contained in:
Snowram 2021-06-10 04:06:13 +02:00
parent 858b4c0bc8
commit 138eb8a7ae
6 changed files with 206 additions and 109 deletions

41
Cargo.lock generated
View File

@ -2162,13 +2162,22 @@ dependencies = [
"serde",
]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"ahash 0.7.2",
]
[[package]]
name = "hashlink"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d99cf782f0dc4372d26846bec3de7804ceb5df083c2d4462c0b8d2330e894fa8"
dependencies = [
"hashbrown",
"hashbrown 0.9.1",
]
[[package]]
@ -2395,7 +2404,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
dependencies = [
"autocfg",
"hashbrown",
"hashbrown 0.9.1",
"serde",
]
@ -3584,9 +3593,9 @@ dependencies = [
[[package]]
name = "packed_simd_2"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3278e0492f961fd4ae70909f56b2723a7e8d01a228427294e19cdfdebda89a17"
checksum = "0e64858a2d3733fdd61adfdd6da89aa202f7ff0e741d2fc7ed1e452ba9dc99d7"
dependencies = [
"cfg-if 0.1.10",
"libm 0.1.4",
@ -4639,7 +4648,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3a9dff29ab65f4b7b4a5a38ca78e73b35eb8ffd7d4b5e5a77fc6936a1735eab"
dependencies = [
"arrayvec",
"hashbrown",
"hashbrown 0.9.1",
"mopa",
"rayon",
"shred-derive",
@ -4778,7 +4787,7 @@ version = "0.16.1"
source = "git+https://github.com/amethyst/specs.git?rev=5a9b71035007be0e3574f35184acac1cd4530496#5a9b71035007be0e3574f35184acac1cd4530496"
dependencies = [
"crossbeam-queue",
"hashbrown",
"hashbrown 0.9.1",
"hibitset",
"log",
"rayon",
@ -5496,7 +5505,7 @@ dependencies = [
"byteorder",
"clap",
"futures-util",
"hashbrown",
"hashbrown 0.9.1",
"image",
"num 0.4.0",
"rayon",
@ -5531,7 +5540,7 @@ dependencies = [
"csv",
"dot_vox",
"enum-iterator",
"hashbrown",
"hashbrown 0.9.1",
"image",
"indexmap",
"lazy_static",
@ -5598,7 +5607,7 @@ version = "0.9.0"
dependencies = [
"bincode",
"flate2",
"hashbrown",
"hashbrown 0.9.1",
"image",
"num-traits",
"serde",
@ -5615,7 +5624,7 @@ name = "veloren-common-state"
version = "0.9.0"
dependencies = [
"bincode",
"hashbrown",
"hashbrown 0.9.1",
"num_cpus",
"rayon",
"scopeguard",
@ -5637,7 +5646,7 @@ dependencies = [
name = "veloren-common-systems"
version = "0.9.0"
dependencies = [
"hashbrown",
"hashbrown 0.9.1",
"indexmap",
"ordered-float 2.1.1",
"rand 0.8.3",
@ -5666,7 +5675,7 @@ dependencies = [
"crossbeam-channel",
"futures-core",
"futures-util",
"hashbrown",
"hashbrown 0.11.2",
"lazy_static",
"lz-fear",
"prometheus",
@ -5692,7 +5701,7 @@ dependencies = [
"bitflags",
"bytes",
"criterion",
"hashbrown",
"hashbrown 0.11.2",
"prometheus",
"rand 0.8.3",
"tokio",
@ -5735,7 +5744,7 @@ dependencies = [
"chrono",
"crossbeam-channel",
"futures-util",
"hashbrown",
"hashbrown 0.9.1",
"itertools 0.10.0",
"lazy_static",
"num_cpus",
@ -5819,7 +5828,7 @@ dependencies = [
"glutin",
"glyph_brush",
"guillotiere",
"hashbrown",
"hashbrown 0.9.1",
"iced_native",
"iced_winit",
"image",
@ -5893,7 +5902,7 @@ dependencies = [
"enum-iterator",
"flate2",
"fxhash",
"hashbrown",
"hashbrown 0.9.1",
"image",
"inline_tweak",
"itertools 0.10.0",

View File

@ -32,11 +32,8 @@ use crate::{
};
use rand::prelude::*;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{convert::AsRef, marker::PhantomData};
use tracing::warn;
use std::{
convert::AsRef,
marker::PhantomData,
};
#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct Lottery<T, Items: AsRef<[(f32, T)]> = Vec<(f32, T)>> {
@ -60,7 +57,11 @@ impl<T> From<Vec<(f32, T)>> for Lottery<T> {
*rate = total - *rate;
}
Self { items, total, phantom: PhantomData }
Self {
items,
total,
phantom: PhantomData,
}
}
}
@ -73,7 +74,11 @@ impl<'a, T> Lottery<T, &'a mut [(f32, T)]> {
*rate = total - *rate;
}
Self { items, total, phantom: PhantomData }
Self {
items,
total,
phantom: PhantomData,
}
}
}

View File

@ -67,7 +67,8 @@ impl Fill {
let inner = Aabr {
min: aabb.min.xy() - 1 + inset,
max: aabb.max.xy() - inset,
}.made_valid();
}
.made_valid();
aabb_contains(*aabb, pos)
&& ((inner.projected_point(pos.xy()) - pos.xy())
.map(|e| e.abs())

View File

@ -21,7 +21,7 @@ impl Structure for Cemetary {
) -> Option<Self> {
let (tile_aabr, root) = site.tiles.find_near(Vec2::zero(), |tile, _| {
if rng.gen_range(0..16) == 0 {
site.tiles.grow_aabr(tile, 15..20, (2, 2), 2).ok()
site.tiles.grow_aabr(tile, 45..50, (2, 2), 2).ok()
} else {
None
}
@ -84,6 +84,17 @@ impl Render for Cemetary {
}),
false => Block::empty(),
});
let flower_sprite = Fill::Block(match rng.gen_bool(0.1) {
true => Block::air(match rng.gen_range(0..6) {
0 => SpriteKind::BlueFlower,
1 => SpriteKind::PinkFlower,
2 => SpriteKind::PurpleFlower,
3 => SpriteKind::RedFlower,
4 => SpriteKind::WhiteFlower,
_ => SpriteKind::YellowFlower,
}),
false => Block::empty(),
});
let structural_wood = Fill::Block(Block::new(BlockKind::Rock, Rgb::new(80, 80, 80)));
let path = Fill::Block(Block::new(
BlockKind::Rock,
@ -93,7 +104,7 @@ impl Render for Cemetary {
// Walls
let inner = prim(Primitive::Aabb(Aabb {
min: (self.bounds.min + 1).with_z(self.alt),
max: self.bounds.max.with_z(self.alt + roof),
max: (self.bounds.max).with_z(self.alt + roof),
}));
let outer = prim(Primitive::Aabb(Aabb {
min: self.bounds.min.with_z(self.alt),
@ -103,8 +114,6 @@ impl Render for Cemetary {
let walls = prim(Primitive::Xor(outer, inner));
// lol
// Windows x axis
{
let mut windows = prim(Primitive::Empty);
@ -141,9 +150,9 @@ impl Render for Cemetary {
);
}
// wall pillars
// Wall pillars
let mut pillars_y = prim(Primitive::Empty);
for x in self.tile_aabr.min.x..self.tile_aabr.max.x + 2 {
for x in self.tile_aabr.min.x..self.tile_aabr.max.x + 1 {
let pillar = prim(Primitive::Aabb(Aabb {
min: site
.tile_wpos(Vec2::new(x, self.tile_aabr.min.y))
@ -154,7 +163,7 @@ impl Render for Cemetary {
pillars_y = prim(Primitive::Or(pillars_y, pillar));
}
let mut pillars_x = prim(Primitive::Empty);
for y in self.tile_aabr.min.y..self.tile_aabr.max.y + 2 {
for y in self.tile_aabr.min.y..self.tile_aabr.max.y + 1 {
let pillar = prim(Primitive::Aabb(Aabb {
min: site
.tile_wpos(Vec2::new(self.tile_aabr.min.x, y))
@ -166,8 +175,47 @@ impl Render for Cemetary {
}
let pillars = prim(Primitive::And(pillars_x, pillars_y));
fill(pillars, structural_wood);
// Fill inner
fill(inner, Fill::Block(Block::empty()));
// Slice
let slice = prim(Primitive::Aabb(Aabb {
min: self.bounds.min.with_z(self.alt),
max: (self.bounds.max + 1).with_z(self.alt + 2),
}));
fill(slice, structural_wood);
// Entrance
let high = prim(Primitive::Pyramid {
aabb: Aabb {
min: Vec2::new(mid.x - 3, self.bounds.min.y).with_z(self.alt + 6),
max: Vec2::new(mid.x + 3, self.bounds.min.y + 1).with_z(self.alt + 9),
},
inset: Vec2::broadcast(5),
});
let door = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x - 3, self.bounds.min.y).with_z(self.alt),
max: Vec2::new(mid.x + 3, self.bounds.min.y + 1).with_z(self.alt + 6),
}));
let door_empty = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x - 2, self.bounds.min.y).with_z(self.alt),
max: Vec2::new(mid.x + 2, self.bounds.min.y + 1).with_z(self.alt + 6),
}));
let lamp_1 = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x - 3, self.bounds.min.y - 1).with_z(self.alt + 3),
max: Vec2::new(mid.x - 2, self.bounds.min.y).with_z(self.alt + 4),
}));
let lamp_2 = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x + 2, self.bounds.min.y - 1).with_z(self.alt + 3),
max: Vec2::new(mid.x + 3, self.bounds.min.y).with_z(self.alt + 4),
}));
fill(door, structural_wood);
fill(door_empty, Fill::Block(Block::empty()));
fill(high, structural_wood);
fill(lamp_1, lamp);
fill(lamp_2, lamp);
// Floor
let floor = prim(Primitive::Aabb(Aabb {
min: (self.bounds.min).with_z(self.alt),
@ -181,12 +229,6 @@ impl Render for Cemetary {
)),
);
let slice = prim(Primitive::Aabb(Aabb {
min: self.bounds.min.with_z(self.alt),
max: (self.bounds.max + 1).with_z(self.alt + 2),
}));
fill(prim(Primitive::AndNot(slice, floor)), structural_wood);
// Grass
let grass = Aabb {
min: (self.bounds.min + 1).with_z(self.alt + 1),
@ -211,8 +253,25 @@ impl Render for Cemetary {
}
}
// Tombstones
// Horizontal paths
let cemetary = Aabb {
min: (self.bounds.min + 1).with_z(self.alt),
max: Vec2::new(self.bounds.max.x, self.bounds.max.y - 8).with_z(self.alt + roof),
};
for x in cemetary.min.x..cemetary.max.x {
for y in cemetary.min.y..cemetary.max.y {
let block = prim(Primitive::Aabb(Aabb {
min: Vec2::new(x, y).with_z(self.alt),
max: Vec2::new(x + 1, y + 1).with_z(self.alt + 1),
}));
if (y % 5 == 3 || y % 5 == 4) && rng.gen_bool(0.95) {
fill(block, path);
}
}
}
// Tombstones
let dalle_block = Fill::Block(Block::new(BlockKind::Rock, Rgb::new(40, 40, 40)));
for x in grass.min.x..grass.max.x {
@ -235,82 +294,96 @@ impl Render for Cemetary {
}
}
// Paths
for x in grass.min.x..grass.max.x {
for y in grass.min.y..grass.max.y {
// Floor
let floor = Aabb {
min: Vec2::new(self.bounds.min.x + 1, self.bounds.max.y - 8).with_z(self.alt + 1),
max: Vec2::new(self.bounds.max.x, self.bounds.max.y).with_z(self.alt + 2),
};
for x in floor.min.x..floor.max.x {
for y in floor.min.y..floor.max.y {
let block = prim(Primitive::Aabb(Aabb {
min: Vec2::new(x, y).with_z(self.alt),
max: Vec2::new(x + 1, y + 1).with_z(self.alt + 1),
min: Vec2::new(x, y).with_z(self.alt + 1),
max: Vec2::new(x + 1, y + 1).with_z(self.alt + 2),
}));
if (y % 5 == 3 || y % 5 == 4) && rng.gen_bool(0.95) {
fill(block, path);
}
let flower_sprite = Fill::Block(match rng.gen_bool(0.3) {
true => Block::air(match rng.gen_range(0..6) {
0 => SpriteKind::BlueFlower,
1 => SpriteKind::PinkFlower,
2 => SpriteKind::PurpleFlower,
3 => SpriteKind::RedFlower,
4 => SpriteKind::WhiteFlower,
_ => SpriteKind::YellowFlower,
}),
false => Block::empty(),
});
fill(block, flower_sprite);
}
}
/*let path_x = prim(Primitive::Aabb(Aabb {
min: Vec3::new(mid.x - 2, grass.min.y, self.alt),
max: Vec3::new(mid.x + 3, grass.max.y, self.alt + 1),
}));*/
for x in grass.min.x..grass.max.x {
for y in grass.min.y..grass.max.y {
let block = prim(Primitive::Aabb(Aabb {
min: Vec2::new(x, y).with_z(self.alt),
max: Vec2::new(x + 1, y + 1).with_z(self.alt + 1),
}));
if x > mid.x - 2 && x < mid.x + 2 && rng.gen_bool(0.95) {
fill(block, path);
}
}
}
//fill(path_x, path);
/*let test1 = prim(Primitive::Cylinder(Aabb {
min: Vec3::new(mid.x - inline_tweak::tweak!(5), self.bounds.min.y - inline_tweak::tweak!(5), self.alt),
max: Vec3::new(mid.x + inline_tweak::tweak!(5), self.bounds.min.y + inline_tweak::tweak!(5), self.alt + 3),
// Crypt
let crypt = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x - 6, self.bounds.max.y - 8).with_z(self.alt + 1),
max: Vec2::new(mid.x + 6, self.bounds.max.y).with_z(self.alt + 6),
}));
let test2 = prim(Primitive::Cylinder(Aabb {
min: Vec3::new(mid.x - 3, mid.y - 4, self.alt),
max: Vec3::new(mid.x + 3, mid.y + 4, self.alt),
let crypt_inner = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x - 5, self.bounds.max.y - 7).with_z(self.alt + 1),
max: Vec2::new(mid.x + 5, self.bounds.max.y - 1).with_z(self.alt + 6),
}));
let xor = prim(Primitive::Xor(test1, test2));
let rotation = Mat3::new(
1, 0, 0,
0, 0, -1,
0, 1, 0
);
let rotated = prim(Primitive::Rotate(test1, rotation));
let translated = prim(Primitive::Offset(rotated, Vec3::new(0, 5, 0)));
fill(translated, structural_wood);*/
let crypt_door = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x - 2, self.bounds.max.y - 8).with_z(self.alt + 1),
max: Vec2::new(mid.x + 2, self.bounds.max.y - 7).with_z(self.alt + 4),
}));
let high = prim(Primitive::Pyramid {
let roof = prim(Primitive::Pyramid {
aabb: Aabb {
min: Vec2::new(mid.x - 3, self.bounds.min.y).with_z(self.alt + 6),
max: Vec2::new(mid.x + 3, self.bounds.min.y + 1).with_z(self.alt + 9),
min: Vec2::new(mid.x - 8, self.bounds.max.y - 8).with_z(self.alt + 6),
max: Vec2::new(mid.x + 8, self.bounds.max.y).with_z(self.alt + 10),
},
inset: Vec2::broadcast(5),
inset: Vec2::broadcast(4),
});
let door = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x - 3, self.bounds.min.y).with_z(self.alt + 1),
max: Vec2::new(mid.x + 3, self.bounds.min.y + 1).with_z(self.alt + 6),
}));
let door_empty = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x - 2, self.bounds.min.y).with_z(self.alt + 1),
max: Vec2::new(mid.x + 2, self.bounds.min.y + 1).with_z(self.alt + 6),
}));
let lamp_1 = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x - 3, self.bounds.min.y - 1).with_z(self.alt + 3),
max: Vec2::new(mid.x - 2, self.bounds.min.y).with_z(self.alt + 4),
min: Vec2::new(mid.x - 3, self.bounds.max.y - 9).with_z(self.alt + 2),
max: Vec2::new(mid.x - 2, self.bounds.max.y - 8).with_z(self.alt + 3),
}));
let lamp_2 = prim(Primitive::Aabb(Aabb {
min: Vec2::new(mid.x + 2, self.bounds.min.y - 1).with_z(self.alt + 3),
max: Vec2::new(mid.x + 3, self.bounds.min.y).with_z(self.alt + 4),
min: Vec2::new(mid.x + 2, self.bounds.max.y - 9).with_z(self.alt + 2),
max: Vec2::new(mid.x + 3, self.bounds.max.y - 8).with_z(self.alt + 3),
}));
fill(door, structural_wood);
fill(door_empty, Fill::Block(Block::empty()));
fill(high, structural_wood);
fill(crypt, structural_wood);
fill(crypt_inner, Fill::Block(Block::empty()));
fill(crypt_door, Fill::Block(Block::empty()));
fill(roof, structural_wood);
fill(lamp_1, lamp);
fill(lamp_2, lamp);
for x in cemetary.min.x..cemetary.max.x {
for y in cemetary.min.y..cemetary.max.y {
let block = prim(Primitive::Aabb(Aabb {
min: Vec2::new(x, y).with_z(self.alt),
max: Vec2::new(x + 1, y + 1).with_z(self.alt + 1),
}));
if x > mid.x - 3 && x < mid.x + 2 && rng.gen_bool(0.95) {
fill(block, path);
}
}
}
// Vertical path
for x in cemetary.min.x..cemetary.max.x {
for y in cemetary.min.y..cemetary.max.y {
let block = prim(Primitive::Aabb(Aabb {
min: Vec2::new(x, y).with_z(self.alt + 1),
max: Vec2::new(x + 1, y + 1).with_z(self.alt + 2),
}));
if x > mid.x - 3 && x < mid.x + 2 {
fill(block, Fill::Block(Block::empty()))
}
}
}
}
}

View File

@ -13,15 +13,19 @@ pub struct Hut {
impl Structure for Hut {
type Config = ();
fn choose_location<R: Rng>(cfg: Self::Config, land: &Land, site: &Site, rng: &mut R) -> Option<Self> {
let (tile_aabr, root) = site.tiles.find_near(
Vec2::zero(),
|tile, _| if rng.gen_range(0..16) == 0 {
fn choose_location<R: Rng>(
cfg: Self::Config,
land: &Land,
site: &Site,
rng: &mut R,
) -> Option<Self> {
let (tile_aabr, root) = site.tiles.find_near(Vec2::zero(), |tile, _| {
if rng.gen_range(0..16) == 0 {
site.tiles.grow_aabr(tile, 4..9, (2, 2), 2).ok()
} else {
None
},
)?;
}
})?;
let center = (tile_aabr.min + (tile_aabr.max - 1)) / 2;
Some(Self {
@ -79,10 +83,13 @@ impl Render for Hut {
}));
let door_pos = site.tile_center_wpos(self.root);
let door = prim(Primitive::Aabb(Aabb {
min: door_pos.with_z(self.alt),
max: (door_pos + self.door_dir * 32).with_z(self.alt + 2),
}.made_valid()));
let door = prim(Primitive::Aabb(
Aabb {
min: door_pos.with_z(self.alt),
max: (door_pos + self.door_dir * 32).with_z(self.alt + 2),
}
.made_valid(),
));
let space = prim(Primitive::And(inner, door));
@ -98,7 +105,7 @@ impl Render for Hut {
/ 2
+ roof_lip
+ 1;
let roof = prim(Primitive::Pyramid{
let roof = prim(Primitive::Pyramid {
aabb: Aabb {
min: (self.bounds.min + 1 - roof_lip).with_z(self.alt + self.height),
max: (self.bounds.max - 1 + roof_lip).with_z(self.alt + self.height + roof_height),

View File

@ -94,11 +94,13 @@ impl TileGrid {
let mut last_growth = 0;
for i in 0..32 {
if i - last_growth >= 4
|| (inner_size(aabr) + if i % 2 == 0 {
|| (inner_size(aabr)
+ if i % 2 == 0 {
Extent2::new(0, 1)
} else {
Extent2::new(1, 0)
}).product()
})
.product()
> area_range.end as i32
{
break;