newer terragen test wip

This commit is contained in:
minjaesong
2024-09-23 01:41:13 +09:00
parent e14c832028
commit a2dc001909
12 changed files with 525 additions and 18 deletions

View File

@@ -0,0 +1,439 @@
package com.sudoplay.joise.module
import com.sudoplay.joise.ModuleInstanceMap
import com.sudoplay.joise.ModuleMap
import com.sudoplay.joise.ModulePropertyMap
import java.util.*
/**
* Created by minjaesong on 2024-09-22.
*/
class TerrarumModuleCombiner : Module() {
enum class CombinerType {
ADD, MULT, MAX, MIN, AVG, VECTORISE
}
protected var sources: Array<ScalarParameter?> = arrayOfNulls(MAX_SOURCES)
protected var type: CombinerType? = null
fun ModuleCombiner(type: CombinerType?) {
this.type = type
}
fun ModuleCombiner() {
// serialization
}
fun setSource(index: Int, source: Module?) {
sources[index] = ScalarParameter(source)
}
fun setSource(index: Int, source: Double) {
sources[index] = ScalarParameter(source)
}
fun clearAllSources() {
for (i in 0 until MAX_SOURCES) {
sources[i] = null
}
}
/**
* Noise values from empty indices will be substituted with NaN
*/
fun getVectorise(x: Double, y: Double, z: Double): List<Double> {
return when (type) {
CombinerType.VECTORISE -> vectorGet(x, y, z)
else -> throw UnsupportedOperationException("Use get")
}
}
fun vectorGet(x: Double, y: Double, z: Double): List<Double> {
return sources.map { it?.get(x, y, z) ?: Double.NaN }
}
override fun get(x: Double, y: Double): Double {
return when (type) {
CombinerType.ADD -> addGet(x, y)
CombinerType.AVG -> avgGet(x, y)
CombinerType.MAX -> maxGet(x, y)
CombinerType.MIN -> minGet(x, y)
CombinerType.MULT -> multGet(x, y)
CombinerType.VECTORISE -> throw UnsupportedOperationException("Use getVector")
else -> 0.0
}
}
override fun get(x: Double, y: Double, z: Double): Double {
return when (type) {
CombinerType.ADD -> addGet(x, y, z)
CombinerType.AVG -> avgGet(x, y, z)
CombinerType.MAX -> maxGet(x, y, z)
CombinerType.MIN -> minGet(x, y, z)
CombinerType.MULT -> multGet(x, y, z)
CombinerType.VECTORISE -> throw UnsupportedOperationException("Use getVector")
else -> 0.0
}
}
override fun get(x: Double, y: Double, z: Double, w: Double): Double {
return when (type) {
CombinerType.ADD -> addGet(x, y, z, w)
CombinerType.AVG -> avgGet(x, y, z, w)
CombinerType.MAX -> maxGet(x, y, z, w)
CombinerType.MIN -> minGet(x, y, z, w)
CombinerType.MULT -> multGet(x, y, z, w)
CombinerType.VECTORISE -> throw UnsupportedOperationException("Use getVector")
else -> 0.0
}
}
override fun get(x: Double, y: Double, z: Double, w: Double, u: Double, v: Double): Double {
return when (type) {
CombinerType.ADD -> addGet(x, y, z, w, u, v)
CombinerType.AVG -> avgGet(x, y, z, w, u, v)
CombinerType.MAX -> maxGet(x, y, z, w, u, v)
CombinerType.MIN -> minGet(x, y, z, w, u, v)
CombinerType.MULT -> multGet(x, y, z, w, u, v)
CombinerType.VECTORISE -> throw UnsupportedOperationException("Use getVector")
else -> 0.0
}
}
// ==========================================================================
// = ADD
// ==========================================================================
protected fun addGet(x: Double, y: Double): Double {
var value = 0.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) value += sources[i]!![x, y]
}
return value
}
protected fun addGet(x: Double, y: Double, z: Double): Double {
var value = 0.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) value += sources[i]!![x, y, z]
}
return value
}
protected fun addGet(x: Double, y: Double, z: Double, w: Double): Double {
var value = 0.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) value += sources[i]!![x, y, z, w]
}
return value
}
protected fun addGet(
x: Double, y: Double, z: Double, w: Double, u: Double,
v: Double
): Double {
var value = 0.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) value += sources[i]!![x, y, z, w, u, v]
}
return value
}
// ==========================================================================
// = AVG
// ==========================================================================
protected fun avgGet(x: Double, y: Double): Double {
var count = 0
var value = 0.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) {
value += sources[i]!![x, y]
count++
}
}
if (count == 0) return 0.0
return value / count.toDouble()
}
protected fun avgGet(x: Double, y: Double, z: Double): Double {
var count = 0
var value = 0.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) {
value += sources[i]!![x, y, z]
count++
}
}
if (count == 0) return 0.0
return value / count.toDouble()
}
protected fun avgGet(x: Double, y: Double, z: Double, w: Double): Double {
var count = 0
var value = 0.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) {
value += sources[i]!![x, y, z, w]
count++
}
}
if (count == 0) return 0.0
return value / count.toDouble()
}
protected fun avgGet(
x: Double, y: Double, z: Double, w: Double, u: Double,
v: Double
): Double {
var count = 0
var value = 0.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) {
value += sources[i]!![x, y, z, w, u, v]
count++
}
}
if (count == 0) return 0.0
return value / count.toDouble()
}
// ==========================================================================
// = MAX
// ==========================================================================
protected fun maxGet(x: Double, y: Double): Double {
var mx: Double
var c = 0
while (c < MAX_SOURCES && sources[c] == null) {
c++
}
if (c == MAX_SOURCES) return 0.0
mx = sources[c]!![x, y]
for (d in c until MAX_SOURCES) {
if (sources[d] != null) {
val `val` = sources[d]!![x, y]
if (`val` > mx) mx = `val`
}
}
return mx
}
protected fun maxGet(x: Double, y: Double, z: Double): Double {
var mx: Double
var c = 0
while (c < MAX_SOURCES && sources[c] == null) {
c++
}
if (c == MAX_SOURCES) return 0.0
mx = sources[c]!![x, y, z]
for (d in c until MAX_SOURCES) {
if (sources[d] != null) {
val `val` = sources[d]!![x, y, z]
if (`val` > mx) mx = `val`
}
}
return mx
}
protected fun maxGet(x: Double, y: Double, z: Double, w: Double): Double {
var mx: Double
var c = 0
while (c < MAX_SOURCES && sources[c] == null) {
c++
}
if (c == MAX_SOURCES) return 0.0
mx = sources[c]!![x, y, z, w]
for (d in c until MAX_SOURCES) {
if (sources[d] != null) {
val `val` = sources[d]!![x, y, z, w]
if (`val` > mx) mx = `val`
}
}
return mx
}
protected fun maxGet(
x: Double, y: Double, z: Double, w: Double, u: Double,
v: Double
): Double {
var mx: Double
var c = 0
while (c < MAX_SOURCES && sources[c] == null) {
c++
}
if (c == MAX_SOURCES) return 0.0
mx = sources[c]!![x, y, z, w, u, v]
for (d in c until MAX_SOURCES) {
if (sources[d] != null) {
val `val` = sources[d]!![x, y, z, w, u, v]
if (`val` > mx) mx = `val`
}
}
return mx
}
// ==========================================================================
// = MIN
// ==========================================================================
protected fun minGet(x: Double, y: Double): Double {
var mn: Double
var c = 0
while (c < MAX_SOURCES && sources[c] == null) {
c++
}
if (c == MAX_SOURCES) return 0.0
mn = sources[c]!![x, y]
for (d in c until MAX_SOURCES) {
if (sources[d] != null) {
val `val` = sources[d]!![x, y]
if (`val` < mn) mn = `val`
}
}
return mn
}
protected fun minGet(x: Double, y: Double, z: Double): Double {
var mn: Double
var c = 0
while (c < MAX_SOURCES && sources[c] == null) {
c++
}
if (c == MAX_SOURCES) return 0.0
mn = sources[c]!![x, y, z]
for (d in c until MAX_SOURCES) {
if (sources[d] != null) {
val `val` = sources[d]!![x, y, z]
if (`val` < mn) mn = `val`
}
}
return mn
}
protected fun minGet(x: Double, y: Double, z: Double, w: Double): Double {
var mn: Double
var c = 0
while (c < MAX_SOURCES && sources[c] == null) {
c++
}
if (c == MAX_SOURCES) return 0.0
mn = sources[c]!![x, y, z, w]
for (d in c until MAX_SOURCES) {
if (sources[d] != null) {
val `val` = sources[d]!![x, y, z, w]
if (`val` < mn) mn = `val`
}
}
return mn
}
protected fun minGet(
x: Double, y: Double, z: Double, w: Double, u: Double,
v: Double
): Double {
var mn: Double
var c = 0
while (c < MAX_SOURCES && sources[c] == null) {
c++
}
if (c == MAX_SOURCES) return 0.0
mn = sources[c]!![x, y, z, w, u, v]
for (d in c until MAX_SOURCES) {
if (sources[d] != null) {
val `val` = sources[d]!![x, y, z, w, u, v]
if (`val` < mn) mn = `val`
}
}
return mn
}
// ==========================================================================
// = MULT
// ==========================================================================
protected fun multGet(x: Double, y: Double): Double {
var value = 1.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) value *= sources[i]!![x, y]
}
return value
}
protected fun multGet(x: Double, y: Double, z: Double): Double {
var value = 1.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) value *= sources[i]!![x, y, z]
}
return value
}
protected fun multGet(x: Double, y: Double, z: Double, w: Double): Double {
var value = 1.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) value *= sources[i]!![x, y, z, w]
}
return value
}
protected fun multGet(
x: Double, y: Double, z: Double, w: Double, u: Double,
v: Double
): Double {
var value = 1.0
for (i in 0 until MAX_SOURCES) {
if (sources[i] != null) value *= sources[i]!![x, y, z, w, u, v]
}
return value
}
override fun _writeToMap(map: ModuleMap) {
val props = ModulePropertyMap(this)
writeEnum("type", type, props)
for (i in 0 until MAX_SOURCES) {
writeScalar("source$i", sources[i], props, map)
}
map[id] = props
}
override fun buildFromPropertyMap(
props: ModulePropertyMap,
map: ModuleInstanceMap
): Module {
readEnum("type", "setType", CombinerType::class.java, props)
var name: String
var o: Any?
for (i in 0 until MAX_SOURCES) {
o = props["source$i"]
if (o != null) {
name = o.toString()
setSource(i, map[name])
}
}
return this
}
}

View File

@@ -12,8 +12,12 @@ object Block {
const val STONE_QUARRIED = "basegame:17"
const val STONE_TILE_WHITE = "basegame:18"
const val STONE_BRICKS = "basegame:19"
const val STONE_SLATE = "basegame:20"
const val STONE_GNEISS = "basegame:20"
const val STONE_MARBLE = "basegame:21"
const val STONE_ORTHOCLASE = "basegame:22"
const val STONE_PLAGIOCLASE = "basegame:23"
const val STONE_MICROCLINE = "basegame:24"
const val STONE_BASALT = "basegame:25"
const val DIRT = "basegame:32"
const val GRASS = "basegame:33"

View File

@@ -5,6 +5,7 @@ import com.sudoplay.joise.module.*
import net.torvald.random.HQRNG
import net.torvald.terrarum.LoadScreenBase
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.worldgenerator.Worldgen.getClampedHeight
import net.torvald.terrarum.realestate.LandUtil.CHUNK_H
@@ -34,7 +35,7 @@ class Terragen(world: GameWorld, isFinal: Boolean, val groundScalingCached: Modu
private val groundDepthBlock = listOf(
Block.AIR, Block.DIRT, Block.STONE, Block.STONE_SLATE
Block.AIR, Block.DIRT, Block.STONE, Block.STONE_GNEISS
)
private fun Double.tiered(tiers: List<Double>): Int {
@@ -229,7 +230,10 @@ class Terragen(world: GameWorld, isFinal: Boolean, val groundScalingCached: Modu
}
interface TerragenParams {
val version: Long
val terragenTiers: List<Double>
val terragenTiles: List<ItemID>
val featureSize: Double
val lowlandScaleOffset: Double // linearly alters the height
val highlandScaleOffset: Double // linearly alters the height
@@ -245,10 +249,15 @@ interface TerragenParams {
val caveBlockageSelectThre: Double // adjust cave closing-up strength. Lower = more closing
val rockBandCutoffFreq: Double
val lavaShapeFreg: Double }
val lavaShapeFreg: Double
}
data class TerragenParamsAlpha1(
override val terragenTiers: List<Double> = listOf(.0, .5, 1.0, 2.5, 11.0 * 9999),
override val version: Long = 0L,
override val terragenTiers: List<Double> = listOf(.0, .5, 1.0, 2.5),
override val terragenTiles: List<ItemID> = listOf(Block.AIR, Block.DIRT, Block.STONE, Block.STONE_GNEISS),
override val featureSize: Double = 333.0,
override val lowlandScaleOffset: Double = -0.65, // linearly alters the height
@@ -268,10 +277,36 @@ data class TerragenParamsAlpha1(
override val rockBandCutoffFreq: Double = 4.0,
override val lavaShapeFreg: Double = 0.03,
) : TerragenParams
data class TerragenParamsAlpha2(
override val terragenTiers: List<Double> = listOf(.0, .5, 1.5, 4.2, 11.0 * 9999),
override val version: Long = 0x0000_000004_000004,
// override val terragenTiers: List<Double> = listOf(.0, .5, 1.5, 4.2),
override val terragenTiers: List<Double> = listOf(.0, .5, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 6.25, 6.50, 6.75, 7.0, 8.0, 9.0, 10.0, 11.0),
override val terragenTiles: List<ItemID> = listOf(Block.AIR, Block.DIRT,
Block.STONE, // 1.0
Block.SANDSTONE, // 1.1
Block.STONE_MICROCLINE, // 1.2
Block.STONE_ORTHOCLASE, // 1.3
Block.STONE_MARBLE, // 1.4
Block.STONE, // 1.5
Block.STONE_MICROCLINE, // 2.0
Block.STONE_PLAGIOCLASE, // 3.0
Block.STONE, // 4.0
Block.STONE_ORTHOCLASE, // 5.0
Block.STONE_MICROCLINE, // 6.0
Block.STONE_MARBLE, // 6.25
Block.STONE, // 6.50
Block.STONE_MARBLE, // 6.75
Block.STONE_PLAGIOCLASE, // 7.0
Block.STONE, // 8.0
Block.STONE_BASALT, // 9.0
Block.STONE, // 10.0
Block.STONE_GNEISS, // 11.0
),
override val featureSize: Double = 333.0,
override val lowlandScaleOffset: Double = -0.65, // linearly alters the height

View File

@@ -22,6 +22,7 @@ import net.torvald.random.HQRNG
import net.torvald.terrarum.FlippingSpriteBatch
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.concurrent.ThreadExecutor
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.inUse
import net.torvald.terrarum.modulebasegame.worldgenerator.BiomegenParams
import net.torvald.terrarum.modulebasegame.worldgenerator.TerragenParams
@@ -43,6 +44,8 @@ const val NOISEBOX_WIDTH = 90 * 18
const val NOISEBOX_HEIGHT = 90 * 26
const val TWO_PI = Math.PI * 2
//const val WORLDGEN_YOFF = 0
//const val WORLDGEN_YOFF = 1500
const val WORLDGEN_YOFF = 5400 - NOISEBOX_HEIGHT
/**
@@ -398,12 +401,15 @@ internal class TerragenTest(val params: TerragenParams) : NoiseMaker {
Color(0.97f, 0.6f, 0.56f, 1f)
)
private val groundDepthBlockWall = listOf(
/*private val groundDepthBlockWall = listOf(
Block.AIR, Block.DIRT, Block.STONE, Block.STONE_SLATE, Block.STONE_SLATE
)
private val groundDepthBlockTERR = ArrayList(groundDepthBlockWall).also {
it[it.lastIndex] = Block.AIR
}
}*/
private val groundDepthBlockWall = params.terragenTiles
private val groundDepthBlockTERR = groundDepthBlockWall
private fun Double.tiered(tiers: List<Double>): Int {
tiers.reversed().forEachIndexed { index, it ->
@@ -418,8 +424,13 @@ internal class TerragenTest(val params: TerragenParams) : NoiseMaker {
Block.AIR to Color(0f, 0f, 0f, 1f),
Block.DIRT to Color(0.588f, 0.45f, 0.3f, 1f),
Block.STONE to Color(0.4f, 0.4f, 0.4f, 1f),
Block.STONE_SLATE to Color(0.2f, 0.2f, 0.2f, 1f),
Block.STONE_MARBLE to Color(0.8f, 0.8f, 0.8f, 1f)
Block.STONE_GNEISS to Color(0.2f, 0.2f, 0.2f, 1f),
Block.STONE_MARBLE to Color(0.8f, 0.8f, 0.8f, 1f),
Block.STONE_ORTHOCLASE to Color(0xa3836bff.toInt()),
Block.STONE_PLAGIOCLASE to Color(0xaa998fff.toInt()),
Block.STONE_MICROCLINE to Color(0x9ea3adff.toInt()),
Block.STONE_BASALT to Color(0x3f3e3fff.toInt()),
Block.SANDSTONE to Color(0xe0c688ff.toInt())
)
private val COPPER_ORE = 0x00e9c8ff.toInt()
@@ -445,6 +456,8 @@ internal class TerragenTest(val params: TerragenParams) : NoiseMaker {
private val terragenYscaling = (NOISEBOX_HEIGHT / 2400.0).pow(0.75)
private val terragenTiers = (params.terragenTiers).map { it * terragenYscaling } // 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 ItemID.isRock() = this.substringAfter(':').toInt() in 16 until 32
override fun draw(x: Int, y: Int, noiseValue: List<Double>, outTex: Pixmap) {
val terr = noiseValue[0].tiered(terragenTiers)
val cave = if (noiseValue[1] < 0.5) 0 else 1
@@ -470,20 +483,20 @@ internal class TerragenTest(val params: TerragenParams) : NoiseMaker {
outTex.drawPixel(x, y,
if (water) WATER
else if (waterShell) {
if ((terrBlockNoAir == Block.STONE || terrBlockNoAir == Block.STONE_SLATE))
if (terrBlockNoAir.isRock())
ore ?: blockToCol[terrBlockNoAir]!!.toRGBA()
else
blockToCol[terrBlockNoAir]!!.toRGBA()
}
else if (oil) OIL
else if (oilShell) {
if ((terrBlockNoAir == Block.STONE || terrBlockNoAir == Block.STONE_SLATE))
if (terrBlockNoAir.isRock())
ore ?: blockToCol[terrBlockNoAir]!!.toRGBA()
else
blockToCol[terrBlockNoAir]!!.toRGBA()
}
else if (lava) LAVA
else if (ore != null && (terrBlock == Block.STONE || terrBlock == Block.STONE_SLATE)) ore
else if (ore != null && (terrBlock.isRock())) ore
else if (wallBlock == Block.AIR && terrBlock == Block.AIR) BACK
else blockToCol[terrBlock]!!.toRGBA()
)