terragen: proportion of layer depth is better preserved

This commit is contained in:
minjaesong
2023-11-15 12:43:24 +09:00
parent 3ebedbb9cf
commit 1affb24cae
2 changed files with 11 additions and 9 deletions

View File

@@ -8,10 +8,8 @@ import net.torvald.terrarum.LoadScreenBase
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.concurrent.sliceEvenly
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.FancyWorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import kotlin.math.cos
import kotlin.math.max
import kotlin.math.pow
import kotlin.math.sin
/**
@@ -54,13 +52,15 @@ class Terragen(world: GameWorld, val highlandLowlandSelectCache: ModuleCache, se
Block.AIR, Block.DIRT, Block.STONE, Block.STONE_SLATE
)
private fun Double.tiered(vararg tiers: Double): Int {
private fun Double.tiered(tiers: List<Double>): Int {
tiers.reversed().forEachIndexed { index, it ->
if (this >= it) return (tiers.lastIndex - index) // why??
}
return tiers.lastIndex
}
private val terragenTiers = listOf(.0, .5, 1.0, 2.5).map { it * (world.height / 2400.0).pow(0.75) } // pow 1.0 for 1-to-1 scaling; 0.75 is used to make deep-rock layers actually deep for huge world size
//private fun draw(x: Int, y: Int, width: Int, height: Int, noiseValue: List<Double>, world: GameWorld) {
private fun draw(x: Int, noises: List<Joise>, st: Double, soff: Double) {
var dirtStoneTransition = 0
@@ -73,7 +73,7 @@ class Terragen(world: GameWorld, val highlandLowlandSelectCache: ModuleCache, se
// DEBUG NOTE: it is the OFFSET FROM THE IDEAL VALUE (observed land height - (HEIGHT * DIVISOR)) that must be constant
val noiseValue = noises.map { it.get(sx, sy, sz) }
val terr = noiseValue[0].tiered(.0, .5, .88, 1.88)
val terr = noiseValue[0].tiered(terragenTiers)
// mark off the position where the transition occurred
if (dirtStoneTransition == 0 && terr == 2)

View File

@@ -349,7 +349,7 @@ internal object TerragenTest : NoiseMaker {
Block.AIR, Block.DIRT, Block.STONE, Block.STONE_SLATE
)
private fun Double.tiered(vararg tiers: Double): Int {
private fun Double.tiered(tiers: List<Double>): Int {
tiers.reversed().forEachIndexed { index, it ->
if (this >= it) return (tiers.lastIndex - index) // why??
}
@@ -379,8 +379,10 @@ internal object TerragenTest : NoiseMaker {
COPPER_ORE, IRON_ORE, COAL_ORE, ZINC_ORE, TIN_ORE, GOLD_ORE, SILVER_ORE, LEAD_ORE
)
private val terragenTiers = listOf(.0, .5, 1.0, 2.5).map { it * (NOISEBOX_HEIGHT / 2400.0).pow(0.75) } // pow 1.0 for 1-to-1 scaling; 0.75 is used to make deep-rock layers actually deep for huge world size
override fun draw(x: Int, y: Int, noiseValue: List<Double>, outTex: Pixmap) {
val terr = noiseValue[0].tiered(.0, .5, .88, 1.88)
val terr = noiseValue[0].tiered(terragenTiers)
val cave = if (noiseValue[1] < 0.5) 0 else 1
val ore = (noiseValue.subList(2, noiseValue.size)).zip(oreCols).firstNotNullOfOrNull { (n, colour) -> if (n > 0.5) colour else null }
@@ -712,8 +714,8 @@ internal object TerragenTest : NoiseMaker {
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:7", 0.013, 0.300, 0.476, 1.0)),
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:8", 0.017, 0.020, 0.511, 1.0)),
Joise(generate1Dline(seed shake 10, 1.88)),
Joise(generate1Dline(seed shake 10, 1.90)),
Joise(generate1Dline(seed shake 10, 2.6)),
Joise(generate1Dline(seed shake 10, 2.62)),
)
}