tile damage and wire layers are now save/loaded

This commit is contained in:
minjaesong
2021-08-26 23:11:03 +09:00
parent e5c25c5a10
commit c2fdb4b26a
15 changed files with 390 additions and 270 deletions

View File

@@ -84,6 +84,7 @@ object IngameRenderer : Disposable {
var world: GameWorld = GameWorld.makeNullWorld()
private set // the grammar "IngameRenderer.world = gameWorld" seemes mundane and this function needs special care!
private var newWorldLoadedLatch = false
// these codes will run regardless of the invocation of the "initialise()" function
// the "initialise()" function will also be called
@@ -162,6 +163,8 @@ object IngameRenderer : Disposable {
LightmapRenderer.internalSetWorld(world)
BlocksDrawer.world = world
FeaturesDrawer.world = world
newWorldLoadedLatch = true
}
}
catch (e: UninitializedPropertyAccessException) {
@@ -201,10 +204,10 @@ object IngameRenderer : Disposable {
this.player = player
if (!gamePaused) {
if (!gamePaused || newWorldLoadedLatch) {
measureDebugTime("Renderer.ApparentLightRun") {
// recalculate for even frames, or if the sign of the cam-x changed
if (AppLoader.GLOBAL_RENDER_TIMER % 3 == 0 || WorldCamera.x * oldCamX < 0)
if (AppLoader.GLOBAL_RENDER_TIMER % 3 == 0 || WorldCamera.x * oldCamX < 0 || newWorldLoadedLatch)
LightmapRenderer.fireRecalculateEvent(actorsRenderBehind, actorsRenderFront, actorsRenderMidTop, actorsRenderMiddle, actorsRenderOverlay)
oldCamX = WorldCamera.x
@@ -345,6 +348,9 @@ object IngameRenderer : Disposable {
// works but some UI elements have wrong transparency -> should be fixed with Terrarum.gdxCleanAndSetBlend -- Torvald 2019-01-12
blendNormal(batch)
batch.color = Color.WHITE
if (newWorldLoadedLatch) newWorldLoadedLatch = false
}

View File

@@ -560,7 +560,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// will also queue up the block/wall/wire placed events
ingameController.update()
if (!paused) {
if (!paused || newWorldLoadedLatch) {
//hypothetical_input_capturing_function_if_you_finally_decided_to_forgo_gdx_input_processor_and_implement_your_own_to_synchronise_everything()
@@ -583,7 +583,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// fill up visibleActorsRenderFront for wires, if:
// 1. something is cued on the wire change queue
// 2. wire renderclass changed
if (wireChangeQueue.isNotEmpty() || selectedWireRenderClass != oldSelectedWireRenderClass) {
if (newWorldLoadedLatch || wireChangeQueue.isNotEmpty() || selectedWireRenderClass != oldSelectedWireRenderClass) {
measureDebugTime("Ingame.FillUpWiresBuffer") {
fillUpWiresBuffer()
}
@@ -614,7 +614,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
if (!paused) {
if (!paused || newWorldLoadedLatch) {
// completely consume block change queues because why not
terrainChangeQueue.clear()
wallChangeQueue.clear()
@@ -638,6 +638,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
//println("paused = $paused")
if (!paused && newWorldLoadedLatch) newWorldLoadedLatch = false
}

View File

@@ -0,0 +1,37 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.gameworld.BlockAddress
import kotlin.reflect.full.memberProperties
/**
* Created by minjaesong on 2021-08-26.
*/
object PrintWorld : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
val w = Terrarum.ingame!!.world
val field = w::class.java.getDeclaredField(args[1])
val fieldAccessibility = field.isAccessible
field.isAccessible = true
Echo(field.get(w).toString())
Echo(field.get(w).javaClass.simpleName)
w.wirings.forEach { i, node ->
Echo(i.toString())
}
field.isAccessible = fieldAccessibility
}
else {
printUsage()
}
}
override fun printUsage() {
Echo("Usage: Exportworld <field>")
}
}

View File

@@ -48,11 +48,11 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
Terrarum.ingame!!.world.getAllWiringGraph(mx, my)?.forEach { (itemID, simCell) ->
if (sb.isNotEmpty()) sb.append('\n')
val connexionIcon = (simCell.connections + 0xE0A0).toChar()
val connexionIcon = (simCell.cnx + 0xE0A0).toChar()
val wireName = WireCodex[itemID].nameKey
val emit = simCell.emitState
val recv = simCell.recvStates
val emit = simCell.emt
val recv = simCell.rcv
sb.append("$connexionIcon $wireName")
sb.append("\nE: $emit")