mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
80 fps with unsafe access
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
package net.torvald.terrarum.serialise
|
||||
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Only being used by the title screen and the demoworld. This object may get deleted at any update
|
||||
*
|
||||
@@ -14,8 +9,11 @@ import java.util.*
|
||||
@Deprecated("TEMD is deprecated format; use TEMz which does compression")
|
||||
internal object ReadLayerData {
|
||||
|
||||
init {
|
||||
throw Error("TEMD is old and removed format; use TEMz which does compression")
|
||||
}
|
||||
|
||||
internal operator fun invoke(inputStream: InputStream, inWorld: GameWorldExtension? = null): GameWorldExtension {
|
||||
/*internal operator fun invoke(inputStream: InputStream, inWorld: GameWorldExtension? = null): GameWorldExtension {
|
||||
val magicBytes = ByteArray(4)
|
||||
val layerSizeBytes = ByteArray(1)
|
||||
val layerCountBytes = ByteArray(1)
|
||||
@@ -109,7 +107,7 @@ internal object ReadLayerData {
|
||||
}
|
||||
|
||||
return i
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
fun Int.toLittle() = byteArrayOf(
|
||||
|
||||
@@ -3,9 +3,8 @@ package net.torvald.terrarum.serialise
|
||||
import com.badlogic.gdx.utils.compression.Lzma
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.gameworld.BlockAddress
|
||||
import net.torvald.terrarum.gameworld.BlockLayer
|
||||
import net.torvald.terrarum.gameworld.FluidType
|
||||
import net.torvald.terrarum.gameworld.MapLayer
|
||||
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.DiskSkimmer.Companion.read
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import java.io.*
|
||||
@@ -143,14 +142,7 @@ internal object ReadLayerDataLzma {
|
||||
|
||||
val inflatedFile = inflatedOS.toByteArray()
|
||||
|
||||
// deal with (MSB ++ LSB)
|
||||
if (t == "TERR" || t == "WALL") {
|
||||
payloadBytes["${t}_MSB"] = inflatedFile.sliceArray(0 until worldSize.toInt()) // FIXME deflated stream cannot be larger than 2 GB
|
||||
payloadBytes["${t}_LSB"] = inflatedFile.sliceArray(worldSize.toInt() until u.uncompressedSize.toInt()) // FIXME deflated stream cannot be larger than 2 GB
|
||||
}
|
||||
else {
|
||||
payloadBytes[t] = inflatedFile
|
||||
}
|
||||
payloadBytes[t] = inflatedFile
|
||||
}
|
||||
|
||||
val spawnPoint = LandUtil.resolveBlockAddr(width, spawnAddress)
|
||||
@@ -184,13 +176,10 @@ internal object ReadLayerDataLzma {
|
||||
|
||||
// TODO parse fluid(Types|Fills)
|
||||
|
||||
|
||||
|
||||
return ReadLayerDataZip.LayerData(
|
||||
MapLayer(width, height, payloadBytes["WALL_MSB"]!!),
|
||||
MapLayer(width, height, payloadBytes["TERR_MSB"]!!),
|
||||
MapLayer(width, height, payloadBytes["WIRE"]!!),
|
||||
PairedMapLayer(width, height, payloadBytes["WALL_LSB"]!!),
|
||||
PairedMapLayer(width, height, payloadBytes["TERR_LSB"]!!),
|
||||
BlockLayer(width, height, payloadBytes["WALL"]!!),
|
||||
BlockLayer(width, height, payloadBytes["TERR"]!!),
|
||||
|
||||
spawnPoint.first, spawnPoint.second,
|
||||
|
||||
|
||||
@@ -2,9 +2,8 @@ package net.torvald.terrarum.serialise
|
||||
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.gameworld.BlockAddress
|
||||
import net.torvald.terrarum.gameworld.BlockLayer
|
||||
import net.torvald.terrarum.gameworld.FluidType
|
||||
import net.torvald.terrarum.gameworld.MapLayer
|
||||
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.DiskSkimmer.Companion.read
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import java.io.File
|
||||
@@ -144,14 +143,7 @@ internal object ReadLayerDataZip {
|
||||
if (uncompLen.toLong() != u.uncompressedSize)
|
||||
throw InternalError("Payload $t DEFLATE size mismatch -- expected ${u.uncompressedSize}, got $uncompLen")
|
||||
|
||||
// deal with (MSB ++ LSB)
|
||||
if (t == "TERR" || t == "WALL") {
|
||||
payloadBytes["${t}_MSB"] = inflatedFile.sliceArray(0 until worldSize.toInt()) // FIXME deflated stream cannot be larger than 2 GB
|
||||
payloadBytes["${t}_LSB"] = inflatedFile.sliceArray(worldSize.toInt() until uncompLen) // FIXME deflated stream cannot be larger than 2 GB
|
||||
}
|
||||
else {
|
||||
payloadBytes[t] = inflatedFile
|
||||
}
|
||||
payloadBytes[t] = inflatedFile
|
||||
}
|
||||
|
||||
val spawnPoint = LandUtil.resolveBlockAddr(width, spawnAddress)
|
||||
@@ -187,11 +179,8 @@ internal object ReadLayerDataZip {
|
||||
|
||||
|
||||
return LayerData(
|
||||
MapLayer(width, height, payloadBytes["WALL_MSB"]!!),
|
||||
MapLayer(width, height, payloadBytes["TERR_MSB"]!!),
|
||||
MapLayer(width, height, payloadBytes["WIRE"]!!),
|
||||
PairedMapLayer(width, height, payloadBytes["WALL_LSB"]!!),
|
||||
PairedMapLayer(width, height, payloadBytes["TERR_LSB"]!!),
|
||||
BlockLayer(width, height, payloadBytes["WALL"]!!),
|
||||
BlockLayer(width, height, payloadBytes["TERR"]!!),
|
||||
|
||||
spawnPoint.first, spawnPoint.second,
|
||||
|
||||
@@ -203,16 +192,15 @@ internal object ReadLayerDataZip {
|
||||
* Immediately deployable, a part of the gameworld
|
||||
*/
|
||||
internal data class LayerData(
|
||||
val layerWall: MapLayer,
|
||||
val layerTerrain: MapLayer,
|
||||
val layerWire: MapLayer,
|
||||
val layerWallLowBits: PairedMapLayer,
|
||||
val layerTerrainLowBits: PairedMapLayer,
|
||||
val layerWall: BlockLayer,
|
||||
val layerTerrain: BlockLayer,
|
||||
//val layerThermal: MapLayerHalfFloat, // in Kelvins
|
||||
//val layerAirPressure: MapLayerHalfFloat, // (milibar - 1000)
|
||||
|
||||
val spawnX: Int,
|
||||
val spawnY: Int,
|
||||
|
||||
//val wirings: HashMap<BlockAddress, SortedArrayList<GameWorld.WiringNode>>,
|
||||
val wallDamages: HashMap<BlockAddress, Float>,
|
||||
val terrainDamages: HashMap<BlockAddress, Float>,
|
||||
val fluidTypes: HashMap<BlockAddress, FluidType>,
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
package net.torvald.terrarum.serialise
|
||||
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.console.EchoError
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.nio.charset.Charset
|
||||
import java.util.zip.GZIPOutputStream
|
||||
|
||||
/**
|
||||
* TODO this one does not use TerranVirtualDisk
|
||||
*
|
||||
* Created by minjaesong on 2016-03-18.
|
||||
*/
|
||||
// internal for everything: prevent malicious module from messing up the savedata
|
||||
@Deprecated("TEMD is deprecated format; use TEMz which does compression")
|
||||
@Deprecated("TEMD is old and removed format; use TEMz which does compression")
|
||||
internal object WriteLayerData {
|
||||
|
||||
init {
|
||||
throw Error("TEMD is old and removed format; use TEMz which does compression")
|
||||
}
|
||||
|
||||
val LAYERS_FILENAME = "worldinfo1"
|
||||
|
||||
val MAGIC = "TEMD".toByteArray(charset = Charset.forName("US-ASCII"))
|
||||
/*val MAGIC = "TEMD".toByteArray(charset = Charset.forName("US-ASCII"))
|
||||
|
||||
val BYTE_NULL: Byte = 0
|
||||
|
||||
@@ -83,7 +77,7 @@ internal object WriteLayerData {
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -101,15 +101,23 @@ internal object WriteLayerDataLzma {
|
||||
|
||||
wb(PAYLOAD_HEADER); wb("TERR".toByteArray())
|
||||
wi48(world.width * world.height * 3L / 2)
|
||||
Lzma.compress(ByteArrayInputStream(world.terrainArray), outputStream)
|
||||
Lzma.compress(ByteArrayInputStream(world.layerTerrainLowBits.data), outputStream)
|
||||
world.layerTerrain.bytesIterator().forEach {
|
||||
val tempByteArray = ByteArray(1)
|
||||
tempByteArray[0] = it
|
||||
val tempByteArrayStream = ByteArrayInputStream(tempByteArray)
|
||||
Lzma.compress(tempByteArrayStream, outputStream)
|
||||
}
|
||||
wb(PAYLOAD_FOOTER)
|
||||
|
||||
// WALL payload
|
||||
wb(PAYLOAD_HEADER); wb("WALL".toByteArray())
|
||||
wi48(world.width * world.height * 3L / 2)
|
||||
Lzma.compress(ByteArrayInputStream(world.wallArray), outputStream)
|
||||
Lzma.compress(ByteArrayInputStream(world.layerWallLowBits.data), outputStream)
|
||||
world.layerWall.bytesIterator().forEach {
|
||||
val tempByteArray = ByteArray(1)
|
||||
tempByteArray[0] = it
|
||||
val tempByteArrayStream = ByteArrayInputStream(tempByteArray)
|
||||
Lzma.compress(tempByteArrayStream, outputStream)
|
||||
}
|
||||
wb(PAYLOAD_FOOTER)
|
||||
|
||||
// WIRE payload
|
||||
|
||||
@@ -113,8 +113,7 @@ internal object WriteLayerDataZip {
|
||||
wb(PAYLOAD_HEADER); wb("TERR".toByteArray())
|
||||
wi48(world.width * world.height * 3L / 2)
|
||||
deflater = DeflaterOutputStream(outputStream, Deflater(Deflater.BEST_COMPRESSION, true), false)
|
||||
deflater.write(world.terrainArray)
|
||||
deflater.write(world.layerTerrainLowBits.data)
|
||||
world.layerTerrain.bytesIterator().forEach { deflater.write(it.toInt()) }
|
||||
deflater.flush(); deflater.finish()
|
||||
wb(PAYLOAD_FOOTER)
|
||||
|
||||
@@ -122,8 +121,7 @@ internal object WriteLayerDataZip {
|
||||
wb(PAYLOAD_HEADER); wb("WALL".toByteArray())
|
||||
wi48(world.width * world.height * 3L / 2)
|
||||
deflater = DeflaterOutputStream(outputStream, Deflater(Deflater.BEST_COMPRESSION, true), false)
|
||||
deflater.write(world.wallArray)
|
||||
deflater.write(world.layerWallLowBits.data)
|
||||
world.layerWall.bytesIterator().forEach { deflater.write(it.toInt()) }
|
||||
deflater.flush(); deflater.finish()
|
||||
wb(PAYLOAD_FOOTER)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user