mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
worldgen: aggresive use of ModuleCache
This commit is contained in:
@@ -78,10 +78,10 @@ class Cavegen(world: GameWorld, val highlandLowlandSelectCache: ModuleCache, see
|
|||||||
it.seed = seed shake caveMagic
|
it.seed = seed shake caveMagic
|
||||||
}
|
}
|
||||||
|
|
||||||
val caveAttenuateBias = ModuleBias().also {
|
val caveAttenuateBias = ModuleCache().also {it.setSource(ModuleBias().also {
|
||||||
it.setSource(highlandLowlandSelectCache)
|
it.setSource(highlandLowlandSelectCache)
|
||||||
it.setBias(params.caveAttenuateBias) // (0.5+) adjust the "concentration" of the cave gen. Lower = larger voids
|
it.setBias(params.caveAttenuateBias) // (0.5+) adjust the "concentration" of the cave gen. Lower = larger voids
|
||||||
}
|
})}
|
||||||
|
|
||||||
val caveShapeAttenuate = ModuleCombiner().also {
|
val caveShapeAttenuate = ModuleCombiner().also {
|
||||||
it.setType(ModuleCombiner.CombinerType.MULT)
|
it.setType(ModuleCombiner.CombinerType.MULT)
|
||||||
|
|||||||
@@ -5,19 +5,16 @@ import com.sudoplay.joise.module.*
|
|||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.concurrent.sliceEvenly
|
import net.torvald.terrarum.concurrent.sliceEvenly
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.modulebasegame.FancyWorldgenLoadScreen
|
|
||||||
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_DIVISOR
|
||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen.Companion.YHEIGHT_MAGIC
|
import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen.Companion.YHEIGHT_MAGIC
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2023-10-25.
|
* Created by minjaesong on 2023-10-25.
|
||||||
*/
|
*/
|
||||||
class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, private val ores: List<OregenParams>) : Gen(world, seed) {
|
class Oregen(world: GameWorld, private val caveAttenuateBiasScaledCache: ModuleCache, seed: Long, private val ores: List<OregenParams>) : Gen(world, seed) {
|
||||||
override fun getDone(loadscreen: LoadScreenBase) {
|
override fun getDone(loadscreen: LoadScreenBase) {
|
||||||
loadscreen.stageValue += 1
|
loadscreen.stageValue += 1
|
||||||
loadscreen.progress.set(0L)
|
loadscreen.progress.set(0L)
|
||||||
@@ -43,7 +40,7 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
|
|||||||
*/
|
*/
|
||||||
private fun getGenerator(seed: Long): List<Joise> {
|
private fun getGenerator(seed: Long): List<Joise> {
|
||||||
return ores.map {
|
return ores.map {
|
||||||
generateOreVeinModule(caveAttenuateBiasScaled, seed shake it.tile, it.freq, it.power, it.scale, it.ratio)
|
generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake it.tile, it.freq, it.power, it.scale, it.ratio)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +80,7 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, freq: Double, pow: Double, scale: Double, ratio: Double): Joise {
|
private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleCache, seed: Long, freq: Double, pow: Double, scale: Double, ratio: Double): Joise {
|
||||||
val oreShape = ModuleFractal().also {
|
val oreShape = ModuleFractal().also {
|
||||||
it.setType(ModuleFractal.FractalType.RIDGEMULTI)
|
it.setType(ModuleFractal.FractalType.RIDGEMULTI)
|
||||||
it.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.SIMPLEX)
|
it.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.SIMPLEX)
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import net.torvald.terrarum.gameworld.BlockAddress
|
|||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.roundToLong
|
import kotlin.math.roundToLong
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,7 +35,7 @@ object Worldgen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal lateinit var highlandLowlandSelectCache: ModuleCache
|
internal lateinit var highlandLowlandSelectCache: ModuleCache
|
||||||
internal lateinit var caveAttenuateBiasScaled: ModuleScaleDomain
|
internal lateinit var caveAttenuateBiasScaledCache: ModuleCache
|
||||||
internal lateinit var biomeMap: HashMap<BlockAddress, Byte>
|
internal lateinit var biomeMap: HashMap<BlockAddress, Byte>
|
||||||
|
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ object Worldgen {
|
|||||||
}
|
}
|
||||||
return listOf(
|
return listOf(
|
||||||
Work(Lang["MENU_IO_WORLDGEN_RETICULATING_SPLINES"], Terragen(world, highlandLowlandSelectCache, params.seed, params.terragenParams), listOf("TERRAIN")),
|
Work(Lang["MENU_IO_WORLDGEN_RETICULATING_SPLINES"], Terragen(world, highlandLowlandSelectCache, params.seed, params.terragenParams), listOf("TERRAIN")),
|
||||||
Work(Lang["MENU_IO_WORLDGEN_GROWING_MINERALS"], Oregen(world, caveAttenuateBiasScaled, params.seed, oreRegistry), listOf("ORES")),
|
Work(Lang["MENU_IO_WORLDGEN_GROWING_MINERALS"], Oregen(world, caveAttenuateBiasScaledCache, params.seed, oreRegistry), listOf("ORES")),
|
||||||
Work(Lang["MENU_IO_WORLDGEN_POSITIONING_ROCKS"], OregenAutotiling(world, params.seed, oreTilingModes), listOf("ORES")),
|
Work(Lang["MENU_IO_WORLDGEN_POSITIONING_ROCKS"], OregenAutotiling(world, params.seed, oreTilingModes), listOf("ORES")),
|
||||||
// TODO generate rock veins
|
// TODO generate rock veins
|
||||||
// TODO generate gemstones
|
// TODO generate gemstones
|
||||||
@@ -74,7 +73,7 @@ object Worldgen {
|
|||||||
|
|
||||||
fun generateMap(loadscreen: LoadScreenBase) {
|
fun generateMap(loadscreen: LoadScreenBase) {
|
||||||
highlandLowlandSelectCache = getHighlandLowlandSelectCache(params.terragenParams, params.seed)
|
highlandLowlandSelectCache = getHighlandLowlandSelectCache(params.terragenParams, params.seed)
|
||||||
caveAttenuateBiasScaled = getCaveAttenuateBiasScaled(highlandLowlandSelectCache, params.terragenParams)
|
caveAttenuateBiasScaledCache = getCaveAttenuateBiasScaled(highlandLowlandSelectCache, params.terragenParams)
|
||||||
biomeMap = HashMap()
|
biomeMap = HashMap()
|
||||||
|
|
||||||
genSlices = world.width / 9
|
genSlices = world.width / 9
|
||||||
@@ -258,18 +257,22 @@ object Worldgen {
|
|||||||
return highlandLowlandSelectCache
|
return highlandLowlandSelectCache
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCaveAttenuateBiasScaled(highlandLowlandSelectCache: ModuleCache, params: TerragenParams): ModuleScaleDomain {
|
private fun getCaveAttenuateBiasScaled(highlandLowlandSelectCache: ModuleCache, params: TerragenParams): ModuleCache {
|
||||||
val caveAttenuateBias = ModuleBias().also {
|
val caveAttenuateBias = ModuleBias().also {
|
||||||
it.setSource(highlandLowlandSelectCache)
|
it.setSource(highlandLowlandSelectCache)
|
||||||
it.setBias(params.caveAttenuateBias) // (0.5+) adjust the "concentration" of the cave gen. Lower = larger voids
|
it.setBias(params.caveAttenuateBias) // (0.5+) adjust the "concentration" of the cave gen. Lower = larger voids
|
||||||
}
|
}
|
||||||
|
|
||||||
return ModuleScaleDomain().also {
|
val scale = ModuleScaleDomain().also {
|
||||||
it.setScaleX(1.0 / params.featureSize) // adjust this value to change features size
|
it.setScaleX(1.0 / params.featureSize) // adjust this value to change features size
|
||||||
it.setScaleY(1.0 / params.featureSize)
|
it.setScaleY(1.0 / params.featureSize)
|
||||||
it.setScaleZ(1.0 / params.featureSize)
|
it.setScaleZ(1.0 / params.featureSize)
|
||||||
it.setSource(caveAttenuateBias)
|
it.setSource(caveAttenuateBias)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ModuleCache().also {
|
||||||
|
it.setSource(scale)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -595,10 +595,10 @@ internal object TerragenTest : NoiseMaker {
|
|||||||
it.seed = seed shake caveMagic
|
it.seed = seed shake caveMagic
|
||||||
}
|
}
|
||||||
|
|
||||||
val caveAttenuateBias = ModuleBias().also {
|
val caveAttenuateBias = ModuleCache().also { it.setSource(ModuleBias().also {
|
||||||
it.setSource(highlandLowlandSelectCache)
|
it.setSource(highlandLowlandSelectCache)
|
||||||
it.setBias(params.caveAttenuateBias) // (0.5+) adjust the "concentration" of the cave gen. Lower = larger voids
|
it.setBias(params.caveAttenuateBias) // (0.5+) adjust the "concentration" of the cave gen. Lower = larger voids
|
||||||
}
|
})}
|
||||||
|
|
||||||
val caveShapeAttenuate = ModuleCombiner().also {
|
val caveShapeAttenuate = ModuleCombiner().also {
|
||||||
it.setType(ModuleCombiner.CombinerType.MULT)
|
it.setType(ModuleCombiner.CombinerType.MULT)
|
||||||
@@ -703,24 +703,28 @@ internal object TerragenTest : NoiseMaker {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val groundScalingCached = ModuleCache().also { it.setSource(groundScaling) }
|
||||||
|
val caveAttenuateBiasScaledCache = ModuleCache().also { it.setSource(caveAttenuateBiasScaled) }
|
||||||
|
|
||||||
|
|
||||||
//return Joise(caveInMix)
|
//return Joise(caveInMix)
|
||||||
return listOf(
|
return listOf(
|
||||||
Joise(groundScaling),
|
Joise(groundScalingCached),
|
||||||
Joise(caveScaling),
|
Joise(caveScaling),
|
||||||
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:1", 0.026, 0.010, 0.517, 1.0)),
|
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:1", 0.026, 0.010, 0.517, 1.0)),
|
||||||
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:2", 0.045, 0.011, 0.517, 1.0)),
|
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:2", 0.045, 0.011, 0.517, 1.0)),
|
||||||
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:3", 0.017, 0.070, 0.511, 3.8)),
|
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:3", 0.017, 0.070, 0.511, 3.8)),
|
||||||
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:4", 0.019, 0.011, 0.511, 1.0)),
|
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:4", 0.019, 0.011, 0.511, 1.0)),
|
||||||
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:5", 0.017, 0.017, 0.511, 1.0)),
|
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:5", 0.017, 0.017, 0.511, 1.0)),
|
||||||
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:6", 0.009, 0.300, 0.474, 1.0)),
|
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:6", 0.009, 0.300, 0.474, 1.0)),
|
||||||
Joise(generateOreVeinModule(caveAttenuateBiasScaled, seed shake "ores@basegame:7", 0.013, 0.300, 0.476, 1.0)),
|
Joise(generateOreVeinModule(caveAttenuateBiasScaledCache, 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(generateOreVeinModule(caveAttenuateBiasScaledCache, seed shake "ores@basegame:8", 0.017, 0.020, 0.511, 1.0)),
|
||||||
|
|
||||||
Joise(generateRockLayer(groundScaling, seed shake 10, 2.6, 2.62)),
|
Joise(generateRockLayer(groundScalingCached, seed shake 10, 2.6, 2.62)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateRockLayer(ground: Module, seed: Long, rangeStart: Double, rangeEnd: Double): Module {
|
private fun generateRockLayer(ground: ModuleCache, seed: Long, rangeStart: Double, rangeEnd: Double): Module {
|
||||||
val thresholdLow = ModuleSelect().also {
|
val thresholdLow = ModuleSelect().also {
|
||||||
it.setLowSource(0.0)
|
it.setLowSource(0.0)
|
||||||
it.setHighSource(1.0)
|
it.setHighSource(1.0)
|
||||||
@@ -759,7 +763,7 @@ internal object TerragenTest : NoiseMaker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateOreVeinModule(caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, freq: Double, pow: Double, scale: Double, ratio: Double): Module {
|
private fun generateOreVeinModule(caveAttenuateBiasScaledCache: ModuleCache, seed: Long, freq: Double, pow: Double, scale: Double, ratio: Double): Module {
|
||||||
val oreShape = ModuleFractal().also {
|
val oreShape = ModuleFractal().also {
|
||||||
it.setType(ModuleFractal.FractalType.RIDGEMULTI)
|
it.setType(ModuleFractal.FractalType.RIDGEMULTI)
|
||||||
it.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.SIMPLEX)
|
it.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.SIMPLEX)
|
||||||
@@ -775,7 +779,7 @@ internal object TerragenTest : NoiseMaker {
|
|||||||
it.setOffset(-0.5)
|
it.setOffset(-0.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
val caveAttenuateBias3 = applyPowMult(caveAttenuateBiasScaled, pow, scale)
|
val caveAttenuateBias3 = applyPowMult(caveAttenuateBiasScaledCache, pow, scale)
|
||||||
|
|
||||||
val oreShapeAttenuate = ModuleCombiner().also {
|
val oreShapeAttenuate = ModuleCombiner().also {
|
||||||
it.setType(ModuleCombiner.CombinerType.MULT)
|
it.setType(ModuleCombiner.CombinerType.MULT)
|
||||||
|
|||||||
Reference in New Issue
Block a user