From 1e1c5a83c14a37c159a7e8196c088e18c8123c79 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 4 Sep 2023 20:58:28 +0700 Subject: [PATCH] Chunk render offsets this thing is broken --- .../kotlin/ru/dbotthepony/kstarbound/Main.kt | 2 +- .../kstarbound/client/ClientChunk.kt | 19 ++---- .../kstarbound/client/ClientWorld.kt | 61 +++++++------------ .../dbotthepony/kstarbound/world/ChunkPos.kt | 2 +- .../ru/dbotthepony/kstarbound/world/World.kt | 51 +++++++++++----- 5 files changed, 65 insertions(+), 70 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt index 61e96011..10b96b3c 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt @@ -148,7 +148,7 @@ fun main() { //ent.position += Vector2d(y = 14.0, x = -10.0) ent.position = Vector2d(600.0 + 16.0, 721.0 + 48.0) - client.camera.pos = Vector2f(7f, 685f) + client.camera.pos = Vector2f(-2967f, 685f) client.onDrawGUI { client.gl.font.render("${ent.position}", y = 100f, scale = 0.25f) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt index 8fb79283..49068cab 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt @@ -15,6 +15,7 @@ import ru.dbotthepony.kstarbound.world.api.ITileAccess import ru.dbotthepony.kstarbound.world.entities.Entity import ru.dbotthepony.kvector.arrays.Matrix4fStack import ru.dbotthepony.kvector.vector.Vector2d +import ru.dbotthepony.kvector.vector.Vector2f import java.io.Closeable import java.util.LinkedList @@ -66,14 +67,6 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk 0) { - it.quad(pos.x.roundToInt() + column.toFloat() - lightsize, pos.y.roundToInt() + row.toFloat() - lightsize, pos.x.roundToInt() + column + 1f - lightsize, pos.y.roundToInt() + row + 1f - lightsize) + client.gl.quadWireframe { + for (column in 0 until lightmap.columns) { + for (row in 0 until lightmap.rows) { + if (lightmap[column, row] > 0) { + it.quad(pos.x.roundToInt() + column.toFloat() - lightsize, pos.y.roundToInt() + row.toFloat() - lightsize, pos.x.roundToInt() + column + 1f - lightsize, pos.y.roundToInt() + row + 1f - lightsize) + } } } } - }*/ + } /* val rayFan = ArrayList() diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt index a3fa2168..3dffc1e2 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt @@ -26,7 +26,7 @@ private fun circulate(value: Int, bounds: Int): Int { * * Вверх у нас положительный Y * * Вниз у нас отрицательный Y */ -class ChunkPos(val x: Int, val y: Int) : Comparable { +data class ChunkPos(val x: Int, val y: Int) : IStruct2i, Comparable { constructor(pos: IStruct2i) : this(pos.component1(), pos.component2()) // bottom left corner diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt index 7cb4e223..36e6102c 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt @@ -38,8 +38,9 @@ abstract class World, ChunkType : Chunk, ChunkType : Chunk, ChunkType : Chunk= 0) { + return (chunk / this.chunk) * misalignedTiles2 + } else { + return ((chunk + 1) / this.chunk - 1) * misalignedTiles2 + } + } + override fun cell(value: Int): Int { return positiveModulo(value, cell) } @@ -95,10 +109,6 @@ abstract class World, ChunkType : Chunk, ChunkType : Chunk, ChunkType : Chunk, ChunkType : Chunk() @@ -414,12 +425,19 @@ abstract class World, ChunkType : Chunk { val output = ArrayList() - for (pos in boundingBox.chunkPositions) { - val chunk = chunkMap[pos] + if ( + chunkMap.x.cellOffset(boundingBox.mins.x) == chunkMap.x.cellOffset(boundingBox.maxs.x) && + chunkMap.y.cellOffset(boundingBox.mins.y) == chunkMap.y.cellOffset(boundingBox.maxs.y) + ) { + for (pos in boundingBox.chunkPositions) { + val chunk = chunkMap[pos] - if (chunk != null && (loopX || chunkMap.x.inBoundsChunk(pos.x)) && (loopY || chunkMap.y.inBoundsChunk(pos.y))) { - output.add(chunk) + if (chunk != null && (loopX || chunkMap.x.inBoundsChunk(pos.x)) && (loopY || chunkMap.y.inBoundsChunk(pos.y))) { + output.add(chunk) + } } + } else { + } return output @@ -492,7 +510,7 @@ abstract class World, ChunkType : Chunk, ChunkType : Chunk 1) {