mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
terragen now works column-wise (wip soil-rock layer dithering)
This commit is contained in:
@@ -28,22 +28,11 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
|||||||
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->
|
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->
|
||||||
ThreadExecutor.submit {
|
ThreadExecutor.submit {
|
||||||
val localJoise = getGenerator(seed, params as TerragenParams)
|
val localJoise = getGenerator(seed, params as TerragenParams)
|
||||||
//val localLock = java.lang.Object() // in an attempt to fix the "premature exit" issue of a thread run
|
for (x in xs) {
|
||||||
//synchronized(localLock) { // also see: https://stackoverflow.com/questions/28818494/threads-stopping-prematurely-for-certain-values
|
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
|
||||||
for (x in xs) {
|
val sampleOffset = world.width / 8.0
|
||||||
for (y in 0 until world.height) {
|
draw(x, localJoise, sampleTheta, sampleOffset)
|
||||||
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
|
}
|
||||||
val sampleOffset = world.width / 8.0
|
|
||||||
val sampleX = sin(sampleTheta) * sampleOffset + sampleOffset // plus sampleOffset to make only
|
|
||||||
val sampleZ = cos(sampleTheta) * sampleOffset + sampleOffset // positive points are to be sampled
|
|
||||||
val sampleY = y - (world.height - YHEIGHT_MAGIC) * YHEIGHT_DIVISOR // Q&D offsetting to make ratio of sky:ground to be constant
|
|
||||||
// DEBUG NOTE: it is the OFFSET FROM THE IDEAL VALUE (observed land height - (HEIGHT * DIVISOR)) that must be constant
|
|
||||||
val noise = localJoise.map { it.get(sampleX, sampleY, sampleZ) }
|
|
||||||
|
|
||||||
draw(x, y, noise, world)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,22 +46,31 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
|||||||
Block.AIR, Block.DIRT, Block.STONE
|
Block.AIR, Block.DIRT, Block.STONE
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun draw(x: Int, y: Int, noiseValue: List<Double>, world: GameWorld) {
|
private fun Double.tiered(vararg tiers: Double): Int {
|
||||||
fun Double.tiered(vararg tiers: Double): Int {
|
tiers.reversed().forEachIndexed { index, it ->
|
||||||
tiers.reversed().forEachIndexed { index, it ->
|
if (this >= it) return (tiers.lastIndex - index) // why??
|
||||||
if (this >= it) return (tiers.lastIndex - index) // why??
|
|
||||||
}
|
|
||||||
return tiers.lastIndex
|
|
||||||
}
|
}
|
||||||
|
return tiers.lastIndex
|
||||||
|
}
|
||||||
|
|
||||||
val terr = noiseValue[0].tiered(.0, .5, .88)
|
//private fun draw(x: Int, y: Int, width: Int, height: Int, noiseValue: List<Double>, world: GameWorld) {
|
||||||
val cave = if (noiseValue[1] < 0.5) 0 else 1
|
private fun draw(x: Int, noises: List<Joise>, st: Double, soff: Double) {
|
||||||
|
for (y in 0 until world.height) {
|
||||||
|
val sx = sin(st) * soff + soff // plus sampleOffset to make only
|
||||||
|
val sz = cos(st) * soff + soff // positive points are to be sampled
|
||||||
|
val sy = y - (world.height - YHEIGHT_MAGIC) * YHEIGHT_DIVISOR // Q&D offsetting to make ratio of sky:ground to be constant
|
||||||
|
// DEBUG NOTE: it is the OFFSET FROM THE IDEAL VALUE (observed land height - (HEIGHT * DIVISOR)) that must be constant
|
||||||
|
val noiseValue = noises.map { it.get(sx, sy, sz) }
|
||||||
|
|
||||||
val wallBlock = groundDepthBlock[terr]
|
val terr = noiseValue[0].tiered(.0, .5, .88)
|
||||||
val terrBlock = if (cave == 0) Block.AIR else wallBlock //wallBlock * cave // AIR is always zero, this is the standard
|
val cave = if (noiseValue[1] < 0.5) 0 else 1
|
||||||
|
|
||||||
world.setTileTerrain(x, y, terrBlock, true)
|
val wallBlock = groundDepthBlock[terr]
|
||||||
world.setTileWall(x, y, wallBlock, true)
|
val terrBlock = if (cave == 0) Block.AIR else wallBlock //wallBlock * cave // AIR is always zero, this is the standard
|
||||||
|
|
||||||
|
world.setTileTerrain(x, y, terrBlock, true)
|
||||||
|
world.setTileWall(x, y, wallBlock, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user