computer with term lib: somewhat works; new cobblestone texture

Former-commit-id: 8a1a21cc1ea874ec1c243cae7b1e920bdab3be4f
Former-commit-id: ee7aeb05896a36960050f0656764ccf477e5f90d
This commit is contained in:
Song Minjae
2016-09-14 20:28:43 +09:00
parent d8b70887a9
commit abf167d6b8
77 changed files with 1389 additions and 418 deletions

View File

@@ -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)
}

View File

@@ -0,0 +1,25 @@
package net.torvald.terrarum.virtualcomputer.worldobject
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.FixturesBase
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.*
/**
* Created by minjaesong on 16-09-08.
*/
class FixturesBasicTerminal(phosphor: Color) : FixturesBase() {
val vt: Terminal = SimpleTextTerminal(phosphor, 80, 25)
val ui = UITextTerminal(vt)
init {
collisionFlag = COLLISION_PLATFORM
actorValue[AVKey.UUID] = UUID.randomUUID().toString()
}
}

View File

@@ -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)
}
}
}

View File

@@ -0,0 +1,90 @@
package net.torvald.terrarum.virtualcomputer.worldobject.ui
import net.torvald.terrarum.ui.*
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import org.newdawn.slick.Image
import org.newdawn.slick.Input
/**
* Created by minjaesong on 16-09-08.
*/
class UITextTerminal(val terminal: Terminal) : UICanvas, KeyboardControlled, MouseControlled {
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun keyPressed(key: Int, c: Char) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun keyReleased(key: Int, c: Char) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override var width: Int = terminal.displayW// + some
override var height: Int = terminal.displayH// + frame
private var terminalDisplay = Image(terminal.displayW, terminal.displayH)
override fun mousePressed(button: Int, x: Int, y: Int) {
// monitor on/off, reset switch
}
override fun mouseReleased(button: Int, x: Int, y: Int) {
}
override fun mouseWheelMoved(change: Int) {
}
/**
* Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField
*/
override var handler: UIHandler? = null
/**
* In milliseconds
*
* Timer itself is implemented in the handler.
*/
override var openCloseTime: Int = OPENCLOSE_GENERIC
override fun update(gc: GameContainer, delta: Int) {
terminal.update(gc, delta)
}
override fun render(gc: GameContainer, g: Graphics) {
terminal.render(gc, terminalDisplay.graphics)
}
override fun processInput(input: Input) {
}
/**
* Do not modify handler!!.openCloseCounter here.
*/
override fun doOpening(gc: GameContainer, delta: Int) {
}
/**
* Do not modify handler!!.openCloseCounter here.
*/
override fun doClosing(gc: GameContainer, delta: Int) {
}
/**
* Do not modify handler!!.openCloseCounter here.
*/
override fun endOpening(gc: GameContainer, delta: Int) {
}
/**
* Do not modify handler!!.openCloseCounter here.
*/
override fun endClosing(gc: GameContainer, delta: Int) {
}
}