mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
map data format adds world generator version and fluids
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package net.torvald.terrarum.serialise
|
||||
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -123,6 +121,16 @@ fun Int.toLittle() = byteArrayOf(
|
||||
this.ushr(16).and(0xFF).toByte(),
|
||||
this.ushr(24).and(0xFF).toByte()
|
||||
)
|
||||
/** Converts int as 2-byte array, discarding the sign.*/
|
||||
fun Int.toULittleShort() = byteArrayOf(
|
||||
this.and(0xFF).toByte(),
|
||||
this.ushr(8).and(0xFF).toByte()
|
||||
)
|
||||
/** Converts int as 2-byte array, preserving the sign. In other words, it converts int to short. */
|
||||
fun Int.toLittleShort() = byteArrayOf(
|
||||
this.and(0xFF).toByte(),
|
||||
this.shr(8).and(0xFF).toByte()
|
||||
)
|
||||
fun Long.toLittle() = byteArrayOf(
|
||||
this.and(0xFF).toByte(),
|
||||
this.ushr(8).and(0xFF).toByte(),
|
||||
@@ -133,7 +141,8 @@ fun Long.toLittle() = byteArrayOf(
|
||||
this.ushr(48).and(0xFF).toByte(),
|
||||
this.ushr(56).and(0xFF).toByte()
|
||||
)
|
||||
fun Long.toLittle48() = byteArrayOf(
|
||||
/** Converts long as 6-byte array, discarding the sign. */
|
||||
fun Long.toULittle48() = byteArrayOf(
|
||||
this.and(0xFF).toByte(),
|
||||
this.ushr(8).and(0xFF).toByte(),
|
||||
this.ushr(16).and(0xFF).toByte(),
|
||||
@@ -150,6 +159,14 @@ fun ByteArray.toLittleInt() =
|
||||
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
|
||||
@@ -171,4 +188,6 @@ fun ByteArray.toLittleInt48() =
|
||||
fun ByteArray.toLittleFloat() = java.lang.Float.intBitsToFloat(this.toLittleInt())
|
||||
|
||||
fun Byte.toUlong() = java.lang.Byte.toUnsignedLong(this)
|
||||
fun Byte.toUint() = java.lang.Byte.toUnsignedInt(this)
|
||||
fun Byte.toUint() = java.lang.Byte.toUnsignedInt(this)
|
||||
|
||||
const val WORLD_GENERATOR_VERSION = 1
|
||||
|
||||
Reference in New Issue
Block a user