fixed worldgen and threadexecutor so that they will actually wait for the thread termination

This commit is contained in:
minjaesong
2019-11-16 02:41:25 +09:00
parent 7939ff3690
commit e71c56cf0d
9 changed files with 74 additions and 94 deletions

View File

@@ -1,10 +1,12 @@
package net.torvald.terrarum.modulebasegame
import com.badlogic.gdx.ScreenAdapter
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.IngameInstance
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.util.HistoryArray
import net.torvald.util.CircularArray
import kotlin.math.roundToInt
/**
@@ -25,7 +27,25 @@ class WorldgenLoadScreen(private var world: GameWorld, private var screenToLoad:
private lateinit var screenLoadingThread: Thread
private lateinit var previewPixmap: Pixmap
private lateinit var previewTexture: Texture
private val messages = HistoryArray<String>(20)
private val messages = CircularArray<String>(20, true) // this many texts will be shown at once
override fun show() {
previewPixmap = Pixmap(previewWidth, previewHeight, Pixmap.Format.RGBA8888)
previewTexture = Texture(1, 1, Pixmap.Format.RGBA8888)
}
override fun render(delta: Float) {
previewTexture.dispose()
previewTexture = Texture(previewPixmap)
//
}
override fun dispose() {
previewPixmap.dispose()
previewTexture.dispose()
}
}

View File

@@ -3,11 +3,8 @@ package net.torvald.terrarum.modulebasegame.worldgenerator
import com.sudoplay.joise.Joise
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
@@ -31,7 +28,7 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
// 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")
printdbg(this, "Tile draw for x=$x")
for (y in 0 until world.height) {
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
val sampleOffset = world.width / 8.0
@@ -45,6 +42,8 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
}
}
ThreadExecutor.join()
printdbg(this, "Waking up Worldgen")
//Worldgen.wake()
}

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulebasegame.worldgenerator
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.LoadScreen
import net.torvald.terrarum.gameworld.GameWorld