Added initial setup of WorldScreen in worldscreen creation, so it doesn't take too long in the render, hopefully

This commit is contained in:
Yair Morgenstern 2019-06-21 14:29:55 +03:00
parent d4ead7bbf2
commit 7d17265032

View File

@ -93,6 +93,13 @@ class WorldScreen : CameraStageBaseScreen() {
else -> Vector2.Zero
}
tileMapHolder.setCenterPosition(tileToCenterOn,true)
// On the one hand, all updates to e.g. TileGroups need to happen on the main rendering thread.
// On the other hand, the initial setup requires setting up a lot of items on the map,
// and we would sometimes get an "Input dispatching timed out" ANR when doing so.
// Putting it in a postRunnnable is our way of attempting to avoid this.
Gdx.app.postRunnable { render(0f) }
}
// This is private so that we will set the shouldUpdate to true instead.
@ -313,8 +320,11 @@ class WorldScreen : CameraStageBaseScreen() {
}
var shouldUpdate=true
override fun render(delta: Float) {
if (shouldUpdate) { // This is so that updates happen in the MAIN THREAD, where there is a GL Context,
if (currentPlayerCiv != gameInfo.getCurrentPlayerCivilization()) {
UnCivGame.Current.screen = PlayerReadyScreen(gameInfo.getCurrentPlayerCivilization())
return
@ -325,6 +335,7 @@ class WorldScreen : CameraStageBaseScreen() {
showTutorialsOnNextTurn()
shouldUpdate = false
}
super.render(delta)
}