mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
game-maker selectable game update governor
This commit is contained in:
@@ -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) -
|
||||
(
|
||||
|
||||
@@ -158,6 +158,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
particlesContainer.overwritingPolicy = {
|
||||
it.dispose()
|
||||
}
|
||||
|
||||
gameUpdateGovernor = LimitUpdateRate
|
||||
}
|
||||
|
||||
|
||||
@@ -703,32 +705,22 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
postInit()
|
||||
|
||||
gameUpdateGovernor.reset()
|
||||
|
||||
gameFullyLoaded = true
|
||||
}
|
||||
|
||||
ingameController.update()
|
||||
|
||||
|
||||
// define custom update rate
|
||||
val updateRate = App.UPDATE_RATE // if (KeyToggler.isOn(Input.Keys.APOSTROPHE)) 1f / 8f else App.UPDATE_RATE
|
||||
|
||||
// ASYNCHRONOUS UPDATE AND RENDER //
|
||||
|
||||
/** UPDATE CODE GOES HERE */
|
||||
val dt = Gdx.graphics.deltaTime
|
||||
updateAkku += dt
|
||||
autosaveTimer += dt
|
||||
|
||||
var i = 0L
|
||||
while (updateAkku >= updateRate) {
|
||||
measureDebugTime("Ingame.Update") { updateGame(updateRate) }
|
||||
updateAkku -= updateRate
|
||||
i += 1
|
||||
}
|
||||
setDebugTime("Ingame.UpdateCounter", i)
|
||||
gameUpdateGovernor.update(dt, App.UPDATE_RATE, { dt -> updateGame(dt) }, { renderGame() })
|
||||
|
||||
/** RENDER CODE GOES HERE */
|
||||
measureDebugTime("Ingame.Render") { renderGame() }
|
||||
|
||||
val autosaveInterval = App.getConfigInt("autosaveinterval").coerceAtLeast(60000) / 1000f
|
||||
if (autosaveTimer >= autosaveInterval) {
|
||||
|
||||
@@ -126,6 +126,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
init {
|
||||
warning32bitJavaIcon.flip(false, false)
|
||||
gameUpdateGovernor = LimitUpdateRate.also { it.reset() }
|
||||
}
|
||||
|
||||
private fun loadThingsWhileIntroIsVisible() {
|
||||
@@ -246,32 +247,10 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
private val introUncoverTime: Second = 0.3f
|
||||
private var introUncoverDeltaCounter = 0f
|
||||
private var updateAkku = 0f
|
||||
|
||||
private var fucklatch = false
|
||||
|
||||
override fun render(updateRate: Float) {
|
||||
if (!fucklatch) {
|
||||
printdbg(this, "render start")
|
||||
fucklatch = true
|
||||
}
|
||||
|
||||
// async update and render
|
||||
|
||||
val dt = Gdx.graphics.deltaTime
|
||||
updateAkku += dt
|
||||
|
||||
var i = 0L
|
||||
while (updateAkku >= updateRate) {
|
||||
App.measureDebugTime("Ingame.Update") { updateScreen(updateRate) }
|
||||
updateAkku -= updateRate
|
||||
i += 1
|
||||
}
|
||||
App.setDebugTime("Ingame.UpdateCounter", i)
|
||||
|
||||
|
||||
// render? just do it anyway
|
||||
App.measureDebugTime("Ingame.Render") { renderScreen() }
|
||||
gameUpdateGovernor.update(Gdx.graphics.deltaTime, App.UPDATE_RATE, { dt -> updateScreen(dt) }, { renderScreen() })
|
||||
}
|
||||
|
||||
fun updateScreen(delta: Float) {
|
||||
|
||||
Reference in New Issue
Block a user