things are not quite working yet but here's more descriptive error message for ya

This commit is contained in:
minjaesong
2021-08-25 20:55:21 +09:00
parent 9a8bd8d6ec
commit 29c5599746
7 changed files with 39 additions and 62 deletions

View File

@@ -35,37 +35,6 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
data.forEachIndexed { index, byte -> UnsafeHelper.unsafe.putByte(ptr.ptr + index, byte) }
}
/**
* Returns an iterator over blocks of type `Int`.
*
* @return an Iterator.
*/
fun blocksIterator(): Iterator<Int> {
return object : Iterator<Int> {
private var iteratorCount = 0
override fun hasNext(): Boolean {
return iteratorCount < width * height
}
override fun next(): Int {
val y = iteratorCount / width
val x = iteratorCount % width
// advance counter
iteratorCount += 1
val offset = BYTES_PER_BLOCK * (y * width + x)
val lsb = ptr[offset]
val msb = ptr[offset + 1]
return lsb.toUint() + msb.toUint().shl(8)
}
}
}
/**
* Returns an iterator over stored bytes.
*
@@ -73,17 +42,13 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
*/
fun bytesIterator(): Iterator<Byte> {
return object : Iterator<Byte> {
private var iteratorCount = 0L
override fun hasNext(): Boolean {
return iteratorCount < width * height
return iteratorCount < width * height * BYTES_PER_BLOCK
}
override fun next(): Byte {
iteratorCount += 1
return ptr[iteratorCount]
return ptr[iteratorCount - 1]
}
}
}

View File

@@ -222,8 +222,8 @@ class GameWorld : Disposable {
return tileNumberToNameMap[layerWall.unsafeGetTile(x, y)]!!
}
catch (e: NullPointerException) {
System.err.println("NPE for wall ${layerWall.unsafeGetTile(x, y)} in ($x, $y)")
throw e
val msg = "No tile name mapping for wall ${layerWall.unsafeGetTile(x, y)} in ($x, $y)"
throw NoSuchElementException(msg)
}
}
@@ -237,8 +237,8 @@ class GameWorld : Disposable {
return tileNumberToNameMap[layerTerrain.unsafeGetTile(x, y)]!!
}
catch (e: NullPointerException) {
System.err.println("NPE for terrain ${layerTerrain.unsafeGetTile(x, y)} in ($x, $y)")
throw e
val msg = "No tile name mapping for terrain ${layerTerrain.unsafeGetTile(x, y)} in ($x, $y)"
throw NoSuchElementException(msg)
}
}