From 5633ec9cdd957384cbb788d05bdd758074dc6f59 Mon Sep 17 00:00:00 2001 From: dags- Date: Fri, 6 Mar 2020 20:50:57 +0000 Subject: [PATCH] Make sure connecting rivers aren't wider than the river they're connecting to at the point of connection --- .../terraforged/core/world/river/River.java | 2 ++ .../core/world/river/RiverConfig.java | 30 +++++++++++++++++++ .../core/world/river/RiverRegion.java | 12 +++++--- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/river/River.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/river/River.java index 610a3a2..3632e75 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/river/River.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/river/River.java @@ -54,6 +54,7 @@ public class River extends TerrainPopulator { private final Line bed; private final Line banks; private final Line valley; + public final RiverConfig config; public final RiverBounds bounds; private final Terrains terrains; @@ -72,6 +73,7 @@ public class River extends TerrainPopulator { Module bankWidth = Source.constant(config.bankWidth * config.bankWidth); Module valleyWidth = Source.constant(VALLEY_WIDTH * VALLEY_WIDTH); this.bounds = bounds; + this.config = config; this.main = config.main; this.terrains = terrains; this.connecting = connecting; diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/river/RiverConfig.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/river/RiverConfig.java index d893be3..0f7a2ed 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/river/RiverConfig.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/river/RiverConfig.java @@ -26,6 +26,7 @@ package com.terraforged.core.world.river; import com.terraforged.core.world.heightmap.Levels; +import me.dags.noise.util.NoiseUtil; public class RiverConfig { @@ -49,6 +50,35 @@ public class RiverConfig { fade = builder.fade; } + private RiverConfig(boolean main, int bedWidth, int bankWidth, float bedHeight, float minBankHeight, float maxBankHeight, int length2, double fade) { + this.main = main; + this.bedWidth = bedWidth; + this.bankWidth = bankWidth; + this.bedHeight = bedHeight; + this.minBankHeight = minBankHeight; + this.maxBankHeight = maxBankHeight; + this.length2 = length2; + this.fade = fade; + } + + public RiverConfig createFork(float connectWidth) { + if (bankWidth < connectWidth) { + return this; + } + + float scale = bankWidth / connectWidth; + return new RiverConfig( + false, + NoiseUtil.round(bedWidth / scale), + NoiseUtil.round(bankWidth / scale), + bedHeight, + minBankHeight, + maxBankHeight, + length2, + fade + ); + } + public static Builder builder(Levels levels) { return new Builder(levels); } diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/river/RiverRegion.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/river/RiverRegion.java index f88949e..718c302 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/river/RiverRegion.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/river/RiverRegion.java @@ -95,15 +95,15 @@ public class RiverRegion { generateRiver(x, z, pos, primary, random, rivers); } - for (int i = 0; rivers.size() < 10 && i < 50; i++) { + for (int i = 0; rivers.size() < 15 && i < 100; i++) { generateRiver(x, z, pos, secondary, random, rivers); } - for (int i = 0; rivers.size() < 20 && i < 50; i++) { + for (int i = 0; rivers.size() < 25 && i < 75; i++) { generateRiverFork(x, z, pos, tertiary, random, rivers); } - for (int i = 0; rivers.size() < 30 && i < 50; i++) { + for (int i = 0; rivers.size() < 40 && i < 50; i++) { generateRiver(x, z, pos, tertiary, random, rivers); } @@ -211,7 +211,11 @@ public class RiverRegion { generateLake(bounds, random); - return rivers.add(new River(bounds, config, terrains, config.fade, 0, true)); + // scale the connecting river's width down so that it's narrower than the one it's connecting to + float forkWidth = closest.config.bankWidth * distance * 0.6F; + RiverConfig forkConfig = config.createFork(forkWidth); + + return rivers.add(new River(bounds, forkConfig, terrains, forkConfig.fade, 0, true)); } private void generateLake(RiverBounds bounds, Random random) {