mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-11 16:28:12 -04:00
Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComputers into master-MC1.8.9
This commit is contained in:
commit
5f04b13f04
@ -103,7 +103,7 @@ public interface Network {
|
|||||||
Iterable<Node> nodes();
|
Iterable<Node> nodes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of addressed nodes in the network visible to the specified node.
|
* The list of addressed nodes in the network reachable by the specified node.
|
||||||
* <p/>
|
* <p/>
|
||||||
* This does <em>not</em> include nodes with a visibility of <tt>None</tt>
|
* This does <em>not</em> include nodes with a visibility of <tt>None</tt>
|
||||||
* or a visibility of <tt>Neighbors</tt> when there is no direct connection
|
* or a visibility of <tt>Neighbors</tt> when there is no direct connection
|
||||||
|
@ -21,7 +21,7 @@ local function get(pasteId, filename)
|
|||||||
end
|
end
|
||||||
|
|
||||||
io.write("Downloading from pastebin.com... ")
|
io.write("Downloading from pastebin.com... ")
|
||||||
local url = "http://pastebin.com/raw.php?i=" .. pasteId
|
local url = "http://pastebin.com/raw/" .. pasteId
|
||||||
local result, response = pcall(internet.request, url)
|
local result, response = pcall(internet.request, url)
|
||||||
if result then
|
if result then
|
||||||
io.write("success.\n")
|
io.write("success.\n")
|
||||||
|
@ -15,7 +15,8 @@ function loadfile(filename, mode, env)
|
|||||||
end
|
end
|
||||||
table.insert(buffer, data)
|
table.insert(buffer, data)
|
||||||
end
|
end
|
||||||
buffer = table.concat(buffer):gsub("^#![^\n]+", "") -- remove shebang if any
|
buffer[1] = (buffer[1] or ""):gsub("^#![^\n]+", "") -- remove shebang if any
|
||||||
|
buffer = table.concat(buffer)
|
||||||
return load(buffer, "=" .. filename, mode, env)
|
return load(buffer, "=" .. filename, mode, env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@ function internet.request(url, data, headers)
|
|||||||
checkArg(2, data, "string", "table", "nil")
|
checkArg(2, data, "string", "table", "nil")
|
||||||
checkArg(3, headers, "table", "nil")
|
checkArg(3, headers, "table", "nil")
|
||||||
|
|
||||||
local inet = component.internet
|
if not component.isAvailable("internet") then
|
||||||
if not inet then
|
|
||||||
error("no primary internet card found", 2)
|
error("no primary internet card found", 2)
|
||||||
end
|
end
|
||||||
|
local inet = component.internet
|
||||||
|
|
||||||
local post
|
local post
|
||||||
if type(data) == "string" then
|
if type(data) == "string" then
|
||||||
@ -31,23 +31,35 @@ function internet.request(url, data, headers)
|
|||||||
error(reason, 2)
|
error(reason, 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
return function()
|
return setmetatable(
|
||||||
while true do
|
{
|
||||||
local data, reason = request.read()
|
["()"] = "function():string -- Tries to read data from the socket stream and return the read byte array.",
|
||||||
if not data then
|
close = setmetatable({},
|
||||||
request.close()
|
{
|
||||||
if reason then
|
__call = request.close,
|
||||||
error(reason, 2)
|
__tostring = function() return "function() -- closes the connection" end
|
||||||
else
|
})
|
||||||
return nil -- eof
|
},
|
||||||
|
{
|
||||||
|
__call = function()
|
||||||
|
while true do
|
||||||
|
local data, reason = request.read()
|
||||||
|
if not data then
|
||||||
|
request.close()
|
||||||
|
if reason then
|
||||||
|
error(reason, 2)
|
||||||
|
else
|
||||||
|
return nil -- eof
|
||||||
|
end
|
||||||
|
elseif #data > 0 then
|
||||||
|
return data
|
||||||
end
|
end
|
||||||
elseif #data > 0 then
|
-- else: no data, block
|
||||||
return data
|
os.sleep(0)
|
||||||
end
|
end
|
||||||
-- else: no data, block
|
end,
|
||||||
os.sleep(0)
|
__index = request,
|
||||||
end
|
})
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
@ -390,7 +390,13 @@ function term.drawText(value, wrap, window)
|
|||||||
local function scroll(_sy,_y)
|
local function scroll(_sy,_y)
|
||||||
return _sy + term.internal.scroll(window,_y-h), math.min(_y,h)
|
return _sy + term.internal.scroll(window,_y-h), math.min(_y,h)
|
||||||
end
|
end
|
||||||
|
local uptime = computer.uptime
|
||||||
|
local last_sleep = uptime()
|
||||||
while index <= vlen do
|
while index <= vlen do
|
||||||
|
if uptime() - last_sleep > 4 then
|
||||||
|
os.sleep(0)
|
||||||
|
last_sleep = uptime()
|
||||||
|
end
|
||||||
local si,ei = value:find("[\t\r\n\a]", index)
|
local si,ei = value:find("[\t\r\n\a]", index)
|
||||||
si = si or vlen+1
|
si = si or vlen+1
|
||||||
if index==si then
|
if index==si then
|
||||||
@ -401,7 +407,7 @@ function term.drawText(value, wrap, window)
|
|||||||
x,y=1,y+1
|
x,y=1,y+1
|
||||||
sy,y = scroll(sy,y)
|
sy,y = scroll(sy,y)
|
||||||
elseif delim=="\a" and not beeped then
|
elseif delim=="\a" and not beeped then
|
||||||
require("computer").beep()
|
computer.beep()
|
||||||
beeped = true
|
beeped = true
|
||||||
end
|
end
|
||||||
cr_last = delim == "\r"
|
cr_last = delim == "\r"
|
||||||
|
@ -652,7 +652,7 @@ object Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def checkAccess(ctxOpt: Option[DebugCard.AccessContext]): Option[String] = ctxOpt match {
|
def checkAccess(ctxOpt: Option[DebugCard.AccessContext]): Option[String] = ctxOpt match {
|
||||||
case Some(ctx) => values.get(ctx.player) match {
|
case Some(ctx) => values.get(ctx.player.toLowerCase) match {
|
||||||
case Some(x) =>
|
case Some(x) =>
|
||||||
if (x == ctx.nonce) None
|
if (x == ctx.nonce) None
|
||||||
else Some("debug card is invalidated, please re-bind it to yourself")
|
else Some("debug card is invalidated, please re-bind it to yourself")
|
||||||
|
@ -19,7 +19,7 @@ class DebugCard(val parent: Delegator) extends traits.Delegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = {
|
override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = {
|
||||||
if (player.isSneaking) {
|
if (!world.isRemote && player.isSneaking) {
|
||||||
val data = new DebugCardData(stack)
|
val data = new DebugCardData(stack)
|
||||||
val name = player.getName
|
val name = player.getName
|
||||||
|
|
||||||
|
@ -3,13 +3,13 @@ package li.cil.oc.server.component
|
|||||||
import java.util
|
import java.util
|
||||||
|
|
||||||
import li.cil.oc.Constants
|
import li.cil.oc.Constants
|
||||||
import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute
|
|
||||||
import li.cil.oc.api.driver.DeviceInfo.DeviceClass
|
|
||||||
import li.cil.oc.Localization
|
import li.cil.oc.Localization
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.api
|
import li.cil.oc.api
|
||||||
import li.cil.oc.api.Network
|
import li.cil.oc.api.Network
|
||||||
import li.cil.oc.api.driver.DeviceInfo
|
import li.cil.oc.api.driver.DeviceInfo
|
||||||
|
import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute
|
||||||
|
import li.cil.oc.api.driver.DeviceInfo.DeviceClass
|
||||||
import li.cil.oc.api.machine.Arguments
|
import li.cil.oc.api.machine.Arguments
|
||||||
import li.cil.oc.api.machine.Callback
|
import li.cil.oc.api.machine.Callback
|
||||||
import li.cil.oc.api.machine.Context
|
import li.cil.oc.api.machine.Context
|
||||||
@ -72,32 +72,15 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment with DeviceI
|
|||||||
)
|
)
|
||||||
|
|
||||||
def capacityInfo = (maxResolution._1 * maxResolution._2).toString
|
def capacityInfo = (maxResolution._1 * maxResolution._2).toString
|
||||||
|
|
||||||
def widthInfo = Array("1", "4", "8").apply(maxDepth.ordinal())
|
def widthInfo = Array("1", "4", "8").apply(maxDepth.ordinal())
|
||||||
|
|
||||||
def clockInfo = ((2000 / setBackgroundCosts(tier)).toInt / 100).toString + "/" + ((2000 / setForegroundCosts(tier)).toInt / 100).toString + "/" + ((2000 / setPaletteColorCosts(tier)).toInt / 100).toString + "/" + ((2000 / setCosts(tier)).toInt / 100).toString + "/" + ((2000 / copyCosts(tier)).toInt / 100).toString + "/" + ((2000 / fillCosts(tier)).toInt / 100).toString
|
def clockInfo = ((2000 / setBackgroundCosts(tier)).toInt / 100).toString + "/" + ((2000 / setForegroundCosts(tier)).toInt / 100).toString + "/" + ((2000 / setPaletteColorCosts(tier)).toInt / 100).toString + "/" + ((2000 / setCosts(tier)).toInt / 100).toString + "/" + ((2000 / copyCosts(tier)).toInt / 100).toString + "/" + ((2000 / fillCosts(tier)).toInt / 100).toString
|
||||||
|
|
||||||
override def getDeviceInfo: util.Map[String, String] = deviceInfo
|
override def getDeviceInfo: util.Map[String, String] = deviceInfo
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override val canUpdate = true
|
|
||||||
|
|
||||||
override def update() {
|
|
||||||
super.update()
|
|
||||||
if (node.network != null && screenInstance.isEmpty && screenAddress.isDefined) {
|
|
||||||
Option(node.network.node(screenAddress.get)) match {
|
|
||||||
case Some(node: Node) if node.host.isInstanceOf[api.internal.TextBuffer] =>
|
|
||||||
screenInstance = Some(node.host.asInstanceOf[api.internal.TextBuffer])
|
|
||||||
case _ =>
|
|
||||||
// This could theoretically happen after loading an old address, but
|
|
||||||
// if the screen either disappeared between saving and now or changed
|
|
||||||
// type. The first scenario is more likely, and could happen if the
|
|
||||||
// chunk the screen is in isn't loaded when the chunk the GPU is in
|
|
||||||
// gets loaded.
|
|
||||||
screenAddress = None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Callback(doc = """function(address:string[, reset:boolean=true]):boolean -- Binds the GPU to the screen with the specified address and resets screen settings if `reset` is true.""")
|
@Callback(doc = """function(address:string[, reset:boolean=true]):boolean -- Binds the GPU to the screen with the specified address and resets screen settings if `reset` is true.""")
|
||||||
def bind(context: Context, args: Arguments): Array[AnyRef] = {
|
def bind(context: Context, args: Arguments): Array[AnyRef] = {
|
||||||
val address = args.checkString(0)
|
val address = args.checkString(0)
|
||||||
@ -395,6 +378,17 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment with DeviceI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override def onConnect(node: Node): Unit = {
|
||||||
|
super.onConnect(node)
|
||||||
|
if (screenInstance.isEmpty && screenAddress.fold(false)(_ == node.address)) {
|
||||||
|
node.host match {
|
||||||
|
case buffer: api.internal.TextBuffer =>
|
||||||
|
screenInstance = Some(buffer)
|
||||||
|
case _ => // Not the screen node we're looking for.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override def onDisconnect(node: Node) {
|
override def onDisconnect(node: Node) {
|
||||||
super.onDisconnect(node)
|
super.onDisconnect(node)
|
||||||
if (node == this.node || screenAddress.contains(node.address)) {
|
if (node == this.node || screenAddress.contains(node.address)) {
|
||||||
|
@ -160,12 +160,20 @@ private class Network private(private val data: mutable.Map[String, Network.Vert
|
|||||||
|
|
||||||
def nodes: Iterable[ImmutableNode] = data.values.map(_.data)
|
def nodes: Iterable[ImmutableNode] = data.values.map(_.data)
|
||||||
|
|
||||||
def nodes(reference: ImmutableNode): Iterable[ImmutableNode] = {
|
def reachableNodes(reference: ImmutableNode): Iterable[ImmutableNode] = {
|
||||||
val referenceNeighbors = neighbors(reference).toSet
|
val referenceNeighbors = neighbors(reference).toSet
|
||||||
nodes.filter(node => node != reference && (node.reachability == Visibility.Network ||
|
nodes.filter(node => node != reference && (node.reachability == Visibility.Network ||
|
||||||
(node.reachability == Visibility.Neighbors && referenceNeighbors.contains(node))))
|
(node.reachability == Visibility.Neighbors && referenceNeighbors.contains(node))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def reachingNodes(reference: ImmutableNode): Iterable[ImmutableNode] = {
|
||||||
|
if (reference.reachability == Visibility.Network) nodes.filter(node => node != reference)
|
||||||
|
else if (reference.reachability == Visibility.Neighbors) {
|
||||||
|
val referenceNeighbors = neighbors(reference).toSet
|
||||||
|
nodes.filter(node => node != reference && referenceNeighbors.contains(node))
|
||||||
|
} else Iterable.empty
|
||||||
|
}
|
||||||
|
|
||||||
def neighbors(node: ImmutableNode): Iterable[ImmutableNode] = {
|
def neighbors(node: ImmutableNode): Iterable[ImmutableNode] = {
|
||||||
data.get(node.address) match {
|
data.get(node.address) match {
|
||||||
case Some(n) if n.data == node => n.edges.map(_.other(n).data)
|
case Some(n) if n.data == node => n.edges.map(_.other(n).data)
|
||||||
@ -194,13 +202,13 @@ private class Network private(private val data: mutable.Map[String, Network.Vert
|
|||||||
def sendToReachable(source: ImmutableNode, name: String, args: AnyRef*) = {
|
def sendToReachable(source: ImmutableNode, name: String, args: AnyRef*) = {
|
||||||
if (source.network != wrapper)
|
if (source.network != wrapper)
|
||||||
throw new IllegalArgumentException("Source node must be in this network.")
|
throw new IllegalArgumentException("Source node must be in this network.")
|
||||||
send(source, nodes(source), name, args: _*)
|
send(source, reachableNodes(source), name, args: _*)
|
||||||
}
|
}
|
||||||
|
|
||||||
def sendToVisible(source: ImmutableNode, name: String, args: AnyRef*) = {
|
def sendToVisible(source: ImmutableNode, name: String, args: AnyRef*) = {
|
||||||
if (source.network != wrapper)
|
if (source.network != wrapper)
|
||||||
throw new IllegalArgumentException("Source node must be in this network.")
|
throw new IllegalArgumentException("Source node must be in this network.")
|
||||||
send(source, nodes(source) collect {
|
send(source, reachableNodes(source) collect {
|
||||||
case component: api.network.Component if component.canBeSeenFrom(source) => component
|
case component: api.network.Component if component.canBeSeenFrom(source) => component
|
||||||
}, name, args: _*)
|
}, name, args: _*)
|
||||||
}
|
}
|
||||||
@ -236,11 +244,11 @@ private class Network private(private val data: mutable.Map[String, Network.Vert
|
|||||||
connects += ((addedNode, Iterable(addedNode)))
|
connects += ((addedNode, Iterable(addedNode)))
|
||||||
case Visibility.Neighbors =>
|
case Visibility.Neighbors =>
|
||||||
connects += ((addedNode, Iterable(addedNode) ++ neighbors(addedNode)))
|
connects += ((addedNode, Iterable(addedNode) ++ neighbors(addedNode)))
|
||||||
nodes(addedNode).foreach(node => connects += ((node, Iterable(addedNode))))
|
reachingNodes(addedNode).foreach(node => connects += ((node, Iterable(addedNode))))
|
||||||
case Visibility.Network =>
|
case Visibility.Network =>
|
||||||
// Explicitly send to the added node itself first.
|
// Explicitly send to the added node itself first.
|
||||||
connects += ((addedNode, Iterable(addedNode) ++ nodes.filter(_ != addedNode)))
|
connects += ((addedNode, Iterable(addedNode) ++ nodes.filter(_ != addedNode)))
|
||||||
nodes(addedNode).foreach(node => connects += ((node, Iterable(addedNode))))
|
reachingNodes(addedNode).foreach(node => connects += ((node, Iterable(addedNode))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -746,7 +754,7 @@ object Network extends api.detail.NetworkAPI {
|
|||||||
|
|
||||||
def nodes = network.nodes.asJava
|
def nodes = network.nodes.asJava
|
||||||
|
|
||||||
def nodes(reference: ImmutableNode) = network.nodes(reference).asJava
|
def nodes(reference: ImmutableNode) = network.reachableNodes(reference).asJava
|
||||||
|
|
||||||
def neighbors(node: ImmutableNode) = network.neighbors(node).asJava
|
def neighbors(node: ImmutableNode) = network.neighbors(node).asJava
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user