mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Removed old settlement code, removed zcache from dependency of site generators for forward compatibility
This commit is contained in:
parent
1c6a6cd6cf
commit
41b77a9b10
@ -109,7 +109,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
.ray(
|
.ray(
|
||||||
pos.0 + Vec3::unit_z(),
|
pos.0 + Vec3::unit_z(),
|
||||||
pos.0
|
pos.0
|
||||||
+ Vec3::from(*bearing).normalized() * 1.5
|
+ Vec3::from(*bearing)
|
||||||
|
.try_normalized()
|
||||||
|
.unwrap_or(Vec3::zero())
|
||||||
|
* 1.5
|
||||||
+ Vec3::unit_z(),
|
+ Vec3::unit_z(),
|
||||||
)
|
)
|
||||||
.until(|block| block.is_solid())
|
.until(|block| block.is_solid())
|
||||||
|
@ -136,10 +136,20 @@ impl World {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sim_chunk
|
// Apply site generation
|
||||||
.sites
|
sim_chunk.sites.iter().for_each(|site| {
|
||||||
.iter()
|
site.apply_to(
|
||||||
.for_each(|site| site.apply_to(chunk_wpos2d, &zcache_grid, &mut chunk));
|
chunk_wpos2d,
|
||||||
|
|offs| {
|
||||||
|
zcache_grid
|
||||||
|
.get(offs)
|
||||||
|
.map(Option::as_ref)
|
||||||
|
.flatten()
|
||||||
|
.map(|zc| &zc.sample)
|
||||||
|
},
|
||||||
|
&mut chunk,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
let gen_entity_pos = || {
|
let gen_entity_pos = || {
|
||||||
let lpos2d = TerrainChunkSize::RECT_SIZE
|
let lpos2d = TerrainChunkSize::RECT_SIZE
|
||||||
|
@ -2,7 +2,6 @@ mod diffusion;
|
|||||||
mod erosion;
|
mod erosion;
|
||||||
mod location;
|
mod location;
|
||||||
mod map;
|
mod map;
|
||||||
mod settlement;
|
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
// Reexports
|
// Reexports
|
||||||
|
@ -1,86 +0,0 @@
|
|||||||
use rand::Rng;
|
|
||||||
use vek::*;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Settlement {
|
|
||||||
lot: Lot,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Settlement {
|
|
||||||
pub fn generate(rng: &mut impl Rng) -> Self {
|
|
||||||
Self {
|
|
||||||
lot: Lot::generate(0, 32.0, 1.0, rng),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_at(&self, pos: Vec2<f32>) -> Option<&Building> { self.lot.get_at(pos) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Building {
|
|
||||||
pub seed: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
enum Lot {
|
|
||||||
None,
|
|
||||||
One(Building),
|
|
||||||
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 };
|
|
||||||
|
|
||||||
if (depth < 1.0 || deep > 6) && !(deep < 3 || deep % 2 == 1) {
|
|
||||||
if rng.gen::<f32>() < 0.5 {
|
|
||||||
Lot::One(Building { seed: rng.gen() })
|
|
||||||
} else {
|
|
||||||
Lot::None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Lot::Many {
|
|
||||||
split_x: aspect > 1.0,
|
|
||||||
lots: {
|
|
||||||
let pow2 = 1 + rng.gen::<usize>() % 1;
|
|
||||||
let n = 1 << pow2;
|
|
||||||
|
|
||||||
let new_aspect = if aspect > 1.0 {
|
|
||||||
aspect / n as f32
|
|
||||||
} else {
|
|
||||||
aspect * n as f32
|
|
||||||
};
|
|
||||||
|
|
||||||
let vari = (rng.gen::<f32>() - 0.35) * 2.8;
|
|
||||||
let new_depth = depth * 0.5 * (1.0 + vari);
|
|
||||||
|
|
||||||
(0..n)
|
|
||||||
.map(|_| Lot::generate(deep + 1, new_depth, new_aspect, rng))
|
|
||||||
.collect()
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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::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;
|
|
||||||
lots[idx.min(lots.len() - 1)].get_at(if *split_x {
|
|
||||||
Vec2::new((pos.x * lots.len() as f32).fract(), pos.y)
|
|
||||||
} else {
|
|
||||||
Vec2::new(pos.x, (pos.y * lots.len() as f32).fract())
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,13 +4,12 @@ mod settlement;
|
|||||||
pub use self::settlement::Settlement;
|
pub use self::settlement::Settlement;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
block::ZCache,
|
|
||||||
column::ColumnSample,
|
column::ColumnSample,
|
||||||
util::{Grid, Sampler},
|
util::{Grid, Sampler},
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
terrain::Block,
|
terrain::Block,
|
||||||
vol::{BaseVol, WriteVol},
|
vol::{BaseVol, RectSizedVol, WriteVol},
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
@ -33,14 +32,14 @@ impl Site {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_to(
|
pub fn apply_to<'a>(
|
||||||
&self,
|
&'a self,
|
||||||
wpos2d: Vec2<i32>,
|
wpos2d: Vec2<i32>,
|
||||||
zcaches: &Grid<Option<ZCache>>,
|
get_column: impl FnMut(Vec2<i32>) -> Option<&'a ColumnSample<'a>>,
|
||||||
vol: &mut (impl BaseVol<Vox = Block> + WriteVol),
|
vol: &mut (impl BaseVol<Vox = Block> + RectSizedVol + WriteVol),
|
||||||
) {
|
) {
|
||||||
match self {
|
match self {
|
||||||
Site::Settlement(settlement) => settlement.apply_to(wpos2d, zcaches, vol),
|
Site::Settlement(settlement) => settlement.apply_to(wpos2d, get_column, vol),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
block::ZCache,
|
column::ColumnSample,
|
||||||
sim::{SimChunk, WorldSim},
|
sim::{SimChunk, WorldSim},
|
||||||
util::{Grid, RandomField, Sampler, StructureGen2d},
|
util::{Grid, RandomField, Sampler, StructureGen2d},
|
||||||
};
|
};
|
||||||
@ -8,7 +8,7 @@ use common::{
|
|||||||
path::Path,
|
path::Path,
|
||||||
spiral::Spiral2d,
|
spiral::Spiral2d,
|
||||||
terrain::{Block, BlockKind},
|
terrain::{Block, BlockKind},
|
||||||
vol::{BaseVol, WriteVol},
|
vol::{BaseVol, RectSizedVol, WriteVol},
|
||||||
};
|
};
|
||||||
use hashbrown::{HashMap, HashSet};
|
use hashbrown::{HashMap, HashSet};
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
@ -124,6 +124,7 @@ impl Settlement {
|
|||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Designate hazardous terrain based on world data
|
||||||
pub fn designate_from_world(&mut self, sim: &WorldSim, rng: &mut impl Rng) {
|
pub fn designate_from_world(&mut self, sim: &WorldSim, rng: &mut impl Rng) {
|
||||||
let tile_radius = self.radius() as i32 / AREA_SIZE as i32;
|
let tile_radius = self.radius() as i32 / AREA_SIZE as i32;
|
||||||
let hazard = self.land.new_plot(Plot::Hazard);
|
let hazard = self.land.new_plot(Plot::Hazard);
|
||||||
@ -146,6 +147,7 @@ impl Settlement {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Testing only
|
||||||
pub fn place_river(&mut self, rng: &mut impl Rng) {
|
pub fn place_river(&mut self, rng: &mut impl Rng) {
|
||||||
let river_dir = Vec2::new(rng.gen::<f32>() - 0.5, rng.gen::<f32>() - 0.5).normalized();
|
let river_dir = Vec2::new(rng.gen::<f32>() - 0.5, rng.gen::<f32>() - 0.5).normalized();
|
||||||
let radius = 500.0 + rng.gen::<f32>().powf(2.0) * 1000.0;
|
let radius = 500.0 + rng.gen::<f32>().powf(2.0) * 1000.0;
|
||||||
@ -352,20 +354,20 @@ impl Settlement {
|
|||||||
|
|
||||||
pub fn radius(&self) -> f32 { 1200.0 }
|
pub fn radius(&self) -> f32 { 1200.0 }
|
||||||
|
|
||||||
pub fn apply_to(
|
pub fn apply_to<'a>(
|
||||||
&self,
|
&'a self,
|
||||||
wpos2d: Vec2<i32>,
|
wpos2d: Vec2<i32>,
|
||||||
zcaches: &Grid<Option<ZCache>>,
|
mut get_column: impl FnMut(Vec2<i32>) -> Option<&'a ColumnSample<'a>>,
|
||||||
vol: &mut (impl BaseVol<Vox = Block> + WriteVol),
|
vol: &mut (impl BaseVol<Vox = Block> + RectSizedVol + WriteVol),
|
||||||
) {
|
) {
|
||||||
let rand_field = RandomField::new(0);
|
let rand_field = RandomField::new(0);
|
||||||
|
|
||||||
for y in 0..zcaches.size().y {
|
for y in 0..vol.size_xy().y as i32 {
|
||||||
for x in 0..zcaches.size().x {
|
for x in 0..vol.size_xy().x as i32 {
|
||||||
let offs = Vec2::new(x, y);
|
let offs = Vec2::new(x, y);
|
||||||
|
|
||||||
let zcache = if let Some(Some(zcache)) = zcaches.get(offs) {
|
let col_sample = if let Some(col_sample) = get_column(offs) {
|
||||||
zcache
|
col_sample
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
@ -385,7 +387,7 @@ impl Settlement {
|
|||||||
< ((1.0 - z as f32 / 12.0) * 2.0).min(1.0)
|
< ((1.0 - z as f32 / 12.0) * 2.0).min(1.0)
|
||||||
{
|
{
|
||||||
vol.set(
|
vol.set(
|
||||||
Vec3::new(offs.x, offs.y, zcache.sample.alt.floor() as i32 + z),
|
Vec3::new(offs.x, offs.y, col_sample.alt.floor() as i32 + z),
|
||||||
Block::new(BlockKind::Normal, color),
|
Block::new(BlockKind::Normal, color),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -394,7 +396,7 @@ impl Settlement {
|
|||||||
Sample::Tower(Tower::Wall, _pos) => {
|
Sample::Tower(Tower::Wall, _pos) => {
|
||||||
for z in 0..16 {
|
for z in 0..16 {
|
||||||
vol.set(
|
vol.set(
|
||||||
Vec3::new(offs.x, offs.y, zcache.sample.alt.floor() as i32 + z),
|
Vec3::new(offs.x, offs.y, col_sample.alt.floor() as i32 + z),
|
||||||
Block::new(BlockKind::Normal, Rgb::new(50, 50, 50)),
|
Block::new(BlockKind::Normal, Rgb::new(50, 50, 50)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -446,14 +448,14 @@ impl Settlement {
|
|||||||
Vec2::new(-1, 1),
|
Vec2::new(-1, 1),
|
||||||
];
|
];
|
||||||
let furrow_dir = furrow_dirs[*seed as usize % furrow_dirs.len()];
|
let furrow_dir = furrow_dirs[*seed as usize % furrow_dirs.len()];
|
||||||
let furrow = (pos * furrow_dir).sum().rem_euclid(4) < 2;
|
let furrow = (pos * furrow_dir).sum().rem_euclid(6) < 3;
|
||||||
Rgb::new(
|
Rgb::new(
|
||||||
if furrow {
|
if furrow {
|
||||||
120
|
100
|
||||||
} else {
|
} else {
|
||||||
48 + seed.to_le_bytes()[0] % 64
|
32 + seed.to_le_bytes()[0] % 64
|
||||||
},
|
},
|
||||||
128 + seed.to_le_bytes()[1] % 128,
|
64 + seed.to_le_bytes()[1] % 128,
|
||||||
16 + seed.to_le_bytes()[2] % 32,
|
16 + seed.to_le_bytes()[2] % 32,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user