options for ore spawn tiling; actual ore tile textures

This commit is contained in:
minjaesong
2023-10-27 13:21:29 +09:00
parent 19f1eb2278
commit ffac61fbc5
10 changed files with 66 additions and 14 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,20 @@
"id";"freq";"power";"scale";"comment" "id";"freq";"power";"scale";"tiling";"comment"
"1";"0.026";"0.01";"0.505";"copper (malachite)" "1";"0.026";"0.01";"0.505";"a16";"copper (malachite)"
"2";"0.040";"0.01";"0.505";"iron (haematite)" "2";"0.040";"0.01";"0.505";"a16";"iron (haematite)"
#"3";"0.040";"0.08";"0.501";"coal" #"3";"0.040";"0.08";"0.501";"r16";"coal"
################################################################################
# id: ore ID to spawn, the ID must exist on the ores.csv
#
# 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
#
# tiling: determines how the tiles are tiled
# - a16: use 4-neighbour autotiling (16 possible cases)
# - a47: use 8-neighbour autotiling (47 possible cases)
# - r16: use the hash of the tile position as a variant selection, module 16
# - r8: use the hash of the tile position as a variant selection, module 8
#
# comment: human-readable comments, not actually parsed
Can't render this file because it contains an unexpected character in line 4 and column 2.

View File

@@ -520,8 +520,9 @@ object ModMgr {
val freq = rec.get("freq").toDouble() val freq = rec.get("freq").toDouble()
val power = rec.get("power").toDouble() val power = rec.get("power").toDouble()
val scale = rec.get("scale").toDouble() val scale = rec.get("scale").toDouble()
val tiling = rec.get("tiling")
Worldgen.registerOre(OregenParams(tile, freq, power, scale)) Worldgen.registerOre(OregenParams(tile, freq, power, scale, tiling))
} }
} }
catch (e: IOException) { catch (e: IOException) {

View File

@@ -143,8 +143,9 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
} }
data class OregenParams( data class OregenParams(
val tile: String, val tile: String, // ores@<modname>:<id>
val freq: Double, //adjust the "density" of the caves val freq: Double, //adjust the "density" of the caves
val power: Double, // adjust the "concentration" of the cave gen. Lower = larger voids 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 scale: Double, // also adjust this if you've touched the bias value. Number can be greater than 1.0
val tiling: String, // a16, a47, r16, r8
) )

View File

@@ -1,10 +1,13 @@
package net.torvald.terrarum.modulebasegame.worldgenerator package net.torvald.terrarum.modulebasegame.worldgenerator
import net.torvald.random.XXHash64
import net.torvald.terrarum.Point2i import net.torvald.terrarum.Point2i
import net.torvald.terrarum.concurrent.sliceEvenly import net.torvald.terrarum.concurrent.sliceEvenly
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.isOre import net.torvald.terrarum.gameitems.isOre
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.serialise.toBig64
import net.torvald.terrarum.toInt import net.torvald.terrarum.toInt
import net.torvald.terrarum.utils.OrePlacement import net.torvald.terrarum.utils.OrePlacement
import net.torvald.terrarum.worlddrawer.BlocksDrawer import net.torvald.terrarum.worlddrawer.BlocksDrawer
@@ -13,7 +16,7 @@ import kotlin.math.max
/** /**
* Created by minjaesong on 2023-10-26. * Created by minjaesong on 2023-10-26.
*/ */
class OregenAutotiling(world: GameWorld, seed: Long) : Gen(world, seed) { class OregenAutotiling(world: GameWorld, seed: Long, val tilingModes: HashMap<ItemID, String>) : Gen(world, seed) {
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
private val genSlices = max(threadExecutor.threadCount, world.width / 8) private val genSlices = max(threadExecutor.threadCount, world.width / 8)
@@ -37,11 +40,34 @@ class OregenAutotiling(world: GameWorld, seed: Long) : Gen(world, seed) {
val (ore, _) = world.getTileFromOre(x, y) val (ore, _) = world.getTileFromOre(x, y)
if (ore.isOre()) { if (ore.isOre()) {
// get placement (tile connection) info // get tiling mode
val autotiled = getNearbyOres8(x, y).foldIndexed(0) { index, acc, placement -> val tilingMode = tilingModes[ore]
acc or (placement.item == ore).toInt(index)
val placement = when (tilingMode) {
"a16" -> {
// get placement (tile connection) info
val autotiled = getNearbyOres8(x, y).foldIndexed(0) { index, acc, placement ->
acc or (placement.item == ore).toInt(index)
}
BlocksDrawer.connectLut16[autotiled]
}
"a47" -> {
// get placement (tile connection) info
val autotiled = getNearbyOres8(x, y).foldIndexed(0) { index, acc, placement ->
acc or (placement.item == ore).toInt(index)
}
BlocksDrawer.connectLut47[autotiled]
}
"r16" -> {
(XXHash64.hash((y.toLong().shl(32) or x.toLong().and(0xFFFFFFFF)).toBig64(), 16L) % 16).toInt()
}
"r8" -> {
(XXHash64.hash((y.toLong().shl(32) or x.toLong().and(0xFFFFFFFF)).toBig64(), 8L) % 8).toInt()
}
else -> throw IllegalArgumentException("Unknown tiling mode: $tilingMode")
} }
val placement = BlocksDrawer.connectLut16[autotiled]
// actually put the ore block // actually put the ore block
world.setTileOre(x, y, ore, placement) // autotiling will be handled by the other worldgen process world.setTileOre(x, y, ore, placement) // autotiling will be handled by the other worldgen process

View File

@@ -5,6 +5,7 @@ import net.torvald.random.XXHash64
import net.torvald.terrarum.App import net.torvald.terrarum.App
import net.torvald.terrarum.App.* import net.torvald.terrarum.App.*
import net.torvald.terrarum.BlockCodex import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import kotlin.math.roundToLong import kotlin.math.roundToLong
@@ -39,6 +40,10 @@ object Worldgen {
private val oreRegistry = ArrayList<OregenParams>() private val oreRegistry = ArrayList<OregenParams>()
fun getJobs(tags: List<String> = emptyList()): List<Work> { fun getJobs(tags: List<String> = emptyList()): List<Work> {
val oreTilingModes = HashMap<ItemID, String>().also {
it.putAll(oreRegistry.map { it.tile to it.tiling })
}
val tagFilter = if (tags.isEmpty()) { { work: Work -> true } } val tagFilter = if (tags.isEmpty()) { { work: Work -> true } }
else { else {
{ work: Work -> { work: Work ->
@@ -48,7 +53,7 @@ object Worldgen {
return listOf( return listOf(
Work("Reticulating Splines", Terragen(world, highlandLowlandSelectCache, params.seed, params.terragenParams), listOf("TERRAIN")), Work("Reticulating Splines", Terragen(world, highlandLowlandSelectCache, params.seed, params.terragenParams), listOf("TERRAIN")),
Work("Adding Rocks", Oregen(world, caveAttenuateBiasScaled, params.seed, oreRegistry), listOf("ORES")), Work("Adding Rocks", Oregen(world, caveAttenuateBiasScaled, params.seed, oreRegistry), listOf("ORES")),
Work("Positioning Rocks", OregenAutotiling(world, params.seed), listOf("ORES")), Work("Positioning Rocks", OregenAutotiling(world, params.seed, oreTilingModes), listOf("ORES")),
Work("Adding Vegetations", Biomegen(world, params.seed, params.biomegenParams), listOf("BIOME")), Work("Adding Vegetations", Biomegen(world, params.seed, params.biomegenParams), listOf("BIOME")),
).filter(tagFilter) ).filter(tagFilter)
} }

Binary file not shown.