fix: missing params that caused backwards incompatibility

This commit is contained in:
minjaesong
2024-09-25 11:53:52 +09:00
parent b4f512ddef
commit 1c54b40898
5 changed files with 14 additions and 12 deletions

View File

@@ -2,7 +2,6 @@ package net.torvald.terrarum.modulebasegame.worldgenerator
import com.sudoplay.joise.Joise import com.sudoplay.joise.Joise
import com.sudoplay.joise.module.* import com.sudoplay.joise.module.*
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.INGAME import net.torvald.terrarum.INGAME
import net.torvald.terrarum.LoadScreenBase import net.torvald.terrarum.LoadScreenBase
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
@@ -19,7 +18,7 @@ import kotlin.math.sin
*/ */
class Aquagen(world: GameWorld, isFinal: Boolean, val groundScalingCached: ModuleCache, seed: Long, params: Any) : Gen(world, isFinal, seed, params) { class Aquagen(world: GameWorld, isFinal: Boolean, val groundScalingCached: ModuleCache, seed: Long, params: Any) : Gen(world, isFinal, seed, params) {
private val isAlpha2 = ((params as TerragenParams).version >= 0x0000_000004_000004) private val isAlpha2 = ((params as TerragenParams).versionSince >= 0x0000_000004_000004)
private val FLUID_FILL = 1.2f private val FLUID_FILL = 1.2f

View File

@@ -16,7 +16,7 @@ import kotlin.math.sin
*/ */
class Cavegen(world: GameWorld, isFinal: Boolean, val highlandLowlandSelectCache: ModuleCache, seed: Long, params: Any) : Gen(world, isFinal, seed, params) { class Cavegen(world: GameWorld, isFinal: Boolean, val highlandLowlandSelectCache: ModuleCache, seed: Long, params: Any) : Gen(world, isFinal, seed, params) {
private val isAlpha2 = ((params as TerragenParams).version >= 0x0000_000004_000004) private val isAlpha2 = ((params as TerragenParams).versionSince >= 0x0000_000004_000004)
override fun getDone(loadscreen: LoadScreenBase?) { override fun getDone(loadscreen: LoadScreenBase?) {
loadscreen?.let { loadscreen?.let {

View File

@@ -13,9 +13,9 @@ import kotlin.math.sqrt
/** /**
* Created by minjaesong on 2023-10-25. * Created by minjaesong on 2023-10-25.
*/ */
class Oregen(world: GameWorld, isFinal: Boolean, private val caveAttenuateBiasScaledCache: ModuleCache, seed: Long, private val ores: List<OregenParams>) : Gen(world, isFinal, seed) { class Oregen(world: GameWorld, isFinal: Boolean, private val caveAttenuateBiasScaledCache: ModuleCache, seed: Long, private val ores: List<OregenParams>, terragenParams: TerragenParams) : Gen(world, isFinal, seed, terragenParams) {
private val isAlpha2 = ((params as TerragenParams).version >= 0x0000_000004_000004) private val isAlpha2 = (terragenParams.versionSince >= 0x0000_000004_000004)
override fun getDone(loadscreen: LoadScreenBase?) { override fun getDone(loadscreen: LoadScreenBase?) {
loadscreen?.let { loadscreen?.let {

View File

@@ -18,7 +18,7 @@ import kotlin.math.sin
*/ */
class Terragen(world: GameWorld, isFinal: Boolean, val groundScalingCached: ModuleCache, seed: Long, params: Any) : Gen(world, isFinal, seed, params) { class Terragen(world: GameWorld, isFinal: Boolean, val groundScalingCached: ModuleCache, seed: Long, params: Any) : Gen(world, isFinal, seed, params) {
private val isAlpha2 = ((params as TerragenParams).version >= 0x0000_000004_000004) private val isAlpha2 = ((params as TerragenParams).versionSince >= 0x0000_000004_000004)
override fun getDone(loadscreen: LoadScreenBase?) { override fun getDone(loadscreen: LoadScreenBase?) {
loadscreen?.let { loadscreen?.let {
@@ -223,7 +223,7 @@ class Terragen(world: GameWorld, isFinal: Boolean, val groundScalingCached: Modu
abstract class TerragenParams { abstract class TerragenParams {
val LANDBLOCK_VAR_COUNTS = 16 val LANDBLOCK_VAR_COUNTS = 16
abstract val version: Long abstract val versionSince: Long
abstract val strata: List<Stratum> abstract val strata: List<Stratum>
abstract val featureSize: Double abstract val featureSize: Double
abstract val lowlandScaleOffset: Double // linearly alters the height abstract val lowlandScaleOffset: Double // linearly alters the height
@@ -297,12 +297,15 @@ abstract class TerragenParams {
* @param h: STARTING height of the strata relative to the ground select gradient * @param h: STARTING height of the strata relative to the ground select gradient
* @param v: linear ± to the `h` * @param v: linear ± to the `h`
*/ */
data class Hv(val h: Double, val v: Double) data class Hv(val h: Double, val v: Double) { init {
if (h.isNaN() || h.isInfinite() || h < 0.0) throw IllegalArgumentException("h-value must be zero or positive (got $h)")
if (v.isNaN() || v.isInfinite() || v < 0.0) throw IllegalArgumentException("v-value must be zero or positive (got $v)")
} }
class Stratum(val yheight: Hv, vararg val tiles: ItemID) class Stratum(val yheight: Hv, vararg val tiles: ItemID)
class StratumObj(val yheight: Double, val tiles: ItemID) class StratumObj(val yheight: Double, val tiles: ItemID)
data class TerragenParamsAlpha1( data class TerragenParamsAlpha1(
override val version: Long = 0L, override val versionSince: Long = 0L,
// 0. randomiser gets two-element buffer // 0. randomiser gets two-element buffer
// 1. randomiser consults the buffer and removes matching elements from the random pool // 1. randomiser consults the buffer and removes matching elements from the random pool
@@ -340,7 +343,7 @@ data class TerragenParamsAlpha1(
) : TerragenParams() ) : TerragenParams()
data class TerragenParamsAlpha2( data class TerragenParamsAlpha2(
override val version: Long = 0x0000_000004_000004, override val versionSince: Long = 0x0000_000004_000004,
override val strata: List<Stratum> = listOf( override val strata: List<Stratum> = listOf(
Stratum(Hv(.0, .0), Block.AIR), Stratum(Hv(.0, .0), Block.AIR),
@@ -396,4 +399,4 @@ data class TerragenParamsAlpha2(
override val landBlockScale: Double = 0.5, override val landBlockScale: Double = 0.5,
) : TerragenParams() ) : TerragenParams()

View File

@@ -98,7 +98,7 @@ object Worldgen {
Work(Lang["MENU_IO_WORLDGEN_RETICULATING_SPLINES"], Terragen(world, false, groundScalingCached, params.seed, params.terragenParams), listOf("TERRAIN")), // also generates marble veins Work(Lang["MENU_IO_WORLDGEN_RETICULATING_SPLINES"], Terragen(world, false, groundScalingCached, params.seed, params.terragenParams), listOf("TERRAIN")), // also generates marble veins
Work(Lang["MENU_IO_WORLDGEN_CARVING_EARTH"], Cavegen(world, false, highlandLowlandSelectCache, params.seed, params.terragenParams), listOf("TERRAIN", "CAVE")), Work(Lang["MENU_IO_WORLDGEN_CARVING_EARTH"], Cavegen(world, false, highlandLowlandSelectCache, params.seed, params.terragenParams), listOf("TERRAIN", "CAVE")),
Work(Lang["MENU_IO_WORLDGEN_FLOODING_UNDERGROUND"], Aquagen(world, false, groundScalingCached, params.seed, params.terragenParams), listOf("WATER")), Work(Lang["MENU_IO_WORLDGEN_FLOODING_UNDERGROUND"], Aquagen(world, false, groundScalingCached, params.seed, params.terragenParams), listOf("WATER")),
Work(Lang["MENU_IO_WORLDGEN_GROWING_MINERALS"], Oregen(world, false, caveAttenuateBiasScaledForOresCache, params.seed, oreRegistry), listOf("ORES")), Work(Lang["MENU_IO_WORLDGEN_GROWING_MINERALS"], Oregen(world, false, caveAttenuateBiasScaledForOresCache, params.seed, oreRegistry, params.terragenParams), listOf("ORES")),
Work(Lang["MENU_IO_WORLDGEN_POSITIONING_ROCKS"], OregenAutotiling(world, false, params.seed, oreTilingModes), listOf("ORES")), Work(Lang["MENU_IO_WORLDGEN_POSITIONING_ROCKS"], OregenAutotiling(world, false, params.seed, oreTilingModes), listOf("ORES")),
// TODO generate gemstones // TODO generate gemstones
Work(Lang["MENU_IO_WORLDGEN_PAINTING_GREEN"], Biomegen(world, false, params.seed, params.biomegenParams, biomeMap), listOf("BIOME")), Work(Lang["MENU_IO_WORLDGEN_PAINTING_GREEN"], Biomegen(world, false, params.seed, params.biomegenParams, biomeMap), listOf("BIOME")),