From df1939cb0eca340ba95aeef39aba44e060c5685a Mon Sep 17 00:00:00 2001 From: payonel Date: Tue, 11 Jun 2019 09:09:40 -0700 Subject: [PATCH] rack send message to mountables immediately relay (hub) doesn't repeat message in reverse relay shows actual packets/cycle closes #3095 --- .../li/cil/oc/common/tileentity/Rack.scala | 23 ++++++++++++++----- .../cil/oc/common/tileentity/traits/Hub.scala | 14 +++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Rack.scala b/src/main/scala/li/cil/oc/common/tileentity/Rack.scala index f12cc0f05..48bd57d21 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Rack.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Rack.scala @@ -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() diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala index b2b1377f4..4c9d303fa 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala @@ -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) + } + } } }