Fixed CPU and memory not being neighbor only visible.

Fixed tier numbers being used 0-indexed in device info texts.
Fixed machine hosts' device info not being exposed.
This commit is contained in:
Florian Nücke 2016-06-05 11:04:06 +02:00
parent 735ed6b271
commit 8da15681bf
7 changed files with 21 additions and 8 deletions

View File

@ -7,6 +7,11 @@ import java.util.Map;
* expose some (typically static) information about the device represented by
* that environment to a {@link li.cil.oc.api.Machine} connected to it.
* <p/>
* You may also implement this on a {@link li.cil.oc.api.machine.MachineHost}
* in which case the <code>Machine</code> will forward that information as
* its own (since <code>MachineHost</code>s usually use the machine's node as
* their own, this avoids a dummy environment used solely for device info).
* <p/>
* This is intended to permit programs to reflect on the hardware they are
* running on, typically for purely informational purposes, but possibly to
* toggle certain hardware specific features.

View File

@ -41,7 +41,7 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
DeviceAttribute.Class -> DeviceClass.Display,
DeviceAttribute.Description -> "Holographic projector",
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
DeviceAttribute.Product -> ("VirtualViewer H1-" + tier.toString),
DeviceAttribute.Product -> ("VirtualViewer H1-" + (tier + 1).toString),
DeviceAttribute.Capacity -> (width * width * height).toString,
DeviceAttribute.Width -> colors.length.toString
)

View File

@ -14,7 +14,7 @@ class APU(tier: Int) extends GraphicsCard(tier) {
DeviceAttribute.Class -> DeviceClass.Processor,
DeviceAttribute.Description -> "APU",
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
DeviceAttribute.Product -> ("FlexiArch " + tier.toString + " Processor (Builtin Graphics)"),
DeviceAttribute.Product -> ("FlexiArch " + (tier + 1).toString + " Processor (Builtin Graphics)"),
DeviceAttribute.Capacity -> capacityInfo,
DeviceAttribute.Width -> widthInfo,
DeviceAttribute.Clock -> ((Settings.get.callBudgets(tier) * 1000).toInt.toString + "+" + clockInfo)

View File

@ -14,14 +14,14 @@ import li.cil.oc.api.prefab
import scala.collection.convert.WrapAsJava._
class CPU(val tier: Int) extends prefab.ManagedEnvironment with DeviceInfo {
override val node = Network.newNode(this, Visibility.Network).
override val node = Network.newNode(this, Visibility.Neighbors).
create()
private final lazy val deviceInfo = Map(
DeviceAttribute.Class -> DeviceClass.Processor,
DeviceAttribute.Description -> "CPU",
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
DeviceAttribute.Product -> ("FlexiArch " + tier.toString + " Processor"),
DeviceAttribute.Product -> ("FlexiArch " + (tier + 1).toString + " Processor"),
DeviceAttribute.Clock -> (Settings.get.callBudgets(tier) * 1000).toInt.toString
)

View File

@ -65,7 +65,7 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment with DeviceI
DeviceAttribute.Class -> DeviceClass.Display,
DeviceAttribute.Description -> "Graphics controller",
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
DeviceAttribute.Product -> ("MPG" + (tier * 1000).toString + " GTZ"),
DeviceAttribute.Product -> ("MPG" + ((tier + 1) * 1000).toString + " GTZ"),
DeviceAttribute.Capacity -> capacityInfo,
DeviceAttribute.Width -> widthInfo,
DeviceAttribute.Clock -> clockInfo

View File

@ -14,7 +14,7 @@ import li.cil.oc.api.prefab
import scala.collection.convert.WrapAsJava._
class Memory(val tier: Int) extends prefab.ManagedEnvironment with DeviceInfo {
override val node = Network.newNode(this, Visibility.Network).
override val node = Network.newNode(this, Visibility.Neighbors).
create()
private final lazy val deviceInfo = Map(

View File

@ -1,5 +1,6 @@
package li.cil.oc.server.machine
import java.util
import java.util.concurrent.TimeUnit
import li.cil.oc.OpenComputers
@ -47,7 +48,7 @@ import scala.collection.convert.WrapAsJava._
import scala.collection.convert.WrapAsScala._
import scala.collection.mutable
class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with machine.Machine with Runnable {
class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with machine.Machine with Runnable with DeviceInfo {
override val node = Network.newNode(this, Visibility.Network).
withComponent("computer", Visibility.Neighbors).
withConnector(Settings.get.bufferComputer).
@ -178,6 +179,13 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
// ----------------------------------------------------------------------- //
override def getDeviceInfo: util.Map[String, String] = host match {
case deviceInfo: DeviceInfo => deviceInfo.getDeviceInfo
case _ => null
}
// ----------------------------------------------------------------------- //
override def canInteract(player: String) = !Settings.get.canComputersBeOwned ||
_users.synchronized(_users.isEmpty || _users.contains(player)) ||
MinecraftServer.getServer.isSinglePlayer || {
@ -426,7 +434,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
context.pause(1) // Iterating all nodes is potentially expensive, and I see no practical reason for having to call this frequently.
Array[AnyRef](node.network.nodes.map(n => (n, n.host)).collect {
case (n: Component, deviceInfo: DeviceInfo) =>
if (n.canBeSeenFrom(node)) {
if (n.canBeSeenFrom(node) || n == node) {
Option(deviceInfo.getDeviceInfo) match {
case Some(info) => Option(n.address -> info)
case _ => None