mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added test generator
This commit is contained in:
parent
1fcb4a0313
commit
4777921680
@ -2,6 +2,7 @@ mod natural;
|
||||
|
||||
use crate::{
|
||||
column::{ColumnGen, ColumnSample, StructureData},
|
||||
generator::TownGen,
|
||||
util::{HashCache, RandomField, Sampler, SamplerMut},
|
||||
World, CONFIG,
|
||||
};
|
||||
@ -155,6 +156,8 @@ impl<'a> BlockGen<'a> {
|
||||
cliff_hill,
|
||||
close_cliffs,
|
||||
temp,
|
||||
|
||||
chunk,
|
||||
..
|
||||
} = &z_cache?.sample;
|
||||
|
||||
@ -352,6 +355,15 @@ impl<'a> BlockGen<'a> {
|
||||
}
|
||||
});
|
||||
|
||||
// Structures (like towns)
|
||||
let block = block.or_else(|| {
|
||||
chunk
|
||||
.structures
|
||||
.town
|
||||
.as_ref()
|
||||
.and_then(|town| TownGen.get((town, wpos)))
|
||||
});
|
||||
|
||||
let block = structures
|
||||
.iter()
|
||||
.find_map(|st| {
|
||||
|
@ -514,6 +514,8 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
|
||||
temp,
|
||||
spawn_rate,
|
||||
location: sim_chunk.location.as_ref(),
|
||||
|
||||
chunk: sim_chunk,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -541,6 +543,8 @@ pub struct ColumnSample<'a> {
|
||||
pub temp: f32,
|
||||
pub spawn_rate: f32,
|
||||
pub location: Option<&'a LocationInfo>,
|
||||
|
||||
pub chunk: &'a SimChunk,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
|
@ -1,10 +1,13 @@
|
||||
mod town;
|
||||
|
||||
// Reexports
|
||||
pub use self::town::TownGen;
|
||||
pub use self::town::{TownGen, TownState};
|
||||
|
||||
use crate::util::Sampler;
|
||||
use common::terrain::Block;
|
||||
use vek::*;
|
||||
|
||||
pub trait Generator<'a, T: 'a>: Sampler<'a, Index = (&'a T, Vec3<i32>), Sample = Block> {}
|
||||
pub trait Generator<'a, T: 'a>:
|
||||
Sampler<'a, Index = (&'a T, Vec3<i32>), Sample = Option<Block>>
|
||||
{
|
||||
}
|
||||
|
@ -1,18 +1,23 @@
|
||||
use super::Generator;
|
||||
use crate::util::Sampler;
|
||||
use common::terrain::Block;
|
||||
use common::terrain::{Block, BlockKind};
|
||||
use vek::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TownState;
|
||||
|
||||
pub struct TownGen;
|
||||
|
||||
impl<'a> Sampler<'a> for TownGen {
|
||||
type Index = (&'a TownState, Vec3<i32>);
|
||||
type Sample = Block;
|
||||
type Sample = Option<Block>;
|
||||
|
||||
fn get(&self, (town, pos): Self::Index) -> Self::Sample {
|
||||
unimplemented!()
|
||||
if pos.z < 150 {
|
||||
Some(Block::new(BlockKind::Normal, Rgb::broadcast(255)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ use self::util::{
|
||||
|
||||
use crate::{
|
||||
all::ForestKind,
|
||||
generator::TownState,
|
||||
util::{seed_expan, Sampler, StructureGen2d},
|
||||
CONFIG,
|
||||
};
|
||||
@ -26,6 +27,7 @@ use rand_chacha::ChaChaRng;
|
||||
use std::{
|
||||
f32,
|
||||
ops::{Add, Div, Mul, Neg, Sub},
|
||||
sync::Arc,
|
||||
};
|
||||
use vek::*;
|
||||
|
||||
@ -499,6 +501,8 @@ pub struct SimChunk {
|
||||
pub forest_kind: ForestKind,
|
||||
pub spawn_rate: f32,
|
||||
pub location: Option<LocationInfo>,
|
||||
|
||||
pub structures: Structures,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -515,6 +519,11 @@ pub struct LocationInfo {
|
||||
pub near: Vec<RegionInfo>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Structures {
|
||||
pub town: Option<Arc<TownState>>,
|
||||
}
|
||||
|
||||
impl SimChunk {
|
||||
fn generate(posi: usize, gen_ctx: &mut GenCtx, gen_cdf: &GenCdf) -> Self {
|
||||
let pos = uniform_idx_as_vec2(posi);
|
||||
@ -657,6 +666,8 @@ impl SimChunk {
|
||||
},
|
||||
spawn_rate: 1.0,
|
||||
location: None,
|
||||
|
||||
structures: Structures { town: None },
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user