mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
fixed wrong scroll up behaviour
Former-commit-id: 07837a20ae008e1072497e25b25709a6cbe97df1 Former-commit-id: 93db3957e5e9d745c78a864eb2cddd5a80a94320
This commit is contained in:
@@ -12,8 +12,10 @@ constructor(var width: Int, var height: Int) {
|
||||
/**
|
||||
* 0000_0000_00000000
|
||||
|
||||
* Upper bits: Background colour 0 black 1 dark grey 2 grey 3 white
|
||||
* Middle bits: Foreground colour ditto.
|
||||
* Upper bits: Background colour
|
||||
*
|
||||
* Middle bits: Foreground colour
|
||||
*
|
||||
* Lower 8 bits: CP437
|
||||
*/
|
||||
internal val frameBuffer: CharArray
|
||||
@@ -25,7 +27,7 @@ constructor(var width: Int, var height: Int) {
|
||||
}
|
||||
|
||||
fun drawBuffer(x: Int, y: Int, c: Char, colourKey: Int) {
|
||||
if (y * width + x >= frameBuffer.size)
|
||||
if (y * width + x >= frameBuffer.size || y * width + x < 0)
|
||||
throw ArrayIndexOutOfBoundsException("x: $x, y; $y")
|
||||
frameBuffer[y * width + x] = ((c.toInt().and(0xFF)) + colourKey.shl(8)).toChar()
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.torvald.aa.ColouredFastFont
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.blendMul
|
||||
import net.torvald.terrarum.blendScreen
|
||||
import net.torvald.terrarum.gameactors.abs
|
||||
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||
import org.lwjgl.BufferUtils
|
||||
import org.lwjgl.openal.AL
|
||||
@@ -205,13 +206,15 @@ open class SimpleTextTerminal(
|
||||
/** Emits a bufferChar. Does not move cursor
|
||||
* It is also not affected by the control sequences; just print them out as symbol */
|
||||
override fun emitChar(bufferChar: Int, x: Int, y: Int) {
|
||||
screenBuffer.drawBuffer(x, y, bufferChar.toChar())
|
||||
try { screenBuffer.drawBuffer(x, y, bufferChar.toChar()) }
|
||||
catch (e: ArrayIndexOutOfBoundsException) { e.printStackTrace() }
|
||||
}
|
||||
|
||||
/** Emits a char. Does not move cursor
|
||||
* It is also not affected by the control sequences; just print them out as symbol */
|
||||
override fun emitChar(c: Char, x: Int, y: Int) {
|
||||
screenBuffer.drawBuffer(x, y, c.toInt().and(0xFF).toChar(), colourKey)
|
||||
try { screenBuffer.drawBuffer(x, y, c.toInt().and(0xFF).toChar(), colourKey) }
|
||||
catch (e: ArrayIndexOutOfBoundsException) { e.printStackTrace() }
|
||||
}
|
||||
|
||||
/** Prints a char and move cursor accordingly. */
|
||||
@@ -292,15 +295,31 @@ open class SimpleTextTerminal(
|
||||
}
|
||||
|
||||
override fun scroll(amount: Int) {
|
||||
if (amount < 0) throw IllegalArgumentException("cannot scroll up")
|
||||
val offset = amount.times(width).abs()
|
||||
val bsize = screenBuffer.sizeof.ushr(1)
|
||||
|
||||
val offset = amount * width
|
||||
for (i in offset..screenBuffer.sizeof.ushr(1) - 1) {
|
||||
screenBuffer.frameBuffer[i - offset] = screenBuffer.frameBuffer[i]
|
||||
if (amount == 0) return
|
||||
|
||||
if (amount > 0) {
|
||||
for (i in 0..bsize - 1) {
|
||||
if (i < Math.min(bsize, bsize - offset - 1))
|
||||
// displace contents in buffer
|
||||
screenBuffer.frameBuffer[i] = screenBuffer.frameBuffer[i + offset]
|
||||
else
|
||||
// clean up garbages
|
||||
screenBuffer.frameBuffer[i] = 0.toChar()
|
||||
}
|
||||
cursorY -= amount
|
||||
}
|
||||
for (c in 1..amount) {
|
||||
cursorY -= 1
|
||||
clearLine()
|
||||
else {
|
||||
for (i in bsize - 1 downTo 0) {
|
||||
if (i > Math.max(offset - 1, 0))
|
||||
// displace contents in buffer
|
||||
screenBuffer.frameBuffer[i] = screenBuffer.frameBuffer[i - offset]
|
||||
else
|
||||
screenBuffer.frameBuffer[i] = 0.toChar()
|
||||
}
|
||||
cursorY += amount
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user