diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt index 46f9de2a..9c7e5ba8 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt @@ -18,7 +18,7 @@ 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.api.ITileAccess import ru.dbotthepony.kstarbound.world.entities.Entity import ru.dbotthepony.kvector.arrays.Matrix4fStack import ru.dbotthepony.kvector.arrays.Matrix4f @@ -41,7 +41,7 @@ const val Z_LEVEL_LIQUID = 10000 class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk(world, pos), Closeable { val state: GLStateTracker get() = world.client.gl - private inner class TileLayerRenderer(private val view: ITileChunk, private val isBackground: Boolean) : AutoCloseable { + private inner class TileLayerRenderer(private val view: ITileAccess, private val isBackground: Boolean) : AutoCloseable { private val layers = TileLayerList() val bakedMeshes = LinkedList>() var isDirty = true @@ -153,8 +153,8 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk IChunkCell?>(CHUNK_SIZE * 3, CHUNK_SIZE * 3) as Object2DArray<(CellView) -> IChunkCell?> - - private fun put(half: (CellView) -> IChunk?, x: Int, y: Int) { - for (ix in 0 until CHUNK_SIZE) { - for (iy in 0 until CHUNK_SIZE) { - indices[x + ix, y + iy] = { half(it)?.getCell(ix, iy) } - } - } - } - - init { - put(CellView::bottomLeft, 0, 0) - put(CellView::bottom, CHUNK_SIZE, 0) - put(CellView::bottomRight, CHUNK_SIZE * 2, 0) - - put(CellView::left, 0, CHUNK_SIZE) - put(CellView::center, CHUNK_SIZE, CHUNK_SIZE) - put(CellView::right, CHUNK_SIZE * 2, CHUNK_SIZE) - - put(CellView::topLeft, 0, CHUNK_SIZE * 2) - put(CellView::top, CHUNK_SIZE, CHUNK_SIZE * 2) - put(CellView::topRight, CHUNK_SIZE * 2, CHUNK_SIZE * 2) - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt index e9803ab0..b0c18bf6 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt @@ -7,19 +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.world.api.BackgroundChunkView -import ru.dbotthepony.kstarbound.world.api.BackgroundLocalizedView import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_BITS 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.ForegroundChunkView -import ru.dbotthepony.kstarbound.world.api.ForegroundLocalizedView -import ru.dbotthepony.kstarbound.world.api.IChunk +import ru.dbotthepony.kstarbound.world.api.ICellAccess 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.OffsetCellAccess import ru.dbotthepony.kstarbound.world.api.TileColor +import ru.dbotthepony.kstarbound.world.api.TileView import ru.dbotthepony.kstarbound.world.entities.Entity import ru.dbotthepony.kstarbound.world.phys.RectTileFlooderDepthFirst import ru.dbotthepony.kstarbound.world.phys.RectTileFlooderSizeFirst @@ -40,7 +38,7 @@ 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, val pos: ChunkPos) : ICellAccess { var changeset = 0 private set var tileChangeset = 0 @@ -57,6 +55,35 @@ abstract class Chunk, This : Chunk() + private val collisionCacheView = Collections.unmodifiableCollection(collisionCache) + + private val body = world.physics.createBody(BodyDef( + position = pos.firstTile.toDoubleVector(), + userData = this + )) + + private val collisionChains = ArrayList() + protected open fun foregroundChanges() { changeset++ cellChangeset++ @@ -86,10 +113,6 @@ abstract class Chunk, This : Chunk, This : Chunk() - private val collisionCacheView = Collections.unmodifiableCollection(collisionCache) - inner class Cell(val x: Int, val y: Int) : IChunkCell { inner class Tile(private val foreground: Boolean) : ITileState { private fun change() { @@ -254,13 +262,6 @@ abstract class Chunk, This : Chunk() - fun bakeCollisions() { if (collisionChangeset == changeset) return @@ -320,7 +321,7 @@ abstract class Chunk, This : Chunk() diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Helpers.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Helpers.kt index 62ee1749..6d729610 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Helpers.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Helpers.kt @@ -1,13 +1,13 @@ 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.ICellAccess import ru.dbotthepony.kstarbound.world.api.IChunkCell import ru.dbotthepony.kstarbound.world.api.ITileAccess 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> { +fun ICellAccess.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 diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Raycasting.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Raycasting.kt index 86d794b8..86e939a2 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Raycasting.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Raycasting.kt @@ -14,7 +14,6 @@ import kotlin.math.cos import kotlin.math.roundToInt import kotlin.math.sin - const val EARTH_FREEFALL_ACCELERATION = 9.8312 / METRES_IN_STARBOUND_UNIT data class RayCastResult( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt index c0fc5be3..09acddd5 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt @@ -11,13 +11,12 @@ import ru.dbotthepony.kbox2d.dynamics.B2World import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact import ru.dbotthepony.kstarbound.math.* import ru.dbotthepony.kstarbound.util.Timer -import ru.dbotthepony.kstarbound.world.api.BackgroundAccessView import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_BITS import ru.dbotthepony.kstarbound.world.api.CHUNK_SIZE_MASK -import ru.dbotthepony.kstarbound.world.api.ForegroundAccessView import ru.dbotthepony.kstarbound.world.api.ICellAccess import ru.dbotthepony.kstarbound.world.api.IChunkCell +import ru.dbotthepony.kstarbound.world.api.TileView import ru.dbotthepony.kstarbound.world.entities.Entity import ru.dbotthepony.kvector.api.IStruct2d import ru.dbotthepony.kvector.api.IStruct2i @@ -128,8 +127,12 @@ abstract class World, ChunkType : Chunk, ChunkType : Chunk, ChunkType : Chunk, ChunkType : Chunk, ChunkType : Chunk, ChunkType : Chunk, ChunkType : Chunk, ChunkType : Chunk, ChunkType : Chunk