From 7803122ea14a7a6e0e77489c9e9846e5cb72528a Mon Sep 17 00:00:00 2001 From: dags- Date: Thu, 26 Mar 2020 22:49:19 +0000 Subject: [PATCH] tweaks to sea-level dependent functions (treeline + beach line) --- .../terraforged/core/filter/Steepness.java | 19 ++++++++----------- .../terraforged/core/world/WorldFilters.java | 2 +- .../core/world/climate/Climate.java | 4 +++- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Steepness.java b/TerraForgedCore/src/main/java/com/terraforged/core/filter/Steepness.java index 8c7be9f..dc16467 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Steepness.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/filter/Steepness.java @@ -26,26 +26,23 @@ package com.terraforged.core.filter; import com.terraforged.core.cell.Cell; +import com.terraforged.core.world.heightmap.Levels; import com.terraforged.core.world.terrain.Terrains; public class Steepness implements Filter, Filter.Visitor { private final int radius; private final float scaler; + private final float waterLevel; + private final float maxBeachLevel; private final Terrains terrains; - public Steepness(Terrains terrains) { - this(2, 16F, terrains); - } - - public Steepness(float scaler, Terrains terrains) { - this(2, scaler, terrains); - } - - public Steepness(int radius, float scaler, Terrains terrains) { + public Steepness(int radius, float scaler, Terrains terrains, Levels levels) { this.radius = radius; this.scaler = scaler; this.terrains = terrains; + this.waterLevel = levels.water; + this.maxBeachLevel = levels.water(6); } @Override @@ -69,13 +66,13 @@ public class Steepness implements Filter, Filter.Visitor { continue; } - float height = Math.max(neighbour.value, 62 / 256F); + float height = Math.max(neighbour.value, waterLevel); totalHeightDif += (Math.abs(cell.value - height) / radius); } } cell.steepness = Math.min(1, totalHeightDif * scaler); - if (cell.tag == terrains.coast && cell.steepness < 0.22F) { + if (cell.tag == terrains.coast && cell.steepness < 0.225F && cell.value < maxBeachLevel) { cell.tag = terrains.beach; } } diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldFilters.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldFilters.java index b9e20c3..b5f4d32 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldFilters.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldFilters.java @@ -45,7 +45,7 @@ public class WorldFilters { this.settings = context.settings.filters; this.erosion = new Erosion(context.settings, context.levels); this.smoothing = new Smoothing(context.settings, context.levels); - this.steepness = new Steepness(1, 10F, context.terrain); + this.steepness = new Steepness(1, 10F, context.terrain, context.levels); } public void apply(Region region) { diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java index accf2ee..4a52538 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java @@ -53,7 +53,9 @@ public class Climate { this.biomeNoise = new ClimateModule(context.seed, context.settings); this.treeLine = Source.perlin(context.seed.next(), context.settings.generator.biome.biomeSize * 2, 1) - .scale(0.1).bias(0.4); + .scale(context.levels.scale(25)) // 30 units worth of variance + .bias(context.levels.ground(40)) // start at-least 30 units above ground level + .clamp(0, 1); this.rand = new Rand(Source.builder().seed(context.seed.next())); this.offsetX = context.settings.generator.biomeEdgeNoise.build(context.seed.next());