Implement configurable weight for tiles
authorunC0Rr
Thu, 30 Jan 2025 16:38:00 +0100
changeset 16106 aba25f4e4645
parent 16105 8c90c8751b90
child 16107 e12d9a4d0e04
Implement configurable weight for tiles
rust/landgen/src/wavefront_collapse/generator.rs
rust/landgen/src/wavefront_collapse/tile_image.rs
rust/mapgen/src/template/wavefront_collapse.rs
--- a/rust/landgen/src/wavefront_collapse/generator.rs	Thu Jan 30 13:59:41 2025 +0100
+++ b/rust/landgen/src/wavefront_collapse/generator.rs	Thu Jan 30 16:38:00 2025 +0100
@@ -27,6 +27,7 @@
 #[derive(Debug, Clone)]
 pub struct TileDescription {
     pub name: String,
+    pub weight: u8,
     pub edges: EdgesDescription,
     pub is_negative: Option<bool>,
     pub can_flip: Option<bool>,
@@ -137,7 +138,7 @@
         ];
 
         let tile =
-            TileImage::<T, String>::new(tiles_image, top_edge, right_edge, bottom_edge, left_edge);
+            TileImage::<T, String>::new(tiles_image, tile_description.weight, top_edge, right_edge, bottom_edge, left_edge);
 
         result.push(tile.clone());
 
@@ -278,7 +279,7 @@
                 - probability_distribution_factor) as u32;
 
             rules.push(CollapseRule {
-                weight,
+                weight: weight * tile.weight as u32 + 1,
                 tile: Tile::Numbered(i),
                 top,
                 right,
--- a/rust/landgen/src/wavefront_collapse/tile_image.rs	Thu Jan 30 13:59:41 2025 +0100
+++ b/rust/landgen/src/wavefront_collapse/tile_image.rs	Thu Jan 30 16:38:00 2025 +0100
@@ -38,6 +38,7 @@
 #[derive(Clone)]
 pub struct TileImage<T, I: PartialEq + Clone> {
     image: Rc<Vec2D<T>>,
+    pub weight: u8,
     pub transform: Transform,
     top: Edge<I>,
     right: Edge<I>,
@@ -48,6 +49,7 @@
 impl<T: Copy, I: PartialEq + Clone> TileImage<T, I> {
     pub fn new(
         image: Vec2D<T>,
+        weight: u8,
         top: Edge<I>,
         right: Edge<I>,
         bottom: Edge<I>,
@@ -55,6 +57,7 @@
     ) -> Self {
         Self {
             image: Rc::new(image),
+            weight,
             transform: Transform::default(),
             top,
             right,
@@ -66,6 +69,7 @@
     pub fn mirrored(&self) -> Self {
         Self {
             image: self.image.clone(),
+            weight: self.weight,
             transform: self.transform.mirror(),
             top: self.top.reversed(),
             right: self.left.reversed(),
@@ -77,6 +81,7 @@
     pub fn flipped(&self) -> Self {
         Self {
             image: self.image.clone(),
+            weight: self.weight,
             transform: self.transform.flip(),
             top: self.bottom.reversed(),
             right: self.right.reversed(),
@@ -88,6 +93,7 @@
     pub fn rotated90(&self) -> Self {
         Self {
             image: self.image.clone(),
+            weight: self.weight,
             transform: self.transform.rotate90(),
             top: self.left.clone(),
             right: self.top.clone(),
@@ -99,6 +105,7 @@
     pub fn rotated180(&self) -> Self {
         Self {
             image: self.image.clone(),
+            weight: self.weight,
             transform: self.transform.rotate180(),
             top: self.bottom.clone(),
             right: self.left.clone(),
@@ -110,6 +117,7 @@
     pub fn rotated270(&self) -> Self {
         Self {
             image: self.image.clone(),
+            weight: self.weight,
             transform: self.transform.rotate270(),
             top: self.right.clone(),
             right: self.bottom.clone(),
--- a/rust/mapgen/src/template/wavefront_collapse.rs	Thu Jan 30 13:59:41 2025 +0100
+++ b/rust/mapgen/src/template/wavefront_collapse.rs	Thu Jan 30 16:38:00 2025 +0100
@@ -8,6 +8,7 @@
 #[derive(Debug, Deserialize)]
 pub struct TileDesc {
     pub name: String,
+    pub weight: Option<u8>,
     pub edges: [String; 4],
     pub is_negative: Option<bool>,
     pub can_flip: Option<bool>,
@@ -95,6 +96,7 @@
 
         Self {
             name: desc.name.clone(),
+            weight: desc.weight.unwrap_or(10),
             edges: EdgesDescription {
                 top,
                 right,