mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
layer export: tested output seems legit but can't confirm
This commit is contained in:
@@ -24,7 +24,7 @@ import kotlin.system.measureNanoTime
|
||||
*/
|
||||
class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
val gameWorld = GameWorldExtension(1024, 256)
|
||||
val gameWorld = GameWorldExtension(1, 1024, 256)
|
||||
|
||||
init {
|
||||
// ghetto world for building
|
||||
|
||||
@@ -2,26 +2,25 @@ package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.serialise.WriteLayerData
|
||||
import net.torvald.terrarum.console.EchoError
|
||||
import net.torvald.terrarum.serialise.WriteLayerDataZip
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-07-18.
|
||||
*/
|
||||
object ExportLayerData : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size < 2) {
|
||||
printUsage()
|
||||
return
|
||||
try {
|
||||
val outfile = WriteLayerDataZip()
|
||||
Echo("Layer data exported to ${outfile!!.canonicalPath}")
|
||||
}
|
||||
catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
EchoError("Layer data export failed; see console for error traces.")
|
||||
}
|
||||
|
||||
val saveDirectoryName = args[1]
|
||||
|
||||
WriteLayerData(saveDirectoryName)
|
||||
|
||||
Echo("Layer data exported to $saveDirectoryName/${WriteLayerData.LAYERS_FILENAME}")
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: exportlayer savename")
|
||||
Echo("Usage: exportlayer")
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,8 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
|
||||
printdbg(this, 1)
|
||||
|
||||
val ingame = Ingame(Terrarum.batch)
|
||||
ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
|
||||
//ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
|
||||
ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(8192, 2048, 0x51621DL)
|
||||
ingame.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
|
||||
|
||||
printdbg(this, 2)
|
||||
|
||||
@@ -161,6 +161,7 @@ class DiskSkimmer(private val diskFile: File) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** Only use it when you're sure you won't reach EOF; unavailable cells in array will be filled with -1. */
|
||||
fun InputStream.read(size: Int): ByteArray {
|
||||
val ba = ByteArray(size)
|
||||
this.read(ba)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.torvald.terrarum.virtualcomputer.tvd.finder
|
||||
package net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.finder
|
||||
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.GridLayout
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.torvald.terrarum.virtualcomputer.tvd.finder
|
||||
package net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.finder
|
||||
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.*
|
||||
import java.awt.BorderLayout
|
||||
|
||||
@@ -63,7 +63,7 @@ internal object ReadLayerData {
|
||||
|
||||
// create world out of tiles data
|
||||
|
||||
val retWorld = inWorld ?: GameWorldExtension(worldWidth, worldHeight)
|
||||
val retWorld = inWorld ?: GameWorldExtension(1, worldWidth, worldHeight)
|
||||
|
||||
retWorld.layerTerrain.data = terrainLayerMSB
|
||||
retWorld.layerWall.data = wallLayerMSB
|
||||
|
||||
@@ -26,7 +26,11 @@ import java.util.zip.GZIPOutputStream
|
||||
// internal for everything: prevent malicious module from messing up the savedata
|
||||
internal object WriteLayerDataZip {
|
||||
|
||||
// FIXME UNTESTED !!
|
||||
// FIXME output seems legit, but I can't confirm right now !!
|
||||
|
||||
|
||||
// 2400x800 world sizes about 90 kB
|
||||
// 8192x2048 world sizes about 670 kB
|
||||
|
||||
val LAYERS_FILENAME = "world"
|
||||
|
||||
@@ -73,7 +77,7 @@ internal object WriteLayerDataZip {
|
||||
|
||||
fun wb(byteArray: ByteArray) { outputStream.write(byteArray) }
|
||||
fun wb(byte: Byte) { outputStream.write(byte.toInt()) }
|
||||
fun wb(byte: Int) { outputStream.write(byte) }
|
||||
//fun wb(byte: Int) { outputStream.write(byte) }
|
||||
fun wi32(int: Int) { wb(int.toLittle()) }
|
||||
fun wi48(long: Long) { wb(long.toLittle48()) }
|
||||
fun wi64(long: Long) { wb(long.toLittle()) }
|
||||
@@ -89,7 +93,7 @@ internal object WriteLayerDataZip {
|
||||
wb(MAGIC); wb(VERSION_NUMBER); wb(NUMBER_OF_LAYERS); wb(NUMBER_OF_PAYLOADS); wb(COMPRESSION_ALGORITHM)
|
||||
|
||||
// world width, height, and spawn point
|
||||
wb(world.width); wb(world.height)
|
||||
wi32(world.width); wi32(world.height)
|
||||
wi48(LandUtil.getBlockAddr(world, world.spawnX, world.spawnY))
|
||||
|
||||
// write payloads //
|
||||
@@ -101,7 +105,6 @@ internal object WriteLayerDataZip {
|
||||
deflater.write(world.terrainArray)
|
||||
deflater.write(world.layerTerrainLowBits.data)
|
||||
deflater.flush()
|
||||
deflater.finish()
|
||||
wb(PAYLOAD_FOOTER)
|
||||
|
||||
// WALL payload
|
||||
@@ -110,7 +113,6 @@ internal object WriteLayerDataZip {
|
||||
deflater.write(world.wallArray)
|
||||
deflater.write(world.layerWall.data)
|
||||
deflater.flush()
|
||||
deflater.finish()
|
||||
wb(PAYLOAD_FOOTER)
|
||||
|
||||
// WIRE payload
|
||||
@@ -118,7 +120,6 @@ internal object WriteLayerDataZip {
|
||||
wi48(world.width * world.height.toLong())
|
||||
deflater.write(world.wireArray)
|
||||
deflater.flush()
|
||||
deflater.finish()
|
||||
wb(PAYLOAD_FOOTER)
|
||||
|
||||
// TdMG payload
|
||||
@@ -131,7 +132,6 @@ internal object WriteLayerDataZip {
|
||||
}
|
||||
|
||||
deflater.flush()
|
||||
deflater.finish()
|
||||
wb(PAYLOAD_FOOTER)
|
||||
|
||||
// WdMG payload
|
||||
@@ -144,7 +144,6 @@ internal object WriteLayerDataZip {
|
||||
}
|
||||
|
||||
deflater.flush()
|
||||
deflater.finish()
|
||||
wb(PAYLOAD_FOOTER)
|
||||
|
||||
// write footer
|
||||
@@ -159,6 +158,7 @@ internal object WriteLayerDataZip {
|
||||
|
||||
// replace savemeta with tempfile
|
||||
try {
|
||||
deflater.finish()
|
||||
deflater.close()
|
||||
|
||||
outputStream.flush()
|
||||
|
||||
Reference in New Issue
Block a user