adaptive tilemap update rate

This commit is contained in:
minjaesong
2024-09-05 19:48:21 +09:00
parent c17d742d68
commit 56b98f3086
2 changed files with 5 additions and 2 deletions

View File

@@ -286,6 +286,8 @@ class BasicDebugInfoWindow : UICanvas() {
batch.draw(icons.get(0,0), gap + 7f*cxyX, line(cxyY))
App.fontSmallNumbers.draw(batch, "X$ccG${WorldCamera.x.toString().padStart(7)}", gap + 7f*(cxyX + 3), line(cxyY))
App.fontSmallNumbers.draw(batch, "Y$ccG${WorldCamera.y.toString().padStart(7)}", gap + 7f*(cxyX + 3), line(cxyY+1))
// App.fontSmallNumbers.draw(batch, "X$ccG${WorldCamera.deltaX.toString().padStart(7)}", gap + 7f*(cxyX + 3), line(cxyY))
// App.fontSmallNumbers.draw(batch, "Y$ccG${WorldCamera.deltaY.toString().padStart(7)}", gap + 7f*(cxyX + 3), line(cxyY+1))
// sun and weather

View File

@@ -13,6 +13,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.App.measureDebugTime
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameitems.ItemID
@@ -1177,8 +1178,8 @@ internal object BlocksDrawer {
private val doTilemapUpdate: Boolean
get() {
// TODO adaptive rate control via cam delta
val rate = 4
val rate = ((2f * TILE_SIZEF) / maxOf(WorldCamera.deltaX.abs(), WorldCamera.deltaY.abs()).coerceAtLeast(1)).roundToInt().coerceIn(1, 4)
// App.debugTimers.put("Renderer.tilemapUpdateDivider", rate.toLong())
return (!world.layerTerrain.ptrDestroyed && App.GLOBAL_RENDER_TIMER % rate == 0L)
}