From 76d6579ce9ea7e5b4a0f175816dccadf8c0ddbdf Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 28 Oct 2023 16:49:34 +0900 Subject: [PATCH] new oregen param: ratio --- assets/mods/basegame/ores/worldgen.csv | 9 ++++--- src/net/torvald/terrarum/ModMgr.kt | 3 ++- .../modulebasegame/worldgenerator/Oregen.kt | 21 ++++++++++++--- .../terrarum/tests/WorldgenNoiseSandbox.kt | 26 +++++++++++++++---- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/assets/mods/basegame/ores/worldgen.csv b/assets/mods/basegame/ores/worldgen.csv index 71124f989..f914f9324 100644 --- a/assets/mods/basegame/ores/worldgen.csv +++ b/assets/mods/basegame/ores/worldgen.csv @@ -1,7 +1,7 @@ -"id";"freq";"power";"scale";"tiling";"comment" -"1";"0.026";"0.01";"0.505";"a16";"copper (malachite)" -"2";"0.040";"0.01";"0.505";"a16";"iron (haematite)" -#"3";"0.040";"0.08";"0.501";"r16";"coal" +"id";"freq";"power";"scale";"ratio";"tiling";"comment" +"1";"0.026";"0.01";"0.505";"1.0";"a16";"copper (malachite)" +"2";"0.040";"0.01";"0.505";"1.0";"a16";"iron (haematite)" +#"3";"0.040";"0.08";"0.501";"1.0";"r16";"coal" ################################################################################ @@ -10,6 +10,7 @@ # freq: frequency value used to set up noise generator. Larger = ore veins are closer together # power: power value (as in: randomNumber ^ power) used to set up the noise generator. Larger = veins are larger as you go deeper. 0.01 almost negates this effect # scale: scale value used to set up the noise generator. Larger = thicker veins. A valid value tend to play around the 0.5; you'll need figure out this value by trial and error +# ratio: how elongated (or squeeze) the ore veins are. >1.0 = stretched horizontally, <1.0 = stretched vertically # # tiling: determines how the tiles are tiled # - a16: use 4-neighbour autotiling (16 possible cases) diff --git a/src/net/torvald/terrarum/ModMgr.kt b/src/net/torvald/terrarum/ModMgr.kt index 63dbb79ce..d8af1953d 100644 --- a/src/net/torvald/terrarum/ModMgr.kt +++ b/src/net/torvald/terrarum/ModMgr.kt @@ -520,9 +520,10 @@ object ModMgr { val freq = rec.get("freq").toDouble() val power = rec.get("power").toDouble() val scale = rec.get("scale").toDouble() + val ratio = rec.get("ratio").toDouble() val tiling = rec.get("tiling") - Worldgen.registerOre(OregenParams(tile, freq, power, scale, tiling)) + Worldgen.registerOre(OregenParams(tile, freq, power, scale, ratio, tiling)) } } catch (e: IOException) { diff --git a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Oregen.kt b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Oregen.kt index 3f2a46ccd..ccf382f1f 100644 --- a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Oregen.kt +++ b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Oregen.kt @@ -10,12 +10,14 @@ import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen.Companion.YHEIGHT_DIVISOR import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen.Companion.YHEIGHT_MAGIC +import net.torvald.terrarum.sqr import net.torvald.terrarum.toInt import net.torvald.terrarum.utils.OrePlacement import net.torvald.terrarum.worlddrawer.BlocksDrawer import kotlin.math.cos import kotlin.math.max import kotlin.math.sin +import kotlin.math.sqrt /** * Created by minjaesong on 2023-10-25. @@ -46,7 +48,7 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD */ private fun getGenerator(seed: Long): List { return ores.map { - Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake it.tile, it.freq, it.power, it.scale)) + Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake it.tile, it.freq, it.power, it.scale, it.ratio)) } } @@ -86,7 +88,7 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD } } - private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, freq: Double, pow: Double, scale: Double): Module { + private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, freq: Double, pow: Double, scale: Double, ratio: Double): Module { val oreShape = ModuleFractal().also { it.setType(ModuleFractal.FractalType.RIDGEMULTI) it.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT) @@ -130,10 +132,22 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD it.setAxisXSource(orePerturbScale) } + val oreStrecth = ModuleScaleDomain().also { + val xratio = if (ratio >= 1.0) ratio else 1.0 + val yratio = if (ratio < 1.0) 1.0 / ratio else 1.0 + val k = sqrt(2.0 / (xratio.sqr() + yratio.sqr())) + val xs = xratio * k + val ys = yratio * k + + it.setSource(orePerturb) + it.setScaleX(1.0 / xs) + it.setScaleY(1.0 / ys) + } + val oreSelect = ModuleSelect().also { it.setLowSource(0.0) it.setHighSource(1.0) - it.setControlSource(orePerturb) + it.setControlSource(oreStrecth) it.setThreshold(0.5) it.setFalloff(0.0) } @@ -147,5 +161,6 @@ data class OregenParams( val freq: Double, //adjust the "density" of the caves val power: Double, // adjust the "concentration" of the cave gen. Lower = larger voids val scale: Double, // also adjust this if you've touched the bias value. Number can be greater than 1.0 + val ratio: Double, // how stretched the ore veins are. >1.0 = stretched horizontally, <1.0 = stretched vertically val tiling: String, // a16, a47, r16, r8 ) \ No newline at end of file diff --git a/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt b/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt index cf0c2a7ae..edf740a07 100644 --- a/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt +++ b/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt @@ -29,6 +29,7 @@ import java.util.concurrent.Future import kotlin.math.* import kotlin.random.Random import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen +import net.torvald.terrarum.sqr const val NOISEBOX_WIDTH = 922 const val NOISEBOX_HEIGHT = 2000 @@ -361,17 +362,19 @@ internal object TerragenTest : NoiseMaker { private val IRON_ORE = 0xff9a5dff.toInt() private val COPPER_ORE = 0x00e9c8ff + private val COAL_ORE = 0xffffffff.toInt() override fun draw(x: Int, y: Int, noiseValue: List, outTex: Pixmap) { val terr = noiseValue[0].tiered(.0, .5, .88, 1.88) val cave = if (noiseValue[1] < 0.5) 0 else 1 val copper = (noiseValue[2] > 0.5) val iron = (noiseValue[3] > 0.5) + val coal = (noiseValue[4] > 0.5) val wallBlock = groundDepthBlock[terr] val terrBlock = if (cave == 0) Block.AIR else wallBlock - val ore = if (iron) IRON_ORE else if (copper) COPPER_ORE else null + val ore = if (iron) IRON_ORE else if (copper) COPPER_ORE else if (coal) COAL_ORE else null outTex.drawPixel(x, y, if (ore != null && (terrBlock == Block.STONE || terrBlock == Block.STONE_SLATE)) ore @@ -686,8 +689,9 @@ internal object TerragenTest : NoiseMaker { return listOf( Joise(groundScaling), Joise(caveScaling), - Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:1", 0.024, 0.01, 0.505)), - Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:2", 0.04, 0.01, 0.505)), + Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:1", 0.024, 0.01, 0.505, 1.0)), + Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:2", 0.04, 0.01, 0.505, 1.0)), + Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:3", 0.04, 0.01, 0.505, 10.0)), ) } @@ -701,7 +705,7 @@ internal object TerragenTest : NoiseMaker { } } - private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, freq: Double, pow: Double, scale: Double): Module { + private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, freq: Double, pow: Double, scale: Double, ratio: Double): Module { val oreShape = ModuleFractal().also { it.setType(ModuleFractal.FractalType.RIDGEMULTI) it.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT) @@ -745,10 +749,22 @@ internal object TerragenTest : NoiseMaker { it.setAxisXSource(orePerturbScale) } + val oreStrecth = ModuleScaleDomain().also { + val xratio = if (ratio >= 1.0) ratio else 1.0 + val yratio = if (ratio < 1.0) 1.0 / ratio else 1.0 + val k = sqrt(2.0 / (xratio.sqr() + yratio.sqr())) + val xs = xratio * k + val ys = yratio * k + + it.setSource(orePerturb) + it.setScaleX(1.0 / xs) + it.setScaleY(1.0 / ys) + } + val oreSelect = ModuleSelect().also { it.setLowSource(0.0) it.setHighSource(1.0) - it.setControlSource(orePerturb) + it.setControlSource(oreStrecth) it.setThreshold(0.5) it.setFalloff(0.0) }