mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Rocks!
This commit is contained in:
parent
c4f2cae04a
commit
8db5acd987
@ -4,12 +4,13 @@
|
|||||||
(
|
(
|
||||||
caverns: false, // TODO: Disabled by default until cave overhaul
|
caverns: false, // TODO: Disabled by default until cave overhaul
|
||||||
caves: true,
|
caves: true,
|
||||||
rocks: false,
|
rocks: true,
|
||||||
shrubs: false,
|
shrubs: false,
|
||||||
trees: true,
|
trees: true,
|
||||||
scatter: false,
|
scatter: false,
|
||||||
paths: true,
|
paths: true,
|
||||||
spots: true,
|
spots: true,
|
||||||
|
snow: true,
|
||||||
wildlife_density: 1.0,
|
wildlife_density: 1.0,
|
||||||
peak_naming: true,
|
peak_naming: true,
|
||||||
biome_naming: true,
|
biome_naming: true,
|
||||||
|
@ -91,6 +91,7 @@ pub struct Features {
|
|||||||
pub wildlife_density: f32,
|
pub wildlife_density: f32,
|
||||||
pub peak_naming: bool,
|
pub peak_naming: bool,
|
||||||
pub biome_naming: bool,
|
pub biome_naming: bool,
|
||||||
|
pub snow: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl assets::Asset for Features {
|
impl assets::Asset for Features {
|
||||||
|
@ -14,92 +14,132 @@ use vek::*;
|
|||||||
struct Rock {
|
struct Rock {
|
||||||
wpos: Vec3<i32>,
|
wpos: Vec3<i32>,
|
||||||
seed: u32,
|
seed: u32,
|
||||||
units: Vec2<Vec2<i32>>,
|
// units: Vec2<Vec2<i32>>,
|
||||||
kind: RockKind,
|
kind: RockKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_rocks_to(canvas: &mut Canvas, _dynamic_rng: &mut impl Rng) {
|
pub fn apply_rocks_to(canvas: &mut Canvas, _dynamic_rng: &mut impl Rng) {
|
||||||
let mut rock_gen = StructureGenCache::new(StructureGen2d::new(canvas.index().seed, 24, 10));
|
// let mut rock_gen = StructureGenCache::new(StructureGen2d::new(canvas.index().seed, 24, 10));
|
||||||
|
|
||||||
let info = canvas.info();
|
let info = canvas.info();
|
||||||
canvas.foreach_col(|canvas, wpos2d, col| {
|
|
||||||
let rocks = rock_gen.get(wpos2d, |wpos, seed| {
|
let area_size = Vec2::from(info.area().size().map(|e| e as i32));
|
||||||
let col = info.col_or_gen(wpos)?;
|
let render_area = Aabr {
|
||||||
|
min: info.wpos(),
|
||||||
|
max: info.wpos() + area_size,
|
||||||
|
};
|
||||||
|
|
||||||
|
let info = canvas.info();
|
||||||
|
info.chunks()
|
||||||
|
.gen_ctx
|
||||||
|
.rock_gen
|
||||||
|
.iter(render_area.min, render_area.max)
|
||||||
|
.for_each(|(wpos, seed)| {
|
||||||
|
/*canvas.foreach_col(|canvas, wpos2d, col| {
|
||||||
|
let rocks = rock_gen.get(wpos2d, |wpos, seed| {*/
|
||||||
|
let col = if let Some(col) = info.col_or_gen(wpos) {
|
||||||
|
col
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let mut rng = ChaChaRng::from_seed(seed_expan::rng_state(seed));
|
let mut rng = ChaChaRng::from_seed(seed_expan::rng_state(seed));
|
||||||
|
|
||||||
const BASE_ROCK_DENSITY: f64 = 0.15;
|
const BASE_ROCK_DENSITY: f64 = 0.15;
|
||||||
if rng.gen_bool((BASE_ROCK_DENSITY * col.rock_density as f64).clamped(0.0, 1.0))
|
let rock = if rng.gen_bool((BASE_ROCK_DENSITY * col.rock_density as f64).clamped(0.0, 1.0))
|
||||||
&& col.path.map_or(true, |(d, _, _, _)| d > 6.0)
|
&& col.path.map_or(true, |(d, _, _, _)| d > 6.0)
|
||||||
{
|
{
|
||||||
match (
|
let kind = match (
|
||||||
(col.alt - CONFIG.sea_level) as i32,
|
(col.alt - CONFIG.sea_level) as i32,
|
||||||
(col.alt - col.water_level) as i32,
|
(col.alt - col.water_level) as i32,
|
||||||
col.water_dist.map_or(i32::MAX, |d| d as i32),
|
col.water_dist.map_or(i32::MAX, |d| d as i32),
|
||||||
) {
|
) {
|
||||||
(-3..=2, _, _) => {
|
(-3..=2, _, _) => {
|
||||||
if rng.gen_bool(0.3) {
|
if rng.gen_bool(0.3) {
|
||||||
Some(RockKind::Rauk(Pillar::generate(&mut rng)))
|
/*Some(*/RockKind::Rauk(Pillar::generate(&mut rng))/*)*/
|
||||||
} else {
|
} else {
|
||||||
Some(RockKind::Rock(VoronoiCell::generate(
|
/*Some(*/RockKind::Rock(VoronoiCell::generate(
|
||||||
rng.gen_range(1.0..3.0),
|
rng.gen_range(1.0..3.0),
|
||||||
&mut rng,
|
&mut rng,
|
||||||
)))
|
))/*)*/
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(_, -15..=3, _) => Some(RockKind::Rock(VoronoiCell::generate(
|
(_, -15..=3, _) => /*Some(*/RockKind::Rock(VoronoiCell::generate(
|
||||||
rng.gen_range(1.0..4.0),
|
rng.gen_range(1.0..4.0),
|
||||||
&mut rng,
|
&mut rng,
|
||||||
))),
|
))/*)*/,
|
||||||
(5..=i32::MAX, _, 0..=i32::MAX) => {
|
(5..=i32::MAX, _, 0..=i32::MAX) => {
|
||||||
if col.temp > CONFIG.desert_temp - 0.1
|
if col.temp > CONFIG.desert_temp - 0.1
|
||||||
&& col.humidity < CONFIG.desert_hum + 0.1
|
&& col.humidity < CONFIG.desert_hum + 0.1
|
||||||
{
|
{
|
||||||
Some(RockKind::Sandstone(VoronoiCell::generate(
|
/*Some(*/RockKind::Sandstone(VoronoiCell::generate(
|
||||||
rng.gen_range(2.0..20.0 - 10.0 * col.tree_density),
|
rng.gen_range(2.0..20.0 - 10.0 * col.tree_density),
|
||||||
&mut rng,
|
&mut rng,
|
||||||
)))
|
))/*)*/
|
||||||
} else {
|
} else {
|
||||||
Some(RockKind::Rock(VoronoiCell::generate(
|
/*Some(*/RockKind::Rock(VoronoiCell::generate(
|
||||||
rng.gen_range(2.0..20.0 - 10.0 * col.tree_density),
|
rng.gen_range(2.0..20.0 - 10.0 * col.tree_density),
|
||||||
&mut rng,
|
&mut rng,
|
||||||
)))
|
))/*)*/
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => /*None*/return,
|
||||||
}
|
};
|
||||||
.map(|kind| Rock {
|
/*.map(|kind| */Rock {
|
||||||
wpos: wpos.with_z(col.alt as i32),
|
wpos: wpos.with_z(col.alt as i32),
|
||||||
seed,
|
seed,
|
||||||
units: UnitChooser::new(seed).get(seed).into(),
|
// units: UnitChooser::new(seed).get(seed).into(),
|
||||||
kind,
|
kind,
|
||||||
})
|
}/*)*/
|
||||||
} else {
|
} else {
|
||||||
None
|
/* None */return
|
||||||
|
};
|
||||||
|
/*});
|
||||||
|
|
||||||
|
for rock in rocks {*/
|
||||||
|
let bounds = rock.kind.get_bounds();
|
||||||
|
let mut aabb = Aabb {
|
||||||
|
min: rock.wpos + bounds.min.as_(),
|
||||||
|
max: rock.wpos + bounds.max.as_(),
|
||||||
|
};
|
||||||
|
if !aabb.is_valid() {
|
||||||
|
// Negative-size rock somehow?
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aabb.intersect(Aabb {
|
||||||
|
min: render_area.min.with_z(aabb.min.z),
|
||||||
|
max: render_area.max.with_z(aabb.max.z),
|
||||||
});
|
});
|
||||||
|
|
||||||
for rock in rocks {
|
/* let rpos2d = (wpos2d - rock.wpos.xy())
|
||||||
let bounds = rock.kind.get_bounds();
|
|
||||||
|
|
||||||
let rpos2d = (wpos2d - rock.wpos.xy())
|
|
||||||
.map2(rock.units, |p, unit| unit * p)
|
.map2(rock.units, |p, unit| unit * p)
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
if !Aabr::from(bounds).contains_point(rpos2d) {
|
if !Aabr::from(bounds).contains_point(rpos2d) {
|
||||||
// Skip this column
|
// Skip this column
|
||||||
continue;
|
continue;
|
||||||
}
|
} */
|
||||||
|
|
||||||
/* let mut is_top = true; */
|
/* let mut is_top = true; */
|
||||||
let mut last_block = Block::empty();
|
let mut last_block = Block::empty();
|
||||||
for z in (bounds.min.z..bounds.max.z).rev() {
|
(/*bounds*/aabb.min.x../*bounds*/aabb.max.x).for_each(|x| {
|
||||||
let wpos = Vec3::new(wpos2d.x, wpos2d.y, rock.wpos.z + z);
|
(/*bounds*/aabb.min.y../*bounds*/aabb.max.y).for_each(|y| {
|
||||||
let model_pos = (wpos - rock.wpos)
|
let col = if let Some(col) = info.col(Vec2::new(x, y)) {
|
||||||
|
col
|
||||||
|
} else {
|
||||||
|
// NOTE: Should never happen as we're always within the render area.
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
for z in (/*bounds*/aabb.min.z../*bounds*/aabb.max.z).rev() {
|
||||||
|
let wpos = Vec3::new(x, y, z);
|
||||||
|
let model_pos = wpos - rock.wpos;
|
||||||
|
// let wpos = Vec3::new(wpos2d.x, wpos2d.y, rock.wpos.z + z);
|
||||||
|
/* let model_pos = (wpos - rock.wpos)
|
||||||
.xy()
|
.xy()
|
||||||
.map2(rock.units, |rpos, unit| unit * rpos)
|
.map2(rock.units, |rpos, unit| unit * rpos)
|
||||||
.sum()
|
.sum()
|
||||||
.with_z(wpos.z - rock.wpos.z);
|
.with_z(wpos.z - rock.wpos.z); */
|
||||||
|
|
||||||
rock.kind
|
rock.kind
|
||||||
.take_sample(model_pos, rock.seed, last_block, col)
|
.take_sample(model_pos, rock.seed, last_block, col)
|
||||||
@ -114,9 +154,9 @@ pub fn apply_rocks_to(canvas: &mut Canvas, _dynamic_rng: &mut impl Rng) {
|
|||||||
/* is_top = false; */
|
/* is_top = false; */
|
||||||
last_block = block;
|
last_block = block;
|
||||||
});
|
});
|
||||||
}
|
}});});
|
||||||
}
|
/*}
|
||||||
});
|
}*/});
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VoronoiCell {
|
struct VoronoiCell {
|
||||||
|
@ -548,7 +548,7 @@ impl World {
|
|||||||
|
|
||||||
// Apply snow cover (we do this after defragmentation to benefit from faster iteration over
|
// Apply snow cover (we do this after defragmentation to benefit from faster iteration over
|
||||||
// air underground).
|
// air underground).
|
||||||
if has_snow {
|
if index.features.snow && has_snow {
|
||||||
let snow = Block::new(BlockKind::Snow, Rgb::new(210, 210, 255));
|
let snow = Block::new(BlockKind::Snow, Rgb::new(210, 210, 255));
|
||||||
// NOTE: We assume throughout Veloren that u32 fits in usize (we need to make this a static
|
// NOTE: We assume throughout Veloren that u32 fits in usize (we need to make this a static
|
||||||
// assertion). RECT_SIZE.product() is statically valid.
|
// assertion). RECT_SIZE.product() is statically valid.
|
||||||
|
@ -126,6 +126,7 @@ pub(crate) struct GenCtx {
|
|||||||
pub _region_gen: StructureGen2d,
|
pub _region_gen: StructureGen2d,
|
||||||
|
|
||||||
// pub _fast_turb_x_nz: FastNoise,
|
// pub _fast_turb_x_nz: FastNoise,
|
||||||
|
pub rock_gen: StructureGen2d,
|
||||||
pub _fast_turb_y_nz: FastNoise,
|
pub _fast_turb_y_nz: FastNoise,
|
||||||
|
|
||||||
pub _town_gen: StructureGen2d,
|
pub _town_gen: StructureGen2d,
|
||||||
@ -578,8 +579,8 @@ impl WorldSim {
|
|||||||
.set_seed(rng.gen()),
|
.set_seed(rng.gen()),
|
||||||
|
|
||||||
// _fast_turb_x_nz: FastNoise::new(rng.gen()),
|
// _fast_turb_x_nz: FastNoise::new(rng.gen()),
|
||||||
fast_hill_nz: Value::new()
|
rock_gen: StructureGen2d::new(rng.gen(), 24, 10),
|
||||||
.set_seed({ let _ = rng.gen::<u32>(); hill_nz_seed }),
|
fast_hill_nz: Value::new().set_seed(hill_nz_seed),
|
||||||
_fast_turb_y_nz: FastNoise::new(rng.gen()),
|
_fast_turb_y_nz: FastNoise::new(rng.gen()),
|
||||||
|
|
||||||
_town_gen: StructureGen2d::new(rng.gen(), 2048, 1024),
|
_town_gen: StructureGen2d::new(rng.gen(), 2048, 1024),
|
||||||
|
Loading…
Reference in New Issue
Block a user