Added Generator trait, fixed ocean lighting

This commit is contained in:
Joshua Barretto 2019-08-23 20:56:21 +01:00
parent 75f5419571
commit 1fcb4a0313
10 changed files with 44 additions and 14 deletions

View File

@ -104,8 +104,8 @@ impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone>
.map(|vox| block_shadow_density(vox.kind()))
.unwrap_or((0.0, 0.0));
neighbour_light[0][i][j] =
(neighbour_light[0][i][j] * (1.0 - density)).max(cap);
neighbour_light[0][i][j] = (neighbour_light[0][i][j] * (1.0 - density))
.max(cap.min(neighbour_light[1][i][j]));
}
}

View File

@ -410,7 +410,7 @@ impl<'a> ZCache<'a> {
}
}
impl<'a> SamplerMut for BlockGen<'a> {
impl<'a> SamplerMut<'static> for BlockGen<'a> {
type Index = Vec3<i32>;
type Sample = Option<Block>;

View File

@ -121,7 +121,7 @@ impl<'a> ColumnGen<'a> {
}
}
impl<'a> Sampler for ColumnGen<'a> {
impl<'a> Sampler<'a> for ColumnGen<'a> {
type Index = Vec2<i32>;
type Sample = Option<ColumnSample<'a>>;

View File

@ -0,0 +1,10 @@
mod town;
// Reexports
pub use self::town::TownGen;
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> {}

View File

@ -0,0 +1,19 @@
use super::Generator;
use crate::util::Sampler;
use common::terrain::Block;
use vek::*;
pub struct TownState;
pub struct TownGen;
impl<'a> Sampler<'a> for TownGen {
type Index = (&'a TownState, Vec3<i32>);
type Sample = Block;
fn get(&self, (town, pos): Self::Index) -> Self::Sample {
unimplemented!()
}
}
impl<'a> Generator<'a, TownState> for TownGen {}

View File

@ -10,6 +10,7 @@ mod all;
mod block;
mod column;
pub mod config;
pub mod generator;
pub mod sim;
pub mod util;

View File

@ -11,7 +11,7 @@ impl RandomField {
}
}
impl Sampler for RandomField {
impl Sampler<'static> for RandomField {
type Index = Vec3<i32>;
type Sample = u32;
@ -46,7 +46,7 @@ impl RandomPerm {
}
}
impl Sampler for RandomPerm {
impl Sampler<'static> for RandomPerm {
type Index = u32;
type Sample = u32;

View File

@ -1,13 +1,13 @@
pub trait Sampler: Sized {
type Index;
type Sample;
pub trait Sampler<'a>: Sized {
type Index: 'a;
type Sample: 'a;
fn get(&self, index: Self::Index) -> Self::Sample;
}
pub trait SamplerMut: Sized {
type Index;
type Sample;
pub trait SamplerMut<'a>: Sized {
type Index: 'a;
type Sample: 'a;
fn get(&mut self, index: Self::Index) -> Self::Sample;
}

View File

@ -21,7 +21,7 @@ impl StructureGen2d {
}
}
impl Sampler for StructureGen2d {
impl Sampler<'static> for StructureGen2d {
type Index = Vec2<i32>;
type Sample = [(Vec2<i32>, u32); 9];

View File

@ -24,7 +24,7 @@ impl UnitChooser {
}
}
impl Sampler for UnitChooser {
impl Sampler<'static> for UnitChooser {
type Index = u32;
type Sample = (Vec2<i32>, Vec2<i32>);