new loadscreen for worldgen

This commit is contained in:
minjaesong
2023-10-31 00:11:43 +09:00
parent 3f3e4ad2e7
commit 0079bc5378
13 changed files with 60 additions and 51 deletions

View File

@@ -8,6 +8,7 @@ import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.util.CircularArray
import java.util.concurrent.atomic.AtomicLong
open class LoadScreenBase : ScreenAdapter(), Disposable, TerrarumGamescreen {
@@ -26,6 +27,8 @@ open class LoadScreenBase : ScreenAdapter(), Disposable, TerrarumGamescreen {
var camera = OrthographicCamera(App.scr.wf, App.scr.hf)
var progress = AtomicLong(0L) // generic variable, interpretation will vary by the screen
override fun show() {
messages.clear()
doContextChange = false

View File

@@ -3,17 +3,19 @@ package net.torvald.terrarum.modulebasegame
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.realestate.LandUtil.CHUNK_W
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.math.roundToInt
import kotlin.math.roundToLong
import kotlin.math.sqrt
/**
* Created by minjaesong on 2023-10-30.
*/
class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidth: Int, private val worldheight: Int, override var preLoadJob: (LoadScreenBase) -> Unit) : LoadScreenBase() {
open class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidth: Int, private val worldheight: Int, override var preLoadJob: (LoadScreenBase) -> Unit) : LoadScreenBase() {
init {
CommonResourcePool.addToLoadingList("basegame-gui-loadscrlayer01") {
@@ -29,9 +31,6 @@ class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private val wor
override var screenToLoad: IngameInstance? = screenToBeLoaded
private val world: GameWorld // must use Getter, as the field WILL BE redefined by the TerrarumIngame.enterCreateNewWorld() !
get() = screenToLoad!!.world
val ratio = worldwidth * sqrt(2.0 / (worldwidth.sqr() + worldheight.sqr())) // world size is always wider than tall
val htilesCount = worldwidth / CHUNK_W
@@ -58,8 +57,6 @@ class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private val wor
TextureRegionPack(it, visibleTileSize, imgYoff + previewHeight, gapSize, 0, xoff, 0)
}
var chunksLoaded = 0 // only increments when all the chunks were loaded
override fun render(delta: Float) {
gdxClearAndEnableBlend(.063f, .070f, .086f, 1f)
@@ -69,7 +66,8 @@ class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private val wor
val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).roundToFloat()
Toolkit.drawBoxBorder(it, previewX.toInt()-1, previewY.toInt()-1, previewWidth+2, previewHeight+2)
drawTiles(it, getStage(), getProgress(), previewX, previewY - imgYoff)
val prog = progress.get()
drawTiles(it, getStage(prog), getProgress(prog), previewX, previewY - imgYoff)
val text = messages.getHeadElem() ?: ""
App.fontGame.draw(it,
@@ -83,20 +81,38 @@ class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private val wor
super.render(delta)
}
private fun getProgress(): Int {
return (chunksLoaded.toDouble() / vtilesCount).roundToInt()
protected open fun getProgress(progress: Long): Int {
return ((progress / 3.0) / vtilesCount).roundToInt()
}
private fun getStage(): Int {
protected open fun getStage(progress: Long): Int {
return 2 // fixed value for Read screen
}
private fun drawTiles(batch: FlippingSpriteBatch, layerCount: Int, tileCount: Int, x: Float, y: Float) {
protected open fun drawTiles(batch: FlippingSpriteBatch, layerCount: Int, tileCount: Int, x: Float, y: Float) {
for (layer in 0 until layerCount) {
// for (i in 0 until if (layer == layerCount - 1) tileCount else htilesCount) {
for (i in 0 until tileCount) {
batch.draw(tiles[layer].get(i, 0), x + i * tileSize, y)
}
}
}
}
}
class FancyWorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidth: Int, private val worldheight: Int) : FancyWorldReadLoadScreen(screenToBeLoaded, worldwidth, worldheight, {}) {
override fun getProgress(progress: Long): Int {
return ((progress and 0xFFFFFF_FFFFFFL) / CHUNK_W).toInt()
}
override fun getStage(progress: Long): Int {
return (progress ushr 48).toInt() + 1
}
override fun drawTiles(batch: FlippingSpriteBatch, layerCount: Int, tileCount: Int, x: Float, y: Float) {
for (layer in 0 until layerCount) {
for (i in 0 until if (layer == layerCount - 1) tileCount else htilesCount) {
batch.draw(tiles[layer].get(i, 0), x + i * tileSize, y)
}
}
}
}

View File

@@ -490,7 +490,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
//WorldGenerator.SEED = worldParams.worldGenSeed
//WorldGenerator.generateMap()
Worldgen.attachMap(world, WorldgenParams(worldParams.worldGenSeed))
Worldgen.generateMap()
Worldgen.generateMap(App.getLoadScreen())
historicalFigureIDBucket = ArrayList<Int>()

View File

@@ -1,27 +1,18 @@
package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.random.XXHash64
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.FancyWorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.WorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory.Companion.CAPACITY_MODE_WEIGHT
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarum.modulebasegame.serialise.LoadSavegame
import net.torvald.terrarum.modulebasegame.serialise.ReadActor
import net.torvald.terrarum.modulebasegame.ui.UILoadGovernor
import net.torvald.terrarum.modulebasegame.ui.UIWorldPortal
import net.torvald.terrarum.savegame.ByteArray64Reader
import net.torvald.terrarum.savegame.DiskSkimmer
import net.torvald.terrarum.savegame.VDFileID
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import org.dyn4j.geometry.Vector2
import java.util.HashMap
/**
* Created by minjaesong on 2023-05-28.
@@ -99,7 +90,7 @@ class FixtureWorldPortal : Electric {
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW
Terrarum.setCurrentIngameInstance(ingame)
val loadScreen = WorldgenLoadScreen(ingame, wx, wy)
val loadScreen = FancyWorldgenLoadScreen(ingame, wx, wy)
App.setLoadScreen(loadScreen)
}
}

View File

@@ -199,8 +199,8 @@ object LoadSavegame {
val chunkXY = LandUtil.chunkNumToChunkXY(world, chunk.toInt())
ReadWorld.decodeChunkToLayer(chunkFile.getContent(), worldLayer[layer]!!, chunkXY.x, chunkXY.y)
loadscreen.progress.getAndAdd(1)
}
it.chunksLoaded += 1
}
loadscreen.addMessage("Updating Block Mappings...")

View File

@@ -10,9 +10,9 @@ import net.torvald.random.XXHash64
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.FancyWorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.TerrarumIngame.Companion.NEW_WORLD_SIZE
import net.torvald.terrarum.modulebasegame.WorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarum.modulebasegame.serialise.LoadSavegame
import net.torvald.terrarum.savegame.ByteArray64Reader
@@ -197,7 +197,7 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW
Terrarum.setCurrentIngameInstance(ingame)
val loadScreen = WorldgenLoadScreen(ingame, wx, wy)
val loadScreen = FancyWorldgenLoadScreen(ingame, wx, wy)
App.setLoadScreen(loadScreen)
}
else {

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.random.HQRNG
@@ -8,9 +7,8 @@ import net.torvald.terrarum.App
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.FancyWorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.WorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.gameactors.PlayerBuilderTestSubject1
import net.torvald.terrarum.modulebasegame.gameactors.PlayerBuilderWerebeastTest
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.utils.RandomWordsName
@@ -57,7 +55,7 @@ class UIProxyNewRandomGame(val remoCon: UIRemoCon) : UICanvas() {
Terrarum.setCurrentIngameInstance(ingame)
//LoadScreen.screenToLoad = ingame
//AppLoader.setScreen(LoadScreen)
val loadScreen = WorldgenLoadScreen(ingame, worldParam.newWorldParams.width, worldParam.newWorldParams.height)
val loadScreen = FancyWorldgenLoadScreen(ingame, worldParam.newWorldParams.width, worldParam.newWorldParams.height)
App.setLoadScreen(loadScreen)
}

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.Texture
@@ -9,20 +8,13 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.random.HQRNG
import net.torvald.random.XXHash64
import net.torvald.terrarum.*
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.WorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.gameactors.FixtureWorldPortal
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarum.modulebasegame.serialise.ReadActor
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
import net.torvald.terrarum.modulebasegame.worldgenerator.Worldgen
import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.savegame.ByteArray64Reader
import net.torvald.terrarum.savegame.VDFileID
import net.torvald.terrarum.savegame.VirtualDisk
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.ui.*
import net.torvald.terrarum.utils.RandomWordsName
import kotlin.math.roundToInt

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.worldgenerator
import com.sudoplay.joise.Joise
import com.sudoplay.joise.module.*
import net.torvald.terrarum.App
import net.torvald.terrarum.LoadScreenBase
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.concurrent.ThreadExecutor
import net.torvald.terrarum.concurrent.sliceEvenly
@@ -25,7 +26,9 @@ class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
private val YHEIGHT_MAGIC = 2800.0 / 3.0
private val YHEIGHT_DIVISOR = 2.0 / 7.0
override fun getDone() {
override fun getDone(loadscreen: LoadScreenBase) {
// loadscreen.progress.set((loadscreen.progress.get() + 0x1_000000_000000L) and 0x7FFF_000000_000000L)
threadExecutor.renew()
(0 until world.width).sliceEvenly(genSlices).map { xs ->
threadExecutor.submit {

View File

@@ -2,16 +2,13 @@ package net.torvald.terrarum.modulebasegame.worldgenerator
import com.sudoplay.joise.Joise
import com.sudoplay.joise.module.*
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.Point2i
import net.torvald.terrarum.*
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.concurrent.sliceEvenly
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen.Companion.YHEIGHT_DIVISOR
import net.torvald.terrarum.modulebasegame.worldgenerator.Terragen.Companion.YHEIGHT_MAGIC
import net.torvald.terrarum.sqr
import net.torvald.terrarum.toInt
import net.torvald.terrarum.utils.OrePlacement
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import kotlin.math.cos
@@ -27,7 +24,9 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
private val genSlices = max(threadExecutor.threadCount, world.width / 9)
override fun getDone() {
override fun getDone(loadscreen: LoadScreenBase) {
loadscreen.progress.set((loadscreen.progress.get() + 0x1_000000_000000L) and 0x7FFF_000000_000000L)
threadExecutor.renew()
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->
threadExecutor.submit {
@@ -37,6 +36,7 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
val sampleOffset = world.width / 8.0
draw(x, localJoise, sampleTheta, sampleOffset)
}
loadscreen.progress.addAndGet((xs.last - xs.first + 1).toLong())
}
}

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.modulebasegame.worldgenerator
import net.torvald.random.XXHash64
import net.torvald.terrarum.LoadScreenBase
import net.torvald.terrarum.Point2i
import net.torvald.terrarum.concurrent.sliceEvenly
import net.torvald.terrarum.gameitems.ItemID
@@ -22,7 +23,7 @@ class OregenAutotiling(world: GameWorld, seed: Long, val tilingModes: HashMap<It
private val threadExecutor = TerrarumIngame.worldgenThreadExecutor
private val genSlices = max(threadExecutor.threadCount, world.width / 9)
override fun getDone() {
override fun getDone(loadscreen: LoadScreenBase) {
threadExecutor.renew()
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->
threadExecutor.submit {

View File

@@ -4,6 +4,7 @@ import com.sudoplay.joise.Joise
import com.sudoplay.joise.module.*
import net.torvald.random.XXHash32
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.LoadScreenBase
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.concurrent.sliceEvenly
import net.torvald.terrarum.gameworld.GameWorld
@@ -30,7 +31,9 @@ class Terragen(world: GameWorld, val highlandLowlandSelectCache: ModuleCache, se
private val dirtStoneDitherSize = 3 // actual dither size will be double of this value
private val stoneSlateDitherSize = 4
override fun getDone() {
override fun getDone(loadscreen: LoadScreenBase) {
loadscreen.progress.set(0L)
threadExecutor.renew()
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->
threadExecutor.submit {
@@ -40,6 +43,7 @@ class Terragen(world: GameWorld, val highlandLowlandSelectCache: ModuleCache, se
val sampleOffset = world.width / 8.0
draw(x, localJoise, sampleTheta, sampleOffset)
}
loadscreen.progress.addAndGet((xs.last - xs.first + 1).toLong())
}
}

View File

@@ -5,6 +5,7 @@ import net.torvald.random.XXHash64
import net.torvald.terrarum.App
import net.torvald.terrarum.App.*
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.LoadScreenBase
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.GameWorld
import kotlin.math.roundToLong
@@ -58,7 +59,7 @@ object Worldgen {
).filter(tagFilter)
}
fun generateMap() {
fun generateMap(loadscreen: LoadScreenBase) {
highlandLowlandSelectCache = getHighlandLowlandSelectCache(params.terragenParams, params.seed)
caveAttenuateBiasScaled = getCaveAttenuateBiasScaled(highlandLowlandSelectCache, params.terragenParams)
@@ -71,7 +72,7 @@ object Worldgen {
val it = jobs[i]
App.getLoadScreen().addMessage(it.loadingScreenName)
it.theWork.getDone()
it.theWork.getDone(loadscreen)
}
// determine spawn point
@@ -257,7 +258,7 @@ object Worldgen {
}
abstract class Gen(val world: GameWorld, val seed: Long, val params: Any? = null) {
open fun getDone() { } // trying to use different name so that it won't be confused with Runnable or Callable
open fun getDone(loadscreen: LoadScreenBase) { } // trying to use different name so that it won't be confused with Runnable or Callable
}
data class WorldgenParams(