module UI now has margin; game update will drop consecutive updates if its try count is exhausted (reduced lag after window move/resize)

This commit is contained in:
minjaesong
2017-09-15 01:40:12 +09:00
parent 553816e8c4
commit d3b54ae300
6 changed files with 31 additions and 5 deletions

View File

@@ -394,9 +394,15 @@ class Ingame(val batch: SpriteBatch) : Screen {
///////////////
private class ThreadIngameUpdate(val ingame: Ingame): Runnable {
override fun run() {
var updateTries = 0
while (ingame.updateDeltaCounter >= ingame.updateRate) {
ingame.updateGame(Terrarum.deltaTime)
ingame.updateDeltaCounter -= ingame.updateRate
updateTries++
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
break
}
}
}
}
@@ -451,9 +457,15 @@ class Ingame(val batch: SpriteBatch) : Screen {
// else, NOP;
}
else {
var updateTries = 0
while (updateDeltaCounter >= updateRate) {
updateGame(delta)
updateDeltaCounter -= updateRate
updateTries++
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
break
}
}
}

View File

@@ -116,6 +116,8 @@ object Terrarum : Screen {
*/
val TARGET_INTERNAL_FPS: Double = 60.0
internal val UPDATE_CATCHUP_MAX_TRIES = 10

View File

@@ -34,6 +34,7 @@ public class TerrarumAppLoader implements ApplicationListener {
public static final String COPYRIGHT_DATE_NAME = "Copyright 2013-2017 Torvald (minjaesong)";
public static final String GAME_LOCALE = System.getProperty("user.language") + System.getProperty("user.country");
/**
* 0xAA_BB_XXXX
* AA: Major version

View File

@@ -190,9 +190,15 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
else {
// async update
updateDeltaCounter += delta
var updateTries = 0
while (updateDeltaCounter >= updateRate) {
updateScreen(delta)
updateDeltaCounter -= updateRate
updateTries++
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
break
}
}
// render? just do it anyway

View File

@@ -31,13 +31,14 @@ class UIItemList<Item: UIItem>(
val inactiveCol: Color = Color(0xc0c0c0_ff.toInt()),
val backgroundCol: Color = Color(0x242424_80),
val backgroundBlendMode: String = BlendMode.NORMAL,
val kinematic: Boolean = false
val kinematic: Boolean = false,
val border: Int = 0
) : UIItem(parentUI) {
init {
itemList.forEachIndexed { index, item ->
item.posX = this.posX
item.posY = if (index == 0) this.posY else itemList[index - 1].posY + itemList[index - 1].height
item.posX = this.posX + border
item.posY = if (index == 0) this.posY + border else itemList[index - 1].posY + itemList[index - 1].height
}
}

View File

@@ -40,6 +40,9 @@ class UITitleRemoConModules(val superMenu: UICanvas) : UICanvas() {
private val moduleAreaHMargin = 48
private val moduleAreaBorder = 8
private val moduleAreaWidth = (Terrarum.WIDTH * 0.75).toInt() - moduleAreaHMargin
private val moduleAreaHeight = Terrarum.HEIGHT - moduleAreaHMargin * 2
@@ -50,7 +53,7 @@ class UITitleRemoConModules(val superMenu: UICanvas) : UICanvas() {
moduleInfoCells.add(UIItemModuleInfoCell(
this,
it.first,
moduleAreaWidth,
moduleAreaWidth - 2 * moduleAreaBorder,
0, 0 // placeholder
))
}
@@ -62,7 +65,8 @@ class UITitleRemoConModules(val superMenu: UICanvas) : UICanvas() {
(Terrarum.WIDTH * 0.25f).toInt(), moduleAreaHMargin,
moduleAreaWidth,
moduleAreaHeight,
inactiveCol = Color.WHITE
inactiveCol = Color.WHITE,
border = moduleAreaBorder
)