sorta working unsafesvecarray; and then issue #26 is fucking shit up

This commit is contained in:
minjaesong
2019-06-22 04:16:03 +09:00
parent b45caebda0
commit 64bbe6b53b
7 changed files with 283 additions and 78 deletions

View File

@@ -22,7 +22,7 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
private var layerPtr = unsafe.allocateMemory(width * height * BYTES_PER_BLOCK.toLong())
init {
unsafe.setMemory(layerPtr, width * height * BYTES_PER_BLOCK.toLong(), 0) // sometimes does not work?!
unsafe.setMemory(layerPtr, width * height * BYTES_PER_BLOCK.toLong(), 0) // does reliably fill the memory with zeroes
}
/**
@@ -89,12 +89,9 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
}
override fun next(): Byte {
val y = iteratorCount / width
val x = iteratorCount % width
// advance counter
iteratorCount += 1
return unsafe.getByte(layerPtr + 1)
return unsafe.getByte(layerPtr + iteratorCount)
}
}
}

View File

@@ -165,17 +165,13 @@ open class GameWorld : Disposable {
private fun coerceXY(x: Int, y: Int) = (x fmod width) to (y.coerceIn(0, height - 1))
fun getTileFromWall(x: Int, y: Int): Int {
val (x, y) = coerceXY(x, y)
if (y !in 0 until height) throw Error("Y coord out of world boundary: $y")
fun getTileFromWall(rawX: Int, rawY: Int): Int {
val (x, y) = coerceXY(rawX, rawY)
return layerWall.unsafeGetTile(x, y)
}
fun getTileFromTerrain(x: Int, y: Int): Int {
val (x, y) = coerceXY(x, y)
if (y !in 0 until height) throw Error("Y coord out of world boundary: $y")
fun getTileFromTerrain(rawX: Int, rawY: Int): Int {
val (x, y) = coerceXY(rawX, rawY)
return layerTerrain.unsafeGetTile(x, y)
}