mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 10:04:05 +09:00
layer write should write proper zlib
This commit is contained in:
@@ -63,6 +63,9 @@ internal object ReadLayerDataZip {
|
|||||||
|
|
||||||
val payloads = HashMap<String, TEMzPayload>()
|
val payloads = HashMap<String, TEMzPayload>()
|
||||||
|
|
||||||
|
|
||||||
|
// TODO please test the read; write has been fixed up
|
||||||
|
|
||||||
for (pldCnt in 0 until payloadCount) {
|
for (pldCnt in 0 until payloadCount) {
|
||||||
inputStream.read(pldBuffer4)
|
inputStream.read(pldBuffer4)
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ internal object WriteLayerDataZip {
|
|||||||
outFile.createNewFile()
|
outFile.createNewFile()
|
||||||
|
|
||||||
val outputStream = BufferedOutputStream(FileOutputStream(outFile), 8192)
|
val outputStream = BufferedOutputStream(FileOutputStream(outFile), 8192)
|
||||||
val deflater = DeflaterOutputStream(outputStream, true)
|
var deflater: DeflaterOutputStream // couldn't really use one outputstream for all the files.
|
||||||
|
|
||||||
fun wb(byteArray: ByteArray) { outputStream.write(byteArray) }
|
fun wb(byteArray: ByteArray) { outputStream.write(byteArray) }
|
||||||
fun wb(byte: Byte) { outputStream.write(byte.toInt()) }
|
fun wb(byte: Byte) { outputStream.write(byte.toInt()) }
|
||||||
@@ -105,48 +105,55 @@ internal object WriteLayerDataZip {
|
|||||||
|
|
||||||
wb(PAYLOAD_HEADER); wb("TERR".toByteArray())
|
wb(PAYLOAD_HEADER); wb("TERR".toByteArray())
|
||||||
wi48(world.width * world.height * 3L / 2)
|
wi48(world.width * world.height * 3L / 2)
|
||||||
|
deflater = DeflaterOutputStream(outputStream, true)
|
||||||
deflater.write(world.terrainArray)
|
deflater.write(world.terrainArray)
|
||||||
deflater.write(world.layerTerrainLowBits.data)
|
deflater.write(world.layerTerrainLowBits.data)
|
||||||
deflater.flush()
|
deflater.finish()
|
||||||
wb(PAYLOAD_FOOTER)
|
wb(PAYLOAD_FOOTER)
|
||||||
|
|
||||||
// WALL payload
|
// WALL payload
|
||||||
wb(PAYLOAD_HEADER); wb("WALL".toByteArray())
|
wb(PAYLOAD_HEADER); wb("WALL".toByteArray())
|
||||||
wi48(world.width * world.height * 3L / 2)
|
wi48(world.width * world.height * 3L / 2)
|
||||||
|
deflater = DeflaterOutputStream(outputStream, true)
|
||||||
deflater.write(world.wallArray)
|
deflater.write(world.wallArray)
|
||||||
deflater.write(world.layerWall.data)
|
deflater.write(world.layerWallLowBits.data)
|
||||||
deflater.flush()
|
deflater.finish()
|
||||||
wb(PAYLOAD_FOOTER)
|
wb(PAYLOAD_FOOTER)
|
||||||
|
|
||||||
// WIRE payload
|
// WIRE payload
|
||||||
wb(PAYLOAD_HEADER); wb("WIRE".toByteArray())
|
wb(PAYLOAD_HEADER); wb("WIRE".toByteArray())
|
||||||
wi48(world.width * world.height.toLong())
|
wi48(world.width * world.height.toLong())
|
||||||
|
deflater = DeflaterOutputStream(outputStream, true)
|
||||||
deflater.write(world.wireArray)
|
deflater.write(world.wireArray)
|
||||||
deflater.flush()
|
deflater.finish()
|
||||||
wb(PAYLOAD_FOOTER)
|
wb(PAYLOAD_FOOTER)
|
||||||
|
|
||||||
// TdMG payload
|
// TdMG payload
|
||||||
wb(PAYLOAD_HEADER); wb("TdMG".toByteArray())
|
wb(PAYLOAD_HEADER); wb("TdMG".toByteArray())
|
||||||
wi48(world.terrainDamages.size.toLong())
|
wi48(world.terrainDamages.size.toLong())
|
||||||
|
|
||||||
|
deflater = DeflaterOutputStream(outputStream, true)
|
||||||
|
|
||||||
world.terrainDamages.forEach { t, u ->
|
world.terrainDamages.forEach { t, u ->
|
||||||
deflater.write(t.toLittle48())
|
deflater.write(t.toLittle48())
|
||||||
deflater.write(u.toRawBits().toLittle())
|
deflater.write(u.toRawBits().toLittle())
|
||||||
}
|
}
|
||||||
|
|
||||||
deflater.flush()
|
deflater.finish()
|
||||||
wb(PAYLOAD_FOOTER)
|
wb(PAYLOAD_FOOTER)
|
||||||
|
|
||||||
// WdMG payload
|
// WdMG payload
|
||||||
wb(PAYLOAD_HEADER); wb("WdMG".toByteArray())
|
wb(PAYLOAD_HEADER); wb("WdMG".toByteArray())
|
||||||
wi48(world.wallDamages.size.toLong())
|
wi48(world.wallDamages.size.toLong())
|
||||||
|
|
||||||
|
deflater = DeflaterOutputStream(outputStream, true)
|
||||||
|
|
||||||
world.wallDamages.forEach { t, u ->
|
world.wallDamages.forEach { t, u ->
|
||||||
deflater.write(t.toLittle48())
|
deflater.write(t.toLittle48())
|
||||||
deflater.write(u.toRawBits().toLittle())
|
deflater.write(u.toRawBits().toLittle())
|
||||||
}
|
}
|
||||||
|
|
||||||
deflater.flush()
|
deflater.finish()
|
||||||
wb(PAYLOAD_FOOTER)
|
wb(PAYLOAD_FOOTER)
|
||||||
|
|
||||||
// write footer
|
// write footer
|
||||||
@@ -161,9 +168,6 @@ internal object WriteLayerDataZip {
|
|||||||
|
|
||||||
// replace savemeta with tempfile
|
// replace savemeta with tempfile
|
||||||
try {
|
try {
|
||||||
deflater.finish()
|
|
||||||
deflater.close()
|
|
||||||
|
|
||||||
outputStream.flush()
|
outputStream.flush()
|
||||||
outputStream.close()
|
outputStream.close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user