material and 5 temporary vectors no longer go into the savegame

This commit is contained in:
minjaesong
2023-05-21 11:20:45 +09:00
parent b0d83325a7
commit 6268b99c1c
53 changed files with 777 additions and 5682 deletions

View File

@@ -38,39 +38,67 @@ fun Long.toULittle48() = byteArrayOf(
fun Double.toLittle() = java.lang.Double.doubleToRawLongBits(this).toLittle()
fun Boolean.toLittle() = byteArrayOf(if (this) 0xFF.toByte() else 0.toByte())
fun ByteArray.toLittleInt() =
if (this.size != 4) throw Error("Array not in size of 4")
else this[0].toUint() or
this[1].toUint().shl(8) or
this[2].toUint().shl(16) or
this[3].toUint().shl(24)
fun ByteArray.toULittleShort() =
if (this.size != 4) throw Error("Array not in size of 2")
else this[0].toUint() or
this[1].toUint().shl(8)
fun ByteArray.toLittleShort() =
if (this.size != 4) throw Error("Array not in size of 2")
else this[0].toUint() or
this[1].toInt().shl(8)
fun ByteArray.toLittleLong() =
if (this.size != 8) throw Error("Array not in size of 8")
else this[0].toUlong() or
this[1].toUlong().shl(8) or
this[2].toUlong().shl(16) or
this[3].toUlong().shl(24) or
this[4].toUlong().shl(32) or
this[5].toUlong().shl(40) or
this[6].toUlong().shl(48) or
this[7].toUlong().shl(56)
fun ByteArray.toLittleInt48() =
if (this.size != 6) throw Error("Array not in size of 6")
else this[0].toUlong() or
this[1].toUlong().shl(8) or
this[2].toUlong().shl(16) or
this[3].toUlong().shl(24) or
this[4].toUlong().shl(32) or
this[5].toUlong().shl(40)
fun ByteArray.toLittleFloat() = java.lang.Float.intBitsToFloat(this.toLittleInt())
fun ByteArray.toLittleInt32(offset: Int = 0) =
this[0 + offset].toUint() or
this[1 + offset].toUint().shl(8) or
this[2 + offset].toUint().shl(16) or
this[3 + offset].toUint().shl(24)
fun ByteArray.toULittleShort(offset: Int = 0) =
this[0 + offset].toUint() or
this[1 + offset].toUint().shl(8)
fun ByteArray.toLittleShort(offset: Int = 0) =
this[0 + offset].toUint() or
this[1 + offset].toInt().shl(8)
fun ByteArray.toLittleInt64(offset: Int = 0) =
this[0 + offset].toUlong() or
this[1 + offset].toUlong().shl(8) or
this[2 + offset].toUlong().shl(16) or
this[3 + offset].toUlong().shl(24) or
this[4 + offset].toUlong().shl(32) or
this[5 + offset].toUlong().shl(40) or
this[6 + offset].toUlong().shl(48) or
this[7 + offset].toUlong().shl(56)
fun ByteArray.toLittleInt48(offset: Int = 0) =
this[0 + offset].toUlong() or
this[1 + offset].toUlong().shl(8) or
this[2 + offset].toUlong().shl(16) or
this[3 + offset].toUlong().shl(24) or
this[4 + offset].toUlong().shl(32) or
this[5 + offset].toUlong().shl(40)
fun ByteArray.toLittleFloat() = java.lang.Float.intBitsToFloat(this.toLittleInt32())
fun ByteArray.toBigInt16(offset: Int = 0): Int {
return this[0 + offset].toUint().shl(8) or
this[1 + offset].toUint()
}
fun ByteArray.toBigInt24(offset: Int = 0): Int {
return this[0 + offset].toUint().shl(16) or
this[1 + offset].toUint().shl(8) or
this[2 + offset].toUint()
}
fun ByteArray.toBigInt32(offset: Int = 0): Int {
return this[0 + offset].toUint().shl(24) or
this[1 + offset].toUint().shl(16) or
this[2 + offset].toUint().shl(8) or
this[3 + offset].toUint()
}
fun ByteArray.toBigInt48(offset: Int = 0): Long {
return this[0 + offset].toUlong().shl(40) or
this[1 + offset].toUlong().shl(32) or
this[2 + offset].toUlong().shl(24) or
this[3 + offset].toUlong().shl(16) or
this[4 + offset].toUlong().shl(8) or
this[5 + offset].toUlong()
}
fun ByteArray.toBigInt64(offset: Int = 0): Long {
return this[0 + offset].toUlong().shl(56) or
this[1 + offset].toUlong().shl(48) or
this[2 + offset].toUlong().shl(40) or
this[3 + offset].toUlong().shl(32) or
this[4 + offset].toUlong().shl(24) or
this[5 + offset].toUlong().shl(16) or
this[6 + offset].toUlong().shl(8) or
this[7 + offset].toUlong()
}
fun Byte.toUlong() = java.lang.Byte.toUnsignedLong(this)
fun Byte.toUint() = java.lang.Byte.toUnsignedInt(this)