game-maker selectable game update governor

This commit is contained in:
minjaesong
2022-12-25 17:23:05 +09:00
parent 71fd92ad17
commit b5ed33e2e9
6 changed files with 68 additions and 54 deletions

View File

@@ -96,6 +96,8 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
gameWorld.worldTime.addTime(WorldTime.DAY_LENGTH * 32)
world = gameWorld
gameUpdateGovernor = LimitUpdateRate.also { it.reset() }
}
@@ -307,27 +309,13 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
super.show()
}
private var updateAkku = 0f
override fun render(updateRate: Float) {
Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle())
// ASYNCHRONOUS UPDATE AND RENDER //
val dt = Gdx.graphics.deltaTime
updateAkku += dt
var i = 0L
while (updateAkku >= updateRate) {
App.measureDebugTime("Ingame.Update") { updateGame(updateRate) }
updateAkku -= updateRate
i += 1
}
App.setDebugTime("Ingame.UpdateCounter", i)
// render? just do it anyway
App.measureDebugTime("Ingame.Render") { renderGame() }
gameUpdateGovernor.update(Gdx.graphics.deltaTime, App.UPDATE_RATE, { dt -> updateGame(dt) }, { renderGame() })
App.setDebugTime("Ingame.Render - (Light + Tiling)",
((App.debugTimers["Ingame.Render"] as? Long) ?: 0) -
(