how changing the screen should be done

This commit is contained in:
minjaesong
2017-07-13 01:34:09 +09:00
parent ed5997d5b4
commit a4fe26adf8
9 changed files with 101 additions and 31 deletions

Binary file not shown.

View File

@@ -80,7 +80,6 @@ class Ingame(val batch: SpriteBatch) : Screen {
private val worldFBOformat = if (Terrarum.environment == RunningEnvironment.MOBILE) Pixmap.Format.RGBA4444 else Pixmap.Format.RGBA8888 private val worldFBOformat = if (Terrarum.environment == RunningEnvironment.MOBILE) Pixmap.Format.RGBA4444 else Pixmap.Format.RGBA8888
private val lightFBOformat = Pixmap.Format.RGB888 private val lightFBOformat = Pixmap.Format.RGB888
private val lightUvFBOformat = Pixmap.Format.RGB888
var worldDrawFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true) var worldDrawFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
var worldGlowFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true) var worldGlowFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
@@ -88,9 +87,6 @@ class Ingame(val batch: SpriteBatch) : Screen {
// RGB elements of Lightmap for Color Vec4(R, G, B, 1.0) 24-bit // RGB elements of Lightmap for Color Vec4(R, G, B, 1.0) 24-bit
var lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true) var lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
var lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true) var lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
// A elements of Lightmap for UV Light Vec4(A, A, A, A) 8-bit
//var lightmapUvFboA = FrameBuffer(lightUvFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
//var lightmapUvFboB = FrameBuffer(lightUvFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
init { init {
@@ -146,6 +142,11 @@ class Ingame(val batch: SpriteBatch) : Screen {
private lateinit var updateThreadWrapper: Thread private lateinit var updateThreadWrapper: Thread
//private val ingameDrawThread: ThreadIngameDraw // draw must be on the main thread //private val ingameDrawThread: ThreadIngameDraw // draw must be on the main thread
private var gameFullyLoaded = false
////////////// //////////////
// GDX code // // GDX code //
////////////// //////////////
@@ -186,9 +187,22 @@ class Ingame(val batch: SpriteBatch) : Screen {
} }
lateinit var gameLoadMode: GameLoadMode
lateinit var gameLoadInfoPayload: Any
enum class GameLoadMode {
CREATE_NEW, LOAD_FROM
}
override fun show() { override fun show() {
// Set up viewport on first load
initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT) initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT)
// gameLoadMode and gameLoadInfoPayload must be set beforehand!!
when (gameLoadMode) {
GameLoadMode.CREATE_NEW -> enter(gameLoadInfoPayload as NewWorldParameters)
GameLoadMode.LOAD_FROM -> enter(gameLoadInfoPayload as GameSaveData)
}
} }
data class GameSaveData( data class GameSaveData(
@@ -197,7 +211,21 @@ class Ingame(val batch: SpriteBatch) : Screen {
val realGamePlayer: ActorHumanoid val realGamePlayer: ActorHumanoid
) )
fun enter(gameSaveData: GameSaveData) { data class NewWorldParameters(
val width: Int,
val height: Int,
val worldGenSeed: Long
// other worldgen options
)
/**
* Init instance by loading saved world
*/
private fun enter(gameSaveData: GameSaveData) {
if (gameFullyLoaded) {
Error("You are doing things horribly wrong, fucknugget.")
}
world = gameSaveData.world world = gameSaveData.world
historicalFigureIDBucket = gameSaveData.historicalFigureIDBucket historicalFigureIDBucket = gameSaveData.historicalFigureIDBucket
playableActorDelegate = PlayableActorDelegate(gameSaveData.realGamePlayer) playableActorDelegate = PlayableActorDelegate(gameSaveData.realGamePlayer)
@@ -206,21 +234,22 @@ class Ingame(val batch: SpriteBatch) : Screen {
initGame() initGame()
gameFullyLoaded = true
} }
/** /**
* Create new world * Init instance by creating new world
*/ */
fun enter() { private fun enter(worldParams: NewWorldParameters) {
// init map as chosen size // init map as chosen size
world = GameWorld(8192, 2048) world = GameWorld(worldParams.width, worldParams.height)
// generate terrain for the map // generate terrain for the map
WorldGenerator.attachMap(world) WorldGenerator.attachMap(world)
//WorldGenerator.SEED = 0x51621D2 WorldGenerator.SEED = worldParams.worldGenSeed
WorldGenerator.SEED = HQRNG().nextLong()
WorldGenerator.generateMap() WorldGenerator.generateMap()
@@ -1463,10 +1492,6 @@ class Ingame(val batch: SpriteBatch) : Screen {
lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true) lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
lightmapFboB.dispose() lightmapFboB.dispose()
lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true) lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
//lightmapUvFboA.dispose()
//lightmapUvFboA = FrameBuffer(lightUvFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
//lightmapUvFboB.dispose()
//lightmapUvFboB = FrameBuffer(lightUvFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
// Set up viewport when window is resized // Set up viewport when window is resized
@@ -1491,7 +1516,9 @@ class Ingame(val batch: SpriteBatch) : Screen {
LightmapRenderer.fireRecalculateEvent() if (gameFullyLoaded) {
LightmapRenderer.fireRecalculateEvent()
}
} }
override fun dispose() { override fun dispose() {

View File

@@ -0,0 +1,32 @@
package net.torvald.terrarum
import com.badlogic.gdx.Screen
import com.badlogic.gdx.ScreenAdapter
import net.torvald.dataclass.HistoryArray
/**
* Created by minjaesong on 2017-07-13.
*/
object LoadScreen : ScreenAdapter() {
private lateinit var actualSceneToBeLoaded: Screen
private lateinit var sceneLoadingThread: Thread
private val messages = HistoryArray<String>(20)
fun setMessage(msg: String) {
messages.add(msg)
}
override fun show() {
}
override fun render(delta: Float) {
}
}

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum package net.torvald.terrarum
import com.badlogic.gdx.ApplicationAdapter import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Screen import com.badlogic.gdx.Screen
import com.badlogic.gdx.backends.lwjgl.LwjglApplication import com.badlogic.gdx.backends.lwjgl.LwjglApplication
@@ -14,6 +15,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.Matrix4 import com.badlogic.gdx.math.Matrix4
import com.google.gson.JsonArray import com.google.gson.JsonArray
import com.google.gson.JsonPrimitive import com.google.gson.JsonPrimitive
import net.torvald.random.HQRNG
import net.torvald.terrarum.Terrarum.RENDER_FPS import net.torvald.terrarum.Terrarum.RENDER_FPS
import net.torvald.terrarum.gamecontroller.GameController import net.torvald.terrarum.gamecontroller.GameController
import net.torvald.terrarum.imagefont.TinyAlphNum import net.torvald.terrarum.imagefont.TinyAlphNum
@@ -62,7 +64,7 @@ fun main(args: Array<String>) {
typealias RGBA8888 = Int typealias RGBA8888 = Int
object Terrarum : ApplicationAdapter() { object Terrarum : Game() {
internal var screenW: Int? = null internal var screenW: Int? = null
internal var screenH: Int? = null internal var screenH: Int? = null
@@ -125,7 +127,6 @@ object Terrarum : ApplicationAdapter() {
return lan + country return lan + country
} }
lateinit var currentScreen: Screen
var previousScreen: Screen? = null // to be used with temporary states like StateMonitorCheck var previousScreen: Screen? = null // to be used with temporary states like StateMonitorCheck
@@ -336,26 +337,27 @@ object Terrarum : ApplicationAdapter() {
ingame = Ingame(batch) ingame = Ingame(batch)
currentScreen = ingame as Screen ingame!!.gameLoadInfoPayload = Ingame.NewWorldParameters(8192, 2048, HQRNG().nextLong())
ingame!!.enter() ingame!!.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
super.setScreen(ingame)
} }
override fun render() { override fun render() {
currentScreen.render(Gdx.graphics.deltaTime) super.screen.render(Gdx.graphics.deltaTime)
GLOBAL_RENDER_TIMER += 1 GLOBAL_RENDER_TIMER += 1
} }
override fun pause() { override fun pause() {
currentScreen.pause() super.screen.pause()
} }
override fun resume() { override fun resume() {
currentScreen.resume() super.screen.resume()
} }
override fun dispose() { override fun dispose() {
currentScreen.dispose() super.screen.dispose()
fontGame.dispose() fontGame.dispose()
fontSmallNumbers.dispose() fontSmallNumbers.dispose()
//dispose any other resources used in this level //dispose any other resources used in this level
@@ -365,7 +367,7 @@ object Terrarum : ApplicationAdapter() {
screenW = width screenW = width
screenH = height screenH = height
currentScreen.resize(WIDTH, HEIGHT) super.screen.resize(WIDTH, HEIGHT)
} }

Binary file not shown.