From d8516f4ad1bc8cb1fa9a327ad40f62d8a6626501 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 7 Aug 2021 18:03:38 +0900 Subject: [PATCH] changes on wire receive state --- .../torvald/terrarum/gameworld/GameWorld.kt | 51 ++++++++++--------- .../gameitems/WireGraphDebugger.kt | 12 +++-- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index 1e9a81509..69e95190c 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -357,24 +357,24 @@ open class GameWorld : Disposable { return wiringGraph[blockAddr]?.get(itemID)?.con } - fun getWireGeneratorStateOf(x: Int, y: Int, itemID: ItemID): Vector2? { + fun getWireEmitStateOf(x: Int, y: Int, itemID: ItemID): Vector2? { val (x, y) = coerceXY(x, y) val blockAddr = LandUtil.getBlockAddr(this, x, y) - return getWireGeneratorStateUnsafe(blockAddr, itemID) + return getWireEmitStateUnsafe(blockAddr, itemID) } - fun getWireGeneratorStateUnsafe(blockAddr: BlockAddress, itemID: ItemID): Vector2? { - return wiringGraph[blockAddr]?.get(itemID)?.generatorState + fun getWireEmitStateUnsafe(blockAddr: BlockAddress, itemID: ItemID): Vector2? { + return wiringGraph[blockAddr]?.get(itemID)?.emitState } - fun getWireConsumerStateOf(x: Int, y: Int, itemID: ItemID): ArrayList? { + fun getWireRecvStateOf(x: Int, y: Int, itemID: ItemID): ArrayList? { val (x, y) = coerceXY(x, y) val blockAddr = LandUtil.getBlockAddr(this, x, y) - return getWireConsumerStateUnsafe(blockAddr, itemID) + return getWireRecvStateUnsafe(blockAddr, itemID) } - fun getWireConsumerStateUnsafe(blockAddr: BlockAddress, itemID: ItemID): ArrayList? { - return wiringGraph[blockAddr]?.get(itemID)?.consumerStates + fun getWireRecvStateUnsafe(blockAddr: BlockAddress, itemID: ItemID): ArrayList? { + return wiringGraph[blockAddr]?.get(itemID)?.recvStates } fun setWireGraphOf(x: Int, y: Int, itemID: ItemID, byte: Byte) { @@ -392,40 +392,40 @@ open class GameWorld : Disposable { wiringGraph[blockAddr]!![itemID]!!.con = byte } - fun setWireGeneratorStateOf(x: Int, y: Int, itemID: ItemID, vector: Vector2) { + fun setWireEmitStateOf(x: Int, y: Int, itemID: ItemID, vector: Vector2) { val (x, y) = coerceXY(x, y) val blockAddr = LandUtil.getBlockAddr(this, x, y) - return setWireGenenatorStateOfUnsafe(blockAddr, itemID, vector) + return setWireEmitStateOfUnsafe(blockAddr, itemID, vector) } - fun setWireGenenatorStateOfUnsafe(blockAddr: BlockAddress, itemID: ItemID, vector: Vector2) { + fun setWireEmitStateOfUnsafe(blockAddr: BlockAddress, itemID: ItemID, vector: Vector2) { if (wiringGraph[blockAddr] == null) wiringGraph[blockAddr] = HashMap() if (wiringGraph[blockAddr]!![itemID] == null) wiringGraph[blockAddr]!![itemID] = WiringSimCell(0, vector) - wiringGraph[blockAddr]!![itemID]!!.generatorState = vector + wiringGraph[blockAddr]!![itemID]!!.emitState = vector } - fun addWireConsumerStateOf(x: Int, y: Int, itemID: ItemID, state: WireConsumerState) { + fun addWireRecvStateOf(x: Int, y: Int, itemID: ItemID, state: WireRecvState) { val (x, y) = coerceXY(x, y) val blockAddr = LandUtil.getBlockAddr(this, x, y) - return addWireConsumerStateOfUnsafe(blockAddr, itemID, state) + return addWireRecvStateOfUnsafe(blockAddr, itemID, state) } - fun clearAllWireConsumerState(x: Int, y: Int) { + fun clearAllWireRecvState(x: Int, y: Int) { val (x, y) = coerceXY(x, y) val blockAddr = LandUtil.getBlockAddr(this, x, y) - return clearAllWireConsumerStateUnsafe(blockAddr) + return clearAllWireRecvStateUnsafe(blockAddr) } - fun addWireConsumerStateOfUnsafe(blockAddr: BlockAddress, itemID: ItemID, state: WireConsumerState) { + fun addWireRecvStateOfUnsafe(blockAddr: BlockAddress, itemID: ItemID, state: WireRecvState) { if (wiringGraph[blockAddr] == null) wiringGraph[blockAddr] = HashMap() if (wiringGraph[blockAddr]!![itemID] == null) wiringGraph[blockAddr]!![itemID] = WiringSimCell(0) - wiringGraph[blockAddr]!![itemID]!!.consumerStates.add(state) + wiringGraph[blockAddr]!![itemID]!!.recvStates.add(state) } fun getAllWiringGraph(x: Int, y: Int): Iterable>? { @@ -438,9 +438,9 @@ open class GameWorld : Disposable { return wiringGraph[blockAddr]?.asIterable() } - fun clearAllWireConsumerStateUnsafe(blockAddr: BlockAddress) { + fun clearAllWireRecvStateUnsafe(blockAddr: BlockAddress) { wiringGraph[blockAddr]?.forEach { - it.value.consumerStates.clear() + it.value.recvStates.clear() } } @@ -637,9 +637,10 @@ open class GameWorld : Disposable { } } - data class WireConsumerState( - var dist: Int, - var state: Vector2 + data class WireRecvState( + var dist: Int, // how many tiles it took to traverse + var src: Point2i // xy position + // to get the state, use the src to get the state of the source emitter directly, then use dist to apply attenuation ) /** @@ -647,8 +648,8 @@ open class GameWorld : Disposable { */ data class WiringSimCell( var con: Byte = 0, // connections - var generatorState: Vector2 = Vector2(0.0, 0.0), // i'm emitting this much power - var consumerStates: ArrayList = ArrayList() // how far away are the power sources + var emitState: Vector2 = Vector2(0.0, 0.0), // i'm emitting this much power + var recvStates: ArrayList = ArrayList() // how far away are the power sources ) fun getTemperature(worldTileX: Int, worldTileY: Int): Float? { diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/WireGraphDebugger.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/WireGraphDebugger.kt index b05be642b..f15202d52 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/WireGraphDebugger.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/WireGraphDebugger.kt @@ -2,16 +2,14 @@ package net.torvald.terrarum.modulebasegame.gameitems import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.EMDASH import net.torvald.terrarum.* import net.torvald.terrarum.blockproperties.WireCodex import net.torvald.terrarum.gameactors.BlockMarkerActor import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.gameitem.ItemID -import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.itemproperties.MaterialCodex import net.torvald.terrarum.modulebasegame.TerrarumIngame -import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore -import kotlin.math.roundToInt class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) { @@ -55,9 +53,15 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) { val connexionIcon = (simCell.con + 0xE0A0).toChar() val wireName = WireCodex[itemID].nameKey - // todo + val emit = simCell.emitState + val recv = simCell.recvStates sb.append("$connexionIcon $wireName") + sb.append("\nE: $emit") + recv.forEach { + val src = Terrarum.ingame!!.world.getWireEmitStateOf(it.src.x, it.src.y, itemID)!! + sb.append("\nR: $src $EMDASH d ${it.dist}") + } } }