using new terragen on main game -- noisy tiles are real issue

This commit is contained in:
minjaesong
2019-10-30 15:13:38 +09:00
parent 288afba105
commit 96158c5a90
3 changed files with 42 additions and 14 deletions

View File

@@ -28,6 +28,8 @@ import net.torvald.terrarum.modulebasegame.ui.*
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
import net.torvald.terrarum.modulebasegame.worldgenerator.Worldgen
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldgenParams
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.TILE_SIZE
@@ -259,9 +261,11 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
world = gameworld
// generate terrain for the map
WorldGenerator.attachMap(world)
WorldGenerator.SEED = worldParams.worldGenSeed
WorldGenerator.generateMap()
//WorldGenerator.attachMap(world)
//WorldGenerator.SEED = worldParams.worldGenSeed
//WorldGenerator.generateMap()
Worldgen.attachMap(world, WorldgenParams(worldParams.worldGenSeed))
Worldgen.generateMap()
historicalFigureIDBucket = ArrayList<Int>()

View File

@@ -2,6 +2,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.ThreadParallel
import net.torvald.terrarum.concurrent.mapToThreadPoolDirectly
@@ -23,6 +25,7 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
(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) {
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
val sampleOffset = world.width / 8.0
@@ -36,9 +39,10 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
}
}
ThreadParallel.startAll()
generationStarted = true
super.run()
ThreadParallel.startAllWaitForDie()
printdbg(this, "Waking up Worldgen")
//Worldgen.wake()
}

View File

@@ -1,6 +1,7 @@
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
@@ -11,10 +12,17 @@ import net.torvald.terrarum.gameworld.GameWorld
*/
object Worldgen {
operator fun invoke(worldIndex: Int, params: WorldgenParams) {
val genTime = AppLoader.getTIME_T()
val world = GameWorld(worldIndex, params.width, params.height, genTime, genTime, 0)
private lateinit var world: GameWorld
private lateinit var params: WorldgenParams
private val threadLock = java.lang.Object()
fun attachMap(world: GameWorld, genParams: WorldgenParams) {
this.world = world
params = genParams
}
fun generateMap() {
val jobs = listOf(
Work("Reticulating Splines", Terragen(world, params.seed, params.terragenParams))
//Work("Adding Vegetations") { Biomegen(world, params.seed, params.biomegenParams) }
@@ -22,15 +30,28 @@ object Worldgen {
for (i in 0 until jobs.size) {
printdbg(this, "Worldgen: job #$i")
val it = jobs[i]
LoadScreen.addMessage(it.loadingScreenName)
it.theWork.run()
// busy wait
while (!it.theWork.generationDone) { }
// wait
//while (!it.theWork.generationDone) { } // busy wait
//synchronized(threadLock) {
// threadLock.wait()
//}
}
printdbg(this, "Generation job finished")
}
fun wake() {
synchronized(threadLock) {
threadLock.notifyAll()
}
}
private data class Work(val loadingScreenName: String, val theWork: Gen)
@@ -41,15 +62,14 @@ abstract class Gen(val world: GameWorld, val seed: Long, val params: Any) {
abstract var generationStarted: Boolean
abstract val generationDone: Boolean
open fun run() {
if (generationDone) {
/*if (generationDone) {
// worldgen.wake()
}
Worldgen.threadLock.notifyAll()
}*/
}
}
data class WorldgenParams(
val width: Int,
val height: Int,
val seed: Long,
// optional parametres
val terragenParams: TerragenParams = TerragenParams(),