rust/landgen/src/lib.rs
author unC0Rr
Wed, 04 Jan 2023 11:56:58 +0100
branchtransitional_engine
changeset 15905 022ec6b916b7
parent 15903 230dc46487ea
child 15912 6e22f4390b7e
permissions -rw-r--r--
Split generation and painting phases, paint by old engine, use template filters
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14100
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
     1
mod outline;
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents: 14054
diff changeset
     2
pub mod outline_template;
14100
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
     3
pub mod template_based;
13908
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
     4
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15903
diff changeset
     5
#[derive(Clone, Copy)]
14027
cef0c685fda8 make useful stuff public
alfadur
parents: 14026
diff changeset
     6
pub struct LandGenerationParameters<T> {
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
     7
    zero: T,
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
     8
    basic: T,
14100
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
     9
    distance_divisor: u32,
14121
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    10
    skip_distort: bool,
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    11
    skip_bezier: bool,
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    12
}
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    13
14100
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
    14
impl<T: Copy + PartialEq> LandGenerationParameters<T> {
15828
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    15
    pub fn new(
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    16
        zero: T,
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    17
        basic: T,
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    18
        distance_divisor: u32,
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    19
        skip_distort: bool,
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    20
        skip_bezier: bool,
44b49f255e31 add type safe power of two sizes
alfadur
parents: 14207
diff changeset
    21
    ) -> Self {
14100
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
    22
        Self {
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
    23
            zero,
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
    24
            basic,
14121
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    25
            distance_divisor,
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    26
            skip_distort,
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    27
            skip_bezier,
14100
4d22be35cfa2 Finish porting FindPoint()
unc0rr
parents: 14069
diff changeset
    28
        }
14054
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14051
diff changeset
    29
    }
15903
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    30
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    31
    pub fn zero(&self) -> T {
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    32
        self.zero
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
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    35
    pub fn basic(&self) -> T {
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    36
        self.basic
230dc46487ea Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents: 15828
diff changeset
    37
    }
14054
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14051
diff changeset
    38
}
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14051
diff changeset
    39
14027
cef0c685fda8 make useful stuff public
alfadur
parents: 14026
diff changeset
    40
pub trait LandGenerator {
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    41
    fn generate_land<T: Copy + PartialEq, I: Iterator<Item = u32>>(
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    42
        &self,
14121
69db1d2e4cec land_dump app for testing templated landgen
unc0rr
parents: 14100
diff changeset
    43
        parameters: &LandGenerationParameters<T>,
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    44
        random_numbers: &mut I,
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    45
    ) -> land2d::Land2D<T>;
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13938
diff changeset
    46
}
13938
1fa905aa4cdb move point struct into integral-geometry and use it to refactor a bit
alfadur
parents: 13908
diff changeset
    47
13908
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    48
#[cfg(test)]
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    49
mod tests {
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    50
    #[test]
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    51
    fn it_works() {
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    52
        assert_eq!(2 + 2, 4);
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    53
    }
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    54
}