shaders moved to subdir; console click on the actor to type its id in

This commit is contained in:
minjaesong
2021-12-04 16:16:01 +09:00
parent 63487a1386
commit c0b2f4c8df
62 changed files with 352 additions and 25 deletions

View File

@@ -0,0 +1,148 @@
package net.torvald.terrarum.modulecomputers.gameactors
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.utils.Disposable
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.modulebasegame.gameactors.*
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import net.torvald.tsvm.*
import net.torvald.tsvm.peripheral.*
/**
* Created by minjaesong on 2021-12-04.
*/
class FixtureHomeComputer : FixtureBase {
private val vm = VM(0x200000, TheRealWorld(), arrayOf(
VMProgramRom(ModMgr.getPath("dwarventech", "bios/tsvmbios.rom"))
))
private val vmRunner: VMRunner
private val coroutineJob: Job
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 1, 1),
mainUI = UIHomeComputer(),
inventory = FixtureInventory(40, FixtureInventory.CAPACITY_MODE_COUNT),
nameFun = { "Computer" }
) {
density = 1400.0
setHitboxDimension(TerrarumAppConfiguration.TILE_SIZE, TerrarumAppConfiguration.TILE_SIZE, 0, -1)
makeNewSprite(TextureRegionPack(CommonResourcePool.getAsTextureRegion("dwarventech-sprites-fixtures-desktop_computer.tga").texture, TerrarumAppConfiguration.TILE_SIZE, TerrarumAppConfiguration.TILE_SIZE))
sprite!!.setRowsAndFrames(1, 1)
actorValue[AVKey.BASEMASS] = 20.0
val gpu = ReferenceGraphicsAdapter(ModMgr.getPath("dwarventech", "gui"), vm)
// vm.getIO().blockTransferPorts[0].attachDevice(TestDiskDrive(vm, 0, ...))
vm.peripheralTable[1] = PeripheralEntry(
gpu,
GraphicsAdapter.VRAM_SIZE,
16,
0
)
vm.getPrintStream = { gpu.getPrintStream() }
vm.getErrorStream = { gpu.getErrorStream() }
vm.getInputStream = { gpu.getInputStream() }
(mainUI as UIHomeComputer).vm = vm
vmRunner = VMRunnerFactory(ModMgr.getPath("dwarventech", "bios"), vm, "js")
coroutineJob = GlobalScope.launch {
vmRunner.executeCommand(vm.roms[0]!!.readAll())
}
App.disposables.add(Disposable {
vmRunner.close()
coroutineJob.cancel("fixture disposal")
vm.dispose()
})
}
override fun reload() {
super.reload()
(mainUI as UIHomeComputer).vm = vm
}
}
internal class UIHomeComputer : UICanvas(
toggleKeyLiteral = Input.Keys.ESCAPE, // FIXME why do I have specify ESC for it to function? ESC should be work as the default key
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
) {
override var width = 640
override var height = 480
override var openCloseTime = 0f
private val drawOffX = (width - 560).div(2).toFloat()
private val drawOffY = (height - 448).div(2).toFloat()
private lateinit var batch: SpriteBatch
private lateinit var camera: OrthographicCamera
internal lateinit var vm: VM
init {
batch = SpriteBatch()
camera = OrthographicCamera(width.toFloat(), height.toFloat())
camera.setToOrtho(false)
camera.update()
batch.projectionMatrix = camera.combined
}
override fun updateUI(delta: Float) {
}
override fun renderUI(otherBatch: SpriteBatch, camera: Camera) {
otherBatch.end()
setCameraPosition(0f, 0f)
(vm.peripheralTable[1].peripheral as? GraphicsAdapter)?.let { gpu ->
val clearCol = gpu.getBackgroundColour()
Gdx.gl.glClearColor(clearCol.r, clearCol.g, clearCol.b, clearCol.a)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
gpu.render(Gdx.graphics.deltaTime, batch, posX + drawOffX, posY + drawOffY)
}
otherBatch.begin()
otherBatch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(otherBatch, posX - 1, posY - 1, width + 2, height + 2)
}
private fun setCameraPosition(newX: Float, newY: Float) {
camera.position.set((-newX + width / 2), (-newY + height / 2), 0f) // deliberate integer division
camera.update()
batch.projectionMatrix = camera.combined
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
}
}

View File

@@ -0,0 +1,51 @@
package net.torvald.terrarum.modulecomputers.gameitems
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.inInteractableRange
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulecomputers.gameactors.FixtureHomeComputer
/**
* Created by minjaesong on 2021-12-04.
*/
class ItemHomeComputer(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "Computer"
override var baseMass = 20.0
override var stackable = true
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegion("dwarventech-sprites-fixtures-desktop_computer.tga")
override var baseToolSize: Double? = baseMass
init {
CommonResourcePool.addToLoadingList("dwarventech-sprites-fixtures-desktop_computer.tga") {
// val t = TextureRegion(Texture(ModMgr.getGdxFile("dwarventech", "nonexisting_file!!!")))
val t = TextureRegion(Texture(ModMgr.getGdxFile("dwarventech", "sprites/fixtures/desktop_computer.tga")))
t.flip(false, true)
/*return*/t
}
CommonResourcePool.loadAll()
equipPosition = EquipPosition.HAND_GRIP
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = inInteractableRange(actor) {
val item = FixtureHomeComputer()
item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
// return true when placed, false when cannot be placed
}
}

View File

@@ -64,7 +64,7 @@ class ItemWearableWorldRadar(originalID: String) : GameItem(originalID) {
vm.getErrorStream = { System.err }
vm.getInputStream = { System.`in` }
vmRunner = VMRunnerFactory(vm, "js")
vmRunner = VMRunnerFactory(ModMgr.getPath("dwarventech", "bios"), vm, "js")
coroutineJob = GlobalScope.launch {
vmRunner.executeCommand(vm.roms[0]!!.readAll())
}