rack send message to mountables immediately

relay (hub) doesn't repeat message in reverse
relay shows actual packets/cycle

closes #3095
This commit is contained in:
payonel 2019-06-11 09:09:40 -07:00
parent fac5ecbe87
commit df1939cb0e
2 changed files with 27 additions and 10 deletions

View File

@ -132,12 +132,7 @@ class Rack extends traits.PowerAcceptor with traits.Hub with traits.PowerBalance
}
}
// ----------------------------------------------------------------------- //
// Hub
override protected def relayPacket(sourceSide: Option[ForgeDirection], packet: Packet): Unit = {
if (isRelayEnabled) super.relayPacket(sourceSide, packet)
protected def sendPacketToMountables(sourceSide: Option[ForgeDirection], packet: Packet): Unit = {
// When a message arrives on a bus, also send it to all secondary nodes
// connected to it. Only deliver it to that very node, if it's not the
// sender, to avoid loops.
@ -159,6 +154,22 @@ class Rack extends traits.PowerAcceptor with traits.Hub with traits.PowerBalance
}
}
// ----------------------------------------------------------------------- //
// Hub
override def tryEnqueuePacket(sourceSide: Option[ForgeDirection], packet: Packet): Boolean = {
sendPacketToMountables(sourceSide, packet)
if (isRelayEnabled)
super.tryEnqueuePacket(sourceSide, packet)
else
true
}
override protected def relayPacket(sourceSide: Option[ForgeDirection], packet: Packet): Unit = {
if (isRelayEnabled)
super.relayPacket(sourceSide, packet)
}
override protected def onPlugConnect(plug: Plug, node: Node): Unit = {
super.onPlugConnect(plug, node)
connectComponents()

View File

@ -69,8 +69,9 @@ trait Hub extends traits.Environment with SidedEnvironment {
else {
relayCooldown = -1
if (queue.nonEmpty) queue.synchronized {
packetsPerCycleAvg += queue.size
for (i <- 0 until math.min(queue.size, relayAmount)) {
val packetsToRely = math.min(queue.size, relayAmount)
packetsPerCycleAvg += packetsToRely
for (i <- 0 until packetsToRely) {
val (sourceSide, packet) = queue.dequeue()
relayPacket(sourceSide, packet)
}
@ -96,8 +97,13 @@ trait Hub extends traits.Environment with SidedEnvironment {
}
protected def relayPacket(sourceSide: Option[ForgeDirection], packet: Packet) {
for (side <- ForgeDirection.VALID_DIRECTIONS if Option(side) != sourceSide && sidedNode(side) != null) {
sidedNode(side).sendToReachable("network.message", packet)
for (side <- ForgeDirection.VALID_DIRECTIONS) {
if (sourceSide.isEmpty || sourceSide.get != side) {
val node = sidedNode(side)
if (node != null) {
node.sendToReachable("network.message", packet)
}
}
}
}