load screen actually draws the world

transition still not working
This commit is contained in:
minjaesong
2019-11-27 16:42:49 +09:00
parent 68ecb9139a
commit 98993f1755
2 changed files with 16 additions and 11 deletions

View File

@@ -180,8 +180,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// gameLoadMode and gameLoadInfoPayload must be set beforehand!!
when (gameLoadMode) {
GameLoadMode.CREATE_NEW -> enter(gameLoadInfoPayload as NewWorldParameters)
GameLoadMode.LOAD_FROM -> enter(gameLoadInfoPayload as GameSaveData)
GameLoadMode.CREATE_NEW -> enterCreateNewWorld(gameLoadInfoPayload as NewWorldParameters)
GameLoadMode.LOAD_FROM -> enterLoadFromSave(gameLoadInfoPayload as GameSaveData)
}
IngameRenderer.setRenderedWorld(gameworld)
@@ -220,7 +220,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
/**
* Init instance by loading saved world
*/
private fun enter(gameSaveData: GameSaveData) {
private fun enterLoadFromSave(gameSaveData: GameSaveData) {
if (gameInitialised) {
printdbg(this, "loaded successfully.")
}
@@ -243,7 +243,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
/**
* Init instance by creating new world
*/
private fun enter(worldParams: NewWorldParameters) {
private fun enterCreateNewWorld(worldParams: NewWorldParameters) {
printdbg(this, "Ingame called")
printStackTrace(this)

View File

@@ -15,7 +15,7 @@ import kotlin.math.roundToInt
*
* Created by minjaesong on 2019-11-09.
*/
class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, worldwidth: Int, worldheight: Int) : LoadScreenBase() {
class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidth: Int, private val worldheight: Int) : LoadScreenBase() {
// a Class impl is chosen to make resize-handling easier, there's not much benefit making this a singleton anyway
@@ -23,8 +23,9 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, worldwidth: Int, worl
AppLoader.disposableSingletonsPool.add(this)
}
private val world = screenToBeLoaded.world
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
companion object {
private const val WIDTH_RATIO = 0.7
@@ -43,6 +44,8 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, worldwidth: Int, worl
private var previewRenderCounter = 0f
// NOTE: actual world init and terragen is called by TerrarumIngame.enterLoadFromSave()
override fun show() {
super.show()
@@ -86,18 +89,20 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, worldwidth: Int, worl
}
private fun renderToPreview() {
for (y in 0 until previewWidth) {
for (x in 0 until previewHeight) {
val wx = (world.width / previewWidth * x).toInt()
val wy = (world.height / previewHeight * y).toInt()
for (y in 0 until previewHeight) {
for (x in 0 until previewWidth) {
val wx = (world.width.toFloat() / previewWidth * x).roundToInt()
val wy = (world.height.toFloat() / previewHeight * y).roundToInt()
val colT = if (world.getTileFromTerrain(wx, wy) != 0) COL_WALL else COL_TERR
val colW = if (world.getTileFromWall(wx, wy) != 0) COL_WALL else COL_AIR
val outCol = colW mul colT
previewPixmap.setColor(outCol)
previewPixmap.drawPixel(x, y)
previewPixmap.drawPixel(x, previewHeight - 1 - y) // this flips Y
}
}
}
override fun addMessage(msg: String) {