i dont even know what am i doing :/

This commit is contained in:
minjaesong
2021-08-10 17:43:44 +09:00
parent f1cece1064
commit c8b5578a91
2 changed files with 25 additions and 6 deletions

View File

@@ -428,14 +428,14 @@ open class GameWorld : Disposable {
wiringGraph[blockAddr]!![itemID]!!.recvStates.add(state)
}
fun getAllWiringGraph(x: Int, y: Int): Iterable<Map.Entry<ItemID, WiringSimCell>>? {
fun getAllWiringGraph(x: Int, y: Int): HashMap<ItemID, WiringSimCell>? {
val (x, y) = coerceXY(x, y)
val blockAddr = LandUtil.getBlockAddr(this, x, y)
return getAllWiringGraphUnsafe(blockAddr)
}
fun getAllWiringGraphUnsafe(blockAddr: BlockAddress): Iterable<Map.Entry<ItemID, WiringSimCell>>? {
return wiringGraph[blockAddr]?.asIterable()
fun getAllWiringGraphUnsafe(blockAddr: BlockAddress): HashMap<ItemID, WiringSimCell>? {
return wiringGraph[blockAddr]
}
fun clearAllWireRecvStateUnsafe(blockAddr: BlockAddress) {

View File

@@ -6,9 +6,11 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.blockproperties.WireCodex
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.TerrarumIngame.Companion.inUpdateRange
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.gameactors.BlockBoxIndex
@@ -478,11 +480,28 @@ object WorldSimulator {
fixture.worldBlockPos?.let {
val branchesVisited = ArrayList<Point2i>()
val branchingStack = Stack<Point2i>()
val startPoint = it + fixture.blockBoxIndexToPoint2i(bbi)
branchingStack.push(startPoint)
val point = it + fixture.blockBoxIndexToPoint2i(bbi)
branchingStack.push(point.copy())
while (branchingStack.isNotEmpty()) {
// get all wires that matches 'accepts' (such as Red/Green/Blue wire) and propagate signal for each of them
world.getAllWiresFrom(point.x, point.y)?.filter { WireCodex[it].accepts == wireType }?.forEach { wire ->
world.getAllWiringGraph(point.x, point.y)?.get(wire)?.let { node ->
val connexion = node.con.toInt()
when (wireConToStatus[connexion]) {
WireConStatus.THRU -> {
// TODO
}
WireConStatus.END -> {
// TODO
}
WireConStatus.BRANCH -> {
// TODO
branchingStack.push(point.copy())
}
}
}
}
}
}
}