code tidy up

This commit is contained in:
Adam 2022-03-12 01:37:35 +01:00
parent e32e2a0311
commit e3954c184a
2 changed files with 15 additions and 8 deletions

View file

@ -16,21 +16,21 @@ value class FactorioServerId(val id: String) {
enum class ChunkSize(
val zoomLevel: Int,
) : Comparable<ChunkSize> {
CHUNK_512(-1), // 512
CHUNK_256(0), // 256
CHUNK_128(1), // 128
CHUNK_064(2), // 64
CHUNK_032(3), // 32
CHUNK_512(-1),
CHUNK_256(0),
CHUNK_128(1),
CHUNK_064(2),
CHUNK_032(3),
;
val tilesPerChunk: Int = 2f.pow(8 - zoomLevel).roundToInt()
init {
require(tilesPerChunk > 0) { "chunkSize must be positive" }
require(tilesPerChunk > 0) { "tilesPerChunk $tilesPerChunk must be positive" }
// 1000 & 0111 = 0000 => pow^2
// 1001 & 1000 = 1000 => !pow^2
require(tilesPerChunk and (tilesPerChunk - 1) == 0) {
"tilesPerChunk must be a power-of-two number"
"tilesPerChunk $tilesPerChunk must be a power-of-two number"
}
}