From 8060db50756b15c68e6a7d76727bf493a83ed5b0 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Sun, 1 Jan 2023 15:54:55 -0800 Subject: [PATCH 1/2] Radar: Improve FPS at high zooms Reduces amount of GL calls to improve FPS. Also added an option to disable rendering the chunk border lines. At high zooms these are not helpful visually and further reduce FPS. --- .../client/event/events/RenderRadarEvent.kt | 3 +- .../client/gui/hudgui/elements/world/Radar.kt | 3 +- .../client/module/modules/render/NewChunks.kt | 17 ++++--- .../client/util/graphics/RenderUtils2D.kt | 47 +++++++++++++++++++ 4 files changed, 62 insertions(+), 8 deletions(-) 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..a027c2b37 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 filledChunkRects: MutableList> = ArrayList() + val outlineChunkRects: MutableList> = ArrayList() 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) + filledChunkRects.add(Pair(pos0, pos1)) } - RenderUtils2D.drawRectOutline(it.vertexHelper, pos0, pos1, 0.3f, chunkGridColor) + outlineChunkRects.add(Pair(pos0, pos1)) } } } + if (filledChunkRects.isNotEmpty()) RenderUtils2D.drawRectFilledList(it.vertexHelper, filledChunkRects, ColorHolder(100, 100, 100, 100)) + if (it.chunkLines && outlineChunkRects.isNotEmpty()) RenderUtils2D.drawRectOutlineList(it.vertexHelper, outlineChunkRects, 0.3f, ColorHolder(255, 0, 0, 100)) + filledChunkRects.clear() 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) + filledChunkRects.add(Pair(pos0, pos1)) } } + if (filledChunkRects.isNotEmpty()) RenderUtils2D.drawRectFilledList(it.vertexHelper, filledChunkRects, 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) From 499e04767fa5d5e137d09e6403d8167cb5a68a43 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Mon, 2 Jan 2023 00:34:05 -0800 Subject: [PATCH 2/2] bring back color settings --- .../client/module/modules/render/NewChunks.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 a027c2b37..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 @@ -122,8 +122,8 @@ object NewChunks : Module( 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 filledChunkRects: MutableList> = ArrayList() - val outlineChunkRects: MutableList> = ArrayList() + 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) @@ -137,25 +137,25 @@ object NewChunks : Module( ) ?: false if (!chunk.isLoaded && !isCachedChunk) { - filledChunkRects.add(Pair(pos0, pos1)) + distantChunkRects.add(Pair(pos0, pos1)) } - outlineChunkRects.add(Pair(pos0, pos1)) + chunkGridRects.add(Pair(pos0, pos1)) } } } - if (filledChunkRects.isNotEmpty()) RenderUtils2D.drawRectFilledList(it.vertexHelper, filledChunkRects, ColorHolder(100, 100, 100, 100)) - if (it.chunkLines && outlineChunkRects.isNotEmpty()) RenderUtils2D.drawRectOutlineList(it.vertexHelper, outlineChunkRects, 0.3f, ColorHolder(255, 0, 0, 100)) - filledChunkRects.clear() + 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)) { - filledChunkRects.add(Pair(pos0, pos1)) + newChunkRects.add(Pair(pos0, pos1)) } } - if (filledChunkRects.isNotEmpty()) RenderUtils2D.drawRectFilledList(it.vertexHelper, filledChunkRects, newChunkColor) + if (newChunkRects.isNotEmpty()) RenderUtils2D.drawRectFilledList(it.vertexHelper, newChunkRects, newChunkColor) } safeListener { event ->