mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-15 08:06:06 +09:00
worldgen estimation change; common worldgen variables moved to Worldgen.kt
This commit is contained in:
@@ -300,10 +300,12 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
|
|||||||
App.fontGame.draw(batch, Lang["CONTEXT_GENERATOR_SEED"], drawX - 4, drawY + sizeSelY + inputLineY2)
|
App.fontGame.draw(batch, Lang["CONTEXT_GENERATOR_SEED"], drawX - 4, drawY + sizeSelY + inputLineY2)
|
||||||
|
|
||||||
val (wx, wy) = TerrarumIngame.NEW_WORLD_SIZE[sizeSelector.selection]
|
val (wx, wy) = TerrarumIngame.NEW_WORLD_SIZE[sizeSelector.selection]
|
||||||
val etaMin = Worldgen.getEstimationSec(wx, wy).div(60f).roundToInt().coerceAtLeast(1)
|
val etaSec = Worldgen.getEstimationSec(wx, wy)
|
||||||
|
val etaMin = etaSec.div(60f).roundToInt().coerceAtLeast(1)
|
||||||
val etaText = Lang.getAndUseTemplate("CONTEXT_ESTIMATED_MINUTES_PLURAL", true, etaMin)
|
val etaText = Lang.getAndUseTemplate("CONTEXT_ESTIMATED_MINUTES_PLURAL", true, etaMin)
|
||||||
|
val etaTextPrint = etaText + (if (App.IS_DEVELOPMENT_BUILD) " ($etaSec s)" else "")
|
||||||
|
|
||||||
Toolkit.drawTextCentered(batch, App.fontGame, etaText, width, drawX, drawY + sizeSelY + inputLineY3)
|
Toolkit.drawTextCentered(batch, App.fontGame, etaTextPrint, width, drawX, drawY + sizeSelY + inputLineY3)
|
||||||
}
|
}
|
||||||
else if (mode == 1) {
|
else if (mode == 1) {
|
||||||
// code input labels
|
// code input labels
|
||||||
|
|||||||
@@ -195,10 +195,12 @@ class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() {
|
|||||||
App.fontGame.draw(batch, Lang["CONTEXT_PLACE_COORDINATE"], drawX - 4, drawY + sizeSelY + inputLineY2)
|
App.fontGame.draw(batch, Lang["CONTEXT_PLACE_COORDINATE"], drawX - 4, drawY + sizeSelY + inputLineY2)
|
||||||
|
|
||||||
val (wx, wy) = TerrarumIngame.NEW_WORLD_SIZE[sizeSelector.selection]
|
val (wx, wy) = TerrarumIngame.NEW_WORLD_SIZE[sizeSelector.selection]
|
||||||
val etaMin = Worldgen.getEstimationSec(wx, wy).div(60f).roundToInt().coerceAtLeast(1)
|
val etaSec = Worldgen.getEstimationSec(wx, wy)
|
||||||
|
val etaMin = etaSec.div(60f).roundToInt().coerceAtLeast(1)
|
||||||
val etaText = Lang.getAndUseTemplate("CONTEXT_ESTIMATED_MINUTES_PLURAL", true, etaMin)
|
val etaText = Lang.getAndUseTemplate("CONTEXT_ESTIMATED_MINUTES_PLURAL", true, etaMin)
|
||||||
|
val etaTextPrint = etaText + (if (App.IS_DEVELOPMENT_BUILD) " ($etaSec s)" else "")
|
||||||
|
|
||||||
Toolkit.drawTextCentered(batch, App.fontGame, etaText, width, drawX, drawY + sizeSelY + inputLineY3)
|
Toolkit.drawTextCentered(batch, App.fontGame, etaTextPrint, width, drawX, drawY + sizeSelY + inputLineY3)
|
||||||
|
|
||||||
// memory gauge
|
// memory gauge
|
||||||
val chunksUsed = full.chunksUsed
|
val chunksUsed = full.chunksUsed
|
||||||
|
|||||||
@@ -19,19 +19,15 @@ import kotlin.math.sin
|
|||||||
*/
|
*/
|
||||||
class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, params) {
|
class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, params) {
|
||||||
|
|
||||||
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
|
||||||
|
|
||||||
private val genSlices = max(threadExecutor.threadCount, world.width / 9)
|
|
||||||
|
|
||||||
private val YHEIGHT_MAGIC = 2800.0 / 3.0
|
private val YHEIGHT_MAGIC = 2800.0 / 3.0
|
||||||
private val YHEIGHT_DIVISOR = 2.0 / 7.0
|
private val YHEIGHT_DIVISOR = 2.0 / 7.0
|
||||||
|
|
||||||
override fun getDone(loadscreen: LoadScreenBase) {
|
override fun getDone(loadscreen: LoadScreenBase) {
|
||||||
// loadscreen.progress.set((loadscreen.progress.get() + 0x1_000000_000000L) and 0x7FFF_000000_000000L)
|
// loadscreen.progress.set((loadscreen.progress.get() + 0x1_000000_000000L) and 0x7FFF_000000_000000L)
|
||||||
|
|
||||||
threadExecutor.renew()
|
Worldgen.threadExecutor.renew()
|
||||||
(0 until world.width).sliceEvenly(genSlices).map { xs ->
|
(0 until world.width).sliceEvenly(Worldgen.genSlices).map { xs ->
|
||||||
threadExecutor.submit {
|
Worldgen.threadExecutor.submit {
|
||||||
val localJoise = getGenerator(seed, params as BiomegenParams)
|
val localJoise = getGenerator(seed, params as BiomegenParams)
|
||||||
for (x in xs) {
|
for (x in xs) {
|
||||||
for (y in 0 until world.height) {
|
for (y in 0 until world.height) {
|
||||||
@@ -49,7 +45,7 @@ class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
threadExecutor.join()
|
Worldgen.threadExecutor.join()
|
||||||
|
|
||||||
App.printdbg(this, "Waking up Worldgen")
|
App.printdbg(this, "Waking up Worldgen")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,17 +18,13 @@ import kotlin.math.sqrt
|
|||||||
* Created by minjaesong on 2023-10-25.
|
* Created by minjaesong on 2023-10-25.
|
||||||
*/
|
*/
|
||||||
class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, private val ores: List<OregenParams>) : Gen(world, seed) {
|
class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleDomain, seed: Long, private val ores: List<OregenParams>) : Gen(world, seed) {
|
||||||
|
|
||||||
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
|
||||||
private val genSlices = max(threadExecutor.threadCount, world.width / 9)
|
|
||||||
|
|
||||||
override fun getDone(loadscreen: LoadScreenBase) {
|
override fun getDone(loadscreen: LoadScreenBase) {
|
||||||
loadscreen.stageValue += 1
|
loadscreen.stageValue += 1
|
||||||
loadscreen.progress.set(0L)
|
loadscreen.progress.set(0L)
|
||||||
|
|
||||||
threadExecutor.renew()
|
Worldgen.threadExecutor.renew()
|
||||||
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->
|
(0 until world.width).sliceEvenly(Worldgen.genSlices).mapIndexed { i, xs ->
|
||||||
threadExecutor.submit {
|
Worldgen.threadExecutor.submit {
|
||||||
val localJoise = getGenerator(seed)
|
val localJoise = getGenerator(seed)
|
||||||
for (x in xs) {
|
for (x in xs) {
|
||||||
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
|
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
|
||||||
@@ -39,7 +35,7 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
threadExecutor.join()
|
Worldgen.threadExecutor.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,20 +20,17 @@ import kotlin.math.max
|
|||||||
*/
|
*/
|
||||||
class OregenAutotiling(world: GameWorld, seed: Long, val tilingModes: HashMap<ItemID, String>) : Gen(world, seed) {
|
class OregenAutotiling(world: GameWorld, seed: Long, val tilingModes: HashMap<ItemID, String>) : Gen(world, seed) {
|
||||||
|
|
||||||
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
|
||||||
private val genSlices = max(threadExecutor.threadCount, world.width / 9)
|
|
||||||
|
|
||||||
override fun getDone(loadscreen: LoadScreenBase) {
|
override fun getDone(loadscreen: LoadScreenBase) {
|
||||||
threadExecutor.renew()
|
Worldgen.threadExecutor.renew()
|
||||||
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->
|
(0 until world.width).sliceEvenly(Worldgen.genSlices).mapIndexed { i, xs ->
|
||||||
threadExecutor.submit {
|
Worldgen.threadExecutor.submit {
|
||||||
for (x in xs) {
|
for (x in xs) {
|
||||||
draw(x)
|
draw(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
threadExecutor.join()
|
Worldgen.threadExecutor.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getHashCoord(x: Int, y: Int, mod: Int) =
|
private fun getHashCoord(x: Int, y: Int, mod: Int) =
|
||||||
|
|||||||
@@ -24,11 +24,6 @@ class Terragen(world: GameWorld, val highlandLowlandSelectCache: ModuleCache, se
|
|||||||
const val YHEIGHT_DIVISOR = 2.0 / 7.0
|
const val YHEIGHT_DIVISOR = 2.0 / 7.0
|
||||||
}
|
}
|
||||||
|
|
||||||
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
|
||||||
|
|
||||||
private val genSlices = max(threadExecutor.threadCount, world.width / 9)
|
|
||||||
|
|
||||||
|
|
||||||
private val dirtStoneDitherSize = 3 // actual dither size will be double of this value
|
private val dirtStoneDitherSize = 3 // actual dither size will be double of this value
|
||||||
private val stoneSlateDitherSize = 4
|
private val stoneSlateDitherSize = 4
|
||||||
|
|
||||||
@@ -36,9 +31,9 @@ class Terragen(world: GameWorld, val highlandLowlandSelectCache: ModuleCache, se
|
|||||||
loadscreen.stageValue += 1
|
loadscreen.stageValue += 1
|
||||||
loadscreen.progress.set(0L)
|
loadscreen.progress.set(0L)
|
||||||
|
|
||||||
threadExecutor.renew()
|
Worldgen.threadExecutor.renew()
|
||||||
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->
|
(0 until world.width).sliceEvenly(Worldgen.genSlices).mapIndexed { i, xs ->
|
||||||
threadExecutor.submit {
|
Worldgen.threadExecutor.submit {
|
||||||
val localJoise = getGenerator(seed, params as TerragenParams)
|
val localJoise = getGenerator(seed, params as TerragenParams)
|
||||||
for (x in xs) {
|
for (x in xs) {
|
||||||
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
|
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
|
||||||
@@ -49,7 +44,7 @@ class Terragen(world: GameWorld, val highlandLowlandSelectCache: ModuleCache, se
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
threadExecutor.join()
|
Worldgen.threadExecutor.join()
|
||||||
|
|
||||||
printdbg(this, "Waking up Worldgen")
|
printdbg(this, "Waking up Worldgen")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import net.torvald.terrarum.BlockCodex
|
|||||||
import net.torvald.terrarum.LoadScreenBase
|
import net.torvald.terrarum.LoadScreenBase
|
||||||
import net.torvald.terrarum.gameitems.ItemID
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.roundToLong
|
import kotlin.math.roundToLong
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,6 +23,9 @@ object Worldgen {
|
|||||||
lateinit var params: WorldgenParams
|
lateinit var params: WorldgenParams
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
val threadExecutor = TerrarumIngame.worldgenThreadExecutor
|
||||||
|
var genSlices = -1
|
||||||
|
|
||||||
private val threadLock = java.lang.Object()
|
private val threadLock = java.lang.Object()
|
||||||
|
|
||||||
fun attachMap(world: GameWorld, genParams: WorldgenParams) {
|
fun attachMap(world: GameWorld, genParams: WorldgenParams) {
|
||||||
@@ -62,6 +67,8 @@ object Worldgen {
|
|||||||
fun generateMap(loadscreen: LoadScreenBase) {
|
fun generateMap(loadscreen: LoadScreenBase) {
|
||||||
highlandLowlandSelectCache = getHighlandLowlandSelectCache(params.terragenParams, params.seed)
|
highlandLowlandSelectCache = getHighlandLowlandSelectCache(params.terragenParams, params.seed)
|
||||||
caveAttenuateBiasScaled = getCaveAttenuateBiasScaled(highlandLowlandSelectCache, params.terragenParams)
|
caveAttenuateBiasScaled = getCaveAttenuateBiasScaled(highlandLowlandSelectCache, params.terragenParams)
|
||||||
|
genSlices = max(threadExecutor.threadCount, world.width / 9)
|
||||||
|
|
||||||
|
|
||||||
val jobs = getJobs()
|
val jobs = getJobs()
|
||||||
|
|
||||||
@@ -99,7 +106,7 @@ object Worldgen {
|
|||||||
data class Work(val loadingScreenName: String, val theWork: Gen, val tags: List<String>)
|
data class Work(val loadingScreenName: String, val theWork: Gen, val tags: List<String>)
|
||||||
|
|
||||||
fun getEstimationSec(width: Int, height: Int): Long {
|
fun getEstimationSec(width: Int, height: Int): Long {
|
||||||
return (23.15 * 1.25 * (48600000.0 / bogoflops) * ((width * height) / 40095000.0) * (32.0 / THREAD_COUNT)).roundToLong()
|
return (23.15 * 1.25 * (48600000.0 / bogoflops) * ((width * height) / 20095000.0) * (32.0 / THREAD_COUNT)).roundToLong()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getHighlandLowlandSelectCache(params: TerragenParams, seed: Long): ModuleCache {
|
private fun getHighlandLowlandSelectCache(params: TerragenParams, seed: Long): ModuleCache {
|
||||||
|
|||||||
Reference in New Issue
Block a user