mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
Update WorldgenLoadScreen.kt, Terragen.kt, and WorldgenNoiseSandbox.kt
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package net.torvald.terrarum.modulebasegame
|
||||
|
||||
import com.badlogic.gdx.ScreenAdapter
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.IngameInstance
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.util.HistoryArray
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* World loading screen with minecraft 1.14-style preview
|
||||
*
|
||||
* Created by minjaesong on 2019-11-09.
|
||||
*/
|
||||
class WorldgenLoadScreen(private var world: GameWorld, private var screenToLoad: IngameInstance) : ScreenAdapter() {
|
||||
|
||||
// a Class impl is chosen to make resize-handling easier, there's not much benefit making this a singleton anyway
|
||||
|
||||
companion object {
|
||||
private const val WIDTH_RATIO = 0.6
|
||||
}
|
||||
|
||||
private val previewWidth = (AppLoader.screenW * WIDTH_RATIO).roundToInt()
|
||||
private val previewHeight = (AppLoader.screenW * WIDTH_RATIO * world.height / world.width).roundToInt()
|
||||
|
||||
private lateinit var screenLoadingThread: Thread
|
||||
|
||||
|
||||
private val messages = HistoryArray<String>(20)
|
||||
|
||||
}
|
||||
@@ -5,9 +5,11 @@ import com.sudoplay.joise.module.*
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.LoadScreen
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.concurrent.ThreadExecutor
|
||||
import net.torvald.terrarum.concurrent.ThreadParallel
|
||||
import net.torvald.terrarum.concurrent.mapToThreadPoolDirectly
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import java.util.concurrent.Future
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
@@ -16,17 +18,21 @@ import kotlin.math.sin
|
||||
*/
|
||||
class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, params) {
|
||||
|
||||
private var genFuture: Future<*>? = null
|
||||
override var generationStarted: Boolean = false
|
||||
override val generationDone: Boolean
|
||||
get() = generationStarted && ThreadParallel.allFinished()
|
||||
get() = generationStarted && genFuture?.isDone ?: false
|
||||
|
||||
override fun run() {
|
||||
val joise = getGenerator(seed, params as TerragenParams)
|
||||
|
||||
(0 until world.width).mapToThreadPoolDirectly(this.javaClass.simpleName) { range ->
|
||||
for (y in 0 until world.height) {
|
||||
printdbg(this, "Tile draw for y=$y")
|
||||
for (x in range) {
|
||||
generationStarted = true
|
||||
|
||||
// single-threaded impl because I couldn't resolve multithread memory corruption issue...
|
||||
genFuture = ThreadExecutor.submit {
|
||||
for (x in 0 until world.width) {
|
||||
//printdbg(this, "Tile draw for y=$y")
|
||||
for (y in 0 until world.height) {
|
||||
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
|
||||
@@ -39,8 +45,6 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
||||
}
|
||||
}
|
||||
|
||||
generationStarted = true
|
||||
ThreadParallel.startAllWaitForDie()
|
||||
printdbg(this, "Waking up Worldgen")
|
||||
//Worldgen.wake()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user