mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 12:17:17 -04:00
fixed access points not directly relaying wireless packets and the way hub relay delays work
This commit is contained in:
parent
2c54b6ddd7
commit
d678024bd6
@ -93,7 +93,7 @@ class Router extends traits.Hub with traits.NotAnalyzable with IPeripheral {
|
||||
override protected def relayPacket(sourceSide: ForgeDirection, packet: Packet) {
|
||||
super.relayPacket(sourceSide, packet)
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - lastMessage > 250) {
|
||||
if (now - lastMessage >= (relayDelay - 1) * 50) {
|
||||
lastMessage = now
|
||||
PacketSender.sendRouterActivity(this)
|
||||
}
|
||||
|
@ -37,9 +37,7 @@ class WirelessRouter extends Router with WirelessEndpoint {
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def receivePacket(packet: Packet, distance: Double) {
|
||||
if (queue.size < maxQueueSize) {
|
||||
queue += ForgeDirection.UNKNOWN -> packet.hop()
|
||||
}
|
||||
tryEnqueuePacket(ForgeDirection.UNKNOWN, packet)
|
||||
if (Loader.isModLoaded("ComputerCraft")) {
|
||||
packet.data.headOption match {
|
||||
case Some(answerPort: java.lang.Double) => queueMessage(packet.source, packet.destination, packet.port, answerPort.toInt, packet.data.drop(1))
|
||||
@ -50,8 +48,8 @@ class WirelessRouter extends Router with WirelessEndpoint {
|
||||
|
||||
override protected def relayPacket(sourceSide: ForgeDirection, packet: Packet) {
|
||||
super.relayPacket(sourceSide, packet)
|
||||
if (sourceSide != ForgeDirection.UNKNOWN && strength > 0) {
|
||||
if (sourceSide == null || {
|
||||
if (strength > 0) {
|
||||
if (sourceSide == null || sourceSide == ForgeDirection.UNKNOWN || {
|
||||
val cost = Settings.get.wirelessCostPerRange
|
||||
val connector = plugs(sourceSide.ordinal).node.asInstanceOf[Connector]
|
||||
connector.tryChangeBuffer(-strength * cost)
|
||||
|
@ -18,6 +18,10 @@ trait Hub extends traits.Environment with SidedEnvironment {
|
||||
|
||||
protected val maxQueueSize = 20
|
||||
|
||||
protected var relayCooldown = 0
|
||||
|
||||
protected val relayDelay = 5
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@ -29,9 +33,22 @@ trait Hub extends traits.Environment with SidedEnvironment {
|
||||
|
||||
override def updateEntity() {
|
||||
super.updateEntity()
|
||||
if (world.getWorldTime % 5 == 0 && queue.nonEmpty) {
|
||||
if (relayCooldown > 0) {
|
||||
relayCooldown -= 1
|
||||
}
|
||||
else if (queue.nonEmpty) {
|
||||
val (sourceSide, packet) = queue.dequeue()
|
||||
relayPacket(sourceSide, packet)
|
||||
relayCooldown = relayDelay
|
||||
}
|
||||
}
|
||||
|
||||
protected def tryEnqueuePacket(sourceSide: ForgeDirection, packet: Packet) {
|
||||
if (packet.ttl > 0 && queue.size < maxQueueSize) {
|
||||
queue += sourceSide -> packet.hop()
|
||||
if (relayCooldown <= 0) {
|
||||
relayCooldown = relayDelay
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +68,9 @@ trait Hub extends traits.Environment with SidedEnvironment {
|
||||
val packet = api.Network.newPacket(tag)
|
||||
queue += side -> packet
|
||||
})
|
||||
if (nbt.hasKey(Settings.namespace + "relayCooldown")) {
|
||||
relayCooldown = nbt.getInteger(Settings.namespace + "relayCooldown")
|
||||
}
|
||||
}
|
||||
|
||||
override def writeToNBT(nbt: NBTTagCompound) {
|
||||
@ -69,6 +89,9 @@ trait Hub extends traits.Environment with SidedEnvironment {
|
||||
packet.save(tag)
|
||||
tag
|
||||
})
|
||||
if (relayCooldown > 0) {
|
||||
nbt.setInteger(Settings.namespace + "relayCooldown", relayCooldown)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +121,7 @@ trait Hub extends traits.Environment with SidedEnvironment {
|
||||
|
||||
protected def onPlugMessage(plug: Plug, message: Message) {
|
||||
if (message.name == "network.message") message.data match {
|
||||
case Array(packet: Packet) if packet.ttl > 0 && queue.size < maxQueueSize => queue += plug.side -> packet.hop()
|
||||
case Array(packet: Packet) => tryEnqueuePacket(plug.side, packet)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user