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 else -> Vector2.Zero
} }
tileMapHolder.setCenterPosition(tileToCenterOn,true) 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. // This is private so that we will set the shouldUpdate to true instead.
@ -313,9 +320,12 @@ class WorldScreen : CameraStageBaseScreen() {
} }
var shouldUpdate=true var shouldUpdate=true
override fun render(delta: Float) { override fun render(delta: Float) {
if(shouldUpdate){ // This is so that updates happen in the MAIN THREAD, where there is a GL Context, if (shouldUpdate) { // This is so that updates happen in the MAIN THREAD, where there is a GL Context,
if(currentPlayerCiv!=gameInfo.getCurrentPlayerCivilization()){
if (currentPlayerCiv != gameInfo.getCurrentPlayerCivilization()) {
UnCivGame.Current.screen = PlayerReadyScreen(gameInfo.getCurrentPlayerCivilization()) UnCivGame.Current.screen = PlayerReadyScreen(gameInfo.getCurrentPlayerCivilization())
return return
} }
@ -323,8 +333,9 @@ class WorldScreen : CameraStageBaseScreen() {
// otherwise images will not load properly! // otherwise images will not load properly!
update() update()
showTutorialsOnNextTurn() showTutorialsOnNextTurn()
shouldUpdate=false shouldUpdate = false
} }
super.render(delta) super.render(delta)
} }