mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-12 22:56:06 +09:00
Various Loadscreens WIP
This commit is contained in:
67
src/net/torvald/terrarum/LoadScreenBase.kt
Normal file
67
src/net/torvald/terrarum/LoadScreenBase.kt
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,19 +14,7 @@ import net.torvald.util.CircularArray
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2017-07-13.
|
* Created by minjaesong on 2017-07-13.
|
||||||
*/
|
*/
|
||||||
object LoadScreen : ScreenAdapter() {
|
object LoadScreen : LoadScreenBase() {
|
||||||
|
|
||||||
var screenToLoad: IngameInstance? = null
|
|
||||||
private lateinit var screenLoadingThread: Thread
|
|
||||||
|
|
||||||
|
|
||||||
private val messages = CircularArray<String>(20, true)
|
|
||||||
|
|
||||||
fun addMessage(msg: String) {
|
|
||||||
messages.appendHead(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private var arrowObjPos = 0f // 0 means at starting position, regardless of screen position
|
private var arrowObjPos = 0f // 0 means at starting position, regardless of screen position
|
||||||
private var arrowObjGlideOffsetX = 0f
|
private var arrowObjGlideOffsetX = 0f
|
||||||
@@ -47,52 +35,11 @@ object LoadScreen : ScreenAdapter() {
|
|||||||
private val ghostMaxZoomX = 1.25f
|
private val ghostMaxZoomX = 1.25f
|
||||||
private val ghostAlphaMax = 1f
|
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() {
|
override fun show() {
|
||||||
messages.clear()
|
|
||||||
doContextChange = false
|
|
||||||
glideTimer = 0f
|
glideTimer = 0f
|
||||||
|
|
||||||
|
super.show()
|
||||||
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)
|
|
||||||
|
|
||||||
textFbo = FrameBuffer(
|
textFbo = FrameBuffer(
|
||||||
Pixmap.Format.RGBA4444,
|
Pixmap.Format.RGBA4444,
|
||||||
@@ -114,7 +61,6 @@ object LoadScreen : ScreenAdapter() {
|
|||||||
val textX: Float; get() = (AppLoader.screenW * 0.72f).floor()
|
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 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 messageBackgroundColour = Color(0x404040ff)
|
||||||
private var messageForegroundColour = Color.WHITE
|
private var messageForegroundColour = Color.WHITE
|
||||||
@@ -316,8 +262,4 @@ object LoadScreen : ScreenAdapter() {
|
|||||||
|
|
||||||
override fun hide() {
|
override fun hide() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resize(width: Int, height: Int) {
|
|
||||||
initViewPort(AppLoader.screenW, AppLoader.screenH)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -169,6 +169,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
lateinit var theRealGamer: IngamePlayer
|
lateinit var theRealGamer: IngamePlayer
|
||||||
// get() = actorGamer as IngamePlayer
|
// get() = actorGamer as IngamePlayer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum class GameLoadMode {
|
enum class GameLoadMode {
|
||||||
CREATE_NEW, LOAD_FROM
|
CREATE_NEW, LOAD_FROM
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ package net.torvald.terrarum.modulebasegame
|
|||||||
import com.badlogic.gdx.ScreenAdapter
|
import com.badlogic.gdx.ScreenAdapter
|
||||||
import com.badlogic.gdx.graphics.Pixmap
|
import com.badlogic.gdx.graphics.Pixmap
|
||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.IngameInstance
|
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.util.CircularArray
|
import net.torvald.util.CircularArray
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@@ -14,10 +13,12 @@ import kotlin.math.roundToInt
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2019-11-09.
|
* 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
|
// 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 {
|
companion object {
|
||||||
private const val WIDTH_RATIO = 0.6
|
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 previewWidth = (AppLoader.screenW * WIDTH_RATIO).roundToInt()
|
||||||
private val previewHeight = (AppLoader.screenW * WIDTH_RATIO * world.height / world.width).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 previewPixmap: Pixmap
|
||||||
private lateinit var previewTexture: Texture
|
private lateinit var previewTexture: Texture
|
||||||
|
|
||||||
private val messages = CircularArray<String>(20, true) // this many texts will be shown at once
|
|
||||||
|
|
||||||
override fun show() {
|
override fun show() {
|
||||||
previewPixmap = Pixmap(previewWidth, previewHeight, Pixmap.Format.RGBA8888)
|
previewPixmap = Pixmap(previewWidth, previewHeight, Pixmap.Format.RGBA8888)
|
||||||
previewTexture = Texture(1, 1, 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)
|
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() {
|
override fun dispose() {
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package net.torvald.terrarum.modulebasegame.worldgenerator
|
|||||||
|
|
||||||
import com.sudoplay.joise.Joise
|
import com.sudoplay.joise.Joise
|
||||||
import com.sudoplay.joise.module.*
|
import com.sudoplay.joise.module.*
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
|
import net.torvald.terrarum.LoadScreen
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.concurrent.ThreadExecutor
|
import net.torvald.terrarum.concurrent.ThreadExecutor
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
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...
|
// single-threaded impl because I couldn't resolve multithread memory corruption issue...
|
||||||
genFuture = ThreadExecutor.submit {
|
genFuture = ThreadExecutor.submit {
|
||||||
for (x in 0 until world.width) {
|
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) {
|
for (y in 0 until world.height) {
|
||||||
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
|
val sampleTheta = (x.toDouble() / world.width) * TWO_PI
|
||||||
val sampleOffset = world.width / 8.0
|
val sampleOffset = world.width / 8.0
|
||||||
|
|||||||
Reference in New Issue
Block a user