mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 21:14:04 +09:00
now with watchdogs
This commit is contained in:
@@ -668,6 +668,10 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
uiContainer.add(it(this))
|
||||
}
|
||||
|
||||
ModMgr.GameWatchdogLoader.watchdogs.forEach {
|
||||
registerWatchdog(it.key, it.value)
|
||||
}
|
||||
|
||||
// these need to appear on top of any others
|
||||
uiContainer.add(notifier)
|
||||
|
||||
@@ -878,6 +882,12 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
private var deltaTeeCleared = false
|
||||
|
||||
private val terrarumWorldWatchdogs = TreeMap<String, TerrarumWorldWatchdog>()
|
||||
|
||||
fun registerWatchdog(identifier: String, watchdog: TerrarumWorldWatchdog) {
|
||||
terrarumWorldWatchdogs[identifier] = watchdog
|
||||
}
|
||||
|
||||
/**
|
||||
* Ingame (world) related updates; UI update must go to renderGame()
|
||||
*/
|
||||
@@ -896,8 +906,6 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
//hypothetical_input_capturing_function_if_you_finally_decided_to_forgo_gdx_input_processor_and_implement_your_own_to_synchronise_everything()
|
||||
|
||||
WorldSimulator.resetForThisFrame()
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// camera-related updates //
|
||||
@@ -964,6 +972,13 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
fillUpWirePortsView(fixtures)
|
||||
}
|
||||
}
|
||||
terrarumWorldWatchdogs.entries.forEach {
|
||||
measureDebugTime("Ingame.Watchdog.${it.key}*") {
|
||||
if (WORLD_UPDATE_TIMER % it.value.runIntervalByTick.toLong() == 0L) {
|
||||
it.value(world)
|
||||
}
|
||||
}
|
||||
}
|
||||
oldCamX = WorldCamera.x
|
||||
oldPlayerX = actorNowPlaying?.hitbox?.canonicalX ?: 0.0
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.torvald.terrarum.modulebasegame
|
||||
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
|
||||
/**
|
||||
* @param runIntervalByTick how often should the watchdog run. 1: every single tick, 2: every other tick, 60: every second (if tickrate is 60)
|
||||
*
|
||||
* Created by minjaesong on 2025-03-02
|
||||
*/
|
||||
abstract class TerrarumWorldWatchdog(val runIntervalByTick: Int) {
|
||||
abstract operator fun invoke(world: GameWorld)
|
||||
}
|
||||
@@ -69,11 +69,6 @@ object WorldSimulator {
|
||||
private val world: GameWorld
|
||||
get() = ingame.world
|
||||
|
||||
|
||||
fun resetForThisFrame() {
|
||||
|
||||
}
|
||||
|
||||
private val rng = HQRNG()
|
||||
|
||||
/** Must be called BEFORE the actors update -- actors depend on the R-Tree for various things */
|
||||
|
||||
@@ -31,5 +31,11 @@ class NetRunner : TerrarumSavegameExtrafieldSerialisable {
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
fun purgeDeadFrames() {
|
||||
ledger.filter { it.value.getFrameType() == "invalid" }.map { it.key }.forEach {
|
||||
ledger.remove(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user