mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
fixing minor bugs
This commit is contained in:
@@ -31,10 +31,9 @@ open class FixtureRingBusCore : Electric {
|
|||||||
private var portEmit = Point2i(0, 0)
|
private var portEmit = Point2i(0, 0)
|
||||||
private var portSink = Point2i(1, 0)
|
private var portSink = Point2i(1, 0)
|
||||||
|
|
||||||
constructor(portEmit: Point2i, portSink: Point2i, blockBox: BlockBox, nameFun: () -> String, mainUI: UICanvas?) : super(
|
constructor(portEmit: Point2i, portSink: Point2i, blockBox: BlockBox, nameFun: () -> String) : super(
|
||||||
blockBox0 = blockBox,
|
blockBox0 = blockBox,
|
||||||
nameFun = nameFun,
|
nameFun = nameFun,
|
||||||
mainUI = mainUI
|
|
||||||
) {
|
) {
|
||||||
this.portEmit = portEmit
|
this.portEmit = portEmit
|
||||||
this.portSink = portSink
|
this.portSink = portSink
|
||||||
@@ -74,7 +73,7 @@ open class FixtureRingBusCore : Electric {
|
|||||||
NORMAL,
|
NORMAL,
|
||||||
ABORT,
|
ABORT,
|
||||||
ELECTING,
|
ELECTING,
|
||||||
ELECTED_MONITOR
|
IVE_GOT_ELECTED
|
||||||
}
|
}
|
||||||
|
|
||||||
private var currentState = RingBusState.NORMAL
|
private var currentState = RingBusState.NORMAL
|
||||||
@@ -109,7 +108,7 @@ open class FixtureRingBusCore : Electric {
|
|||||||
RingBusState.NORMAL -> handleNormalState(frame, frameNumber)
|
RingBusState.NORMAL -> handleNormalState(frame, frameNumber)
|
||||||
RingBusState.ABORT -> handleAbortState(frame, frameNumber)
|
RingBusState.ABORT -> handleAbortState(frame, frameNumber)
|
||||||
RingBusState.ELECTING -> handleElectingState(frame, frameNumber)
|
RingBusState.ELECTING -> handleElectingState(frame, frameNumber)
|
||||||
RingBusState.ELECTED_MONITOR -> handleElectedMonitorState(frame, frameNumber)
|
RingBusState.IVE_GOT_ELECTED -> handleIveGotElectedState(frame, frameNumber)
|
||||||
}
|
}
|
||||||
} catch (e: NullPointerException) {
|
} catch (e: NullPointerException) {
|
||||||
handleFrameLoss()
|
handleFrameLoss()
|
||||||
@@ -147,7 +146,8 @@ open class FixtureRingBusCore : Electric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (frame.getSender() == mac && frame.getBallot() == mac) {
|
if (frame.getSender() == mac && frame.getBallot() == mac) {
|
||||||
currentState = RingBusState.ELECTED_MONITOR
|
currentState = RingBusState.IVE_GOT_ELECTED
|
||||||
|
// elected Active Monitor sends out the first token
|
||||||
val newFrame = emitNewFrame(NetFrame.makeToken(mac))
|
val newFrame = emitNewFrame(NetFrame.makeToken(mac))
|
||||||
setWireEmissionAt(portEmit.x, portEmit.y, Vector2(1.0, newFrame.toDouble()))
|
setWireEmissionAt(portEmit.x, portEmit.y, Vector2(1.0, newFrame.toDouble()))
|
||||||
} else {
|
} else {
|
||||||
@@ -158,12 +158,15 @@ open class FixtureRingBusCore : Electric {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleElectedMonitorState(frame: NetFrame, frameNumber: Int) {
|
private fun handleIveGotElectedState(frame: NetFrame, frameNumber: Int) {
|
||||||
if (frame.getFrameType() == "abort") {
|
if (frame.getFrameType() == "abort") {
|
||||||
|
// immediately return to normal state
|
||||||
val newFrame = emitNewFrame(NetFrame.makeToken(mac))
|
val newFrame = emitNewFrame(NetFrame.makeToken(mac))
|
||||||
currentState = RingBusState.NORMAL
|
currentState = RingBusState.NORMAL
|
||||||
setWireEmissionAt(portEmit.x, portEmit.y, Vector2(1.0, newFrame.toDouble()))
|
setWireEmissionAt(portEmit.x, portEmit.y, Vector2(1.0, newFrame.toDouble()))
|
||||||
} else {
|
} else {
|
||||||
|
// make sure to skip a turn after the election, even if the NIC has something to send out
|
||||||
|
currentState = RingBusState.NORMAL
|
||||||
setWireEmissionAt(portEmit.x, portEmit.y, Vector2())
|
setWireEmissionAt(portEmit.x, portEmit.y, Vector2())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulecomputers.gameactors
|
|||||||
import net.torvald.terrarum.Point2i
|
import net.torvald.terrarum.Point2i
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.BlockBox
|
import net.torvald.terrarum.modulebasegame.gameactors.BlockBox
|
||||||
|
import net.torvald.terrarum.modulecomputers.ui.UIRingBusAnalyser
|
||||||
import net.torvald.terrarum.modulecomputers.ui.UIRingBusExerciser
|
import net.torvald.terrarum.modulecomputers.ui.UIRingBusExerciser
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,9 +15,10 @@ class FixtureRingBusExerciser : FixtureRingBusCore {
|
|||||||
portEmit = Point2i(0, 0),
|
portEmit = Point2i(0, 0),
|
||||||
portSink = Point2i(1, 0),
|
portSink = Point2i(1, 0),
|
||||||
blockBox = BlockBox(BlockBox.NO_COLLISION, 2, 2),
|
blockBox = BlockBox(BlockBox.NO_COLLISION, 2, 2),
|
||||||
nameFun = { Lang["ITEM_DEBUG_RING_BUS_EXERCISER"] },
|
nameFun = { Lang["ITEM_DEBUG_RING_BUS_EXERCISER"] }
|
||||||
mainUI = UIRingBusExerciser(this)
|
) {
|
||||||
)
|
this.mainUI = UIRingBusExerciser(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -33,8 +35,9 @@ class FixtureRingBusAnalyser : FixtureRingBusCore {
|
|||||||
portSink = Point2i(1, 0),
|
portSink = Point2i(1, 0),
|
||||||
blockBox = BlockBox(BlockBox.NO_COLLISION, 2, 1),
|
blockBox = BlockBox(BlockBox.NO_COLLISION, 2, 1),
|
||||||
nameFun = { Lang["ITEM_DEBUG_RING_BUS_Analyser"] },
|
nameFun = { Lang["ITEM_DEBUG_RING_BUS_Analyser"] },
|
||||||
mainUI = UIRingBusAnalyser()
|
) {
|
||||||
)
|
this.mainUI = UIRingBusAnalyser(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user