mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
changes on wire receive state
This commit is contained in:
@@ -357,24 +357,24 @@ open class GameWorld : Disposable {
|
|||||||
return wiringGraph[blockAddr]?.get(itemID)?.con
|
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 (x, y) = coerceXY(x, y)
|
||||||
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
||||||
return getWireGeneratorStateUnsafe(blockAddr, itemID)
|
return getWireEmitStateUnsafe(blockAddr, itemID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getWireGeneratorStateUnsafe(blockAddr: BlockAddress, itemID: ItemID): Vector2? {
|
fun getWireEmitStateUnsafe(blockAddr: BlockAddress, itemID: ItemID): Vector2? {
|
||||||
return wiringGraph[blockAddr]?.get(itemID)?.generatorState
|
return wiringGraph[blockAddr]?.get(itemID)?.emitState
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getWireConsumerStateOf(x: Int, y: Int, itemID: ItemID): ArrayList<WireConsumerState>? {
|
fun getWireRecvStateOf(x: Int, y: Int, itemID: ItemID): ArrayList<WireRecvState>? {
|
||||||
val (x, y) = coerceXY(x, y)
|
val (x, y) = coerceXY(x, y)
|
||||||
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
||||||
return getWireConsumerStateUnsafe(blockAddr, itemID)
|
return getWireRecvStateUnsafe(blockAddr, itemID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getWireConsumerStateUnsafe(blockAddr: BlockAddress, itemID: ItemID): ArrayList<WireConsumerState>? {
|
fun getWireRecvStateUnsafe(blockAddr: BlockAddress, itemID: ItemID): ArrayList<WireRecvState>? {
|
||||||
return wiringGraph[blockAddr]?.get(itemID)?.consumerStates
|
return wiringGraph[blockAddr]?.get(itemID)?.recvStates
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setWireGraphOf(x: Int, y: Int, itemID: ItemID, byte: Byte) {
|
fun setWireGraphOf(x: Int, y: Int, itemID: ItemID, byte: Byte) {
|
||||||
@@ -392,40 +392,40 @@ open class GameWorld : Disposable {
|
|||||||
wiringGraph[blockAddr]!![itemID]!!.con = byte
|
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 (x, y) = coerceXY(x, y)
|
||||||
val blockAddr = LandUtil.getBlockAddr(this, 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)
|
if (wiringGraph[blockAddr] == null)
|
||||||
wiringGraph[blockAddr] = HashMap()
|
wiringGraph[blockAddr] = HashMap()
|
||||||
if (wiringGraph[blockAddr]!![itemID] == null)
|
if (wiringGraph[blockAddr]!![itemID] == null)
|
||||||
wiringGraph[blockAddr]!![itemID] = WiringSimCell(0, vector)
|
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 (x, y) = coerceXY(x, y)
|
||||||
val blockAddr = LandUtil.getBlockAddr(this, 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 (x, y) = coerceXY(x, y)
|
||||||
val blockAddr = LandUtil.getBlockAddr(this, 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)
|
if (wiringGraph[blockAddr] == null)
|
||||||
wiringGraph[blockAddr] = HashMap()
|
wiringGraph[blockAddr] = HashMap()
|
||||||
if (wiringGraph[blockAddr]!![itemID] == null)
|
if (wiringGraph[blockAddr]!![itemID] == null)
|
||||||
wiringGraph[blockAddr]!![itemID] = WiringSimCell(0)
|
wiringGraph[blockAddr]!![itemID] = WiringSimCell(0)
|
||||||
|
|
||||||
wiringGraph[blockAddr]!![itemID]!!.consumerStates.add(state)
|
wiringGraph[blockAddr]!![itemID]!!.recvStates.add(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllWiringGraph(x: Int, y: Int): Iterable<Map.Entry<ItemID, WiringSimCell>>? {
|
fun getAllWiringGraph(x: Int, y: Int): Iterable<Map.Entry<ItemID, WiringSimCell>>? {
|
||||||
@@ -438,9 +438,9 @@ open class GameWorld : Disposable {
|
|||||||
return wiringGraph[blockAddr]?.asIterable()
|
return wiringGraph[blockAddr]?.asIterable()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearAllWireConsumerStateUnsafe(blockAddr: BlockAddress) {
|
fun clearAllWireRecvStateUnsafe(blockAddr: BlockAddress) {
|
||||||
wiringGraph[blockAddr]?.forEach {
|
wiringGraph[blockAddr]?.forEach {
|
||||||
it.value.consumerStates.clear()
|
it.value.recvStates.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -637,9 +637,10 @@ open class GameWorld : Disposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class WireConsumerState(
|
data class WireRecvState(
|
||||||
var dist: Int,
|
var dist: Int, // how many tiles it took to traverse
|
||||||
var state: Vector2
|
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(
|
data class WiringSimCell(
|
||||||
var con: Byte = 0, // connections
|
var con: Byte = 0, // connections
|
||||||
var generatorState: Vector2 = Vector2(0.0, 0.0), // i'm emitting this much power
|
var emitState: Vector2 = Vector2(0.0, 0.0), // i'm emitting this much power
|
||||||
var consumerStates: ArrayList<WireConsumerState> = ArrayList() // how far away are the power sources
|
var recvStates: ArrayList<WireRecvState> = ArrayList() // how far away are the power sources
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getTemperature(worldTileX: Int, worldTileY: Int): Float? {
|
fun getTemperature(worldTileX: Int, worldTileY: Int): Float? {
|
||||||
|
|||||||
@@ -2,16 +2,14 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
|
import net.torvald.EMDASH
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.blockproperties.WireCodex
|
import net.torvald.terrarum.blockproperties.WireCodex
|
||||||
import net.torvald.terrarum.gameactors.BlockMarkerActor
|
import net.torvald.terrarum.gameactors.BlockMarkerActor
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
|
||||||
import net.torvald.terrarum.itemproperties.MaterialCodex
|
import net.torvald.terrarum.itemproperties.MaterialCodex
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore
|
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
||||||
|
|
||||||
@@ -55,9 +53,15 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
|||||||
val connexionIcon = (simCell.con + 0xE0A0).toChar()
|
val connexionIcon = (simCell.con + 0xE0A0).toChar()
|
||||||
val wireName = WireCodex[itemID].nameKey
|
val wireName = WireCodex[itemID].nameKey
|
||||||
|
|
||||||
// todo
|
val emit = simCell.emitState
|
||||||
|
val recv = simCell.recvStates
|
||||||
|
|
||||||
sb.append("$connexionIcon $wireName")
|
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}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user