tiling optimisation 2.2ms -> 1.7ms

This commit is contained in:
minjaesong
2023-10-10 18:16:35 +09:00
parent 26936fde09
commit 3b32242a2b
16 changed files with 177 additions and 56 deletions

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.gameworld
import com.badlogic.gdx.utils.Disposable
import net.torvald.terrarum.App
import net.torvald.terrarum.serialise.toUint
import net.torvald.unsafe.UnsafeHelper
@@ -55,7 +54,16 @@ class BlockLayerI16I8 (val width: Int, val height: Int) : BlockLayer {
}
}
internal fun unsafeGetTile(x: Int, y: Int): Pair<Int, Int> {
override fun unsafeGetTile(x: Int, y: Int): Int {
val offset = BYTES_PER_BLOCK * (y * width + x)
val lsb = ptr[offset]
val msb = ptr[offset + 1]
val placement = ptr[offset + 2]
return lsb.toUint() + msb.toUint().shl(8)
}
internal fun unsafeGetTile1(x: Int, y: Int): Pair<Int, Int> {
val offset = BYTES_PER_BLOCK * (y * width + x)
val lsb = ptr[offset]
val msb = ptr[offset + 1]
@@ -94,6 +102,16 @@ class BlockLayerI16I8 (val width: Int, val height: Int) : BlockLayer {
ptr[offset + 2] = bytes[2]
}
internal fun unsafeSetTileKeepPlacement(x: Int, y: Int, tile: Int) {
val offset = BYTES_PER_BLOCK * (y * width + x)
val lsb = tile.and(0xff).toByte()
val msb = tile.ushr(8).and(0xff).toByte()
ptr[offset] = lsb
ptr[offset + 1] = msb
}
/**
* @param blockOffset Offset in blocks. BlockOffset of 0x100 is equal to ```layerPtr + 0x200```
*/