rust/landgen/src/lib.rs
author unC0Rr
Mon, 13 Feb 2023 11:00:12 +0100
branchtransitional_engine
changeset 15921 5f00829c55ec
parent 15912 6e22f4390b7e
child 16032 31cc1e450273
permissions -rw-r--r--
Refactor landgen package structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15921
5f00829c55ec Refactor landgen package structure
unC0Rr
parents: 15912
diff changeset
     1
pub mod outline_template_based;
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents: 15905
diff changeset
     2
pub mod wavefront_collapse;
13908
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
     3
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15903
diff changeset
     4
#[derive(Clone, Copy)]
14027
cef0c685fda8 make useful stuff public
alfadur
parents: 14026
diff changeset
     5
pub struct LandGenerationParameters<T> {
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
     6
    zero: T,
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
     7
    basic: T,
14100
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
     8
    distance_divisor: u32,
14121
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
     9
    skip_distort: bool,
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    10
    skip_bezier: bool,
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    11
}
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    12
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents: 15905
diff changeset
    13
impl<T: Copy + PartialEq + Default> LandGenerationParameters<T> {
15828
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    14
    pub fn new(
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    15
        zero: T,
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    16
        basic: T,
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    17
        distance_divisor: u32,
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    18
        skip_distort: bool,
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    19
        skip_bezier: bool,
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    20
    ) -> Self {
14100
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
    21
        Self {
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
    22
            zero,
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
    23
            basic,
14121
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    24
            distance_divisor,
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    25
            skip_distort,
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    26
            skip_bezier,
14100
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
    27
        }
14054
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14051
diff changeset
    28
    }
15903
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    29
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    30
    pub fn zero(&self) -> T {
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    31
        self.zero
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    32
    }
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    33
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    34
    pub fn basic(&self) -> T {
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    35
        self.basic
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    36
    }
14054
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14051
diff changeset
    37
}
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14051
diff changeset
    38
14027
cef0c685fda8 make useful stuff public
alfadur
parents: 14026
diff changeset
    39
pub trait LandGenerator {
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents: 15905
diff changeset
    40
    fn generate_land<T: Copy + PartialEq + Default, I: Iterator<Item = u32>>(
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    41
        &self,
14121
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    42
        parameters: &LandGenerationParameters<T>,
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    43
        random_numbers: &mut I,
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    44
    ) -> land2d::Land2D<T>;
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    45
}