Various Loadscreens WIP

This commit is contained in:
minjaesong
2019-11-18 01:20:17 +09:00
parent 9972f80874
commit a31825dbce
5 changed files with 87 additions and 68 deletions

View File

@@ -0,0 +1,67 @@
package net.torvald.terrarum
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.ScreenAdapter
import com.badlogic.gdx.graphics.OrthographicCamera
import net.torvald.util.CircularArray
open class LoadScreenBase : ScreenAdapter() {
open var screenToLoad: IngameInstance? = null
open lateinit var screenLoadingThread: Thread
internal val messages = CircularArray<String>(20, true)
fun addMessage(msg: String) {
messages.appendHead(msg)
}
internal var errorTrapped = false
internal var doContextChange = false
var camera = OrthographicCamera(AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
override fun show() {
messages.clear()
doContextChange = false
if (screenToLoad == null) {
println("[LoadScreen] Screen to load is not set. Are you testing the UI?")
}
else {
val runnable = {
try {
screenToLoad!!.show()
}
catch (e: Exception) {
addMessage("$ccR$e")
errorTrapped = true
System.err.println("Error while loading:")
e.printStackTrace()
}
}
screenLoadingThread = Thread(runnable, "LoadScreen GameLoader")
screenLoadingThread.start()
}
initViewPort(AppLoader.screenW, AppLoader.screenH)
}
fun initViewPort(width: Int, height: Int) {
// Set Y to point downwards
camera.setToOrtho(true, width.toFloat(), height.toFloat())
// Update camera matrix
camera.update()
// Set viewport to restrict drawing
Gdx.gl20.glViewport(0, 0, width, height)
}
override fun resize(width: Int, height: Int) {
initViewPort(AppLoader.screenW, AppLoader.screenH)
}
}

View File

@@ -14,19 +14,7 @@ import net.torvald.util.CircularArray
/**
* Created by minjaesong on 2017-07-13.
*/
object LoadScreen : ScreenAdapter() {
var screenToLoad: IngameInstance? = null
private lateinit var screenLoadingThread: Thread
private val messages = CircularArray<String>(20, true)
fun addMessage(msg: String) {
messages.appendHead(msg)
}
object LoadScreen : LoadScreenBase() {
private var arrowObjPos = 0f // 0 means at starting position, regardless of screen position
private var arrowObjGlideOffsetX = 0f
@@ -47,52 +35,11 @@ object LoadScreen : ScreenAdapter() {
private val ghostMaxZoomX = 1.25f
private val ghostAlphaMax = 1f
var camera = OrthographicCamera(AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
fun initViewPort(width: Int, height: Int) {
// Set Y to point downwards
camera.setToOrtho(true, width.toFloat(), height.toFloat())
// Update camera matrix
camera.update()
// Set viewport to restrict drawing
Gdx.gl20.glViewport(0, 0, width, height)
}
private var errorTrapped = false
override fun show() {
messages.clear()
doContextChange = false
glideTimer = 0f
if (screenToLoad == null) {
println("[LoadScreen] Screen to load is not set. Are you testing the UI?")
}
else {
val runnable = {
try {
screenToLoad!!.show()
}
catch (e: Exception) {
addMessage("$ccR$e")
errorTrapped = true
System.err.println("Error while loading:")
e.printStackTrace()
}
}
screenLoadingThread = Thread(runnable, "LoadScreen GameLoader")
screenLoadingThread.start()
}
initViewPort(AppLoader.screenW, AppLoader.screenH)
super.show()
textFbo = FrameBuffer(
Pixmap.Format.RGBA4444,
@@ -114,7 +61,6 @@ object LoadScreen : ScreenAdapter() {
val textX: Float; get() = (AppLoader.screenW * 0.72f).floor()
private var genuineSonic = false // the "NOW LOADING..." won't appear unless the arrow first run passes it (it's totally not a GenuineIntel tho)
private var doContextChange = false
private var messageBackgroundColour = Color(0x404040ff)
private var messageForegroundColour = Color.WHITE
@@ -316,8 +262,4 @@ object LoadScreen : ScreenAdapter() {
override fun hide() {
}
override fun resize(width: Int, height: Int) {
initViewPort(AppLoader.screenW, AppLoader.screenH)
}
}

View File

@@ -169,6 +169,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var theRealGamer: IngamePlayer
// get() = actorGamer as IngamePlayer
enum class GameLoadMode {
CREATE_NEW, LOAD_FROM
}

View File

@@ -3,8 +3,7 @@ package net.torvald.terrarum.modulebasegame
import com.badlogic.gdx.ScreenAdapter
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.IngameInstance
import net.torvald.terrarum.*
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.util.CircularArray
import kotlin.math.roundToInt
@@ -14,10 +13,12 @@ import kotlin.math.roundToInt
*
* Created by minjaesong on 2019-11-09.
*/
class WorldgenLoadScreen(private var world: GameWorld, private var screenToLoad: IngameInstance) : ScreenAdapter() {
class WorldgenLoadScreen(private val world: GameWorld, screenToBeLoaded: IngameInstance) : LoadScreenBase() {
// a Class impl is chosen to make resize-handling easier, there's not much benefit making this a singleton anyway
override var screenToLoad: IngameInstance? = screenToBeLoaded
companion object {
private const val WIDTH_RATIO = 0.6
}
@@ -25,13 +26,9 @@ class WorldgenLoadScreen(private var world: GameWorld, private var screenToLoad:
private val previewWidth = (AppLoader.screenW * WIDTH_RATIO).roundToInt()
private val previewHeight = (AppLoader.screenW * WIDTH_RATIO * world.height / world.width).roundToInt()
private lateinit var screenLoadingThread: Thread
private lateinit var previewPixmap: Pixmap
private lateinit var previewTexture: Texture
private val messages = CircularArray<String>(20, true) // this many texts will be shown at once
override fun show() {
previewPixmap = Pixmap(previewWidth, previewHeight, Pixmap.Format.RGBA8888)
previewTexture = Texture(1, 1, Pixmap.Format.RGBA8888)
@@ -42,6 +39,12 @@ class WorldgenLoadScreen(private var world: GameWorld, private var screenToLoad:
previewTexture = Texture(previewPixmap)
//
AppLoader.batch.inUse {
it.draw(previewTexture,
(AppLoader.screenW - previewWidth).div(2f).round(),
(AppLoader.screenH - previewHeight.times(1.25f)).div(2f).round()
)
}
}
override fun dispose() {

View File

@@ -2,7 +2,9 @@ package net.torvald.terrarum.modulebasegame.worldgenerator
import com.sudoplay.joise.Joise
import com.sudoplay.joise.module.*
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.LoadScreen
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.concurrent.ThreadExecutor
import net.torvald.terrarum.gameworld.GameWorld
@@ -28,7 +30,10 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
// single-threaded impl because I couldn't resolve multithread memory corruption issue...
genFuture = ThreadExecutor.submit {
for (x in 0 until world.width) {
printdbg(this, "Tile draw for x=$x")
if (AppLoader.IS_DEVELOPMENT_BUILD)
LoadScreen.addMessage("Tile draw for x=$x")
for (y in 0 until world.height) {
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
val sampleOffset = world.width / 8.0