From ad4359f2dd6743f4a807789512e0fdc186bcf64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 1 Jan 2014 17:50:46 +0100 Subject: [PATCH] making `term.read` check for changes to the term's cursor position between events, to make it less problematic to display text via `print` or `term.write` when there's a read active (e.g. because we're in the shell or so but we want to print something from an event listener, such as a timer) --- assets/opencomputers/lua/rom/lib/term.lua | 6 ++++++ .../oc/client/renderer/MonospaceFontRenderer.scala | 4 ++-- .../client/renderer/tileentity/ScreenRenderer.scala | 13 +++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/assets/opencomputers/lua/rom/lib/term.lua b/assets/opencomputers/lua/rom/lib/term.lua index 6782edeb6..f16e3c55c 100644 --- a/assets/opencomputers/lua/rom/lib/term.lua +++ b/assets/opencomputers/lua/rom/lib/term.lua @@ -284,11 +284,17 @@ function term.read(history) term.setCursorBlink(true) while term.isAvailable() do + local ocx, ocy = getCursor() local ok, name, address, charOrValue, code = pcall(event.pull) if not ok then cleanup() error("interrupted", 0) end + local ncx, ncy = getCursor() + if ocx ~= ncx or ocy ~= ncy then + cleanup() + return "" -- soft fail the read if someone messes with the term + end if term.isAvailable() and -- may have changed since pull type(address) == "string" and component.isPrimary(address) diff --git a/li/cil/oc/client/renderer/MonospaceFontRenderer.scala b/li/cil/oc/client/renderer/MonospaceFontRenderer.scala index 32ad3448e..d4cce67b1 100644 --- a/li/cil/oc/client/renderer/MonospaceFontRenderer.scala +++ b/li/cil/oc/client/renderer/MonospaceFontRenderer.scala @@ -23,10 +23,10 @@ object MonospaceFontRenderer { val fontWidth = 5 val fontHeight = 9 - def drawString(x: Int, y: Int, value: Array[Char], color: Array[Short], depth: PackedColor.Depth.Value) = instance match { + def drawString(x: Int, y: Int, value: Array[Char], color: Array[Short], depth: PackedColor.Depth.Value) = this.synchronized(instance match { case None => OpenComputers.log.warning("Trying to render string with uninitialized MonospaceFontRenderer.") case Some(renderer) => renderer.drawString(x, y, value, color, depth) - } + }) private class Renderer(private val textureManager: TextureManager) { /** Display lists, one per char (renders quad with char's uv coords). */ diff --git a/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala b/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala index 5c05e46c3..929260841 100644 --- a/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala +++ b/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala @@ -132,14 +132,17 @@ object ScreenRenderer extends TileEntitySpecialRenderer with Callable[Int] with } } - private def compileOrDraw(list: Int) = if (screen.bufferIsDirty && !RenderState.compilingDisplayList) { - screen.bufferIsDirty = false + private def compileOrDraw(list: Int) = if (screen.bufferIsDirty) { val sx = screen.width val sy = screen.height val tw = sx * 16f val th = sy * 16f - GL11.glNewList(list, GL11.GL_COMPILE_AND_EXECUTE) + val doCompile = !RenderState.compilingDisplayList + if (doCompile) { + screen.bufferIsDirty = false + GL11.glNewList(list, GL11.GL_COMPILE_AND_EXECUTE) + } transform() @@ -178,7 +181,9 @@ object ScreenRenderer extends TileEntitySpecialRenderer with Callable[Int] with MonospaceFontRenderer.drawString(0, i * MonospaceFontRenderer.fontHeight, line, color, screen.buffer.depth) } - GL11.glEndList() + if (doCompile) { + GL11.glEndList() + } true }