diff --git a/src/main/kotlin/com/lambda/client/event/events/RenderRadarEvent.kt b/src/main/kotlin/com/lambda/client/event/events/RenderRadarEvent.kt index 2fb170275..1b8925024 100644 --- a/src/main/kotlin/com/lambda/client/event/events/RenderRadarEvent.kt +++ b/src/main/kotlin/com/lambda/client/event/events/RenderRadarEvent.kt @@ -6,5 +6,6 @@ import com.lambda.client.util.graphics.VertexHelper class RenderRadarEvent( val vertexHelper: VertexHelper, val radius: Float, - val scale: Float + val scale: Float, + val chunkLines: Boolean ) : Event \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/Radar.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/Radar.kt index f5703e4d4..08bb4f8b6 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/Radar.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/Radar.kt @@ -28,6 +28,7 @@ internal object Radar : HudElement( description = "Shows entities and new chunks" ) { private val zoom by setting("Zoom", 3f, 1f..10f, 0.1f) + private val chunkLines by setting("Chunk Lines", true) private val players = setting("Players", true) private val passive = setting("Passive Mobs", false) @@ -45,7 +46,7 @@ internal object Radar : HudElement( runSafe { drawBorder(vertexHelper) - post(RenderRadarEvent(vertexHelper, radius, zoom)) // Let other modules display radar elements + post(RenderRadarEvent(vertexHelper, radius, zoom, chunkLines)) // Let other modules display radar elements drawEntities(vertexHelper) drawLabels() } diff --git a/src/main/kotlin/com/lambda/client/module/modules/render/NewChunks.kt b/src/main/kotlin/com/lambda/client/module/modules/render/NewChunks.kt index 701bdcc59..1ea57074d 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/render/NewChunks.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/render/NewChunks.kt @@ -118,11 +118,12 @@ object NewChunks : Module( } safeListener { - if (renderMode == RenderMode.WORLD) return@safeListener - val playerOffset = Vec2d((player.posX - (player.chunkCoordX shl 4)), (player.posZ - (player.chunkCoordZ shl 4))) val chunkDist = (it.radius * it.scale).toInt() shr 4 - + // at high zooms (further zoomed out) there will be thousands of rects being rendered + // buffering rects here to reduce GL calls and improve FPS + val distantChunkRects: MutableList> = mutableListOf() + val chunkGridRects: MutableList> = mutableListOf() for (chunkX in -chunkDist..chunkDist) { for (chunkZ in -chunkDist..chunkDist) { val pos0 = getChunkPos(chunkX, chunkZ, playerOffset, it.scale) @@ -136,21 +137,25 @@ object NewChunks : Module( ) ?: false if (!chunk.isLoaded && !isCachedChunk) { - RenderUtils2D.drawRectFilled(it.vertexHelper, pos0, pos1, distantChunkColor) + distantChunkRects.add(Pair(pos0, pos1)) } - RenderUtils2D.drawRectOutline(it.vertexHelper, pos0, pos1, 0.3f, chunkGridColor) + chunkGridRects.add(Pair(pos0, pos1)) } } } + if (distantChunkRects.isNotEmpty()) RenderUtils2D.drawRectFilledList(it.vertexHelper, distantChunkRects, distantChunkColor) + if (it.chunkLines && chunkGridRects.isNotEmpty()) RenderUtils2D.drawRectOutlineList(it.vertexHelper, chunkGridRects, 0.3f, chunkGridColor) + val newChunkRects: MutableList> = mutableListOf() chunks.keys.forEach { chunk -> val pos0 = getChunkPos(chunk.x - player.chunkCoordX, chunk.z - player.chunkCoordZ, playerOffset, it.scale) val pos1 = getChunkPos(chunk.x - player.chunkCoordX + 1, chunk.z - player.chunkCoordZ + 1, playerOffset, it.scale) if (isSquareInRadius(pos0, pos1, it.radius)) { - RenderUtils2D.drawRectFilled(it.vertexHelper, pos0, pos1, newChunkColor) + newChunkRects.add(Pair(pos0, pos1)) } } + if (newChunkRects.isNotEmpty()) RenderUtils2D.drawRectFilledList(it.vertexHelper, newChunkRects, newChunkColor) } safeListener { event -> diff --git a/src/main/kotlin/com/lambda/client/util/graphics/RenderUtils2D.kt b/src/main/kotlin/com/lambda/client/util/graphics/RenderUtils2D.kt index b3b32634f..5a86fb8c6 100644 --- a/src/main/kotlin/com/lambda/client/util/graphics/RenderUtils2D.kt +++ b/src/main/kotlin/com/lambda/client/util/graphics/RenderUtils2D.kt @@ -87,12 +87,59 @@ object RenderUtils2D { drawLineLoop(vertexHelper, vertices, lineWidth, color) } + fun drawRectOutlineList(vertexHelper: VertexHelper, + rects: List>, + lineWidth: Float = 1f, + color: ColorHolder) { + prepareGl() + glLineWidth(lineWidth) + vertexHelper.begin(GL_LINES) + rects.forEach { + val pos1 = it.first // Top left + val pos2 = Vec2d(it.second.x, it.first.y) // Top right + val pos3 = it.second // Bottom right + val pos4 = Vec2d(it.first.x, it.second.y) // Bottom left + vertexHelper.put(pos1, color) + vertexHelper.put(pos2, color) + vertexHelper.put(pos2, color) + vertexHelper.put(pos3, color) + vertexHelper.put(pos3, color) + vertexHelper.put(pos4, color) + vertexHelper.put(pos4, color) + vertexHelper.put(pos1, color) + } + vertexHelper.end() + releaseGl() + glLineWidth(1f) + } + fun drawRectFilled(vertexHelper: VertexHelper, posBegin: Vec2d = Vec2d(0.0, 0.0), posEnd: Vec2d, color: ColorHolder) { val pos2 = Vec2d(posEnd.x, posBegin.y) // Top right val pos4 = Vec2d(posBegin.x, posEnd.y) // Bottom left drawQuad(vertexHelper, posBegin, pos2, posEnd, pos4, color) } + fun drawRectFilledList(vertexHelper: VertexHelper, + rects: List>, + color: ColorHolder) { + prepareGl() + vertexHelper.begin(GL_TRIANGLES) + rects.forEach { + val pos1 = it.first // Top left + val pos2 = Vec2d(it.second.x, it.first.y) // Top right + val pos3 = it.second // Bottom right + val pos4 = Vec2d(it.first.x, it.second.y) // Bottom left + vertexHelper.put(pos1, color) + vertexHelper.put(pos2, color) + vertexHelper.put(pos4, color) + vertexHelper.put(pos4, color) + vertexHelper.put(pos3, color) + vertexHelper.put(pos2, color) + } + vertexHelper.end() + releaseGl() + } + private fun drawQuad(vertexHelper: VertexHelper, pos1: Vec2d, pos2: Vec2d, pos3: Vec2d, pos4: Vec2d, color: ColorHolder) { val vertices = arrayOf(pos1, pos2, pos4, pos3) drawTriangleStrip(vertexHelper, vertices, color)