mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
video card wip for virtual computer
Former-commit-id: 3c71eb0e8614e92e63fd3b29906a3cfd311c916f Former-commit-id: 3472d6eb7d03a29bfd859e9207f76aeb23cef89b
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
package net.torvald.terrarum.virtualcomputer.terminal
|
||||
|
||||
import net.torvald.terrarum.blendMul
|
||||
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||
import net.torvald.terrarum.virtualcomputer.peripheral.PeripheralVideoCard
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-02-08.
|
||||
*/
|
||||
class GraphicsTerminal(
|
||||
private val host: BaseTerrarumComputer, val videoCard: PeripheralVideoCard
|
||||
) : Terminal {
|
||||
override val width = videoCard.termW
|
||||
override val height = videoCard.termH
|
||||
override val coloursCount = videoCard.coloursCount
|
||||
override var cursorX = 0
|
||||
override var cursorY = 0
|
||||
override var cursorBlink = true
|
||||
|
||||
override var backColour = 15 // black
|
||||
override var foreColour = 48 // bright grey
|
||||
|
||||
override var lastInputByte = -1
|
||||
|
||||
override fun getColor(index: Int) = videoCard.CLUT[index]
|
||||
|
||||
override val displayW = videoCard.width //+ 2 * borderSize
|
||||
override val displayH = videoCard.height //+ 2 * borderSize
|
||||
|
||||
private val videoScreen = Image(videoCard.width, videoCard.height)
|
||||
|
||||
override fun printChars(s: String) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
wrap()
|
||||
}
|
||||
|
||||
// copied from SimpleTextTerminal
|
||||
private fun wrap() {
|
||||
// wrap cursor
|
||||
if (cursorX < 0 && cursorY <= 0) {
|
||||
setCursor(0, 0)
|
||||
}
|
||||
else if (cursorX >= width) {
|
||||
setCursor(0, cursorY + 1)
|
||||
}
|
||||
else if (cursorX < 0) {
|
||||
setCursor(width - 1, cursorY - 1)
|
||||
}
|
||||
// auto scroll up
|
||||
if (cursorY >= height) {
|
||||
scroll()
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
videoCard.render(videoScreen.graphics)
|
||||
g.drawImage(videoScreen.getScaledCopy(2f), 0f, 0f)
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun writeChars(s: String) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
/** Unlike lua function, this one in Zero-based. */
|
||||
override fun setCursor(x: Int, y: Int) {
|
||||
cursorX = x
|
||||
cursorY = y
|
||||
}
|
||||
|
||||
override fun openInput(echo: Boolean) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun emitChar(bufferChar: Int, x: Int, y: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun closeInputKey(keyFromUI: Int): Int {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun closeInputString(): String {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override var lastStreamInput: String? = null
|
||||
override var lastKeyPress: Int? = null
|
||||
|
||||
override fun emitChar(c: Char, x: Int, y: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun printChar(c: Char) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun emitString(s: String, x: Int, y: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun printString(s: String, x: Int, y: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun writeString(s: String, x: Int, y: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
videoCard.clearAll()
|
||||
}
|
||||
|
||||
override fun clearLine() {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun newLine() {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun scroll(amount: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun setColour(back: Int, fore: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun resetColour() {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
/** // copied from SimpleTextTerminal
|
||||
* @param duration: milliseconds
|
||||
* @param freg: Frequency (float)
|
||||
*/
|
||||
override fun emitTone(duration: Int, freq: Double) {
|
||||
host.clearBeepQueue()
|
||||
host.enqueueBeep(duration, freq)
|
||||
}
|
||||
|
||||
// copied from SimpleTextTerminal
|
||||
/** for "emitTone code" on modern BIOS. */
|
||||
override fun bell(pattern: String) {
|
||||
host.clearBeepQueue()
|
||||
|
||||
val freq: Double =
|
||||
if (host.luaJ_globals["computer"]["bellpitch"].isnil())
|
||||
1000.0
|
||||
else
|
||||
host.luaJ_globals["computer"]["bellpitch"].checkdouble()
|
||||
|
||||
for (c in pattern) {
|
||||
when (c) {
|
||||
'.' -> { host.enqueueBeep(80, freq); host.enqueueBeep(50, 0.0) }
|
||||
'-' -> { host.enqueueBeep(200, freq); host.enqueueBeep(50, 0.0) }
|
||||
'=' -> { host.enqueueBeep(500, freq); host.enqueueBeep(50, 0.0) }
|
||||
' ' -> { host.enqueueBeep(200, 0.0) }
|
||||
',' -> { host.enqueueBeep(50, 0.0) }
|
||||
else -> throw IllegalArgumentException("Unacceptable pattern: $c (from '$pattern')")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getKeyPress(): Int? {
|
||||
TODO("not implemented")
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.virtualcomputer.terminal
|
||||
import net.torvald.aa.AAFrame
|
||||
import net.torvald.aa.ColouredFastFont
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.DecodeTapestry
|
||||
import net.torvald.terrarum.gameactors.abs
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||
@@ -15,7 +16,7 @@ import java.nio.ByteBuffer
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Default text terminal, four text colours (black, grey, lgrey, white).
|
||||
* Default text terminal.
|
||||
*
|
||||
* Created by minjaesong on 16-09-07.
|
||||
*/
|
||||
@@ -30,36 +31,7 @@ open class SimpleTextTerminal(
|
||||
* Terminals must support AT LEAST 4 colours.
|
||||
* Color index 0 must be default background, index 3 must be default foreground
|
||||
*/
|
||||
open protected val colours = if (colour)
|
||||
// TODO colours updated; also update the documentation
|
||||
arrayOf(
|
||||
Color(0x000000), // 0 black
|
||||
Color(0xffffff), // 1 white
|
||||
Color(0x666666), // 2 dim grey
|
||||
Color(0xcccccc), // 3 bright grey
|
||||
|
||||
Color(0xffee00), // 4 yellow
|
||||
Color(0xee6600), // 5 orange
|
||||
Color(0xee0000), // 6 red
|
||||
Color(0xee22aa), // 7 magenta
|
||||
|
||||
Color(0x442277), // 8 purple
|
||||
Color(0x3322ff), // 9 blue
|
||||
Color(0x44aaff), //10 cyan
|
||||
Color(0x55ff00), //11 lime
|
||||
|
||||
Color(0x339900), //12 green
|
||||
Color(0x335533), //13 dark green
|
||||
Color(0x553333), //14 brown
|
||||
Color(0xaa6633) //15 tan
|
||||
) // THESE ARE THE STANDARD
|
||||
else
|
||||
arrayOf(
|
||||
Color(0x000000), // 0 black
|
||||
Color(0xffffff), // 1 white
|
||||
Color(0x666666), // 2 dim grey
|
||||
Color(0xcccccc) // 3 bright grey
|
||||
) // THESE ARE THE STANDARD
|
||||
open protected val colours = if (colour) CLUT else CLUT.copyOfRange(0, 3)
|
||||
|
||||
val phosphor = if (colour) WHITE7500 else phosphorColour
|
||||
open val colourScreen = if (colour) Color(8, 8, 8) else Color(19, 19, 19)
|
||||
@@ -460,6 +432,8 @@ open class SimpleTextTerminal(
|
||||
ASCII_DC4,
|
||||
ASCII_DLE
|
||||
)
|
||||
|
||||
val CLUT = DecodeTapestry.colourIndices16
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user