diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt index 531f3cf0..ae7d8eca 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt @@ -14,6 +14,10 @@ import ru.dbotthepony.kstarbound.client.render.LayeredRenderer import ru.dbotthepony.kstarbound.client.render.TileLayerList import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition import ru.dbotthepony.kstarbound.world.* +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZEd +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZEf +import ru.dbotthepony.kstarbound.world.api.ITileChunk import ru.dbotthepony.kstarbound.world.entities.Entity import ru.dbotthepony.kvector.arrays.Matrix4fStack import ru.dbotthepony.kvector.arrays.Matrix4f @@ -301,7 +305,8 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk() { JsonToken.STRING -> { val name = `in`.nextString() //return RGBAColor.PRE_DEFINED_MAP[name] ?: throw IllegalArgumentException("Unknown pre defined RGBAColor name $name") - TODO() + TODO("Can't determine color from name yet") } else -> throw IllegalArgumentException("Expected array, object or number; got $type") diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/CellView.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/CellView.kt index 8dc92335..8b10fd45 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/CellView.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/CellView.kt @@ -1,5 +1,12 @@ package ru.dbotthepony.kstarbound.world +import ru.dbotthepony.kstarbound.world.api.BackgroundView +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_FF +import ru.dbotthepony.kstarbound.world.api.ForegroundView +import ru.dbotthepony.kstarbound.world.api.IChunk +import ru.dbotthepony.kstarbound.world.api.IChunkCell + /** * Предоставляет доступ к чанку и его соседям * diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt index 3c7f4efe..d01bd6ca 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt @@ -7,7 +7,17 @@ import ru.dbotthepony.kbox2d.dynamics.B2Fixture import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier import ru.dbotthepony.kstarbound.defs.tile.TileDefinition -import ru.dbotthepony.kstarbound.util.TwoDimensionalArray +import ru.dbotthepony.kstarbound.world.api.BackgroundView +import ru.dbotthepony.kstarbound.world.api.CHUNK_SHIFT +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_FF +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZEd +import ru.dbotthepony.kstarbound.world.api.ForegroundView +import ru.dbotthepony.kstarbound.world.api.IChunk +import ru.dbotthepony.kstarbound.world.api.IChunkCell +import ru.dbotthepony.kstarbound.world.api.ILiquidState +import ru.dbotthepony.kstarbound.world.api.ITileState +import ru.dbotthepony.kstarbound.world.api.TileColor import ru.dbotthepony.kstarbound.world.entities.Entity import ru.dbotthepony.kstarbound.world.phys.RectTileFlooderDepthFirst import ru.dbotthepony.kstarbound.world.phys.RectTileFlooderSizeFirst @@ -28,7 +38,8 @@ import kotlin.collections.HashSet * * Весь игровой мир будет измеряться в Starbound Unit'ах */ -abstract class Chunk, This : Chunk>(val world: WorldType, final override val pos: ChunkPos) : IChunk { +abstract class Chunk, This : Chunk>(val world: WorldType, final override val pos: ChunkPos) : + IChunk { var changeset = 0 private set var tileChangeset = 0 diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt index bdab88f9..6aa897e1 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt @@ -1,6 +1,8 @@ package ru.dbotthepony.kstarbound.world import ru.dbotthepony.kstarbound.math.roundByAbsoluteValue +import ru.dbotthepony.kstarbound.world.api.CHUNK_SHIFT +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_FF import ru.dbotthepony.kvector.api.IStruct2d import ru.dbotthepony.kvector.api.IStruct2i import ru.dbotthepony.kvector.vector.Vector2i diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Helpers.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Helpers.kt new file mode 100644 index 00000000..2ed25ebe --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Helpers.kt @@ -0,0 +1,64 @@ +package ru.dbotthepony.kstarbound.world + +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE +import ru.dbotthepony.kstarbound.world.api.IChunk +import ru.dbotthepony.kstarbound.world.api.IChunkCell +import ru.dbotthepony.kstarbound.world.api.ITileChunk +import ru.dbotthepony.kstarbound.world.api.ITileState +import ru.dbotthepony.kvector.vector.Vector2i + +fun IChunk.iterate(fromX: Int = 0, fromY: Int = 0, toX: Int = fromX + CHUNK_SIZE, toY: Int = fromY + CHUNK_SIZE): Iterator> { + return object : Iterator> { + private var x = fromX + private var y = fromY + + override fun hasNext(): Boolean { + return x < toX && y < toY + } + + override fun next(): Pair { + if (!hasNext()) + throw NoSuchElementException() + + val tile = getCell(x, y) + val pos = Vector2i(x, y) + + x++ + + if (x >= toX) { + y++ + x = 0 + } + + return pos to tile + } + } +} + +fun ITileChunk.iterate(fromX: Int = 0, fromY: Int = 0, toX: Int = fromX + CHUNK_SIZE, toY: Int = fromY + CHUNK_SIZE): Iterator> { + return object : Iterator> { + private var x = fromX + private var y = fromY + + override fun hasNext(): Boolean { + return x < toX && y < toY + } + + override fun next(): Pair { + if (!hasNext()) + throw NoSuchElementException() + + val tile = getTile(x, y) + val pos = Vector2i(x, y) + + x++ + + if (x >= toX) { + y++ + x = 0 + } + + return pos to tile + } + } +} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Tiles.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Tiles.kt deleted file mode 100644 index 03874f72..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Tiles.kt +++ /dev/null @@ -1,181 +0,0 @@ -package ru.dbotthepony.kstarbound.world - -import ru.dbotthepony.kstarbound.RegistryObject -import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition -import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier -import ru.dbotthepony.kstarbound.defs.tile.TileDefinition -import java.io.DataInputStream - -enum class TileColor { - DEFAULT, - RED, - BLUE, - GREEN, - YELLOW, - BROWN, - PURPLE, - BLACK, - WHITE; - - companion object { - private val values = values() - - fun of(index: Int): TileColor { - return values.getOrElse(index) { DEFAULT } - } - } -} - -interface ITileState { - var material: TileDefinition? - var modifier: MaterialModifier? - var color: TileColor - var hueShift: Float - var modifierHueShift: Float - - val isEmpty: Boolean - - fun setHueShift(value: Int) { - if (value < 0) { - hueShift = 0f - } else if (value >= 255) { - hueShift = 360f - } else { - hueShift = value / 255f * 360f - } - } - - fun setModHueShift(value: Int) { - if (value < 0) { - modifierHueShift = 0f - } else if (value >= 255) { - modifierHueShift = 360f - } else { - modifierHueShift = value / 255f * 360f - } - } - - fun read( - materialAccess: (Int) -> RegistryObject?, - modifierAccess: (Int) -> RegistryObject?, - stream: DataInputStream - ) { - material = materialAccess(stream.readUnsignedShort())?.value - setHueShift(stream.read()) - color = TileColor.of(stream.read()) - modifier = modifierAccess(stream.readUnsignedShort())?.value - setModHueShift(stream.read()) - } - - companion object : ITileState { - override var material: TileDefinition? - get() = null - set(value) { throw UnsupportedOperationException("Empty tile state") } - override var modifier: MaterialModifier? - get() = null - set(value) { throw UnsupportedOperationException("Empty tile state") } - override var color: TileColor - get() = TileColor.DEFAULT - set(value) { throw UnsupportedOperationException("Empty tile state") } - override var hueShift: Float - get() = 0f - set(value) { throw UnsupportedOperationException("Empty tile state") } - override var modifierHueShift: Float - get() = 0f - set(value) { throw UnsupportedOperationException("Empty tile state") } - override val isEmpty: Boolean - get() = true - } -} - -interface ILiquidState { - var def: LiquidDefinition? - var level: Float - var pressure: Float - var isInfinite: Boolean - - val isEmpty: Boolean - - fun read( - liquidAccess: (Int) -> RegistryObject?, - stream: DataInputStream - ) { - def = liquidAccess(stream.readUnsignedByte())?.value - level = stream.readFloat() - pressure = stream.readFloat() - isInfinite = stream.readBoolean() - } - - companion object : ILiquidState { - override var def: LiquidDefinition? - get() = null - set(value) { throw UnsupportedOperationException("Empty liquid state") } - override var level: Float - get() = 0f - set(value) { throw UnsupportedOperationException("Empty liquid state") } - override var pressure: Float - get() = 0f - set(value) { throw UnsupportedOperationException("Empty liquid state") } - override var isInfinite: Boolean - get() = false - set(value) { throw UnsupportedOperationException("Empty liquid state") } - override val isEmpty: Boolean - get() = true - } -} - -interface IChunkCell { - val foreground: ITileState - val background: ITileState - val liquid: ILiquidState - - var dungeonId: Int - var biome: Int - var envBiome: Int - var isIndestructible: Boolean - - val isEmpty: Boolean - - fun read( - materialAccess: (Int) -> RegistryObject?, - modifierAccess: (Int) -> RegistryObject?, - liquidAccess: (Int) -> RegistryObject?, - stream: DataInputStream - ) { - foreground.read(materialAccess, modifierAccess, stream) - background.read(materialAccess, modifierAccess, stream) - liquid.read(liquidAccess, stream) - - stream.skipBytes(1) // collisionMap - - dungeonId = stream.readUnsignedShort() - biome = stream.readUnsignedByte() - envBiome = stream.readUnsignedByte() - isIndestructible = stream.readBoolean() - - stream.skipBytes(1) // unknown - } - - companion object : IChunkCell { - override val foreground: ITileState - get() = ITileState.Companion - override val background: ITileState - get() = ITileState.Companion - override val liquid: ILiquidState - get() = ILiquidState.Companion - override var dungeonId: Int - get() = 0 - set(value) { throw UnsupportedOperationException("Empty chunk cell") } - override var biome: Int - get() = 0 - set(value) { throw UnsupportedOperationException("Empty chunk cell") } - override var envBiome: Int - get() = 0 - set(value) { throw UnsupportedOperationException("Empty chunk cell") } - override var isIndestructible: Boolean - get() = false - set(value) { throw UnsupportedOperationException("Empty chunk cell") } - override val isEmpty: Boolean - get() = true - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt index f55e392c..65023d30 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt @@ -13,6 +13,8 @@ import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact import ru.dbotthepony.kstarbound.METRES_IN_STARBOUND_UNIT import ru.dbotthepony.kstarbound.math.* import ru.dbotthepony.kstarbound.util.Timer +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE +import ru.dbotthepony.kstarbound.world.api.IChunkCell import ru.dbotthepony.kstarbound.world.entities.Entity import ru.dbotthepony.kvector.arrays.Double2DArray import ru.dbotthepony.kvector.arrays.Int2DArray diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/Constants.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/Constants.kt new file mode 100644 index 00000000..d3025bf5 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/Constants.kt @@ -0,0 +1,7 @@ +package ru.dbotthepony.kstarbound.world.api + +const val CHUNK_SHIFT = 5 +const val CHUNK_SIZE = 1 shl CHUNK_SHIFT // 32 +const val CHUNK_SIZE_FF = CHUNK_SIZE - 1 +const val CHUNK_SIZEf = CHUNK_SIZE.toFloat() +const val CHUNK_SIZEd = CHUNK_SIZE.toDouble() \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunks.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/IChunk.kt similarity index 51% rename from src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunks.kt rename to src/main/kotlin/ru/dbotthepony/kstarbound/world/api/IChunk.kt index 9939bbc3..4f4a7a0f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunks.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/IChunk.kt @@ -1,15 +1,9 @@ -package ru.dbotthepony.kstarbound.world +package ru.dbotthepony.kstarbound.world.api +import ru.dbotthepony.kstarbound.world.ChunkPos import ru.dbotthepony.kvector.api.IStruct2i import ru.dbotthepony.kvector.vector.Vector2i -const val CHUNK_SHIFT = 5 -const val CHUNK_SIZE = 1 shl CHUNK_SHIFT // 32 - -const val CHUNK_SIZE_FF = CHUNK_SIZE - 1 -const val CHUNK_SIZEf = CHUNK_SIZE.toFloat() -const val CHUNK_SIZEd = CHUNK_SIZE.toDouble() - interface IChunk { val pos: ChunkPos @@ -53,79 +47,4 @@ interface IChunk { * Для использования в рендерах и прочих вещах, которым нужно стабильное число на основе своей позиции */ fun randomDoubleFor(pos: Vector2i) = randomDoubleFor(pos.x, pos.y) -} - -// for getting tiles directly, avoiding manual layer specification -interface ITileChunk : IChunk { - // relative - fun getTile(x: Int, y: Int): ITileState - fun getTile(pos: IStruct2i) = getTile(pos.component1(), pos.component2()) -} - -class ForegroundView(private val parent: IChunk) : ITileChunk, IChunk by parent { - override fun getTile(x: Int, y: Int): ITileState { - return parent.getCell(x, y).foreground - } -} - -class BackgroundView(private val parent: IChunk) : ITileChunk, IChunk by parent { - override fun getTile(x: Int, y: Int): ITileState { - return parent.getCell(x, y).background - } -} - -fun IChunk.iterate(fromX: Int = 0, fromY: Int = 0, toX: Int = fromX + CHUNK_SIZE, toY: Int = fromY + CHUNK_SIZE): Iterator> { - return object : Iterator> { - private var x = fromX - private var y = fromY - - override fun hasNext(): Boolean { - return x < toX && y < toY - } - - override fun next(): Pair { - if (!hasNext()) - throw NoSuchElementException() - - val tile = getCell(x, y) - val pos = Vector2i(x, y) - - x++ - - if (x >= toX) { - y++ - x = 0 - } - - return pos to tile - } - } -} - -fun ITileChunk.iterate(fromX: Int = 0, fromY: Int = 0, toX: Int = fromX + CHUNK_SIZE, toY: Int = fromY + CHUNK_SIZE): Iterator> { - return object : Iterator> { - private var x = fromX - private var y = fromY - - override fun hasNext(): Boolean { - return x < toX && y < toY - } - - override fun next(): Pair { - if (!hasNext()) - throw NoSuchElementException() - - val tile = getTile(x, y) - val pos = Vector2i(x, y) - - x++ - - if (x >= toX) { - y++ - x = 0 - } - - return pos to tile - } - } -} +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/IChunkCell.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/IChunkCell.kt new file mode 100644 index 00000000..39345906 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/IChunkCell.kt @@ -0,0 +1,63 @@ +package ru.dbotthepony.kstarbound.world.api + +import ru.dbotthepony.kstarbound.RegistryObject +import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition +import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier +import ru.dbotthepony.kstarbound.defs.tile.TileDefinition +import java.io.DataInputStream + +interface IChunkCell { + val foreground: ITileState + val background: ITileState + val liquid: ILiquidState + + var dungeonId: Int + var biome: Int + var envBiome: Int + var isIndestructible: Boolean + + val isEmpty: Boolean + + fun read( + materialAccess: (Int) -> RegistryObject?, + modifierAccess: (Int) -> RegistryObject?, + liquidAccess: (Int) -> RegistryObject?, + stream: DataInputStream + ) { + foreground.read(materialAccess, modifierAccess, stream) + background.read(materialAccess, modifierAccess, stream) + liquid.read(liquidAccess, stream) + + stream.skipBytes(1) // collisionMap + + dungeonId = stream.readUnsignedShort() + biome = stream.readUnsignedByte() + envBiome = stream.readUnsignedByte() + isIndestructible = stream.readBoolean() + + stream.skipBytes(1) // unknown + } + + companion object : IChunkCell { + override val foreground: ITileState + get() = ITileState + override val background: ITileState + get() = ITileState + override val liquid: ILiquidState + get() = ILiquidState + override var dungeonId: Int + get() = 0 + set(value) { throw UnsupportedOperationException("Empty chunk cell") } + override var biome: Int + get() = 0 + set(value) { throw UnsupportedOperationException("Empty chunk cell") } + override var envBiome: Int + get() = 0 + set(value) { throw UnsupportedOperationException("Empty chunk cell") } + override var isIndestructible: Boolean + get() = false + set(value) { throw UnsupportedOperationException("Empty chunk cell") } + override val isEmpty: Boolean + get() = true + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ILiquidState.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ILiquidState.kt new file mode 100644 index 00000000..92ef99bc --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ILiquidState.kt @@ -0,0 +1,41 @@ +package ru.dbotthepony.kstarbound.world.api + +import ru.dbotthepony.kstarbound.RegistryObject +import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition +import java.io.DataInputStream + +interface ILiquidState { + var def: LiquidDefinition? + var level: Float + var pressure: Float + var isInfinite: Boolean + + val isEmpty: Boolean + + fun read( + liquidAccess: (Int) -> RegistryObject?, + stream: DataInputStream + ) { + def = liquidAccess(stream.readUnsignedByte())?.value + level = stream.readFloat() + pressure = stream.readFloat() + isInfinite = stream.readBoolean() + } + + companion object : ILiquidState { + override var def: LiquidDefinition? + get() = null + set(value) { throw UnsupportedOperationException("Empty liquid state") } + override var level: Float + get() = 0f + set(value) { throw UnsupportedOperationException("Empty liquid state") } + override var pressure: Float + get() = 0f + set(value) { throw UnsupportedOperationException("Empty liquid state") } + override var isInfinite: Boolean + get() = false + set(value) { throw UnsupportedOperationException("Empty liquid state") } + override val isEmpty: Boolean + get() = true + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ITileChunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ITileChunk.kt new file mode 100644 index 00000000..dad2a267 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ITileChunk.kt @@ -0,0 +1,22 @@ +package ru.dbotthepony.kstarbound.world.api + +import ru.dbotthepony.kvector.api.IStruct2i + +// for getting tiles directly, avoiding manual layer specification +interface ITileChunk : IChunk { + // relative + fun getTile(x: Int, y: Int): ITileState + fun getTile(pos: IStruct2i) = getTile(pos.component1(), pos.component2()) +} + +class ForegroundView(private val parent: IChunk) : ITileChunk, IChunk by parent { + override fun getTile(x: Int, y: Int): ITileState { + return parent.getCell(x, y).foreground + } +} + +class BackgroundView(private val parent: IChunk) : ITileChunk, IChunk by parent { + override fun getTile(x: Int, y: Int): ITileState { + return parent.getCell(x, y).background + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ITileState.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ITileState.kt new file mode 100644 index 00000000..d83a6048 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ITileState.kt @@ -0,0 +1,68 @@ +package ru.dbotthepony.kstarbound.world.api + +import ru.dbotthepony.kstarbound.RegistryObject +import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier +import ru.dbotthepony.kstarbound.defs.tile.TileDefinition +import java.io.DataInputStream + +interface ITileState { + var material: TileDefinition? + var modifier: MaterialModifier? + var color: TileColor + var hueShift: Float + var modifierHueShift: Float + + val isEmpty: Boolean + + fun setHueShift(value: Int) { + if (value < 0) { + hueShift = 0f + } else if (value >= 255) { + hueShift = 360f + } else { + hueShift = value / 255f * 360f + } + } + + fun setModHueShift(value: Int) { + if (value < 0) { + modifierHueShift = 0f + } else if (value >= 255) { + modifierHueShift = 360f + } else { + modifierHueShift = value / 255f * 360f + } + } + + fun read( + materialAccess: (Int) -> RegistryObject?, + modifierAccess: (Int) -> RegistryObject?, + stream: DataInputStream + ) { + material = materialAccess(stream.readUnsignedShort())?.value + setHueShift(stream.read()) + color = TileColor.of(stream.read()) + modifier = modifierAccess(stream.readUnsignedShort())?.value + setModHueShift(stream.read()) + } + + companion object : ITileState { + override var material: TileDefinition? + get() = null + set(value) { throw UnsupportedOperationException("Empty tile state") } + override var modifier: MaterialModifier? + get() = null + set(value) { throw UnsupportedOperationException("Empty tile state") } + override var color: TileColor + get() = TileColor.DEFAULT + set(value) { throw UnsupportedOperationException("Empty tile state") } + override var hueShift: Float + get() = 0f + set(value) { throw UnsupportedOperationException("Empty tile state") } + override var modifierHueShift: Float + get() = 0f + set(value) { throw UnsupportedOperationException("Empty tile state") } + override val isEmpty: Boolean + get() = true + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/TileColor.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/TileColor.kt new file mode 100644 index 00000000..1c57ff70 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/TileColor.kt @@ -0,0 +1,21 @@ +package ru.dbotthepony.kstarbound.world.api + +enum class TileColor { + DEFAULT, + RED, + BLUE, + GREEN, + YELLOW, + BROWN, + PURPLE, + BLACK, + WHITE; + + companion object { + private val values = values() + + fun of(index: Int): TileColor { + return values.getOrElse(index) { DEFAULT } + } + } +} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/phys/RectTileFlooderDepthFirst.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/phys/RectTileFlooderDepthFirst.kt index 7ebcf54c..29e62e59 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/phys/RectTileFlooderDepthFirst.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/phys/RectTileFlooderDepthFirst.kt @@ -1,8 +1,8 @@ package ru.dbotthepony.kstarbound.world.phys -import ru.dbotthepony.kstarbound.world.CHUNK_SHIFT -import ru.dbotthepony.kstarbound.world.CHUNK_SIZE_FF -import ru.dbotthepony.kstarbound.world.IChunkCell +import ru.dbotthepony.kstarbound.world.api.CHUNK_SHIFT +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_FF +import ru.dbotthepony.kstarbound.world.api.IChunkCell import ru.dbotthepony.kvector.arrays.Object2DArray import ru.dbotthepony.kvector.vector.Vector2i diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/phys/RectTileFlooderSizeFirst.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/phys/RectTileFlooderSizeFirst.kt index 82bd9590..db155b90 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/phys/RectTileFlooderSizeFirst.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/phys/RectTileFlooderSizeFirst.kt @@ -1,8 +1,8 @@ package ru.dbotthepony.kstarbound.world.phys -import ru.dbotthepony.kstarbound.world.CHUNK_SHIFT -import ru.dbotthepony.kstarbound.world.CHUNK_SIZE_FF -import ru.dbotthepony.kstarbound.world.IChunkCell +import ru.dbotthepony.kstarbound.world.api.CHUNK_SHIFT +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_FF +import ru.dbotthepony.kstarbound.world.api.IChunkCell import ru.dbotthepony.kvector.arrays.Object2DArray import ru.dbotthepony.kvector.vector.Vector2i diff --git a/src/test/kotlin/ru/dbotthepony/kstarbound/test/MathTests.kt b/src/test/kotlin/ru/dbotthepony/kstarbound/test/MathTests.kt index 9c0110a8..ff021b59 100644 --- a/src/test/kotlin/ru/dbotthepony/kstarbound/test/MathTests.kt +++ b/src/test/kotlin/ru/dbotthepony/kstarbound/test/MathTests.kt @@ -3,8 +3,8 @@ package ru.dbotthepony.kstarbound.test import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import ru.dbotthepony.kstarbound.math.* -import ru.dbotthepony.kstarbound.world.CHUNK_SIZE -import ru.dbotthepony.kstarbound.world.CHUNK_SIZE_FF +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE +import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_FF import ru.dbotthepony.kstarbound.world.ChunkPos object MathTests {