mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
now with watchdogs
This commit is contained in:
@@ -12,6 +12,7 @@ class EntryPoint : ModuleEntryPoint() {
|
||||
|
||||
override fun invoke() {
|
||||
ModMgr.GameItemLoader.invoke(moduleName)
|
||||
ModMgr.GameWatchdogLoader.register(moduleName, NetFrameWatchdog())
|
||||
println("[${moduleName[0].toUpperCase()}${moduleName.substring(1)}] Dirtboard(tm) go drrrrr")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.torvald.terrarum.modulecomputers
|
||||
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumWorldWatchdog
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.NetRunner
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2025-03-02.
|
||||
*/
|
||||
class NetFrameWatchdog : TerrarumWorldWatchdog(App.TICK_SPEED * 60) {
|
||||
override fun invoke(world: GameWorld) {
|
||||
(world.extraFields["tokenring"] as NetRunner).let {
|
||||
it.purgeDeadFrames()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,11 +40,18 @@ class FixtureRingBusExerciser : Electric {
|
||||
|
||||
init {
|
||||
setEmitterAndSink()
|
||||
|
||||
if (!INGAME.world.extraFields.containsKey("tokenring")) {
|
||||
INGAME.world.extraFields["tokenring"] = NetRunner()
|
||||
}
|
||||
}
|
||||
|
||||
override fun reload() {
|
||||
super.reload()
|
||||
setEmitterAndSink()
|
||||
if (!INGAME.world.extraFields.containsKey("tokenring")) {
|
||||
INGAME.world.extraFields["tokenring"] = NetRunner()
|
||||
}
|
||||
}
|
||||
|
||||
private val msgQueue = Queue<Pair<Int, String>>()
|
||||
|
||||
@@ -19,6 +19,7 @@ import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.itemproperties.MaterialCodex
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumWorldWatchdog
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.BlockBase
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.OregenParams
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.Worldgen
|
||||
@@ -892,6 +893,14 @@ object ModMgr {
|
||||
guis.add(uiCreationFun)
|
||||
}
|
||||
}
|
||||
|
||||
object GameWatchdogLoader {
|
||||
internal val watchdogs = TreeMap<String, TerrarumWorldWatchdog>()
|
||||
|
||||
@JvmStatic fun register(moduleName: String, watchdog: TerrarumWorldWatchdog) {
|
||||
watchdogs["$moduleName.${watchdog.javaClass.simpleName}"] = watchdog
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class JarFileLoader(urls: Array<URL>) : URLClassLoader(urls) {
|
||||
|
||||
@@ -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