KStarbound/src/main/kotlin/ru/dbotthepony/kstarbound/world/RigidTileView.kt
2022-09-16 15:29:39 +07:00

44 lines
1.4 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ru.dbotthepony.kstarbound.world
import ru.dbotthepony.kstarbound.util.NotNullTwoDimensionalArray
import ru.dbotthepony.kstarbound.util.TwoDimensionalArray
/**
* Предоставляет доступ к чанку и его соседям
*
* Данный вариант отличается от [TileView] тем, что данный класс *копирует* список тайлов из всех чанков, которые ему известны
* в единый массив.
*
* Полезно в ситуациях, когда необходимо максимально быстрое получение данных о тайлах.
*/
class RigidTileView(
view: TileView,
) : ITileChunk {
constructor(
pos: ChunkPos,
center: ITileChunk?,
right: ITileChunk?,
top: ITileChunk?,
topRight: ITileChunk?,
topLeft: ITileChunk?,
left: ITileChunk?,
bottom: ITileChunk?,
bottomLeft: ITileChunk?,
bottomRight: ITileChunk?,
) : this(TileView(pos, center, right, top, topRight, topLeft, left, bottom, bottomLeft, bottomRight))
override val pos: ChunkPos = view.pos
private val memory: NotNullTwoDimensionalArray<ITileState>
init {
memory = NotNullTwoDimensionalArray(CHUNK_SIZE * 3, CHUNK_SIZE * 3) { a, b -> view[a - CHUNK_SIZE, b - CHUNK_SIZE] }
}
override fun get(x: Int, y: Int): ITileState {
return memory[x + CHUNK_SIZE, y + CHUNK_SIZE]
}
}