mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
using Coroutines instead of Threadpool but the artefact is still there :(
This commit is contained in:
3
.idea/libraries/KotlinJavaRuntime.xml
generated
3
.idea/libraries/KotlinJavaRuntime.xml
generated
@@ -4,6 +4,9 @@
|
|||||||
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib.jar!/" />
|
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib.jar!/" />
|
||||||
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-reflect.jar!/" />
|
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-reflect.jar!/" />
|
||||||
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test.jar!/" />
|
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test.jar!/" />
|
||||||
|
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlinx-coroutines-core-1.0.1.jar!/" />
|
||||||
|
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlinx-coroutines-io-jvm-0.1.1.jar!/" />
|
||||||
|
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlinx-coroutines-jdk8-1.0.1.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
|
|||||||
7
.idea/libraries/lib.xml
generated
7
.idea/libraries/lib.xml
generated
@@ -4,24 +4,17 @@
|
|||||||
<root url="file://$PROJECT_DIR$/lib" />
|
<root url="file://$PROJECT_DIR$/lib" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC>
|
<JAVADOC>
|
||||||
<root url="file://$PROJECT_DIR$/lib/javadoc" />
|
|
||||||
<root url="http://libgdx.badlogicgames.com/nightlies/docs/api/" />
|
<root url="http://libgdx.badlogicgames.com/nightlies/docs/api/" />
|
||||||
<root url="https://libgdx.badlogicgames.com/ci/nightlies/docs/api/" />
|
<root url="https://libgdx.badlogicgames.com/ci/nightlies/docs/api/" />
|
||||||
<root url="jar://$PROJECT_DIR$/lib/javadoc/gdx-docs.zip!/" />
|
|
||||||
</JAVADOC>
|
</JAVADOC>
|
||||||
<NATIVE>
|
<NATIVE>
|
||||||
<root url="file://$PROJECT_DIR$/lib" />
|
<root url="file://$PROJECT_DIR$/lib" />
|
||||||
<root url="file://$PROJECT_DIR$/lib/x86" />
|
|
||||||
<root url="file://$PROJECT_DIR$/lib/x86_64" />
|
|
||||||
</NATIVE>
|
</NATIVE>
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/source" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/Terrarum_Joise.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/Terrarum_Joise.jar!/" />
|
||||||
<root url="jar://$PROJECT_DIR$/lib/source/gdx-backend-lwjgl-sources.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/TerrarumSansBitmap.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/TerrarumSansBitmap.jar!/" />
|
||||||
<root url="jar://$PROJECT_DIR$/lib/prtree.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/prtree.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/source" recursive="false" type="SOURCES" />
|
|
||||||
</library>
|
</library>
|
||||||
</component>
|
</component>
|
||||||
@@ -14,7 +14,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||||
import com.sudoplay.joise.Joise
|
import com.sudoplay.joise.Joise
|
||||||
import com.sudoplay.joise.module.*
|
import com.sudoplay.joise.module.*
|
||||||
import net.torvald.UnsafeHelper
|
|
||||||
import net.torvald.UnsafePtr
|
import net.torvald.UnsafePtr
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.concurrent.*
|
import net.torvald.terrarum.concurrent.*
|
||||||
@@ -24,10 +23,10 @@ import net.torvald.terrarum.modulebasegame.worldgenerator.BiomegenParams
|
|||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.TerragenParams
|
import net.torvald.terrarum.modulebasegame.worldgenerator.TerragenParams
|
||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.shake
|
import net.torvald.terrarum.modulebasegame.worldgenerator.shake
|
||||||
import net.torvald.terrarum.worlddrawer.toRGBA
|
import net.torvald.terrarum.worlddrawer.toRGBA
|
||||||
import java.util.concurrent.Future
|
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
const val WIDTH = 768
|
const val WIDTH = 768
|
||||||
const val HEIGHT = 512
|
const val HEIGHT = 512
|
||||||
@@ -50,7 +49,7 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
private val RNG = HQRNG()
|
private val RNG = HQRNG()
|
||||||
private var seed = 10000L
|
private var seed = 10000L
|
||||||
|
|
||||||
private var generationDone = false
|
private var initialGenDone = false
|
||||||
private var generateKeyLatched = false
|
private var generateKeyLatched = false
|
||||||
|
|
||||||
private var generationTimeInMeasure = false
|
private var generationTimeInMeasure = false
|
||||||
@@ -76,7 +75,7 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
private var generationTime = 0f
|
private var generationTime = 0f
|
||||||
|
|
||||||
override fun render() {
|
override fun render() {
|
||||||
if (!generationDone) {
|
if (!initialGenDone) {
|
||||||
joise = getNoiseGenerator(seed)
|
joise = getNoiseGenerator(seed)
|
||||||
renderNoise()
|
renderNoise()
|
||||||
}
|
}
|
||||||
@@ -96,13 +95,14 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
renderNoise()
|
renderNoise()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val coroutineExecFinished = (coroutineJobs.fold(true) { acc, it -> acc and it.isCompleted })
|
||||||
// check if generation is done
|
// check if generation is done
|
||||||
if (threadExecFinished) {
|
if (coroutineExecFinished) {
|
||||||
generateKeyLatched = false
|
generateKeyLatched = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish time measurement
|
// finish time measurement
|
||||||
if (threadExecFinished && generationTimeInMeasure) {
|
if (coroutineExecFinished && generationTimeInMeasure) {
|
||||||
generationTimeInMeasure = false
|
generationTimeInMeasure = false
|
||||||
val time = System.nanoTime() - generationStartTime
|
val time = System.nanoTime() - generationStartTime
|
||||||
generationTime = time / 1000000000f
|
generationTime = time / 1000000000f
|
||||||
@@ -129,10 +129,6 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
|
|
||||||
private val sampleOffset = WIDTH / 8.0
|
private val sampleOffset = WIDTH / 8.0
|
||||||
|
|
||||||
private val threadExecFuture = Array<Future<*>?>(ThreadExecutor.threadCount) { null }
|
|
||||||
private val threadExecFinished: Boolean
|
|
||||||
get() = threadExecFuture.fold(true) { acc, future -> acc && (future?.isDone ?: true) }
|
|
||||||
|
|
||||||
private val testColSet = arrayOf(
|
private val testColSet = arrayOf(
|
||||||
Color(0xff0000ff.toInt()),
|
Color(0xff0000ff.toInt()),
|
||||||
Color(0xffff00ff.toInt()),
|
Color(0xffff00ff.toInt()),
|
||||||
@@ -165,7 +161,10 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val xSlices = (0 until WIDTH).sliceEvenly(ThreadExecutor.threadCount)
|
//private val xSlices = (0 until WIDTH).sliceEvenly(ThreadExecutor.threadCount)
|
||||||
|
private val xSlices = (0 until WIDTH).sliceEvenly(WIDTH / 8)
|
||||||
|
|
||||||
|
private lateinit var coroutineJobs: List<Job>
|
||||||
|
|
||||||
private fun renderNoise() {
|
private fun renderNoise() {
|
||||||
generationStartTime = System.nanoTime()
|
generationStartTime = System.nanoTime()
|
||||||
@@ -201,11 +200,13 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runnables.forEachIndexed { index, function ->
|
/*runnables.forEachIndexed { index, function ->
|
||||||
threadExecFuture[index] = ThreadExecutor.submit(function)
|
threadExecFuture[index] = ThreadExecutor.submit(function)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
generationDone = true
|
coroutineJobs = runnables.map { r -> GlobalScope.launch { r() } }
|
||||||
|
|
||||||
|
initialGenDone = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
|
|||||||
Reference in New Issue
Block a user