diff --git a/src/main/resources/data/opencomputers/opencomputers/loot_disks/openos/bin/resolution.lua b/src/main/resources/data/opencomputers/opencomputers/loot_disks/openos/bin/resolution.lua index 6c1bfce717..8b086daa4d 100644 --- a/src/main/resources/data/opencomputers/opencomputers/loot_disks/openos/bin/resolution.lua +++ b/src/main/resources/data/opencomputers/opencomputers/loot_disks/openos/bin/resolution.lua @@ -1,9 +1,28 @@ local shell = require("shell") local tty = require("tty") -local args = shell.parse(...) +local args, ops = shell.parse(...) local gpu = tty.gpu() +if ops["max"] or ops["m"] then + local w, h = gpu.maxResolution() + io.write(w," ",h,"\n") + local limited = nil + local gw, gh = gpu.hardwareResolution() + -- Only loads this when we need it + local component = require("component") + local sw, sh = component.invoke(tty.screen(), "hardwareResolution") + if gw < sw or gh < sh then + limited = "GPU" + elseif gw > sw or gh > sh then + limited = "screen" + end + if limited then + io.write("(Limited by ",limited,")\n") + end + return +end + if #args == 0 then local w, h = gpu.getViewport() io.write(w," ",h,"\n") @@ -11,7 +30,7 @@ if #args == 0 then end if #args ~= 2 then - print("Usage: resolution [ ]") + print("Usage: resolution [ ] or resolution --max") return end diff --git a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala index ecfa6d8822..c8e656755d 100644 --- a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala +++ b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala @@ -239,6 +239,16 @@ class TextBuffer(val host: EnvironmentHost) extends AbstractManagedEnvironment w else result((), "unsupported operation") } + @Callback(doc = """function():number -- Get the maximum resolution supported by the screen.""") + def hardwareResolution(context: Context, args: Arguments): Array[AnyRef] = { + val (smw, smh) = maxResolution + result(smw, smh) + } + + @Callback(direct = true, doc = """function():number -- Get the maximum color depth supported by the screen.""") + def hardwareDepth(context: Context, args: Arguments): Array[AnyRef] = + result(PackedColor.Depth.bits(maxDepth)) + // ----------------------------------------------------------------------- // override def setEnergyCostPerTick(value: Double): Unit = { diff --git a/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala b/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala index 6284d29991..8498e001ef 100644 --- a/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala +++ b/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala @@ -407,10 +407,14 @@ class GraphicsCard(val tier: Int, val vramScreens: Option[Double] = None, val vi }) } - @Callback(direct = true, doc = """function():number -- Get the maximum supported color depth.""") + @Callback(direct = true, doc = """function():number -- Get the maximum supported color depth by the current GPU+screen combo.""") def maxDepth(context: Context, args: Arguments): Array[AnyRef] = screen(s => result(PackedColor.Depth.bits(api.internal.TextBuffer.ColorDepth.values.apply(math.min(maxDepth.ordinal, s.getMaximumColorDepth.ordinal))))) + @Callback(direct = true, doc = """function():number -- Get the maximum color depth supported by the GPU.""") + def hardwareDepth(context: Context, args: Arguments): Array[AnyRef] = + result(PackedColor.Depth.bits(maxDepth)) + @Callback(direct = true, doc = """function():number, number -- Get the current screen resolution.""") def getResolution(context: Context, args: Arguments): Array[AnyRef] = screen(s => result(s.getWidth, s.getHeight)) @@ -427,7 +431,7 @@ class GraphicsCard(val tier: Int, val vramScreens: Option[Double] = None, val vi screen(s => result(s.setResolution(w, h))) } - @Callback(direct = true, doc = """function():number, number -- Get the maximum screen resolution.""") + @Callback(direct = true, doc = """function():number, number -- Get the maximum screen resolution supported by the current GPU+screen combo.""") def maxResolution(context: Context, args: Arguments): Array[AnyRef] = screen(s => { val (gmw, gmh) = maxResolution @@ -436,6 +440,12 @@ class GraphicsCard(val tier: Int, val vramScreens: Option[Double] = None, val vi result(math.min(gmw, smw), math.min(gmh, smh)) }) + @Callback(direct = true, doc = """function():number, number -- Get the maximum screen resolution supported by the GPU.""") + def hardwareResolution(context: Context, args: Arguments): Array[AnyRef] = { + val (gmw, gmh) = maxResolution + result(gmw, gmh) + } + @Callback(direct = true, doc = """function():number, number -- Get the current viewport resolution.""") def getViewport(context: Context, args: Arguments): Array[AnyRef] = screen(s => result(s.getViewportWidth, s.getViewportHeight))