computer with term lib: somewhat works; new cobblestone texture
Former-commit-id: 8a1a21cc1ea874ec1c243cae7b1e920bdab3be4f Former-commit-id: ee7aeb05896a36960050f0656764ccf477e5f90d
6
.idea/libraries/lib.xml
generated
@@ -17,6 +17,7 @@
|
||||
<root url="jar://$PROJECT_DIR$/lib/slick.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/OpenComputers-JNLua.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/OpenComputers-LuaJ.jar!/" />
|
||||
<root url="file://$PROJECT_DIR$/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="http://slick.ninjacave.com/javadoc/" />
|
||||
@@ -25,11 +26,14 @@
|
||||
<root url="https://commons.apache.org/proper/commons-csv/archives/1.1/apidocs/index.html" />
|
||||
</JAVADOC>
|
||||
<NATIVE>
|
||||
<root url="file://$PROJECT_DIR$/lib/natives" />
|
||||
<root url="file://$PROJECT_DIR$/lib" />
|
||||
</NATIVE>
|
||||
<SOURCES>
|
||||
<root url="file://$USER_HOME$/Downloads/slick/src" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/kotlin-runtime-sources.jar!/" />
|
||||
<root url="file://$PROJECT_DIR$/lib" />
|
||||
</SOURCES>
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" type="SOURCES" />
|
||||
</library>
|
||||
</component>
|
||||
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.10.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.11.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.12.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
assets/graphics/fonts/MDA.png.13.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.14.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.15.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
assets/graphics/fonts/MDA.png.4.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
assets/graphics/fonts/MDA.png.5.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.6.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.7.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.8.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.9.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
0
lib/natives/OpenAL32.dll → lib/OpenAL32.dll
Normal file → Executable file
0
lib/natives/OpenAL64.dll → lib/OpenAL64.dll
Normal file → Executable file
0
lib/natives/jinput-dx8.dll → lib/jinput-dx8.dll
Normal file → Executable file
0
lib/natives/jinput-dx8_64.dll → lib/jinput-dx8_64.dll
Normal file → Executable file
0
lib/natives/jinput-raw.dll → lib/jinput-raw.dll
Normal file → Executable file
0
lib/natives/jinput-raw_64.dll → lib/jinput-raw_64.dll
Normal file → Executable file
0
lib/natives/libjinput-linux.so → lib/libjinput-linux.so
Normal file → Executable file
0
lib/natives/libjinput-linux64.so → lib/libjinput-linux64.so
Normal file → Executable file
0
lib/natives/libjinput-osx.dylib → lib/libjinput-osx.dylib
Normal file → Executable file
BIN
lib/libjnlua5.2.jnilib
Executable file
0
lib/natives/liblwjgl.dylib → lib/liblwjgl.dylib
Normal file → Executable file
BIN
lib/liblwjgl.so
Executable file
BIN
lib/liblwjgl64.so
Executable file
0
lib/natives/libopenal.so → lib/libopenal.so
Normal file → Executable file
0
lib/natives/libopenal64.so → lib/libopenal64.so
Normal file → Executable file
BIN
lib/natives/lwjgl.dll → lib/lwjgl.dll
Normal file → Executable file
BIN
lib/natives/lwjgl64.dll → lib/lwjgl64.dll
Normal file → Executable file
0
lib/natives/openal.dylib → lib/openal.dylib
Normal file → Executable file
@@ -5,6 +5,7 @@ import org.apache.commons.csv.CSVParser
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Files
|
||||
|
||||
@@ -39,6 +40,24 @@ object CSVFetcher {
|
||||
return csvRecordList
|
||||
}
|
||||
|
||||
fun readFromString(csv: String): List<CSVRecord> {
|
||||
val csvParser = CSVParser.parse(
|
||||
csv,
|
||||
CSVFormat.DEFAULT.withIgnoreSurroundingSpaces()
|
||||
.withHeader()
|
||||
.withIgnoreEmptyLines()
|
||||
.withDelimiter(';')
|
||||
.withCommentMarker('#')
|
||||
.withNullString("N/A")
|
||||
.withRecordSeparator('\n')
|
||||
)
|
||||
|
||||
val csvRecordList = csvParser.records
|
||||
csvParser.close()
|
||||
|
||||
return csvRecordList
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun readCSVasString(path: String): String {
|
||||
csvString = StringBuffer()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.aa
|
||||
|
||||
import net.torvald.terrarum.virtualcomputers.terminal.Terminal
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.Font
|
||||
import org.newdawn.slick.Image
|
||||
|
||||
@@ -133,12 +133,25 @@ object CIELabUtil {
|
||||
private fun Float.powerOf(exp: Float) = FastMath.pow(this, exp)
|
||||
}
|
||||
|
||||
internal val D65 = CIEXYZ(95.047f, 100f, 108.883f)
|
||||
val epsilon = 216.0.div(24389.0).toFloat()
|
||||
val kappa = 24389.0.div(27.0).toFloat()
|
||||
internal val D65 = CIEXYZ(0.95047f, 1.00f, 1.08883f)
|
||||
val epsilon = 216f/24389f
|
||||
val kappa = 24389f/27f
|
||||
|
||||
data class CIEXYZ(var X: Float = 0f, var Y: Float = 0f, var Z: Float = 0f, val alpha: Float = 1f)
|
||||
/** Range: X, Y, Z: 0 - 1.0+ (One-based-plus) */
|
||||
data class CIEXYZ(var X: Float = 0f, var Y: Float = 0f, var Z: Float = 0f, val alpha: Float = 1f) {
|
||||
init {
|
||||
if (X > 2f || Y > 2f || Z > 2f)
|
||||
throw IllegalArgumentException("Value range error - CIEXYZ is one-based (0.0 - 1.0+): ($X, $Y, $Z)")
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Range:
|
||||
* L: 0-100.0
|
||||
* u, v: -100+ - 100+
|
||||
* (Hundred-based-plus)
|
||||
*/
|
||||
data class CIELab(var L: Float = 0f, var a: Float = 0f, var b: Float = 0f, val alpha: Float = 1f)
|
||||
/** Range: r, g, b: 0 - 1.0 (One-based) */
|
||||
data class RGB(var r: Float = 0f, var g: Float = 0f, var b: Float = 0f, val alpha: Float = 1f) {
|
||||
constructor(color: Color) : this() {
|
||||
r = color.r; g = color.g; b = color.b
|
||||
|
||||
@@ -99,4 +99,10 @@ object CIELuvUtil {
|
||||
private fun Float.cube() = this * this * this
|
||||
}
|
||||
|
||||
/**
|
||||
* Range:
|
||||
* L: 0-100.0
|
||||
* u, v: -100+ - 100+
|
||||
* (Hundred-based-plus)
|
||||
*/
|
||||
data class CIELuv(var L: Float = 0f, var u: Float = 0f, var v: Float = 0f, val alpha: Float = 1f)
|
||||
|
||||
@@ -76,11 +76,6 @@ constructor() : BasicGameState() {
|
||||
|
||||
private val CORES = ThreadPool.POOL_SIZE
|
||||
|
||||
val memInUse: Long
|
||||
get() = ManagementFactory.getMemoryMXBean().heapMemoryUsage.used shr 20
|
||||
val totalVMMem: Long
|
||||
get() = Runtime.getRuntime().maxMemory() shr 20
|
||||
|
||||
val auth = Authenticator()
|
||||
|
||||
val KEY_LIGHTMAP_RENDER = Key.F7
|
||||
@@ -231,9 +226,9 @@ constructor() : BasicGameState() {
|
||||
|
||||
private fun setAppTitle() {
|
||||
Terrarum.appgc.setTitle(
|
||||
"Simple Slick Game" +
|
||||
"${Terrarum.NAME}" +
|
||||
" — F: ${Terrarum.appgc.fps} (${Terrarum.TARGET_INTERNAL_FPS})" +
|
||||
" — M: ${memInUse}M / ${totalVMMem}M")
|
||||
" — M: ${Terrarum.memInUse}M / ${Terrarum.totalVMMem}M")
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.CSVFetcher
|
||||
import net.torvald.colourutil.CIELabUtil.toXYZ
|
||||
import net.torvald.colourutil.CIELabUtil.toLab
|
||||
import net.torvald.colourutil.CIELabUtil.toRGB
|
||||
import net.torvald.colourutil.CIELuv
|
||||
import net.torvald.colourutil.CIELuvUtil.toRawRGB
|
||||
import net.torvald.colourutil.CIELuvUtil.toLuv
|
||||
import net.torvald.colourutil.RGB
|
||||
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
@@ -20,21 +12,10 @@ import org.newdawn.slick.state.StateBasedGame
|
||||
*/
|
||||
class StateTestingSandbox : BasicGameState() {
|
||||
|
||||
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
val records = CSVFetcher("./src/net/torvald/terrarum/tileproperties/tileprop_10bcol.csv")
|
||||
records.forEach {
|
||||
val tenOpacity = intVal(it, "opacity")
|
||||
val tenLum = intVal(it, "lumcolor")
|
||||
|
||||
val eightOpacity = tenOpacity.and(0xff) or
|
||||
tenOpacity.ushr(10).and(0xff).shl(8) or
|
||||
tenOpacity.ushr(20).and(0xff).shl(16)
|
||||
val eightLum = tenLum.and(0xff) or
|
||||
tenLum.ushr(10).and(0xff).shl(8) or
|
||||
tenLum.ushr(20).and(0xff).shl(16)
|
||||
|
||||
println("$eightOpacity\t$eightLum")
|
||||
}
|
||||
}
|
||||
|
||||
override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import net.torvald.terrarum.virtualcomputers.terminal.SimpleTextTerminal
|
||||
import org.newdawn.slick.Color
|
||||
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.SimpleTextTerminal
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* ComputerCraft/OpenComputers like-alike, just for fun!
|
||||
@@ -17,19 +16,24 @@ import java.util.*
|
||||
*/
|
||||
class StateVTTest : BasicGameState() {
|
||||
|
||||
val vt = SimpleTextTerminal(SimpleTextTerminal.ELECTRIC_BLUE, 80, 25)
|
||||
val vt = SimpleTextTerminal(SimpleTextTerminal.IBM_GREEN, 80, 25)
|
||||
val computerInside = BaseTerrarumComputer(vt)
|
||||
|
||||
val vtUI = Image(vt.displayW, vt.displayH)
|
||||
|
||||
override fun init(container: GameContainer, game: StateBasedGame) {
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
override fun init(container: GameContainer, game: StateBasedGame) {
|
||||
vt.openInput()
|
||||
}
|
||||
|
||||
override fun update(container: GameContainer, game: StateBasedGame, delta: Int) {
|
||||
Terrarum.appgc.setTitle("VT — F: ${container.fps}")
|
||||
Terrarum.appgc.setTitle("VT — F: ${container.fps}" +
|
||||
" — M: ${Terrarum.memInUse}M / ${Terrarum.totalVMMem}M")
|
||||
vt.update(container, delta)
|
||||
|
||||
|
||||
computerInside.update(container, delta)
|
||||
}
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TEST_TTY
|
||||
@@ -46,10 +50,16 @@ class StateVTTest : BasicGameState() {
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
super.keyPressed(key, c)
|
||||
vt.keyPressed(key, c)
|
||||
|
||||
if (key == Key.RETURN)
|
||||
vt.printChar(10.toChar())
|
||||
else
|
||||
vt.printChar(c)
|
||||
if (key == Key.RETURN) {
|
||||
val input = vt.closeInput()
|
||||
|
||||
computerInside.runCommand(input, "consoleinput")
|
||||
|
||||
vt.openInput()
|
||||
|
||||
computerInside.runCommand("io.write(_COMPUTER.prompt)", "prompt")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import org.newdawn.slick.*
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.logging.FileHandler
|
||||
@@ -104,8 +105,9 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
||||
//addState(StateSplash())
|
||||
//addState(StateMonitorCheck())
|
||||
//addState(StateFontTester())
|
||||
ingame = StateInGame()
|
||||
addState(ingame)
|
||||
|
||||
//ingame = StateInGame()
|
||||
//addState(ingame)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -152,6 +154,11 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
||||
lateinit var defaultSaveDir: String
|
||||
private set
|
||||
|
||||
val memInUse: Long
|
||||
get() = ManagementFactory.getMemoryMXBean().heapMemoryUsage.used shr 20
|
||||
val totalVMMem: Long
|
||||
get() = Runtime.getRuntime().maxMemory() shr 20
|
||||
|
||||
lateinit var environment: RunningEnvironment
|
||||
|
||||
private val localeSimple = arrayOf("de", "en", "es", "it")
|
||||
@@ -408,7 +415,9 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = Terrarum.main(args)
|
||||
fun main(args: Array<String>) {
|
||||
Terrarum.main(args)
|
||||
}
|
||||
|
||||
fun blendMul() {
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
|
||||
165
src/net/torvald/terrarum/tileproperties/TilePropCSV.kt
Normal file
@@ -0,0 +1,165 @@
|
||||
package net.torvald.terrarum.tileproperties
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-11.
|
||||
*/
|
||||
object TilePropCSV {
|
||||
const val text = """
|
||||
"id";"dmg";"name" ; "opacity";"strength";"dsty";"fluid";"solid";"wall"; "lumcolor";"drop";"ddmg";"fall";"dlfn";"friction"
|
||||
"0"; "0";"TILE_AIR" ; "8396808"; "0"; "1"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0";"4"
|
||||
"1"; "0";"TILE_STONE" ; "33587232"; "25";"2400"; "0"; "1"; "1"; "0"; "1"; "0"; "0"; "0";"16"
|
||||
"1"; "1";"TILE_STONE_QUARRIED" ; "33587232"; "25";"2400"; "0"; "1"; "1"; "0"; "1"; "1"; "0"; "0";"16"
|
||||
"1"; "2";"TILE_STONE_TILE_WHITE" ; "33587232"; "25";"2400"; "0"; "1"; "1"; "0"; "1"; "2"; "0"; "0";"16"
|
||||
"1"; "3";"TILE_STONE_BRICKS" ; "33587232"; "25";"2400"; "0"; "1"; "1"; "0"; "1"; "3"; "0"; "0";"16"
|
||||
"2"; "0";"TILE_DIRT" ; "33587232"; "6";"1400"; "0"; "1"; "1"; "0"; "2"; "0"; "0"; "0";"16"
|
||||
"2"; "1";"TILE_GRASS" ; "33587232"; "6";"1400"; "0"; "1"; "1"; "0"; "2"; "1"; "0"; "0";"16"
|
||||
"3"; "0";"TILE_PLANK_NORMAL" ; "33587232"; "12"; "740"; "0"; "1"; "1"; "0"; "3"; "0"; "0"; "0";"16"
|
||||
"3"; "1";"TILE_PLANK_EBONY" ; "33587232"; "12";"1200"; "0"; "1"; "1"; "0"; "3"; "1"; "0"; "0";"16"
|
||||
"3"; "2";"TILE_PLANK_BIRCH" ; "33587232"; "12"; "670"; "0"; "1"; "1"; "0"; "3"; "2"; "0"; "0";"16"
|
||||
"3"; "3";"TILE_PLANK_BLOODROSE" ; "33587232"; "12"; "900"; "0"; "1"; "1"; "0"; "3"; "3"; "0"; "0";"16"
|
||||
"4"; "0";"TILE_TRUNK_NORMAL" ; "33587232"; "12"; "740"; "0"; "1"; "0"; "0"; "3"; "0"; "0"; "0";"16"
|
||||
"4"; "1";"TILE_TRUNK_EBONY" ; "33587232"; "12";"1200"; "0"; "1"; "0"; "0"; "3"; "1"; "0"; "0";"16"
|
||||
"4"; "2";"TILE_TRUNK_BIRCH" ; "33587232"; "12"; "670"; "0"; "1"; "0"; "0"; "3"; "2"; "0"; "0";"16"
|
||||
"4"; "3";"TILE_TRUNK_BLOODROSE" ; "33587232"; "12"; "900"; "0"; "1"; "0"; "0"; "3"; "3"; "0"; "0";"16"
|
||||
"5"; "0";"TILE_SAND" ; "33587232"; "6";"2400"; "0"; "1"; "0"; "0"; "5"; "0"; "1"; "0";"16"
|
||||
"5"; "1";"TILE_SAND_WHITE" ; "33587232"; "6";"2400"; "0"; "1"; "0"; "0"; "5"; "1"; "1"; "0";"16"
|
||||
"5"; "2";"TILE_SAND_RED" ; "33587232"; "6";"2400"; "0"; "1"; "0"; "0"; "5"; "2"; "1"; "0";"16"
|
||||
"5"; "3";"TILE_SAND_DESERT" ; "33587232"; "6";"2400"; "0"; "1"; "0"; "0"; "5"; "3"; "1"; "0";"16"
|
||||
"5"; "4";"TILE_SAND_BLACK" ; "33587232"; "6";"2400"; "0"; "1"; "0"; "0"; "5"; "4"; "1"; "0";"16"
|
||||
"5"; "5";"TILE_SAND_GREEN" ; "33587232"; "6";"2400"; "0"; "1"; "0"; "0"; "5"; "5"; "1"; "0";"16"
|
||||
"6"; "0";"TILE_GRAVEL" ; "33587232"; "6";"2400"; "0"; "1"; "0"; "0"; "6"; "0"; "1"; "0";"16"
|
||||
"6"; "1";"TILE_GRAVEL_GREY" ; "33587232"; "6";"2400"; "0"; "1"; "0"; "0"; "6"; "1"; "1"; "0";"16"
|
||||
"7"; "0";"TILE_ORE_MALACHITE" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "7"; "0"; "0"; "0";"16"
|
||||
"7"; "1";"TILE_ORE_HEMATITE" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "7"; "1"; "0"; "0";"16"
|
||||
"7"; "2";"TILE_ORE_NATURAL_GOLD" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "7"; "2"; "0"; "0";"16"
|
||||
"7"; "3";"TILE_ORE_NATURAL_SILVER" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "7"; "3"; "0"; "0";"16"
|
||||
"7"; "4";"TILE_ORE_RUTILE" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "7"; "4"; "0"; "0";"16"
|
||||
"7"; "5";"TILE_ORE_AURICHALCUMITE" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "7"; "5"; "0"; "0";"16"
|
||||
"8"; "0";"TILE_GEM_RUBY" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "8"; "0"; "0"; "0";"16"
|
||||
"8"; "1";"TILE_GEM_EMERALD" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "8"; "1"; "0"; "0";"16"
|
||||
"8"; "2";"TILE_GEM_SAPPHIRE" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "8"; "2"; "0"; "0";"16"
|
||||
"8"; "3";"TILE_GEM_TOPAZ" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "8"; "3"; "0"; "0";"16"
|
||||
"8"; "4";"TILE_GEM_DIAMOND" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "8"; "4"; "0"; "0";"16"
|
||||
"8"; "5";"TILE_GEM_AMETHYST" ; "33587232"; "25";"2400"; "0"; "1"; "0"; "0"; "8"; "5"; "0"; "0";"16"
|
||||
"9"; "0";"TILE_SNOW" ; "33587232"; "6"; "500"; "0"; "1"; "1"; "0"; "9"; "0"; "0"; "0";"16"
|
||||
"9"; "1";"TILE_ICE_FRAGILE" ; "13644813"; "1"; "930"; "0"; "1"; "0"; "0"; "9"; "1"; "0"; "0";"16"
|
||||
"9"; "2";"TILE_ICE_NATURAL" ; "27289626"; "25"; "930"; "0"; "1"; "1"; "0"; "9"; "2"; "0"; "0"; "8"
|
||||
"9"; "3";"TILE_ICE_CLEAR_MAGICAL" ; "33587232"; "25";"3720"; "0"; "1"; "1"; "19955770"; "9"; "3"; "0"; "0"; "8"
|
||||
"9"; "4";"TILE_GLASS_CRUDE" ; "3146755"; "1";"2500"; "0"; "1"; "1"; "0"; "9"; "4"; "0"; "0";"16"
|
||||
"9"; "5";"TILE_GLASS_CLEAN" ; "1049601"; "1";"2203"; "0"; "1"; "1"; "0"; "9"; "5"; "0"; "0";"16"
|
||||
"10"; "0";"TILE_PLATFORM_STONE" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "10"; "0"; "0"; "0";"16"
|
||||
"10"; "1";"TILE_PLATFORM_WOODEN" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "10"; "1"; "0"; "0";"16"
|
||||
"10"; "2";"TILE_PLATFORM_EBONY" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "10"; "2"; "0"; "0";"16"
|
||||
"10"; "3";"TILE_PLATFORM_BIRCH" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "10"; "3"; "0"; "0";"16"
|
||||
"10"; "4";"TILE_PLATFORM_BLOODROSE" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "10"; "4"; "0"; "0";"16"
|
||||
"11"; "0";"TILE_TORCH" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "266453040"; "11"; "0"; "0"; "1";"16"
|
||||
"11"; "1";"TILE_TORCH_FROST" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "81916159"; "11"; "1"; "0"; "1";"16"
|
||||
"12"; "0";"TILE_TORCH" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "11"; "0"; "0"; "0";"16"
|
||||
"12"; "1";"TILE_TORCH_FROST" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "11"; "1"; "0"; "0";"16"
|
||||
"13"; "0";"TILE_ILLUMINATOR_WHITE" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "239319274"; "13"; "0"; "0"; "0";"16"
|
||||
"13"; "1";"TILE_ILLUMINATOR_YELLOW" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "267607040"; "13"; "1"; "0"; "0";"16"
|
||||
"13"; "2";"TILE_ILLUMINATOR_ORANGE" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "267546624"; "13"; "2"; "0"; "0";"16"
|
||||
"13"; "3";"TILE_ILLUMINATOR_RED" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "246415360"; "13"; "3"; "0"; "0";"16"
|
||||
"13"; "4";"TILE_ILLUMINATOR_FUCHSIA" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "246415543"; "13"; "4"; "0"; "0";"16"
|
||||
"13"; "5";"TILE_ILLUMINATOR_PURPLE" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "191889643"; "13"; "5"; "0"; "0";"16"
|
||||
"13"; "6";"TILE_ILLUMINATOR_BLUE" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "52479"; "13"; "6"; "0"; "0";"16"
|
||||
"13"; "7";"TILE_ILLUMINATOR_CYAN" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "219391"; "13"; "7"; "0"; "0";"16"
|
||||
"13"; "8";"TILE_ILLUMINATOR_GREEN" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "56884224"; "13"; "8"; "0"; "0";"16"
|
||||
"13"; "9";"TILE_ILLUMINATOR_GREEN_DARK";"8396808"; "0"; "N/A"; "0"; "1"; "1"; "33660928"; "13"; "9"; "0"; "0";"16"
|
||||
"13"; "10";"TILE_ILLUMINATOR_BROWN" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "89161728"; "13"; "10"; "0"; "0";"16"
|
||||
"13"; "11";"TILE_ILLUMINATOR_TAN" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "157392948"; "13"; "11"; "0"; "0";"16"
|
||||
"13"; "12";"TILE_ILLUMINATOR_GREY_LIGHT";"8396808"; "0"; "N/A"; "0"; "1"; "1"; "198374589"; "13"; "12"; "0"; "0";"16"
|
||||
"13"; "13";"TILE_ILLUMINATOR_GREY_MED"; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "122803317"; "13"; "13"; "0"; "0";"16"
|
||||
"13"; "14";"TILE_ILLUMINATOR_GREY_DARK"; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "68224065"; "13"; "14"; "0"; "0";"16"
|
||||
"13"; "15";"TILE_ILLUMINATOR_BLACK" ; "8396808"; "0"; "N/A"; "0"; "1"; "1"; "116392191"; "13"; "15"; "0"; "0";"16"
|
||||
"14"; "0";"TILE_ILLUMINATOR_WHITE" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "0"; "0"; "0";"16"
|
||||
"14"; "1";"TILE_ILLUMINATOR_YELLOW" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "1"; "0"; "0";"16"
|
||||
"14"; "2";"TILE_ILLUMINATOR_ORANGE" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "2"; "0"; "0";"16"
|
||||
"14"; "3";"TILE_ILLUMINATOR_RED" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "3"; "0"; "0";"16"
|
||||
"14"; "4";"TILE_ILLUMINATOR_FUCHSIA" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "4"; "0"; "0";"16"
|
||||
"14"; "5";"TILE_ILLUMINATOR_PURPLE" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "5"; "0"; "0";"16"
|
||||
"14"; "6";"TILE_ILLUMINATOR_BLUE" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "6"; "0"; "0";"16"
|
||||
"14"; "7";"TILE_ILLUMINATOR_CYAN" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "7"; "0"; "0";"16"
|
||||
"14"; "8";"TILE_ILLUMINATOR_GREEN" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "8"; "0"; "0";"16"
|
||||
"14"; "9";"TILE_ILLUMINATOR_GREEN_DARK";"33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "9"; "0"; "0";"16"
|
||||
"14"; "10";"TILE_ILLUMINATOR_BROWN" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "10"; "0"; "0";"16"
|
||||
"14"; "11";"TILE_ILLUMINATOR_TAN" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "11"; "0"; "0";"16"
|
||||
"14"; "12";"TILE_ILLUMINATOR_GREY_LIGHT";"33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "12"; "0"; "0";"16"
|
||||
"14"; "13";"TILE_ILLUMINATOR_GREY_MED"; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "13"; "0"; "0";"16"
|
||||
"14"; "14";"TILE_ILLUMINATOR_GREY_DARK";"33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "14"; "0"; "0";"16"
|
||||
"14"; "15";"TILE_ILLUMINATOR_BLACK" ; "33587232"; "0"; "N/A"; "0"; "1"; "1"; "0"; "13"; "15"; "0"; "0";"16"
|
||||
"15"; "0";"TILE_SANDSTONE" ; "33587232"; "25";"1900"; "0"; "1"; "1"; "0"; "15"; "0"; "0"; "0";"16"
|
||||
"15"; "1";"TILE_SANDSTONE_WHITE" ; "33587232"; "25";"1900"; "0"; "1"; "1"; "0"; "15"; "1"; "0"; "0";"16"
|
||||
"15"; "2";"TILE_SANDSTONE_RED" ; "33587232"; "25";"1900"; "0"; "1"; "1"; "0"; "15"; "2"; "0"; "0";"16"
|
||||
"15"; "3";"TILE_SANDSTONE_DESERT" ; "33587232"; "25";"1900"; "0"; "1"; "1"; "0"; "15"; "3"; "0"; "0";"16"
|
||||
"15"; "4";"TILE_SANDSTONE_BLACK" ; "33587232"; "25";"1900"; "0"; "1"; "1"; "0"; "15"; "4"; "0"; "0";"16"
|
||||
"15"; "5";"TILE_SANDSTONE_BLACK" ; "33587232"; "25";"1900"; "0"; "1"; "1"; "0"; "15"; "5"; "0"; "0";"16"
|
||||
"16"; "0";"TILE_LANTERN_IRON_REGULAR"; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "266453040"; "16"; "0"; "0"; "0";"16"
|
||||
"16"; "1";"TILE_SUNSTONE" ; "33587232"; "0"; "N/A"; "0"; "1"; "0"; "0"; "16"; "1"; "0"; "2";"16"
|
||||
"16"; "2";"TILE_DAYLIGHT_CAPACITOR" ; "33587232"; "0"; "N/A"; "0"; "1"; "0"; "0"; "16"; "2"; "0"; "3";"16"
|
||||
"254"; "0";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "1";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "2";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "3";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "4";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "5";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "6";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "7";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "8";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "9";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "10";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "11";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "12";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "13";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "14";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"254"; "15";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "0";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "1";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "2";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "3";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "4";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "5";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "6";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "7";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "8";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "9";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "10";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "11";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "12";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "13";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "14";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"255"; "15";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
"256"; "0";"TILE_NULL" ; "0"; "-1";"2600"; "0"; "0"; "0"; "0"; "N/A"; "N/A"; "0"; "0";"16"
|
||||
|
||||
## Notes ##
|
||||
|
||||
# Friction: 0: frictionless, <16: slippery, 16: regular, >16: sticky
|
||||
# Opacity/Lumcolor: 30-bit RGB. Only the light diffusers have a opacity value of ZERO.
|
||||
# Solid: whether the tile has full collision
|
||||
# movr: Movement resistance, (walkspeedmax) / (1 + (n/16)), 16 halves movement speed
|
||||
# dsty: density. As we are putting water an 1000, it is identical to specific gravity. [g/l]
|
||||
# dlfn: dynamic luminosity function.
|
||||
# 0-static, 1-torch flicker, 2-current global light (sun, star, moon), 3-daylight at noon,
|
||||
# 4-slow breath, 5-pulsate
|
||||
|
||||
|
||||
## Illuminators ##
|
||||
|
||||
# Illuminator white: RGB(228,238,234), simulation of a halophosphate FL lamp (If you want high CRI lamp, collect a daylight!)
|
||||
# Defalut torch : L 64 a 51 b 59; real candlelight colour taken from properly configured camera.
|
||||
# Sunstone: Artificial sunlight, change colour over time in sync with sunlight. The light is set by game's code.
|
||||
# Sunlight capacitor: daylight at noon. Set by game's code.
|
||||
|
||||
|
||||
## Tiles ##
|
||||
|
||||
# 16 colour palette : Old Apple Macintosh 16-colour palette
|
||||
# Magical ice: theoretical __metallic__ ice that might form under super-high pressure (> 5 TPa). Its density is a wild guess.
|
||||
|
||||
|
||||
## References ##
|
||||
|
||||
# * Density of various woods : http://www.engineeringtoolbox.com/wood-density-d_40.html
|
||||
# * Density of various phases of ice : http://www1.lsbu.ac.uk/water/ice_phases.html
|
||||
"""
|
||||
}
|
||||
@@ -14,7 +14,7 @@ object TilePropCodex {
|
||||
|
||||
private lateinit var tileProps: Array<TileProp>
|
||||
|
||||
val CSV_PATH = "./src/net/torvald/terrarum/tileproperties/tileprop.csv"
|
||||
val CSV_PATH = "/net/torvald/terrarum/tileproperties/tileprop.csv"
|
||||
|
||||
const val TILE_UNIQUE_MAX = MapLayer.RANGE * PairedMapLayer.RANGE
|
||||
|
||||
|
||||
@@ -155,9 +155,9 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
(Terrarum.WIDTH - 2 - 6*8).toFloat(), 10f)
|
||||
|
||||
g.color = GameFontBase.codeToCol["g"]
|
||||
g.drawString("${Terrarum.ingame.memInUse}M",
|
||||
g.drawString("${Terrarum.memInUse}M",
|
||||
(Terrarum.WIDTH - 11 * 8 - 2).toFloat(), 2f)
|
||||
g.drawString("/${Terrarum.ingame.totalVMMem}M",
|
||||
g.drawString("/${Terrarum.totalVMMem}M",
|
||||
(Terrarum.WIDTH - 6 * 8 - 2).toFloat(), 2f)
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
--[[
|
||||
From https://github.com/prapin/LuaBrainFuck/blob/master/brainfuck.lua
|
||||
|
||||
LuaBrainFuck License
|
||||
--------------------
|
||||
|
||||
LuaBrainFuck is placed under the same license as Lua itself,
|
||||
so licensed under terms of the MIT license reproduced below.
|
||||
This means that the library is free software and can be used for both academic
|
||||
and commercial purposes at absolutely no cost.
|
||||
|
||||
===============================================================================
|
||||
|
||||
Copyright (C) 2012 Patrick Rapin, CH-1543 Grandcour
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
===============================================================================
|
||||
|
||||
(end of COPYRIGHT)
|
||||
|
||||
Example usage: require "brainfuck" "+++>>> your BF code here <<<---"
|
||||
]]
|
||||
return function(s)
|
||||
local subst = {["+"]="v=v+1 ", ["-"]="v=v-1 ", [">"]="i=i+1 ", ["<"]="i=i-1 ",
|
||||
["."] = "w(v)", [","]="v=r()", ["["]="while v~=0 do ", ["]"]="end "}
|
||||
local env = setmetatable({ i=0, t=setmetatable({},{__index=function() return 0 end}),
|
||||
r=function() return io.read(1):byte() end, w=function(c) io.write(string.char(c)) end },
|
||||
{__index=function(t,k) return t.t[t.i] end, __newindex=function(t,k,v) t.t[t.i]=v end })
|
||||
load(s:gsub("[^%+%-<>%.,%[%]]+",""):gsub(".", subst), "brainfuck", "t", env)()
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
-- global variables
|
||||
_COMPUTER = {} -- standard console colours
|
||||
_COMPUTER["DC1"] = string.char(17) -- black
|
||||
_COMPUTER["DC2"] = string.char(18) -- white
|
||||
_COMPUTER["DC3"] = string.char(19) -- dim grey
|
||||
_COMPUTER["DC4"] = string.char(20) -- light grey
|
||||
_COMPUTER["prompt"] = function()
|
||||
io.write(_COMPUTER.DC3 .. "> " .. _COMPUTER.DC4)
|
||||
end
|
||||
-- greet user
|
||||
print("Rom basic " .. _COMPUTER.DC2 .. _VERSION .. _COMPUTER.DC4)
|
||||
-- print(_COMPUTER.DC2 .. freemem .. _COMPUTER.DC4 .. " bytes free"
|
||||
print("Ok")
|
||||
-- prompt start
|
||||
--_COMPUTER.prompt()
|
||||
@@ -0,0 +1,155 @@
|
||||
package net.torvald.terrarum.virtualcomputer.computer
|
||||
|
||||
import li.cil.repack.org.luaj.vm2.Globals
|
||||
import li.cil.repack.org.luaj.vm2.LuaError
|
||||
import li.cil.repack.org.luaj.vm2.LuaValue
|
||||
import li.cil.repack.org.luaj.vm2.lib.jse.JsePlatform
|
||||
import net.torvald.terrarum.virtualcomputer.lualib.TermLib
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.SimpleTextTerminal
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.TerminalInputStream
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.TerminalPrintStream
|
||||
import org.newdawn.slick.GameContainer
|
||||
import java.io.*
|
||||
|
||||
/**
|
||||
* A part that makes "computer fixtures" actually work
|
||||
*
|
||||
* @param term : terminal that is connected to the computer fixtures, null if not connected any.
|
||||
*
|
||||
* Created by minjaesong on 16-09-10.
|
||||
*/
|
||||
class BaseTerrarumComputer(term: Terminal?) {
|
||||
|
||||
val luaJ_globals: Globals = JsePlatform.standardGlobals()
|
||||
|
||||
var termOut: PrintStream? = null
|
||||
private set
|
||||
var termErr: PrintStream? = null
|
||||
private set
|
||||
var termIn: InputStream? = null
|
||||
private set
|
||||
|
||||
init {
|
||||
if (term != null) {
|
||||
termOut = TerminalPrintStream(term)
|
||||
termErr = TerminalPrintStream(term)
|
||||
termIn = TerminalInputStream(term)
|
||||
|
||||
luaJ_globals.STDOUT = termOut
|
||||
luaJ_globals.STDERR = termErr
|
||||
luaJ_globals.STDIN = termIn
|
||||
|
||||
loadTermLib(term)
|
||||
}
|
||||
|
||||
// ROM BASIC
|
||||
val inputStream = javaClass.getResourceAsStream("/net/torvald/terrarum/virtualcomputer/assets/lua/ROMBASIC.lua")
|
||||
runCommand(InputStreamReader(inputStream), "rombasic")
|
||||
}
|
||||
|
||||
var threadTimer = 0
|
||||
val threadMaxTime = 2000
|
||||
|
||||
fun update(gc: GameContainer, delta: Int) {
|
||||
if (currentExecutionThread.state == Thread.State.TERMINATED)
|
||||
unsetThreadRun()
|
||||
|
||||
// time the execution time of the thread
|
||||
if (threadRun) {
|
||||
threadTimer += delta
|
||||
|
||||
// if too long, halt
|
||||
if (threadTimer > threadMaxTime) {
|
||||
//luaJ_globals.STDERR.println("Interrupted: Too long without yielding.")
|
||||
//currentExecutionThread.interrupt()
|
||||
unsetThreadRun()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var currentExecutionThread = Thread()
|
||||
var threadRun = false
|
||||
|
||||
fun runCommand(line: String, env: String) {
|
||||
if (!threadRun) {
|
||||
currentExecutionThread = Thread(ThreadRunCommand(luaJ_globals, line, env))
|
||||
currentExecutionThread.start()
|
||||
threadRun = true
|
||||
}
|
||||
}
|
||||
|
||||
fun runCommand(reader: Reader, filename: String) {
|
||||
if (!threadRun) {
|
||||
currentExecutionThread = Thread(ThreadRunCommand(luaJ_globals, reader, filename))
|
||||
currentExecutionThread.start()
|
||||
threadRun = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun unsetThreadRun() {
|
||||
threadRun = false
|
||||
threadTimer = 0
|
||||
}
|
||||
|
||||
class ThreadRunCommand : Runnable {
|
||||
|
||||
val mode: Int
|
||||
val arg1: Any
|
||||
val arg2: String
|
||||
val lua: Globals
|
||||
|
||||
constructor(luaInstance: Globals, line: String, env: String) {
|
||||
mode = 0
|
||||
arg1 = line
|
||||
arg2 = env
|
||||
lua = luaInstance
|
||||
}
|
||||
|
||||
constructor(luaInstance: Globals, reader: Reader, filename: String) {
|
||||
mode = 1
|
||||
arg1 = reader
|
||||
arg2 = filename
|
||||
lua = luaInstance
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
try {
|
||||
val chunk: LuaValue
|
||||
if (mode == 0)
|
||||
chunk = lua.load(arg1 as String, arg2)
|
||||
else if (mode == 1)
|
||||
chunk = lua.load(arg1 as Reader, arg2)
|
||||
else
|
||||
throw IllegalArgumentException("Unsupported mode: $mode")
|
||||
|
||||
chunk.call()
|
||||
}
|
||||
catch (e: LuaError) {
|
||||
lua.STDERR.println("${SimpleTextTerminal.ASCII_DC2}${e.message}${SimpleTextTerminal.ASCII_DC4}")
|
||||
if (DEBUGTHRE) e.printStackTrace(System.err)
|
||||
}
|
||||
|
||||
lua.load("_COMPUTER.prompt()").call()
|
||||
}
|
||||
|
||||
val DEBUGTHRE = true
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
// MANUAU LIBRARY LOAD //
|
||||
/////////////////////////
|
||||
private fun loadTermLib(term: Terminal) {
|
||||
luaJ_globals["term"] = LuaValue.tableOf()
|
||||
luaJ_globals["term"]["test"] = TermLib.Test(term)
|
||||
luaJ_globals["term"]["setCursorPos"] = TermLib.MoveCursor(term)
|
||||
luaJ_globals["term"]["setcursorpos"] = TermLib.MoveCursor(term)
|
||||
luaJ_globals["term"]["gotoxy"] = TermLib.MoveCursor(term) // pascal-style alias
|
||||
luaJ_globals["term"]["getCursorPos"] = TermLib.GetCursorPos(term)
|
||||
luaJ_globals["term"]["getcursorpos"] = TermLib.GetCursorPos(term)
|
||||
luaJ_globals["term"]["setCursorBlink"] = TermLib.SetCursorBlink(term)
|
||||
luaJ_globals["term"]["setcursorblink"] = TermLib.SetCursorBlink(term)
|
||||
luaJ_globals["term"]["getSize"] = TermLib.GetSize(term)
|
||||
luaJ_globals["term"]["getsize"] = TermLib.GetSize(term)
|
||||
}
|
||||
}
|
||||
68
src/net/torvald/terrarum/virtualcomputer/lualib/TermLib.kt
Normal file
@@ -0,0 +1,68 @@
|
||||
package net.torvald.terrarum.virtualcomputer.lualib
|
||||
|
||||
import li.cil.repack.org.luaj.vm2.*
|
||||
import li.cil.repack.org.luaj.vm2.lib.*
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
|
||||
|
||||
/**
|
||||
* APIs must have some extent of compatibility with ComputerCraft by dan200
|
||||
*
|
||||
* Created by minjaesong on 16-09-12.
|
||||
*/
|
||||
internal class TermLib(val vt: Terminal) : ZeroArgFunction() {
|
||||
var INSTANCE: TermLib? = null
|
||||
|
||||
init {
|
||||
if (INSTANCE == null) INSTANCE = this
|
||||
}
|
||||
|
||||
override fun call(): LuaValue {
|
||||
throw UnsupportedOperationException("""Invalid usage!
|
||||
usage:
|
||||
luaJ_globals["term"] = LuaValue.tableOf()
|
||||
luaJ_globals["term"]["test"] = TermLib.Test(term)
|
||||
...
|
||||
""")
|
||||
}
|
||||
|
||||
class Test(val term: Terminal) : ZeroArgFunction() {
|
||||
override fun call(): LuaValue {
|
||||
return LuaDouble.valueOf("TermTest")
|
||||
}
|
||||
}
|
||||
|
||||
class MoveCursor(val term: Terminal) : TwoArgFunction() {
|
||||
override fun call(x: LuaValue, y: LuaValue): LuaValue {
|
||||
term.setCursor(x.checkint(), y.checkint())
|
||||
return LuaValue.NONE
|
||||
}
|
||||
}
|
||||
|
||||
class GetCursorPos(val term: Terminal) : VarArgFunction() {
|
||||
override fun invoke(args: Varargs?): Varargs {
|
||||
val ret = arrayOf(LuaValue.valueOf(term.cursorX), LuaValue.valueOf(term.cursorY))
|
||||
return LuaValue.varargsOf(ret)
|
||||
}
|
||||
}
|
||||
|
||||
class SetCursorBlink(val term: Terminal) : OneArgFunction() {
|
||||
override fun call(p0: LuaValue): LuaValue {
|
||||
term.cursorBlink = p0.toboolean()
|
||||
return LuaValue.NONE
|
||||
}
|
||||
}
|
||||
|
||||
class GetSize(val term: Terminal) : VarArgFunction() {
|
||||
override fun invoke(args: Varargs?): Varargs {
|
||||
val ret = arrayOf(LuaValue.valueOf(term.width), LuaValue.valueOf(term.height))
|
||||
return LuaValue.varargsOf(ret)
|
||||
}
|
||||
}
|
||||
|
||||
class IsColor(val term: Terminal) : ZeroArgFunction() {
|
||||
override fun call(): LuaValue {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.torvald.terrarum.virtualcomputer.terminal
|
||||
|
||||
import net.torvald.aa.ColouredFastFont
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-12.
|
||||
*/
|
||||
class ColouredTextTerminal(override val width: Int, override val height: Int
|
||||
) : SimpleTextTerminal(Color.white, width, height) {
|
||||
override val colours = arrayOf(
|
||||
Color(0x00, 0x00, 0x00), // black
|
||||
Color(0xff, 0xff, 0xff), // white
|
||||
Color(0x55, 0x55, 0x55), // dim grey
|
||||
Color(0xaa, 0xaa, 0xaa), // light grey
|
||||
|
||||
Color(0xff, 0xff, 0x00), // yellow
|
||||
Color(0xff, 0x66, 0x00), // orange
|
||||
Color(0xdd, 0x00, 0x00), // red
|
||||
Color(0xff, 0x00, 0x99), // magenta
|
||||
|
||||
Color(0x33, 0x00, 0x99), // purple
|
||||
Color(0x00, 0x00, 0xcc), // blue
|
||||
Color(0x00, 0x99, 0xff), // cyan
|
||||
Color(0x66, 0xff, 0x33), // lime
|
||||
|
||||
Color(0x00, 0xaa, 0x00), // green
|
||||
Color(0x00, 0x66, 0x00), // dark green
|
||||
Color(0x66, 0x33, 0x00), // brown
|
||||
Color(0x99, 0x66, 0x33) // tan
|
||||
) // THESE ARE THE STANDARD
|
||||
|
||||
override val coloursCount = colours.size
|
||||
|
||||
override val backDefault = 0
|
||||
override val foreDefault = 3
|
||||
|
||||
override var backColour = backDefault
|
||||
override var foreColour = foreDefault
|
||||
|
||||
override val fontRef = "./assets/graphics/fonts/CGA.png"
|
||||
override val fontImg = Image(fontRef)
|
||||
override val fontW = fontImg.width / 16
|
||||
override val fontH = fontImg.height / 16
|
||||
override val font = ColouredFastFont(this, fontRef, fontW, fontH)
|
||||
|
||||
override val colourScreen = Color.black
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
* See LICENSE.txt for license terms.
|
||||
*/
|
||||
|
||||
package net.torvald.terrarum.virtualcomputers.terminal;
|
||||
package net.torvald.terrarum.virtualcomputer.terminal;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -0,0 +1,411 @@
|
||||
package net.torvald.terrarum.virtualcomputer.terminal
|
||||
|
||||
import net.torvald.aa.AAFrame
|
||||
import net.torvald.aa.ColouredFastFont
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.blendMul
|
||||
import net.torvald.terrarum.blendScreen
|
||||
import org.lwjgl.BufferUtils
|
||||
import org.lwjgl.openal.AL
|
||||
import org.lwjgl.openal.AL10
|
||||
import org.lwjgl.openal.AL11
|
||||
import org.newdawn.slick.*
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
/**
|
||||
* Default text terminal, four text colours (black, grey, lgrey, white).
|
||||
*
|
||||
* Created by minjaesong on 16-09-07.
|
||||
*/
|
||||
open class SimpleTextTerminal(
|
||||
val phosphor: Color, override val width: Int, override val height: Int
|
||||
) : Terminal {
|
||||
/**
|
||||
* Terminals must support AT LEAST 4 colours.
|
||||
* Color index 0 must be default background, index 3 must be default foreground
|
||||
*/
|
||||
open protected val colours = arrayOf(
|
||||
Color(0x00, 0x00, 0x00), // black
|
||||
Color(0xff, 0xff, 0xff), // white
|
||||
Color(0x55, 0x55, 0x55), // dim grey
|
||||
Color(0xaa, 0xaa, 0xaa) // light grey
|
||||
) // THESE ARE THE STANDARD
|
||||
|
||||
override val coloursCount = colours.size
|
||||
|
||||
open protected val backDefault = 0 // STANDARD
|
||||
open protected val foreDefault = 3 // STANDARD
|
||||
|
||||
override var backColour = backDefault
|
||||
override var foreColour = foreDefault
|
||||
private val colourKey: Int
|
||||
get() = backColour.shl(4).plus(foreColour).and(0xFF)
|
||||
|
||||
override var cursorX = 0
|
||||
override var cursorY = 0
|
||||
override var cursorBlink = true
|
||||
|
||||
val screenBuffer = AAFrame(width, height)
|
||||
|
||||
open protected val fontRef = "./assets/graphics/fonts/MDA.png"
|
||||
open protected val fontImg = Image(fontRef)
|
||||
open protected val fontW = fontImg.width / 16
|
||||
open protected val fontH = fontImg.height / 16
|
||||
open protected val font = ColouredFastFont(this, fontRef, fontW, fontH)
|
||||
|
||||
override val displayW = fontW * width
|
||||
override val displayH = fontH * height
|
||||
|
||||
|
||||
private val TABSIZE = 4
|
||||
|
||||
private val ASCII_NUL = 0.toChar()
|
||||
|
||||
private var cursorBlinkTimer = 0
|
||||
private val cursorBlinkLen = 250
|
||||
private var cursorBlinkOn = true
|
||||
|
||||
|
||||
|
||||
override fun getColor(index: Int): Color = colours[index]
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
cursorBlinkTimer = cursorBlinkTimer.plus(delta)
|
||||
if (cursorBlinkTimer > cursorBlinkLen) {
|
||||
cursorBlinkTimer -= cursorBlinkLen
|
||||
cursorBlinkOn = !cursorBlinkOn
|
||||
}
|
||||
|
||||
wrap()
|
||||
|
||||
// beep AL-related
|
||||
if (beepSource != null && AL10.alGetSourcei(beepSource!!, AL10.AL_SOURCE_STATE) != AL10.AL_PLAYING) {
|
||||
AL10.alDeleteSources(beepSource!!)
|
||||
AL10.alDeleteBuffers(beepBuffer!!)
|
||||
beepSource = null
|
||||
beepBuffer == null
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
open protected val colourScreen = Color(0x191919)
|
||||
|
||||
/**
|
||||
* pass UIcanvas to the parameter "g"
|
||||
*/
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
g.font = font
|
||||
|
||||
blendNormal()
|
||||
|
||||
for (y in 0..height - 1) {
|
||||
for (x in 0..width - 1) {
|
||||
val ch = screenBuffer.getChar(x, y)
|
||||
|
||||
// background
|
||||
g.color = getColor(screenBuffer.getBackgroundColour(x, y))
|
||||
g.fillRect(fontW * x.toFloat(), fontH * y.toFloat(), fontW.toFloat(), fontH.toFloat())
|
||||
|
||||
// foreground
|
||||
if (ch.toInt() != 0 && ch.toInt() != 32) {
|
||||
g.color = getColor(screenBuffer.getForegroundColour(x, y))
|
||||
g.drawString(
|
||||
Character.toString(ch),
|
||||
fontW * x.toFloat(), fontH * y.toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// cursor
|
||||
g.color = getColor(foreDefault)
|
||||
if (cursorBlinkOn && cursorBlink)
|
||||
g.fillRect(
|
||||
fontW * cursorX.toFloat(),
|
||||
fontH * cursorY.toFloat(),
|
||||
fontW.toFloat(),
|
||||
fontH.toFloat()
|
||||
)
|
||||
|
||||
|
||||
// not-pure-black screen
|
||||
g.color = colourScreen
|
||||
blendScreen()
|
||||
g.fillRect(0f, 0f, displayW.toFloat(), displayH.toFloat())
|
||||
|
||||
|
||||
// colour overlay
|
||||
g.color = phosphor
|
||||
blendMul()
|
||||
g.fillRect(0f, 0f, displayW.toFloat(), displayH.toFloat())
|
||||
|
||||
|
||||
blendNormal()
|
||||
|
||||
}
|
||||
|
||||
override fun setCursor(x: Int, y: Int) {
|
||||
cursorX = x
|
||||
cursorY = y
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
screenBuffer.drawBuffer(cursorX, cursorY, bufferChar.toChar())
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
screenBuffer.drawBuffer(cursorX, cursorY, c.toInt().and(0xFF).toChar(), colourKey)
|
||||
}
|
||||
|
||||
val asciiControlInUse = charArrayOf(
|
||||
ASCII_NUL,
|
||||
ASCII_BEL,
|
||||
ASCII_BS,
|
||||
ASCII_TAB,
|
||||
ASCII_LF,
|
||||
ASCII_FF,
|
||||
ASCII_CR,
|
||||
ASCII_DEL,
|
||||
ASCII_DC1,
|
||||
ASCII_DC2,
|
||||
ASCII_DC3,
|
||||
ASCII_DC4
|
||||
)
|
||||
|
||||
/** Prints a char and move cursor accordingly. */
|
||||
override fun printChar(c: Char) {
|
||||
wrap()
|
||||
if (c >= ' ' && c.toInt() != 127) {
|
||||
emitChar(c)
|
||||
cursorX += 1
|
||||
}
|
||||
else {
|
||||
when (c) {
|
||||
ASCII_BEL -> beep()
|
||||
ASCII_BS -> { cursorX -= 1; wrap() }
|
||||
ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE }
|
||||
ASCII_LF -> { cursorX = 0; cursorY += 1; wrap() }
|
||||
ASCII_FF -> clear()
|
||||
ASCII_CR -> { cursorX = 0 }
|
||||
ASCII_DEL -> { cursorX -= 1; wrap(); emitChar(colourKey.shl(8)) }
|
||||
ASCII_DC1, ASCII_DC2, ASCII_DC3, ASCII_DC4 -> { foreColour = c - ASCII_DC1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Emits a string and move cursor accordingly. */
|
||||
override fun printString(s: String, x: Int, y: Int) {
|
||||
setCursor(x, y)
|
||||
emitString(s)
|
||||
val absCursorPos = cursorX + cursorY * width + s.length
|
||||
setCursor(absCursorPos % width, absCursorPos / width)
|
||||
|
||||
printChar(ASCII_LF)
|
||||
}
|
||||
|
||||
/** Emits a string. Does not move cursor */
|
||||
override fun emitString(s: String) {
|
||||
val x = cursorX
|
||||
val y = cursorY
|
||||
|
||||
for (i in 0..s.length - 1)
|
||||
printChar(s[i])
|
||||
|
||||
setCursor(x, y)
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
screenBuffer.clear(backColour)
|
||||
cursorX = 0
|
||||
cursorY = 0
|
||||
}
|
||||
|
||||
override fun clearLine() {
|
||||
for (i in 0..width - 1)
|
||||
screenBuffer.drawBuffer(i, cursorY, 0.toChar(), colourKey)
|
||||
}
|
||||
|
||||
override fun scroll(amount: Int) {
|
||||
val offset = amount * width
|
||||
for (i in offset..screenBuffer.sizeof.ushr(1) - 1) {
|
||||
screenBuffer.frameBuffer[i - offset] = screenBuffer.frameBuffer[i]
|
||||
}
|
||||
for (c in 1..amount) {
|
||||
cursorY -= 1
|
||||
clearLine()
|
||||
}
|
||||
}
|
||||
|
||||
override fun setColour(back: Int, fore: Int) {
|
||||
backColour = back
|
||||
foreColour = fore
|
||||
}
|
||||
|
||||
override fun resetColour() {
|
||||
backColour = backDefault
|
||||
foreColour = foreDefault
|
||||
}
|
||||
|
||||
private val sampleRate = 22050
|
||||
private val maxDuration = 10000
|
||||
private val beepSamples = maxDuration.div(1000).times(sampleRate)
|
||||
private var beepSource: Int? = null
|
||||
private var beepBuffer: Int? = null
|
||||
|
||||
override fun beep(freq: Float, duration: Int) {
|
||||
throw NotImplementedError("errenous OpenAL behaviour; *grunts*")
|
||||
|
||||
val audioData = BufferUtils.createByteBuffer(duration.times(sampleRate).div(1000))
|
||||
|
||||
var chop = false
|
||||
val realDuration = Math.min(maxDuration, duration)
|
||||
|
||||
for (i in 0..realDuration - 1) {
|
||||
if (i.mod(freq) < 1.0) chop = !chop
|
||||
audioData.put(if (chop) 0xFF.toByte() else 0x00.toByte())
|
||||
}
|
||||
|
||||
audioData.rewind()
|
||||
|
||||
|
||||
|
||||
// Clear error stack.
|
||||
AL10.alGetError()
|
||||
|
||||
beepBuffer = AL10.alGenBuffers()
|
||||
checkALError()
|
||||
|
||||
try {
|
||||
AL10.alBufferData(beepBuffer!!, AL10.AL_FORMAT_MONO8, audioData, sampleRate)
|
||||
checkALError()
|
||||
|
||||
beepSource = AL10.alGenSources()
|
||||
checkALError()
|
||||
|
||||
try {
|
||||
AL10.alSourceQueueBuffers(beepSource!!, beepBuffer!!)
|
||||
checkALError()
|
||||
|
||||
AL10.alSource3f(beepSource!!, AL10.AL_POSITION, 0f, 0f, 1f)
|
||||
AL10.alSourcef(beepSource!!, AL10.AL_REFERENCE_DISTANCE, 1f)
|
||||
AL10.alSourcef(beepSource!!, AL10.AL_MAX_DISTANCE, 1f)
|
||||
AL10.alSourcef(beepSource!!, AL10.AL_GAIN, 0.3f)
|
||||
checkALError()
|
||||
|
||||
AL10.alSourcePlay(beepSource!!)
|
||||
checkALError()
|
||||
|
||||
}
|
||||
catch (e: ALException) {
|
||||
AL10.alDeleteSources(beepSource!!)
|
||||
}
|
||||
}
|
||||
catch (e: ALException) {
|
||||
if (beepSource != null) AL10.alDeleteSources(beepSource!!)
|
||||
}
|
||||
|
||||
|
||||
/*def checkFinished = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE) != AL10.AL_PLAYING && {
|
||||
AL10.alDeleteSources(source)
|
||||
AL10.alDeleteBuffers(buffer)
|
||||
true
|
||||
}*/
|
||||
}
|
||||
|
||||
// Custom implementation of Util.checkALError() that uses our custom exception.
|
||||
private fun checkALError() {
|
||||
val errorCode = AL10.alGetError()
|
||||
if (errorCode != AL10.AL_NO_ERROR) {
|
||||
throw ALException(errorCode)
|
||||
}
|
||||
}
|
||||
|
||||
/** for "beep code" on modern BIOS. Pattern: - . */
|
||||
override fun beep(pattern: String) {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override var lastInputByte: Int = -1
|
||||
var sb: StringBuilder = StringBuilder()
|
||||
private var inputOpen = false
|
||||
/**
|
||||
* Technically, this is different from Java's InputStream
|
||||
*/
|
||||
fun openInput() {
|
||||
inputOpen = true
|
||||
if (DEBUG) println("[SimpleTextTerminal] openInput()")
|
||||
}
|
||||
|
||||
fun closeInput(): String {
|
||||
inputOpen = false
|
||||
val ret = sb.toString()
|
||||
sb = StringBuilder()
|
||||
|
||||
if (DEBUG) println("[SimpleTextTerminal] closeInput(), $ret")
|
||||
return ret
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
lastInputByte = c.toInt()
|
||||
|
||||
if (inputOpen) {
|
||||
if (c == ASCII_CR)
|
||||
printChar(ASCII_LF)
|
||||
else
|
||||
printChar(c)
|
||||
if (!asciiControlInUse.contains(c)) sb.append(c)
|
||||
else if (c == ASCII_DEL && sb.length > 0) sb.deleteCharAt(sb.length - 1)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getKeyPress(): Int? = lastInputByte
|
||||
|
||||
private fun isOOB(x: Int, y: Int) =
|
||||
(x < 0 || y < 0 || x >= width || y >= height)
|
||||
|
||||
companion object {
|
||||
val AMBER = Color(255, 183, 0) // P3, 602 nm
|
||||
val IBM_GREEN = Color(74, 255, 0) // P39, 525 nm
|
||||
val WHITE = Color(228, 234, 255) // P4, 7 500 K
|
||||
val ELECTRIC_BLUE = Color(0, 239, 255) // imaginary, 486 nm
|
||||
val RED = Color(250, 0, 0) // <= 645 nm
|
||||
|
||||
val ASCII_BEL = 7.toChar() // *BEEP!*
|
||||
val ASCII_BS = 8.toChar() // x = x - 1
|
||||
val ASCII_TAB = 9.toChar() // move cursor to next (TABSIZE * yy) pos (5 -> 8, 3- > 4, 4 -> 8)
|
||||
val ASCII_LF = 10.toChar() // new line
|
||||
val ASCII_FF = 12.toChar() // new page
|
||||
val ASCII_CR = 13.toChar() // x <- 0
|
||||
val ASCII_DEL = 127.toChar() // backspace and delete char
|
||||
val ASCII_DC1 = 17.toChar() // foreground colour 0
|
||||
val ASCII_DC2 = 18.toChar() // foreground colour 1
|
||||
val ASCII_DC3 = 19.toChar() // foreground colour 2
|
||||
val ASCII_DC4 = 20.toChar() // foreground colour 3
|
||||
}
|
||||
|
||||
private val DEBUG = true
|
||||
}
|
||||
|
||||
class ALException(errorCode: Int) : Exception("ALerror: $errorCode") {
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.torvald.terrarum.virtualcomputers.terminal
|
||||
package net.torvald.terrarum.virtualcomputer.terminal
|
||||
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
@@ -24,22 +24,24 @@ interface Terminal {
|
||||
var backColour: Int
|
||||
var foreColour: Int
|
||||
|
||||
var lastInputByte: Int
|
||||
|
||||
// to be used in UI
|
||||
val displayW: Int
|
||||
val displayH: Int
|
||||
|
||||
// more technical
|
||||
var isInputStreamOpen: Boolean
|
||||
|
||||
fun getColor(index: Int): Color
|
||||
fun update(gc: GameContainer, delta: Int)
|
||||
fun render(gc: GameContainer, g: Graphics)
|
||||
fun keyPressed(key: Int, c: Char)
|
||||
|
||||
// API calls
|
||||
fun setCursor(x: Int, y: Int)
|
||||
/** Emits a bufferChar. Does not move cursor */
|
||||
/** Emits a bufferChar. Does not move cursor
|
||||
* It is also not affected by the control sequences; just print them out as symbol */
|
||||
fun emitChar(bufferChar: Int)
|
||||
/** Emits a char. Does not move cursor */
|
||||
/** Emits a char. Does not move cursor
|
||||
* It is also not affected by the control sequences; just print them out as symbol */
|
||||
fun emitChar(c: Char)
|
||||
/** Prints a char and move cursor accordingly. */
|
||||
fun printChar(c: Char)
|
||||
@@ -52,5 +54,24 @@ interface Terminal {
|
||||
fun scroll(amount: Int = 1)
|
||||
fun setColour(back: Int, fore: Int)
|
||||
fun resetColour()
|
||||
fun beep(freq: Int = 1000, duration: Int = 200)
|
||||
/**
|
||||
* @param freg: Frequency (float)
|
||||
* @param duration: milliseconds
|
||||
*/
|
||||
fun beep(freq: Float = 1000f, duration: Int = 200)
|
||||
/** for "beep code" on modern BIOS. Pattern: - . */
|
||||
fun beep(pattern: String)
|
||||
/** Requires keyPressed() event to be processed.
|
||||
*
|
||||
* null indicates the input stream is waiting for an input
|
||||
*
|
||||
* implementation:
|
||||
*
|
||||
* private var lastInputByte: Int? = null
|
||||
* override fun keyPressed(key: Int, c: Char) {
|
||||
lastInputByte = c.toInt()
|
||||
lastInputByte = null
|
||||
}
|
||||
*/
|
||||
fun getKeyPress(): Int?
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.torvald.terrarum.virtualcomputer.terminal
|
||||
|
||||
import org.lwjgl.input.Keyboard
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-10.
|
||||
*/
|
||||
class TerminalInputStream(val term: Terminal) : InputStream() {
|
||||
override fun read(): Int {
|
||||
val ret = term.lastInputByte
|
||||
term.lastInputByte = -1
|
||||
return ret
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package net.torvald.terrarum.virtualcomputer.terminal;
|
||||
|
||||
import li.cil.repack.com.naef.jnlua.LuaException;
|
||||
import li.cil.repack.com.naef.jnlua.LuaRuntimeException;
|
||||
import li.cil.repack.com.naef.jnlua.LuaState;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-10.
|
||||
*/
|
||||
public class TerminalLuaConsole {
|
||||
// -- Static
|
||||
private static final String[] EMPTY_ARGS = new String[0];
|
||||
|
||||
/**
|
||||
* Main routine.
|
||||
*
|
||||
* @param args
|
||||
* the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
LuaConsole luaConsole = new LuaConsole(args);
|
||||
luaConsole.run();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
private PrintStream out;
|
||||
|
||||
// -- State
|
||||
private LuaState luaState;
|
||||
|
||||
// -- Construction
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
public TerminalLuaConsole(Terminal term) {
|
||||
this(EMPTY_ARGS, term);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance with the specified command line arguments. The
|
||||
* arguments are passed to Lua as the <code>argv</code> global variable.
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public TerminalLuaConsole(String[] args, Terminal term) {
|
||||
out = new TerminalPrintStream(term);
|
||||
|
||||
luaState = new LuaState();
|
||||
|
||||
// Process arguments
|
||||
luaState.newTable(args.length, 0);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
luaState.pushString(args[i]);
|
||||
luaState.rawSet(-2, i + 1);
|
||||
}
|
||||
luaState.setGlobal("argv");
|
||||
|
||||
// Open standard libraries
|
||||
luaState.openLibs();
|
||||
|
||||
// Set buffer mode
|
||||
luaState.load("io.stdout:setvbuf(\"no\")", "=consoleInitStdout");
|
||||
luaState.call(0, 0);
|
||||
luaState.load("io.stderr:setvbuf(\"no\")", "=consoleInitStderr");
|
||||
luaState.call(0, 0);
|
||||
}
|
||||
|
||||
// -- Properties
|
||||
/**
|
||||
* Returns the Lua state of this console.
|
||||
*
|
||||
* @return the Lua state
|
||||
*/
|
||||
public LuaState getLuaState() {
|
||||
return luaState;
|
||||
}
|
||||
|
||||
// -- Operations
|
||||
/**
|
||||
* Runs the console.
|
||||
*/
|
||||
public void run() {
|
||||
// Banner
|
||||
out.println(String.format("JNLua %s Console using Lua %s.",
|
||||
LuaState.VERSION, LuaState.LUA_VERSION));
|
||||
out.print("Type 'go' on an empty line to evaluate a chunk. ");
|
||||
out.println("Type =<expression> to print an expression.");
|
||||
|
||||
// Prepare reader
|
||||
BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(System.in));
|
||||
try {
|
||||
// Process chunks
|
||||
chunk: while (true) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
OutputStreamWriter outWriter = new OutputStreamWriter(out,
|
||||
"UTF-8");
|
||||
boolean firstLine = true;
|
||||
|
||||
// Process lines
|
||||
while (true) {
|
||||
String line = bufferedReader.readLine();
|
||||
if (line == null) {
|
||||
break chunk;
|
||||
}
|
||||
if (line.equals("go")) {
|
||||
outWriter.flush();
|
||||
InputStream in = new ByteArrayInputStream(out
|
||||
.toByteArray());
|
||||
runChunk(in);
|
||||
continue chunk;
|
||||
}
|
||||
if (firstLine && line.startsWith("=")) {
|
||||
outWriter.write("return " + line.substring(1));
|
||||
outWriter.flush();
|
||||
InputStream in = new ByteArrayInputStream(out
|
||||
.toByteArray());
|
||||
runChunk(in);
|
||||
continue chunk;
|
||||
}
|
||||
outWriter.write(line);
|
||||
outWriter.write('\n');
|
||||
firstLine = false;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
out.print("IO error: ");
|
||||
out.print(e.getMessage());
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a chunk of Lua code from an input stream.
|
||||
*/
|
||||
protected void runChunk(InputStream in) throws IOException {
|
||||
try {
|
||||
long start = System.nanoTime();
|
||||
luaState.setTop(0);
|
||||
luaState.load(in, "=console", "t");
|
||||
luaState.call(0, LuaState.MULTRET);
|
||||
long stop = System.nanoTime();
|
||||
for (int i = 1; i <= luaState.getTop(); i++) {
|
||||
if (i > 1) {
|
||||
out.print(", ");
|
||||
}
|
||||
switch (luaState.type(i)) {
|
||||
case BOOLEAN:
|
||||
out.print(Boolean.valueOf(luaState.toBoolean(i)));
|
||||
break;
|
||||
case NUMBER:
|
||||
case STRING:
|
||||
out.print(luaState.toString(i));
|
||||
break;
|
||||
default:
|
||||
out.print(luaState.typeName(i));
|
||||
}
|
||||
}
|
||||
out.print("\t#msec=");
|
||||
out.print(String.format("%.3f", (stop - start) / 1000000.0));
|
||||
out.println();
|
||||
} catch (LuaRuntimeException e) {
|
||||
e.printLuaStackTrace();
|
||||
} catch (LuaException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.torvald.terrarum.virtualcomputer.terminal
|
||||
|
||||
import java.io.OutputStream
|
||||
import java.io.PrintStream
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-10.
|
||||
*/
|
||||
class TerminalPrintStream(val term: Terminal) : PrintStream(TerminalOutputStream(term)) {
|
||||
|
||||
}
|
||||
|
||||
class TerminalOutputStream(val term: Terminal) : OutputStream() {
|
||||
override fun write(b: Int) = term.printChar(b.and(0xFF).toChar())
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.torvald.terrarum.virtualcomputer.worldobject
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-08.
|
||||
*/
|
||||
object ComputerPartsCodex {
|
||||
val rams = HashMap<Int, Int>() // itemID, capacity in bytes (0 bytes - 8 GBytes)
|
||||
val processors = HashMap<Int, Int>() // itemID, cycles
|
||||
val harddisks = HashMap<Int, Int>() // itemID, capacity in bytes
|
||||
val diskettes = HashMap<Int, Int>() // itemID, capacity in bytes
|
||||
val opticaldiscs = HashMap<Int, Int>() // itemID, capacity in bytes
|
||||
|
||||
init {
|
||||
// in kilobytes
|
||||
rams.put(4864, 128.KiB()) // 64k is not enough for Lua, so we start here.
|
||||
rams.put(4865, 192.KiB())
|
||||
rams.put(4866, 256.KiB())
|
||||
rams.put(4867, 320.KiB()) // 320 * 2 = "640k ought to be enough for anybody" --Someone that is NOT Bill Gates
|
||||
rams.put(4868, 480.KiB())
|
||||
rams.put(4869, 512.KiB())
|
||||
rams.put(4870, 1024.KiB()) // server ops hate it
|
||||
rams.put(4871, 2048.KiB()) // wait, we can multiplayer?
|
||||
|
||||
processors.put(4872, 1000)
|
||||
processors.put(4873, 2000)
|
||||
processors.put(4874, 4000)
|
||||
processors.put(4875, 8000) // this is totally OP
|
||||
|
||||
harddisks.put(4876, 1.MB())
|
||||
harddisks.put(4877, 2.MB())
|
||||
harddisks.put(4878, 5.MB())
|
||||
harddisks.put(4879, 10.MB())
|
||||
|
||||
// Floppy disk: your primitive and only choice of removable storage
|
||||
diskettes.put(4880, 360.kB()) // single-sided
|
||||
diskettes.put(4881, 720.kB()) // double-sided
|
||||
diskettes.put(4882, 1440.kB()) // 3.5" HD
|
||||
diskettes.put(4883, 2880.kB()) // 3.5" ED
|
||||
|
||||
// CD-Rs
|
||||
opticaldiscs.put(4884, 8.MB()) // arbitrary size
|
||||
}
|
||||
|
||||
fun getRamSize(itemIndex: Int): Int = rams[itemIndex] ?: 0
|
||||
fun getProcessorCycles(itemIndex: Int): Int = processors[itemIndex] ?: 0
|
||||
fun getHDDSize(itemIndex: Int): Int = harddisks[itemIndex] ?: 0
|
||||
fun getFDDSize(itemIndex: Int): Int = diskettes[itemIndex] ?: 0
|
||||
fun getODDSize(itemIndex: Int): Int = opticaldiscs[itemIndex] ?: 0
|
||||
|
||||
private fun Int.MB() = this * 1000000 // 1 MB == 1 000 000 bytes, bitches!
|
||||
private fun Int.kB() = this * 1000
|
||||
private fun Int.KiB() = this.shr(10)
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.torvald.terrarum.virtualcomputers.worldobject
|
||||
package net.torvald.terrarum.virtualcomputer.worldobject
|
||||
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.FixturesBase
|
||||
import net.torvald.terrarum.virtualcomputers.terminal.SimpleTextTerminal
|
||||
import net.torvald.terrarum.virtualcomputers.terminal.Terminal
|
||||
import net.torvald.terrarum.virtualcomputers.worldobject.ui.UITextTerminal
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.SimpleTextTerminal
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
|
||||
import net.torvald.terrarum.virtualcomputer.worldobject.ui.UITextTerminal
|
||||
import org.newdawn.slick.Color
|
||||
import java.util.*
|
||||
|
||||
@@ -13,8 +13,8 @@ import java.util.*
|
||||
*/
|
||||
class FixturesBasicTerminal(phosphor: Color) : FixturesBase() {
|
||||
|
||||
val terminal: Terminal = SimpleTextTerminal(phosphor, 80, 25)
|
||||
val ui = UITextTerminal(terminal)
|
||||
val vt: Terminal = SimpleTextTerminal(phosphor, 80, 25)
|
||||
val ui = UITextTerminal(vt)
|
||||
|
||||
init {
|
||||
collisionFlag = COLLISION_PLATFORM
|
||||
@@ -0,0 +1,95 @@
|
||||
package net.torvald.terrarum.virtualcomputer.worldobject
|
||||
|
||||
import net.torvald.terrarum.gameactors.FixturesBase
|
||||
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.SimpleTextTerminal
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
|
||||
import org.newdawn.slick.GameContainer
|
||||
import java.io.PrintStream
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-08.
|
||||
*/
|
||||
open class FixturesComputerBase() : FixturesBase() {
|
||||
|
||||
val processorCycle: Int // number of Lua statement to process per tick (1/100 s)
|
||||
get() = ComputerPartsCodex.getProcessorCycles(actorValue.getAsInt("processor") ?: -1)
|
||||
val memSize: Int // max: 8 GB
|
||||
get() {
|
||||
var size = 0
|
||||
for (i in 0..3)
|
||||
size += ComputerPartsCodex.getRamSize(actorValue.getAsInt("memSlot$i") ?: -1)
|
||||
|
||||
return size
|
||||
}
|
||||
|
||||
/** Connected terminal */
|
||||
var terminal: FixturesBasicTerminal? = null
|
||||
|
||||
var computerInside: BaseTerrarumComputer? = null
|
||||
|
||||
init {
|
||||
actorValue["memslot0"] = -1 // -1 indicates mem slot is empty
|
||||
actorValue["memslot1"] = -1 // put index of item here
|
||||
actorValue["memslot2"] = -1 // ditto.
|
||||
actorValue["memslot3"] = -1 // do.
|
||||
|
||||
actorValue["processor"] = -1 // do.
|
||||
|
||||
// as in "dev/hda"; refers hard disk drive (and no partitioning)
|
||||
actorValue["hda"] = "none" // 'UUID rendered as String' or "none"
|
||||
actorValue["hdb"] = "none"
|
||||
actorValue["hdc"] = "none"
|
||||
actorValue["hdd"] = "none"
|
||||
// as in "dev/fd1"; refers floppy disk drive
|
||||
actorValue["fd1"] = "none"
|
||||
actorValue["fd2"] = "none"
|
||||
actorValue["fd3"] = "none"
|
||||
actorValue["fd4"] = "none"
|
||||
// SCSI connected optical drive
|
||||
actorValue["sda"] = "none"
|
||||
|
||||
// UUID of this device
|
||||
actorValue["uuid"] = UUID.randomUUID().toString()
|
||||
|
||||
collisionFlag = COLLISION_PLATFORM
|
||||
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// get the computer actually work //
|
||||
////////////////////////////////////
|
||||
|
||||
fun attachTerminal(uuid: String) {
|
||||
val fetchedTerminal = getTerminalByUUID(uuid)
|
||||
computerInside = BaseTerrarumComputer(fetchedTerminal)
|
||||
}
|
||||
|
||||
fun detatchTerminal() {
|
||||
terminal = null
|
||||
}
|
||||
|
||||
private fun getTerminalByUUID(uuid: String): Terminal? {
|
||||
TODO("get terminal by UUID. Return null if not found")
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////
|
||||
// game codes //
|
||||
////////////////
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
super.update(gc, delta)
|
||||
if (terminal != null) terminal!!.update(gc, delta)
|
||||
}
|
||||
|
||||
fun keyPressed(key: Int, c: Char) {
|
||||
if (terminal != null) {
|
||||
terminal!!.vt.keyPressed(key, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.torvald.terrarum.virtualcomputers.worldobject.ui
|
||||
package net.torvald.terrarum.virtualcomputer.worldobject.ui
|
||||
|
||||
import net.torvald.terrarum.ui.*
|
||||
import net.torvald.terrarum.virtualcomputers.terminal.Terminal
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
@@ -1,10 +0,0 @@
|
||||
package net.torvald.terrarum.virtualcomputers
|
||||
|
||||
/**
|
||||
* Reference: https://github.com/MightyPirates/OpenComputers/blob/master-MC1.7.10/src/main/java/li/cil/oc/api/API.java
|
||||
*
|
||||
* Created by minjaesong on 16-09-07.
|
||||
*/
|
||||
object API {
|
||||
// val filesystem = Filesystem()
|
||||
}
|
||||
@@ -1,259 +0,0 @@
|
||||
package net.torvald.terrarum.virtualcomputers.terminal
|
||||
|
||||
import net.torvald.aa.AAFrame
|
||||
import net.torvald.aa.ColouredFastFont
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.blendMul
|
||||
import org.newdawn.slick.*
|
||||
|
||||
/**
|
||||
* Default text terminal, four text colours (black, grey, lgrey, white).
|
||||
*
|
||||
* Created by minjaesong on 16-09-07.
|
||||
*/
|
||||
open class SimpleTextTerminal(
|
||||
val phosphor: Color, override val width: Int, override val height: Int
|
||||
) : Terminal {
|
||||
override val coloursCount = 4
|
||||
|
||||
private val colors = arrayOf(
|
||||
Color(0x19, 0x19, 0x19),
|
||||
Color(0xff, 0xff, 0xff),
|
||||
Color(0x55, 0x55, 0x55),
|
||||
Color(0xaa, 0xaa, 0xaa)
|
||||
)
|
||||
|
||||
private val backDefault = 0
|
||||
private val foreDefault = colors.size - 1
|
||||
|
||||
override var backColour = backDefault
|
||||
override var foreColour = foreDefault
|
||||
private val colourKey: Int
|
||||
get() = backColour.shl(4).plus(foreColour).and(0xFF)
|
||||
|
||||
override var cursorX = 0
|
||||
override var cursorY = 0
|
||||
override var cursorBlink = true
|
||||
|
||||
val screenBuffer = AAFrame(width, height)
|
||||
|
||||
private val fontRef = "./assets/graphics/fonts/MDA.png"
|
||||
private val fontImg = Image(fontRef)
|
||||
private val fontW = fontImg.width / 16
|
||||
private val fontH = fontImg.height / 16
|
||||
private val font = ColouredFastFont(this, fontRef, fontW, fontH)
|
||||
|
||||
override var isInputStreamOpen: Boolean
|
||||
get() = throw UnsupportedOperationException()
|
||||
set(value) {
|
||||
}
|
||||
|
||||
override val displayW = fontW * width
|
||||
override val displayH = fontH * height
|
||||
|
||||
private val TABSIZE = 4
|
||||
|
||||
private val ASCII_NUL = 0.toChar()
|
||||
|
||||
private val ASCII_BEL = 7.toChar() // *BEEP!*
|
||||
private val ASCII_BS = 8.toChar() // x = x - 1
|
||||
private val ASCII_TAB = 9.toChar() // move cursor to next (TABSIZE * yy) pos (5 -> 8, 3- > 4, 4 -> 8)
|
||||
private val ASCII_LF = 10.toChar() // new line
|
||||
private val ASCII_FF = 12.toChar() // new page
|
||||
private val ASCII_CR = 13.toChar() // x <- 0
|
||||
private val ASCII_DEL = 127.toChar() // backspace and delete char
|
||||
|
||||
private var cursorBlinkTimer = 0
|
||||
private val cursorBlinkLen = 250
|
||||
private var cursorBlinkOn = true
|
||||
|
||||
override fun getColor(index: Int): Color = colors[index]
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
cursorBlinkTimer = cursorBlinkTimer.plus(delta)
|
||||
if (cursorBlinkTimer > cursorBlinkLen) {
|
||||
cursorBlinkTimer -= cursorBlinkLen
|
||||
cursorBlinkOn = !cursorBlinkOn
|
||||
}
|
||||
|
||||
wrap()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pass UIcanvas to the parameter "g"
|
||||
*/
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
g.font = font
|
||||
|
||||
blendNormal()
|
||||
|
||||
for (y in 0..height - 1) {
|
||||
for (x in 0..width - 1) {
|
||||
val ch = screenBuffer.getChar(x, y)
|
||||
|
||||
// background
|
||||
g.color = getColor(screenBuffer.getBackgroundColour(x, y))
|
||||
g.fillRect(fontW * x.toFloat(), fontH * y.toFloat(), fontW.toFloat(), fontH.toFloat())
|
||||
|
||||
// foreground
|
||||
if (ch.toInt() != 0 && ch.toInt() != 32) {
|
||||
g.color = getColor(screenBuffer.getForegroundColour(x, y))
|
||||
g.drawString(
|
||||
Character.toString(ch),
|
||||
fontW * x.toFloat(), fontH * y.toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// cursor
|
||||
g.color = getColor(foreColour)
|
||||
if (cursorBlinkOn && cursorBlink)
|
||||
g.fillRect(
|
||||
fontW * cursorX.toFloat(),
|
||||
fontH * cursorY.toFloat(),
|
||||
fontW.toFloat(),
|
||||
fontH.toFloat()
|
||||
)
|
||||
|
||||
|
||||
|
||||
// colour overlay
|
||||
g.color = phosphor
|
||||
blendMul()
|
||||
g.fillRect(0f, 0f, displayW.toFloat(), displayH.toFloat())
|
||||
|
||||
|
||||
blendNormal()
|
||||
|
||||
}
|
||||
|
||||
override fun setCursor(x: Int, y: Int) {
|
||||
cursorX = x
|
||||
cursorY = y
|
||||
}
|
||||
|
||||
/** Emits a bufferChar. Does not move cursor */
|
||||
override fun emitChar(bufferChar: Int) {
|
||||
screenBuffer.drawBuffer(cursorX, cursorY, bufferChar.toChar())
|
||||
}
|
||||
|
||||
/** Emits a char. Does not move cursor */
|
||||
override fun emitChar(c: Char) {
|
||||
screenBuffer.drawBuffer(cursorX, cursorY, c.toInt().and(0xFF).toChar(), colourKey)
|
||||
}
|
||||
|
||||
val asciiControlInUse = charArrayOf(
|
||||
ASCII_BEL,
|
||||
ASCII_BS,
|
||||
ASCII_TAB,
|
||||
ASCII_LF,
|
||||
ASCII_FF,
|
||||
ASCII_CR,
|
||||
ASCII_DEL
|
||||
)
|
||||
|
||||
/** Prints a char and move cursor accordingly. */
|
||||
override fun printChar(c: Char) {
|
||||
wrap()
|
||||
if (c >= ' ' && c.toInt() != 127) {
|
||||
emitChar(c)
|
||||
cursorX += 1
|
||||
}
|
||||
else {
|
||||
when (c) {
|
||||
ASCII_BEL -> beep()
|
||||
ASCII_BS -> { cursorX -= 1; wrap() }
|
||||
ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE }
|
||||
ASCII_LF -> { cursorX = 0; cursorY += 1; wrap() }
|
||||
ASCII_FF -> clear()
|
||||
ASCII_CR -> { cursorX = 0 }
|
||||
ASCII_DEL -> { cursorX -= 1; wrap(); emitChar(colourKey.shl(8)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Emits a string and move cursor accordingly. */
|
||||
override fun printString(s: String, x: Int, y: Int) {
|
||||
setCursor(x, y)
|
||||
emitString(s)
|
||||
val absCursorPos = cursorX + cursorY * width + s.length
|
||||
setCursor(x % width, y / width)
|
||||
}
|
||||
|
||||
/** Emits a string. Does not move cursor */
|
||||
override fun emitString(s: String) {
|
||||
val x = cursorX
|
||||
val y = cursorY
|
||||
|
||||
for (i in 0..s.length - 1)
|
||||
printChar(s[i])
|
||||
|
||||
setCursor(x, y)
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
screenBuffer.clear(backColour)
|
||||
cursorX = 0
|
||||
cursorY = 0
|
||||
}
|
||||
|
||||
override fun clearLine() {
|
||||
for (i in 0..width - 1)
|
||||
screenBuffer.drawBuffer(i, cursorY, 0.toChar(), colourKey)
|
||||
}
|
||||
|
||||
override fun scroll(amount: Int) {
|
||||
val offset = amount * width
|
||||
for (i in offset..screenBuffer.sizeof.ushr(1) - 1) {
|
||||
screenBuffer.frameBuffer[i - offset] = screenBuffer.frameBuffer[i]
|
||||
}
|
||||
for (c in 1..amount) {
|
||||
cursorY -= 1
|
||||
clearLine()
|
||||
}
|
||||
}
|
||||
|
||||
override fun setColour(back: Int, fore: Int) {
|
||||
backColour = back
|
||||
foreColour = fore
|
||||
}
|
||||
|
||||
override fun resetColour() {
|
||||
backColour = backDefault
|
||||
foreColour = foreDefault
|
||||
}
|
||||
|
||||
override fun beep(freq: Int, duration: Int) {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
private fun isOOB(x: Int, y: Int) =
|
||||
(x < 0 || y < 0 || x >= width || y >= height)
|
||||
|
||||
companion object {
|
||||
val AMBER = Color(255, 183, 0) // P3, 602 nm
|
||||
val IBM_GREEN = Color(74, 255, 0) // P39, 525 nm
|
||||
val WHITE = Color(228, 234, 255) // P4, 7 500 K
|
||||
val ELECTRIC_BLUE = Color(0, 239, 255) // imaginary, 486 nm
|
||||
val RED = Color(250, 0, 0) // <= 645 nm
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package net.torvald.terrarum.virtualcomputers.worldobject
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-08.
|
||||
*/
|
||||
object ComputerPartsCodex {
|
||||
val rams = HashMap<Int, Int>() // itemID, capacity in bytes (0 bytes - 8 GBytes)
|
||||
val processors = HashMap<Int, Int>() // itemID, cycles
|
||||
|
||||
init {
|
||||
rams.put(4864, 128.shr(20))
|
||||
rams.put(4865, 192.shr(20))
|
||||
rams.put(4866, 256.shr(20))
|
||||
rams.put(4867, 320.shr(20))
|
||||
rams.put(4868, 480.shr(20))
|
||||
rams.put(4869, 512.shr(20))
|
||||
// two more?
|
||||
|
||||
processors.put(4872, 1000)
|
||||
processors.put(4873, 2000)
|
||||
processors.put(4874, 4000)
|
||||
processors.put(4875, 8000)
|
||||
}
|
||||
|
||||
fun getRamSize(itemIndex: Int): Int = rams[itemIndex] ?: 0
|
||||
fun getProcessorCycles(itemIndex: Int): Int = processors[itemIndex] ?: 0
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package net.torvald.terrarum.virtualcomputers.worldobject
|
||||
|
||||
import net.torvald.terrarum.gameactors.FixturesBase
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-08.
|
||||
*/
|
||||
abstract class FixturesComputerBase() : FixturesBase() {
|
||||
|
||||
init {
|
||||
actorValue["memslot0"] = -1 // -1 indicates mem slot is empty
|
||||
actorValue["memslot1"] = -1 // put index of item here
|
||||
actorValue["memslot2"] = -1 // ditto.
|
||||
actorValue["memslot3"] = -1 // do.
|
||||
|
||||
actorValue["processor"] = -1 // do.
|
||||
|
||||
actorValue["sda0"] = "none" // 'UUID rendered as String' or "none"
|
||||
actorValue["sda1"] = "none"
|
||||
actorValue["sda2"] = "none"
|
||||
actorValue["sda3"] = "none"
|
||||
actorValue["fd1"] = "none"
|
||||
actorValue["fd2"] = "none"
|
||||
actorValue["fd3"] = "none"
|
||||
actorValue["fd4"] = "none"
|
||||
|
||||
actorValue["uuid"] = UUID.randomUUID().toString()
|
||||
|
||||
collisionFlag = COLLISION_PLATFORM
|
||||
}
|
||||
|
||||
val processorCycle: Int // number of Lua statement to process per tick (1/100 s)
|
||||
get() = ComputerPartsCodex.getProcessorCycles(actorValue.getAsInt("processor") ?: -1)
|
||||
val memSize: Int // max: 8 GB
|
||||
get() {
|
||||
var size = 0
|
||||
for (i in 0..3)
|
||||
size += ComputerPartsCodex.getRamSize(actorValue.getAsInt("memSlot$i") ?: -1)
|
||||
|
||||
return size
|
||||
}
|
||||
|
||||
var terminal: FixturesBase? = null
|
||||
|
||||
|
||||
// API-specific
|
||||
|
||||
|
||||
}
|
||||