separating stage value from the progress

This commit is contained in:
minjaesong
2023-10-31 14:29:29 +09:00
parent aef55bdc22
commit 706f5ac507
4 changed files with 15 additions and 16 deletions

View File

@@ -28,6 +28,7 @@ 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
var stageValue = 0
override fun show() {
messages.clear()

View File

@@ -3,13 +3,11 @@ 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.max
import kotlin.math.roundToInt
import kotlin.math.roundToLong
import kotlin.math.sqrt
/**
@@ -66,8 +64,7 @@ open class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private va
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)
val prog = progress.get()
drawTiles(it, getStage(prog), getProgress(prog), previewX, previewY - imgYoff)
drawTiles(it, getStage(), getProgress(), previewX, previewY - imgYoff)
val text = messages.getHeadElem() ?: ""
App.fontGame.draw(it,
@@ -81,11 +78,11 @@ open class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private va
super.render(delta)
}
protected open fun getProgress(progress: Long): Int {
return ((progress / 3.0) / vtilesCount).roundToInt()
protected open fun getProgress(): Int {
return ((progress.get() / 3.0) / vtilesCount).roundToInt()
}
protected open fun getStage(progress: Long): Int {
protected open fun getStage(): Int {
return 2 // fixed value for Read screen
}
@@ -100,12 +97,12 @@ open class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private va
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 getProgress(): Int {
return (progress.get() / CHUNK_W).toInt()
}
override fun getStage(progress: Long): Int {
return (progress ushr 48).toInt() + 1
override fun getStage(): Int {
return stageValue
}
override fun drawTiles(batch: FlippingSpriteBatch, layerCount: Int, tileCount: Int, x: Float, y: Float) {

View File

@@ -3,14 +3,12 @@ package net.torvald.terrarum.modulebasegame.worldgenerator
import com.sudoplay.joise.Joise
import com.sudoplay.joise.module.*
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.FancyWorldgenLoadScreen
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.utils.OrePlacement
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import kotlin.math.cos
import kotlin.math.max
import kotlin.math.sin
@@ -25,7 +23,8 @@ class Oregen(world: GameWorld, private val caveAttenuateBiasScaled: ModuleScaleD
private val genSlices = max(threadExecutor.threadCount, world.width / 9)
override fun getDone(loadscreen: LoadScreenBase) {
loadscreen.progress.set((loadscreen.progress.get() + 0x1_000000_000000L) and 0x7FFF_000000_000000L)
loadscreen.stageValue += 1
loadscreen.progress.set(0L)
threadExecutor.renew()
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->

View File

@@ -8,6 +8,7 @@ import net.torvald.terrarum.LoadScreenBase
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.concurrent.sliceEvenly
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.FancyWorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import kotlin.math.cos
import kotlin.math.max
@@ -32,6 +33,7 @@ class Terragen(world: GameWorld, val highlandLowlandSelectCache: ModuleCache, se
private val stoneSlateDitherSize = 4
override fun getDone(loadscreen: LoadScreenBase) {
loadscreen.stageValue += 1
loadscreen.progress.set(0L)
threadExecutor.renew()