Added third upgrade type for switches (for packets / send cycle), using RAM for that, hard drives for queue size.

Some more GUI ground work.
This commit is contained in:
Florian Nücke 2014-07-15 17:48:52 +02:00
parent 8f572d2b6b
commit 33a8f56d57
18 changed files with 126 additions and 72 deletions

View File

@ -767,20 +767,33 @@ opencomputers {
}
switch {
# This is the size of a queue of a not upgraded switch.
# Increasing it allows to send more messages in a single burst
defaultMaxQueueSize: 20
# This is the amount of additional queue spaces per half upgrade tier
# For tier 1 this is multiplied with 1, for 1.5 its muliplied with 2 and so on
queueSizeUpgrade: 5
# The delay a Switch has by default (in ticks). WARNING: A too
# low value can cause lag lag on the server.
# The delay a switch has by default between relaying packets (in ticks).
# WARNING: lowering this value will result in higher maximum CPU load,
# and may in extreme cases cause server lag.
defaultRelayDelay: 5
# The amount of ticks the delay is *reduced* by per level
# The amount of ticks the delay is *reduced* by per tier of the CPU
# inserted into a switch.
relayDelayUpgrade: 1
# This is the size of the queue of a not upgraded switch. Increasing it
# avoids packets being dropped when many messages are sent in a single
# burst.
defaultMaxQueueSize: 20
# This is the amount by which the queue size increases per tier of the
# hard drive installed in the switch.
queueSizeUpgrade: 5
# The base number of packets that get relayed in one 'cycle'. The
# cooldown between cycles is determined by the delay.
defaultRelayAmount: 1
# The number of additional packets that get relayed per cycle, based on
# the tier of RAM installed in the switch. For built-in RAM this
# increases by one per half-tier, for third-party ram this increases by
# two per item tier.
relayAmountUpgrade: 1
}
# Other settings that you might find useful to tweak.

View File

@ -152,6 +152,7 @@ oc:gui.Terminal.InvalidKey=Ungültiger Schlüssel, vermutlich wurde eine andere
oc:gui.Terminal.OutOfRange=Kein Signal.
# Containers
oc:container.AccessPoint=Access Point
oc:container.Case=Computer
oc:container.Disassembler=Recycler
oc:container.DiskDrive=Diskettenlaufwerk

View File

@ -152,6 +152,7 @@ oc:gui.Terminal.InvalidKey=Invalid key, most likely another terminal has been bo
oc:gui.Terminal.OutOfRange=No signal.
# Containers
oc:container.AccessPoint=Access Point
oc:container.Case=Computer
oc:container.Disassembler=Disassembler
oc:container.DiskDrive=Disk Drive

View File

@ -79,6 +79,7 @@ oc:gui.Robot.TurnOn=Allumer
# Containers
oc:container.Case=Ordinateur
oc:container.DiskDrive=Disque dur
oc:container.Switch=Routeur
# Item / Block Tooltips
oc:tooltip.Acid=Un produit semi-liquide très toxique, uniquement bu par certains pirates. Grâce à ses propriétés corrosives, il est très utile à la gravure de circuits imprimés.
@ -119,8 +120,8 @@ oc:tooltip.Robot=Contrairement aux ordinateurs, les robots peuvent se déplacer
# The underscore makes sure this isn't hidden with the rest of the tooltip.
oc:tooltip.Robot_Level=§fNiveau§7: §a%s§7.
oc:tooltip.Robot_StoredEnergy=§fEnergie stockée§7: §a%s§7.
oc:tooltip.Router=Permet de connecter différents réseaux entre eux. Seulement des messages réseau seront transmis, les composants ne seront pas visibles via celui ci. A utiliser pour séparer des réseaux tout en leur permettant de communiquer entre eux, grâce aux Cartes réseau, par exemple.
oc:tooltip.Screen=Affiche du texte, contrôlé par une Carte graphique dans un Boitier.[nl] Résolution maximum: §f%sx%s§7.[nl] Couleurs maximales: §f%s§7.
oc:tooltip.Switch=Permet de connecter différents réseaux entre eux. Seulement des messages réseau seront transmis, les composants ne seront pas visibles via celui ci. A utiliser pour séparer des réseaux tout en leur permettant de communiquer entre eux, grâce aux Cartes réseau, par exemple.
oc:tooltip.TooLong=Maintenez la touche [§f%s§7] pour plus d'informations.
oc:tooltip.Transistor=Un élément basique constituant la plupart des pièces d'un ordinateur. Il est un peu tordu, mais il fait son boulot.
oc:tooltip.UpgradeCrafting=Permet aux robots d'utiliser le coin en haut à gauche de leur inventaire comme table d'artisanat. Vous devez respecter la position des objets comme pour un artisanat normal.

View File

@ -82,6 +82,7 @@ oc:gui.Robot.TurnOn=Ligar
# Containers
oc:container.Case=Computador
oc:container.DiskDrive=Drive de Disquetes
oc:container.Switch=Roteador
# Item / Block Tooltips
oc:tooltip.Acid=Um líquido muito tóxico, geralmente apenas consumido por alguns piratas. Graças à sua natureza corrosiva é perfeito para gravar placas de circuitos.
@ -122,8 +123,8 @@ oc:tooltip.Robot=Ao contrário dos computadores, os robôs podem mover-se e inte
# The underscore makes sure this isn't hidden with the rest of the tooltip.
oc:tooltip.Robot_Level=§fNível§7: §a%s§7.
oc:tooltip.Robot_StoredEnergy=§fEnergia Armazenada§7: §a%s§7.
oc:tooltip.Router=Permite interligar redes diferentes. Apenas pacotes de rede serão passados, componentes não serão visiveis em redes vizinhas. Usa isto para separar várias redes e ao mesmo tempo permitir comunicação através de placas de rede, por exemplo.
oc:tooltip.Screen=Mostra texto, controlado por uma placa gráfica numa Caixa.[nl] Resolução máxima: §f%sx%s§7.[nl] Profundidade de cor máxima: §f%s§7.
oc:tooltip.Switch=Permite interligar redes diferentes. Apenas pacotes de rede serão passados, componentes não serão visiveis em redes vizinhas. Usa isto para separar várias redes e ao mesmo tempo permitir comunicação através de placas de rede, por exemplo.
oc:tooltip.TooLong=Prime [§f%s§7] para uma descrição detalhada.
oc:tooltip.Transistor=Um componente básico do hardware do computador. É um pouco retorcido, mas faz o seu trabalho.
oc:tooltip.UpgradeCrafting=Permite aos robôs usar a parte superior esquerda do seu inventório para fabricar objectos. Os itens têm de estar alinhados como numa mesa de fabrico.

View File

@ -150,11 +150,13 @@ oc:gui.Terminal.InvalidKey=Неверный ключ, возможно, к се
oc:gui.Terminal.OutOfRange=Нет сигнала.
# Containers
oc:container.AccessPoint=Точка доступа
oc:container.Case=Компьютер
oc:container.Disassembler=Разборщик
oc:container.DiskDrive=Дисковод
oc:container.Rack=Серверная стойка
oc:container.Server=Сервер
oc:container.Switch=Коммутатор
# Keybinds
key.materialCosts=Показать стоимость материала

View File

@ -71,6 +71,7 @@ oc:gui.Robot.TurnOn=开启
# Containers
oc:container.Case=计算机
oc:container.DiskDrive=磁盘驱动
oc:container.Switch=路由器
# Item / Block Tooltips
oc:tooltip.Acid=一种有毒的假液相物质,通常只有某些海盗会使用它们.[nl]它的腐蚀特性令它非常完美地适用于蚀刻电路板的材料.

View File

@ -17,11 +17,11 @@ oc:tile.PowerDistributor.name=能量分配器
oc:tile.Redstone.name=紅石I/O
oc:tile.Robot.name=機器人
oc:tile.RobotAfterimage.name=機器人
oc:tile.Router.name=路由器
oc:tile.Screen0.name=黑白電腦顯示器
oc:tile.Screen1.name=彩色電腦顯示器
oc:tile.Screen2.name=高畫質電腦顯示器
oc:tile.ServerRack.name=伺服器機架
oc:tile.Switch.name=路由器
# Items
oc:item.AbstractBusCard.name=抽象的介面卡
@ -113,6 +113,7 @@ oc:container.Case=電腦
oc:container.DiskDrive=硬碟
oc:container.Rack=伺服器機架
oc:container.Server=伺服器
oc:container.Switch=路由器
# Item / Block Tooltips
oc:tooltip.AbstractBusCard=允許與 §fStargateTech 2§7 抽象卡傳送與接收 LIP 封包.
@ -155,11 +156,11 @@ oc:tooltip.Robot=和計算機不同,機器人能夠移動并且像玩家那些
# The underscore makes sure this isn't hidden with the rest of the tooltip.
oc:tooltip.Robot_Level=§f等級§7: §a%s§7.
oc:tooltip.Robot_StoredEnergy=§f儲能§7: §a%s§7.
oc:tooltip.Router=允許設備相互連接不同的網絡.[nl]僅能傳遞網絡信息,通過路由器方式設備并不互相可見.[nl]例如可以通過這種方式來建立獨立網絡但仍允許其使用網卡通訊.
oc:tooltip.Screen=由電腦機殼內的顯示卡控制來顯示文字.[nl]最高分辨率:§f%sx%s§7.[nl] 最大色深: §f%s§7.
oc:tooltip.Server=這是一台伺服器, 他非常棒, 但是他可以使用元件去升級他功能就像電腦一樣. 他可以插入伺服器機架上執行.[nl] 支援終端機數量: §f%s§7.
oc:tooltip.Server.Components=安裝的元件:
oc:tooltip.ServerRack=提供安裝最多達四個伺服器。為每個伺服器提供了一個內置的虛擬鍵盤和螢幕元件,相當於一個遠程終端。
oc:tooltip.Switch=允許設備相互連接不同的網絡.[nl]僅能傳遞網絡信息,通過路由器方式設備并不互相可見.[nl]例如可以通過這種方式來建立獨立網絡但仍允許其使用網卡通訊.
oc:tooltip.Terminal=允許遠程控制伺服器只要你在它的範圍內。就像一個隨身型螢幕和鍵盤。按住Shift鍵並滑鼠右鍵單擊某個服務器的服務器機架終端綁定它。
oc:tooltip.TooLong=按住潛行鍵([§f%s§7])以查看詳細提示信息.
oc:tooltip.Transistor=在多數其他計算機的零件中都很基礎的元件.[nl]引腳有點彎了,但還能用.

View File

@ -200,10 +200,12 @@ class Settings(config: Config) {
// ----------------------------------------------------------------------- //
// switch
val switchDefaultMaxQueueSize = config.getInt("switch.defaultMaxQueueSize") max 1
val switchQueueSizeUpgrade = config.getInt("switch.queueSizeUpgrade") max 0
val switchDefaultMaxQueueSize = config.getInt("switch.defaultMaxQueueSize") max 1
val switchRelayDelayUpgrade = config.getInt("switch.relayDelayUpgrade") max 0
val switchDefaultRelayDelay = config.getInt("switch.defaultRelayDelay") max switchRelayDelayUpgrade * 3
val switchRelayAmountUpgrade = config.getInt("switch.relayAmountUpgrade") max 0
val switchDefaultRelayAmount = config.getInt("switch.defaultRelayAmount") max 1
// ----------------------------------------------------------------------- //
// misc

View File

@ -10,5 +10,25 @@ class Switch(playerInventory: InventoryPlayer, val switch: tileentity.Switch) ex
fontRenderer.drawString(
StatCollector.translateToLocal(switch.getInvName),
8, 6, 0x404040)
fontRenderer.drawString(
StatCollector.translateToLocal("Transfer rate"),
14, 20, 0x404040)
fontRenderer.drawString(
StatCollector.translateToLocal("Packets / cycle"),
14, 39, 0x404040)
fontRenderer.drawString(
StatCollector.translateToLocal("Queue size"),
14, 58, 0x404040)
fontRenderer.drawString(
StatCollector.translateToLocal("4hz"),
108, 20, 0x404040)
fontRenderer.drawString(
StatCollector.translateToLocal("0 / 1"),
108, 39, 0x404040)
fontRenderer.drawString(
StatCollector.translateToLocal("0 / 20"),
108, 58, 0x404040)
}
}

View File

@ -197,6 +197,12 @@ object InventorySlots {
)
)
val switch = Array(
InventorySlot(Slot.Processor, Tier.Three),
InventorySlot(Slot.Memory, Tier.Three),
InventorySlot(Slot.HardDiskDrive, Tier.Three)
)
object Tier {
val None = -1
val One = 0

View File

@ -13,10 +13,8 @@ import net.minecraft.nbt.NBTTagCompound
import net.minecraft.world.World
import net.minecraftforge.common.ForgeDirection
class AccessPoint(val parent: SimpleDelegator) extends SimpleDelegate {
val unlocalizedName = "AccessPoint"
private val icons = Array.fill[Icon](6)(null)
class AccessPoint(parent: SimpleDelegator) extends Switch(parent) {
override val unlocalizedName = "AccessPoint"
// ----------------------------------------------------------------------- //
@ -36,21 +34,12 @@ class AccessPoint(val parent: SimpleDelegator) extends SimpleDelegate {
}
}
override def icon(side: ForgeDirection) = Some(icons(side.ordinal))
override def registerIcons(iconRegister: IconRegister) = {
icons(ForgeDirection.DOWN.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":generic_top")
super.registerIcons(iconRegister)
icons(ForgeDirection.UP.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":access_point_top")
icons(ForgeDirection.NORTH.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":switch_side")
icons(ForgeDirection.SOUTH.ordinal) = icons(ForgeDirection.NORTH.ordinal)
icons(ForgeDirection.WEST.ordinal) = icons(ForgeDirection.NORTH.ordinal)
icons(ForgeDirection.EAST.ordinal) = icons(ForgeDirection.NORTH.ordinal)
}
// ----------------------------------------------------------------------- //
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.AccessPoint)
}

View File

@ -14,7 +14,7 @@ import net.minecraftforge.common.ForgeDirection
class Switch(val parent: SimpleDelegator) extends SimpleDelegate {
val unlocalizedName = "Switch"
private val icons = Array.fill[Icon](6)(null)
protected val icons = Array.fill[Icon](6)(null)
// ----------------------------------------------------------------------- //

View File

@ -5,7 +5,8 @@ import li.cil.oc.common.tileentity
import net.minecraft.entity.player.InventoryPlayer
class Switch(playerInventory: InventoryPlayer, switch: tileentity.Switch) extends Player(playerInventory, switch) {
addSlotToContainer(60, 35, api.driver.Slot.Processor)
addSlotToContainer(95, 35, api.driver.Slot.Memory)
addSlotToContainer(151, 15, api.driver.Slot.Processor)
addSlotToContainer(151, 34, api.driver.Slot.Memory)
addSlotToContainer(151, 53, api.driver.Slot.HardDiskDrive)
addPlayerInventorySlots(8, 84)
}

View File

@ -80,6 +80,10 @@ class AccessPoint extends Switch with WirelessEndpoint {
// ----------------------------------------------------------------------- //
override def getInvName = Settings.namespace + "container.AccessPoint"
// ----------------------------------------------------------------------- //
override def readFromNBT(nbt: NBTTagCompound) = {
super.readFromNBT(nbt)
if (nbt.hasKey(Settings.namespace + "strength")) {

View File

@ -99,13 +99,7 @@ class Case(var tier: Int, val isRemote: Boolean) extends traits.PowerAcceptor wi
override def getInvName = Settings.namespace + "container.Case"
override def getSizeInventory = tier match {
case 0 => 6
case 1 => 7
case 2 => 9
case 3 => 9
case _ => 0
}
override def getSizeInventory = if (tier < 0 || tier >= InventorySlots.computer.length) 0 else InventorySlots.computer(tier).length
override def isUseableByPlayer(player: EntityPlayer) =
world.getBlockTileEntity(x, y, z) match {

View File

@ -2,17 +2,18 @@ package li.cil.oc.common.tileentity
import cpw.mods.fml.common.Optional
import dan200.computer.api.{IComputerAccess, ILuaContext, IPeripheral}
import li.cil.oc.api.Driver
import li.cil.oc.api.driver
import li.cil.oc.api.driver.Slot
import li.cil.oc.api.network.{Message, Packet}
import li.cil.oc.common.{InventorySlots, item}
import li.cil.oc.server.PacketSender
import li.cil.oc.util.mods.Mods
import li.cil.oc.{Items, Settings, api}
import li.cil.oc.common.item
import net.minecraft.item.ItemStack
import net.minecraftforge.common.ForgeDirection
import scala.collection.mutable
import net.minecraft.item.ItemStack
import li.cil.oc.api.Driver
import li.cil.oc.api.driver.{Processor, Memory, Slot}
// Note on the CC1.5+1.6 compatibility
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -147,39 +148,42 @@ class Switch extends traits.Hub with traits.NotAnalyzable with IPeripheral with
}
}
override def isItemValidForSlot(slot: Int, stack: ItemStack) = (slot, Option(Driver.driverFor(stack))) match {
case (1, Some(driver)) => driver.slot(stack) == Slot.Memory
case (0, Some(driver)) => driver.slot(stack) == Slot.Processor
case _ => false
}
override def getInvName = Settings.namespace + "container.Switch"
override def getSizeInventory = 2
// ----------------------------------------------------------------------- //
override protected def onItemAdded(slot: Int, stack: ItemStack) {
super.onItemAdded(slot, stack)
Driver.driverFor(stack) match {
case mem: Memory =>
maxQueueSize = queueDefaultSize + (Items.multi.subItem(stack) match {
case Some(ram: item.Memory) => (ram.tier + 1) * queueUpgradeSize
case _ => (mem.tier(stack) + 1) * (queueUpgradeSize * 2)
case driver if driver.slot(stack) == Slot.Processor =>
relayDelay = relayBaseDelay - (driver.tier(stack) * relayDelayPerUpgrade)
case driver if driver.slot(stack) == Slot.Memory =>
relayAmount = relayBaseAmount + (Items.multi.subItem(stack) match {
case Some(ram: item.Memory) => (ram.tier + 1) * relayAmountPerUpgrade
case _ => (driver.tier(stack) + 1) * (relayAmountPerUpgrade * 2)
})
case cpu: Processor =>
relayDelay = relayDefaultDelay -
(cpu.tier(stack) * relayUpgradeDelay)
case driver if driver.slot(stack) == Slot.HardDiskDrive =>
maxQueueSize = queueBaseSize + (driver.tier(stack) + 1) * queueSizePerUpgrade
}
}
override protected def onItemRemoved(slot: Int, stack: ItemStack) {
super.onItemRemoved(slot, stack)
slot match {
case 0 => relayDelay = relayDefaultDelay
case 1 => maxQueueSize = queueDefaultSize
Driver.driverFor(stack) match {
case driver if driver.slot(stack) == Slot.Processor => relayDelay = relayBaseDelay
case driver if driver.slot(stack) == Slot.Memory => relayAmount = relayBaseAmount
case driver if driver.slot(stack) == Slot.HardDiskDrive => maxQueueSize = queueBaseSize
}
}
override def getInvName = Settings.namespace + "container.Switch"
override def getSizeInventory = InventorySlots.switch.length
override def isItemValidForSlot(slot: Int, stack: ItemStack) =
Option(Driver.driverFor(stack)).fold(false)(driver => {
val provided = InventorySlots.switch(slot)
driver.slot(stack) == provided.slot && driver.tier(stack) <= provided.tier
})
}
// Abstraction layer for CC computers to support 1.5 and 1.6 API.

View File

@ -19,16 +19,27 @@ trait Hub extends traits.Environment with SidedEnvironment {
protected val queue = mutable.Queue.empty[(ForgeDirection, Packet)]
protected def queueDefaultSize = Settings.get.switchDefaultMaxQueueSize
protected def queueUpgradeSize = Settings.get.switchQueueSizeUpgrade
protected def relayDefaultDelay = Settings.get.switchDefaultRelayDelay
protected def relayUpgradeDelay = Settings.get.switchRelayDelayUpgrade
protected var maxQueueSize = queueBaseSize
protected var maxQueueSize = Settings.get.switchDefaultMaxQueueSize
protected var relayDelay = relayBaseDelay
protected var relayAmount = relayBaseAmount
protected var relayCooldown = -1
protected var relayDelay = Settings.get.switchDefaultRelayDelay
// ----------------------------------------------------------------------- //
protected def queueBaseSize = Settings.get.switchDefaultMaxQueueSize
protected def queueSizePerUpgrade = Settings.get.switchQueueSizeUpgrade
protected def relayBaseDelay = Settings.get.switchDefaultRelayDelay
protected def relayDelayPerUpgrade = Settings.get.switchRelayDelayUpgrade
protected def relayBaseAmount = Settings.get.switchDefaultRelayAmount
protected def relayAmountPerUpgrade = Settings.get.switchRelayAmountUpgrade
// ----------------------------------------------------------------------- //
@ -45,8 +56,10 @@ trait Hub extends traits.Environment with SidedEnvironment {
relayCooldown -= 1
}
else if (queue.nonEmpty) queue.synchronized {
val (sourceSide, packet) = queue.dequeue()
relayPacket(sourceSide, packet)
for (i <- 0 until math.min(queue.size, relayAmount)) {
val (sourceSide, packet) = queue.dequeue()
relayPacket(sourceSide, packet)
}
if (queue.nonEmpty) {
relayCooldown = relayDelay
}