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

View File

@@ -520,8 +520,9 @@ object ModMgr {
val freq = rec.get("freq").toDouble()
val power = rec.get("power").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) {

View File

@@ -143,8 +143,9 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
}
data class OregenParams(
val tile: String,
val tile: String, // ores@<modname>:<id>
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 tiling: String, // a16, a47, r16, r8
)

View File

@@ -1,10 +1,13 @@
package net.torvald.terrarum.modulebasegame.worldgenerator
import net.torvald.random.XXHash64
import net.torvald.terrarum.Point2i
import net.torvald.terrarum.concurrent.sliceEvenly
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.isOre
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.serialise.toBig64
import net.torvald.terrarum.toInt
import net.torvald.terrarum.utils.OrePlacement
import net.torvald.terrarum.worlddrawer.BlocksDrawer
@@ -13,7 +16,7 @@ import kotlin.math.max
/**
* 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 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)
if (ore.isOre()) {
// get placement (tile connection) info
val autotiled = getNearbyOres8(x, y).foldIndexed(0) { index, acc, placement ->
acc or (placement.item == ore).toInt(index)
// get tiling mode
val tilingMode = tilingModes[ore]
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
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.BlockCodex
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.GameWorld
import kotlin.math.roundToLong
@@ -39,6 +40,10 @@ object Worldgen {
private val oreRegistry = ArrayList<OregenParams>()
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 } }
else {
{ work: Work ->
@@ -48,7 +53,7 @@ object Worldgen {
return listOf(
Work("Reticulating Splines", Terragen(world, highlandLowlandSelectCache, params.seed, params.terragenParams), listOf("TERRAIN")),
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")),
).filter(tagFilter)
}