Move files around
This commit is contained in:
parent
808a938144
commit
f2bb0a9d2d
@ -14,6 +14,10 @@ import ru.dbotthepony.kstarbound.client.render.LayeredRenderer
|
|||||||
import ru.dbotthepony.kstarbound.client.render.TileLayerList
|
import ru.dbotthepony.kstarbound.client.render.TileLayerList
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition
|
import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition
|
||||||
import ru.dbotthepony.kstarbound.world.*
|
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.kstarbound.world.entities.Entity
|
||||||
import ru.dbotthepony.kvector.arrays.Matrix4fStack
|
import ru.dbotthepony.kvector.arrays.Matrix4fStack
|
||||||
import ru.dbotthepony.kvector.arrays.Matrix4f
|
import ru.dbotthepony.kvector.arrays.Matrix4f
|
||||||
@ -301,7 +305,8 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk<ClientWorld, Client
|
|||||||
program.localToWorldTransform =
|
program.localToWorldTransform =
|
||||||
Matrix4f.identity().translateWithMultiplication(
|
Matrix4f.identity().translateWithMultiplication(
|
||||||
Vector3f(x = renderOrigin.x * CHUNK_SIZEf,
|
Vector3f(x = renderOrigin.x * CHUNK_SIZEf,
|
||||||
y = renderOrigin.y * CHUNK_SIZEf))
|
y = renderOrigin.y * CHUNK_SIZEf
|
||||||
|
))
|
||||||
|
|
||||||
setOnce = true
|
setOnce = true
|
||||||
}
|
}
|
||||||
@ -337,7 +342,8 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk<ClientWorld, Client
|
|||||||
program.localToWorldTransform =
|
program.localToWorldTransform =
|
||||||
Matrix4f.identity().translateWithMultiplication(
|
Matrix4f.identity().translateWithMultiplication(
|
||||||
Vector3f(x = renderOrigin.x * CHUNK_SIZEf,
|
Vector3f(x = renderOrigin.x * CHUNK_SIZEf,
|
||||||
y = renderOrigin.y * CHUNK_SIZEf))
|
y = renderOrigin.y * CHUNK_SIZEf
|
||||||
|
))
|
||||||
|
|
||||||
setOnce = true
|
setOnce = true
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ import ru.dbotthepony.kstarbound.client.gl.shader.GLTileProgram
|
|||||||
import ru.dbotthepony.kstarbound.client.gl.vertex.GLAttributeList
|
import ru.dbotthepony.kstarbound.client.gl.vertex.GLAttributeList
|
||||||
import ru.dbotthepony.kstarbound.client.gl.vertex.*
|
import ru.dbotthepony.kstarbound.client.gl.vertex.*
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.*
|
import ru.dbotthepony.kstarbound.defs.tile.*
|
||||||
import ru.dbotthepony.kstarbound.world.ITileChunk
|
import ru.dbotthepony.kstarbound.world.api.ITileChunk
|
||||||
import ru.dbotthepony.kstarbound.world.ITileState
|
import ru.dbotthepony.kstarbound.world.api.ITileState
|
||||||
import ru.dbotthepony.kstarbound.world.TileColor
|
import ru.dbotthepony.kstarbound.world.api.TileColor
|
||||||
import ru.dbotthepony.kvector.vector.RGBAColor
|
import ru.dbotthepony.kvector.vector.RGBAColor
|
||||||
import ru.dbotthepony.kvector.vector.Vector2i
|
import ru.dbotthepony.kvector.vector.Vector2i
|
||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
|
@ -6,8 +6,8 @@ import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
|||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory
|
||||||
import ru.dbotthepony.kstarbound.util.WriteOnce
|
import ru.dbotthepony.kstarbound.util.WriteOnce
|
||||||
import ru.dbotthepony.kstarbound.world.ITileChunk
|
import ru.dbotthepony.kstarbound.world.api.ITileChunk
|
||||||
import ru.dbotthepony.kstarbound.world.ITileState
|
import ru.dbotthepony.kstarbound.world.api.ITileState
|
||||||
import ru.dbotthepony.kvector.vector.Vector2i
|
import ru.dbotthepony.kvector.vector.Vector2i
|
||||||
|
|
||||||
@JsonFactory
|
@JsonFactory
|
||||||
|
@ -87,7 +87,7 @@ object ColorTypeAdapter : TypeAdapter<RGBAColor>() {
|
|||||||
JsonToken.STRING -> {
|
JsonToken.STRING -> {
|
||||||
val name = `in`.nextString()
|
val name = `in`.nextString()
|
||||||
//return RGBAColor.PRE_DEFINED_MAP[name] ?: throw IllegalArgumentException("Unknown pre defined RGBAColor name $name")
|
//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")
|
else -> throw IllegalArgumentException("Expected array, object or number; got $type")
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
package ru.dbotthepony.kstarbound.world
|
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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Предоставляет доступ к чанку и его соседям
|
* Предоставляет доступ к чанку и его соседям
|
||||||
*
|
*
|
||||||
|
@ -7,7 +7,17 @@ import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
|||||||
import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition
|
import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier
|
import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
|
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.entities.Entity
|
||||||
import ru.dbotthepony.kstarbound.world.phys.RectTileFlooderDepthFirst
|
import ru.dbotthepony.kstarbound.world.phys.RectTileFlooderDepthFirst
|
||||||
import ru.dbotthepony.kstarbound.world.phys.RectTileFlooderSizeFirst
|
import ru.dbotthepony.kstarbound.world.phys.RectTileFlooderSizeFirst
|
||||||
@ -28,7 +38,8 @@ import kotlin.collections.HashSet
|
|||||||
*
|
*
|
||||||
* Весь игровой мир будет измеряться в Starbound Unit'ах
|
* Весь игровой мир будет измеряться в Starbound Unit'ах
|
||||||
*/
|
*/
|
||||||
abstract class Chunk<WorldType : World<WorldType, This>, This : Chunk<WorldType, This>>(val world: WorldType, final override val pos: ChunkPos) : IChunk {
|
abstract class Chunk<WorldType : World<WorldType, This>, This : Chunk<WorldType, This>>(val world: WorldType, final override val pos: ChunkPos) :
|
||||||
|
IChunk {
|
||||||
var changeset = 0
|
var changeset = 0
|
||||||
private set
|
private set
|
||||||
var tileChangeset = 0
|
var tileChangeset = 0
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package ru.dbotthepony.kstarbound.world
|
package ru.dbotthepony.kstarbound.world
|
||||||
|
|
||||||
import ru.dbotthepony.kstarbound.math.roundByAbsoluteValue
|
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.IStruct2d
|
||||||
import ru.dbotthepony.kvector.api.IStruct2i
|
import ru.dbotthepony.kvector.api.IStruct2i
|
||||||
import ru.dbotthepony.kvector.vector.Vector2i
|
import ru.dbotthepony.kvector.vector.Vector2i
|
||||||
|
64
src/main/kotlin/ru/dbotthepony/kstarbound/world/Helpers.kt
Normal file
64
src/main/kotlin/ru/dbotthepony/kstarbound/world/Helpers.kt
Normal file
@ -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<Pair<Vector2i, IChunkCell>> {
|
||||||
|
return object : Iterator<Pair<Vector2i, IChunkCell>> {
|
||||||
|
private var x = fromX
|
||||||
|
private var y = fromY
|
||||||
|
|
||||||
|
override fun hasNext(): Boolean {
|
||||||
|
return x < toX && y < toY
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun next(): Pair<Vector2i, IChunkCell> {
|
||||||
|
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<Pair<Vector2i, ITileState>> {
|
||||||
|
return object : Iterator<Pair<Vector2i, ITileState>> {
|
||||||
|
private var x = fromX
|
||||||
|
private var y = fromY
|
||||||
|
|
||||||
|
override fun hasNext(): Boolean {
|
||||||
|
return x < toX && y < toY
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun next(): Pair<Vector2i, ITileState> {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<TileDefinition>?,
|
|
||||||
modifierAccess: (Int) -> RegistryObject<MaterialModifier>?,
|
|
||||||
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<LiquidDefinition>?,
|
|
||||||
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<TileDefinition>?,
|
|
||||||
modifierAccess: (Int) -> RegistryObject<MaterialModifier>?,
|
|
||||||
liquidAccess: (Int) -> RegistryObject<LiquidDefinition>?,
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,6 +13,8 @@ import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact
|
|||||||
import ru.dbotthepony.kstarbound.METRES_IN_STARBOUND_UNIT
|
import ru.dbotthepony.kstarbound.METRES_IN_STARBOUND_UNIT
|
||||||
import ru.dbotthepony.kstarbound.math.*
|
import ru.dbotthepony.kstarbound.math.*
|
||||||
import ru.dbotthepony.kstarbound.util.Timer
|
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.kstarbound.world.entities.Entity
|
||||||
import ru.dbotthepony.kvector.arrays.Double2DArray
|
import ru.dbotthepony.kvector.arrays.Double2DArray
|
||||||
import ru.dbotthepony.kvector.arrays.Int2DArray
|
import ru.dbotthepony.kvector.arrays.Int2DArray
|
||||||
|
@ -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()
|
@ -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.api.IStruct2i
|
||||||
import ru.dbotthepony.kvector.vector.Vector2i
|
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 {
|
interface IChunk {
|
||||||
val pos: ChunkPos
|
val pos: ChunkPos
|
||||||
|
|
||||||
@ -53,79 +47,4 @@ interface IChunk {
|
|||||||
* Для использования в рендерах и прочих вещах, которым нужно стабильное число на основе своей позиции
|
* Для использования в рендерах и прочих вещах, которым нужно стабильное число на основе своей позиции
|
||||||
*/
|
*/
|
||||||
fun randomDoubleFor(pos: Vector2i) = randomDoubleFor(pos.x, pos.y)
|
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<Pair<Vector2i, IChunkCell>> {
|
|
||||||
return object : Iterator<Pair<Vector2i, IChunkCell>> {
|
|
||||||
private var x = fromX
|
|
||||||
private var y = fromY
|
|
||||||
|
|
||||||
override fun hasNext(): Boolean {
|
|
||||||
return x < toX && y < toY
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun next(): Pair<Vector2i, IChunkCell> {
|
|
||||||
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<Pair<Vector2i, ITileState>> {
|
|
||||||
return object : Iterator<Pair<Vector2i, ITileState>> {
|
|
||||||
private var x = fromX
|
|
||||||
private var y = fromY
|
|
||||||
|
|
||||||
override fun hasNext(): Boolean {
|
|
||||||
return x < toX && y < toY
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun next(): Pair<Vector2i, ITileState> {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<TileDefinition>?,
|
||||||
|
modifierAccess: (Int) -> RegistryObject<MaterialModifier>?,
|
||||||
|
liquidAccess: (Int) -> RegistryObject<LiquidDefinition>?,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
@ -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<LiquidDefinition>?,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -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<TileDefinition>?,
|
||||||
|
modifierAccess: (Int) -> RegistryObject<MaterialModifier>?,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
@ -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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
package ru.dbotthepony.kstarbound.world.phys
|
package ru.dbotthepony.kstarbound.world.phys
|
||||||
|
|
||||||
import ru.dbotthepony.kstarbound.world.CHUNK_SHIFT
|
import ru.dbotthepony.kstarbound.world.api.CHUNK_SHIFT
|
||||||
import ru.dbotthepony.kstarbound.world.CHUNK_SIZE_FF
|
import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_FF
|
||||||
import ru.dbotthepony.kstarbound.world.IChunkCell
|
import ru.dbotthepony.kstarbound.world.api.IChunkCell
|
||||||
import ru.dbotthepony.kvector.arrays.Object2DArray
|
import ru.dbotthepony.kvector.arrays.Object2DArray
|
||||||
import ru.dbotthepony.kvector.vector.Vector2i
|
import ru.dbotthepony.kvector.vector.Vector2i
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package ru.dbotthepony.kstarbound.world.phys
|
package ru.dbotthepony.kstarbound.world.phys
|
||||||
|
|
||||||
import ru.dbotthepony.kstarbound.world.CHUNK_SHIFT
|
import ru.dbotthepony.kstarbound.world.api.CHUNK_SHIFT
|
||||||
import ru.dbotthepony.kstarbound.world.CHUNK_SIZE_FF
|
import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_FF
|
||||||
import ru.dbotthepony.kstarbound.world.IChunkCell
|
import ru.dbotthepony.kstarbound.world.api.IChunkCell
|
||||||
import ru.dbotthepony.kvector.arrays.Object2DArray
|
import ru.dbotthepony.kvector.arrays.Object2DArray
|
||||||
import ru.dbotthepony.kvector.vector.Vector2i
|
import ru.dbotthepony.kvector.vector.Vector2i
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ package ru.dbotthepony.kstarbound.test
|
|||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import ru.dbotthepony.kstarbound.math.*
|
import ru.dbotthepony.kstarbound.math.*
|
||||||
import ru.dbotthepony.kstarbound.world.CHUNK_SIZE
|
import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE
|
||||||
import ru.dbotthepony.kstarbound.world.CHUNK_SIZE_FF
|
import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_FF
|
||||||
import ru.dbotthepony.kstarbound.world.ChunkPos
|
import ru.dbotthepony.kstarbound.world.ChunkPos
|
||||||
|
|
||||||
object MathTests {
|
object MathTests {
|
||||||
|
Loading…
Reference in New Issue
Block a user