mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
sorta working unsafesvecarray; and then issue #26 is fucking shit up
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user