mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-17 00:56:07 +09:00
terragen: making sky-to-ground ratio to be constant
This commit is contained in:
Binary file not shown.
@@ -18,13 +18,16 @@ import kotlin.math.sin
|
|||||||
*/
|
*/
|
||||||
class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, params) {
|
class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, params) {
|
||||||
|
|
||||||
private val genSlices = world.width / 8
|
private val genSlices = maxOf(world.width, ThreadExecutor.threadCount, world.width / 8)
|
||||||
|
|
||||||
private var genFutures: Array<Future<*>?> = arrayOfNulls(genSlices)
|
private var genFutures: Array<Future<*>?> = arrayOfNulls(genSlices)
|
||||||
override var generationStarted: Boolean = false
|
override var generationStarted: Boolean = false
|
||||||
override val generationDone: Boolean
|
override val generationDone: Boolean
|
||||||
get() = generationStarted && genFutures.fold(true) { acc, f -> acc and (f?.isDone ?: true) }
|
get() = generationStarted && genFutures.fold(true) { acc, f -> acc and (f?.isDone ?: true) }
|
||||||
|
|
||||||
|
private val YHEIGHT_MAGIC = 2800.0 / 3.0
|
||||||
|
private val YHEIGHT_DIVISOR = 2.0 / 7.0
|
||||||
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
|
|
||||||
generationStarted = true
|
generationStarted = true
|
||||||
@@ -38,7 +41,8 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
|||||||
val sampleOffset = world.width / 8.0
|
val sampleOffset = world.width / 8.0
|
||||||
val sampleX = sin(sampleTheta) * sampleOffset + sampleOffset // plus sampleOffset to make only
|
val sampleX = sin(sampleTheta) * sampleOffset + sampleOffset // plus sampleOffset to make only
|
||||||
val sampleZ = cos(sampleTheta) * sampleOffset + sampleOffset // positive points are to be sampled
|
val sampleZ = cos(sampleTheta) * sampleOffset + sampleOffset // positive points are to be sampled
|
||||||
val sampleY = y.toDouble()
|
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) }
|
val noise = localJoise.map { it.get(sampleX, sampleY, sampleZ) }
|
||||||
|
|
||||||
draw(x, y, noise, world)
|
draw(x, y, noise, world)
|
||||||
@@ -50,7 +54,6 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
|||||||
ThreadExecutor.join()
|
ThreadExecutor.join()
|
||||||
|
|
||||||
printdbg(this, "Waking up Worldgen")
|
printdbg(this, "Waking up Worldgen")
|
||||||
//Worldgen.wake()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,31 +28,19 @@ object Worldgen {
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
for (i in 0 until jobs.size) {
|
for (i in jobs.indices) {
|
||||||
printdbg(this, "Worldgen: job #$i")
|
printdbg(this, "Worldgen: job #$i")
|
||||||
|
|
||||||
val it = jobs[i]
|
val it = jobs[i]
|
||||||
|
|
||||||
AppLoader.getLoadScreen().addMessage(it.loadingScreenName)
|
AppLoader.getLoadScreen().addMessage(it.loadingScreenName)
|
||||||
it.theWork.run()
|
it.theWork.run()
|
||||||
|
|
||||||
// wait
|
|
||||||
//while (!it.theWork.generationDone) { } // busy wait
|
|
||||||
//synchronized(threadLock) {
|
|
||||||
// threadLock.wait()
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printdbg(this, "Generation job finished")
|
printdbg(this, "Generation job finished")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun wake() {
|
|
||||||
synchronized(threadLock) {
|
|
||||||
threadLock.notifyAll()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private data class Work(val loadingScreenName: String, val theWork: Gen)
|
private data class Work(val loadingScreenName: String, val theWork: Gen)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -60,12 +48,7 @@ object Worldgen {
|
|||||||
abstract class Gen(val world: GameWorld, val seed: Long, val params: Any) {
|
abstract class Gen(val world: GameWorld, val seed: Long, val params: Any) {
|
||||||
abstract var generationStarted: Boolean
|
abstract var generationStarted: Boolean
|
||||||
abstract val generationDone: Boolean
|
abstract val generationDone: Boolean
|
||||||
open fun run() {
|
open fun run() { }
|
||||||
/*if (generationDone) {
|
|
||||||
// worldgen.wake()
|
|
||||||
Worldgen.threadLock.notifyAll()
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class WorldgenParams(
|
data class WorldgenParams(
|
||||||
|
|||||||
Reference in New Issue
Block a user