more world save and virtualdisk lib update

This commit is contained in:
minjaesong
2021-08-30 13:57:54 +09:00
parent 7ae862dd05
commit fb140ce2da
6 changed files with 61 additions and 84 deletions

View File

@@ -682,62 +682,3 @@ inline class FluidType(val value: Int) {
fun abs() = this.value.absoluteValue
}
/**
* @param b a BlockLayer
* @return Bytes in [b] which are GZip'd then Ascii85-encoded
*/
fun blockLayerToStr(b: BlockLayer): String {
val sb = StringBuilder()
val bo = ByteArray64GrowableOutputStream()
val zo = GZIPOutputStream(bo)
b.bytesIterator().forEachRemaining {
zo.write(it.toInt())
}
zo.flush(); zo.close()
val ba = bo.toByteArray64()
var bai = 0
val buf = IntArray(4) { Ascii85.PAD_BYTE }
ba.forEach {
if (bai > 0 && bai % 4 == 0) {
sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
buf.fill(Ascii85.PAD_BYTE)
}
buf[bai % 4] = it.toInt() and 255
bai += 1
}; sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
return sb.toString()
}
/**
* @param b a BlockLayer
* @return Bytes in [b] which are LZMA'd then Ascii85-encoded
*/
fun blockLayerToStr2(b: BlockLayer): String {
val sb = StringBuilder()
val bi = UnsafePtrInputStream(b.ptr)
val bo = ByteArray64GrowableOutputStream()
Lzma.compress(bi, bo); bo.flush(); bo.close()
val ba = bo.toByteArray64()
var bai = 0
val buf = IntArray(4) { Ascii85.PAD_BYTE }
ba.forEach {
if (bai > 0 && bai % 4 == 0) {
sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
buf.fill(Ascii85.PAD_BYTE)
}
buf[bai % 4] = it.toInt() and 255
bai += 1
}; sb.append(Ascii85.encode(buf[0], buf[1], buf[2], buf[3]))
return sb.toString()
}