Skip to content

Commit b59521a

Browse files
committed
BlockESP performance
1 parent a25d3d6 commit b59521a

File tree

5 files changed

+31
-35
lines changed

5 files changed

+31
-35
lines changed

src/main/kotlin/com/lambda/Lambda.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ object Lambda : ClientModInitializer {
7272
.registerTypeAdapter(Text::class.java, Text.Serializer(DynamicRegistryManager.EMPTY))
7373
.create()
7474

75-
override fun onInitializeClient() {
76-
recordRenderCall {
77-
LOG.info("$MOD_NAME $VERSION initialized in ${Loader.initialize()} ms\n")
78-
}
79-
}
75+
override fun onInitializeClient() =
76+
recordRenderCall { LOG.info("$MOD_NAME $VERSION initialized in ${Loader.initialize()} ms\n") }
8077
}

src/main/kotlin/com/lambda/graphics/renderer/esp/ChunkedESP.kt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import com.lambda.event.events.TickEvent
2222
import com.lambda.event.events.WorldEvent
2323
import com.lambda.event.events.onStaticRender
2424
import com.lambda.event.listener.SafeListener.Companion.listen
25+
import com.lambda.event.listener.SafeListener.Companion.listenConcurrently
2526
import com.lambda.module.modules.client.StyleEditor
27+
import com.lambda.threading.awaitMainThread
2628
import com.lambda.util.world.FastVector
2729
import com.lambda.util.world.fastVectorOf
2830
import net.minecraft.util.math.ChunkPos
@@ -54,7 +56,7 @@ class ChunkedESP private constructor(
5456
listen<WorldEvent.ChunkEvent.Load> { it.chunk.renderer.notifyChunks() }
5557
listen<WorldEvent.ChunkEvent.Unload> { rendererMap.remove(it.chunk.pos.toLong())?.notifyChunks() }
5658

57-
owner.onStaticRender {
59+
listenConcurrently<TickEvent.Pre> {
5860
if (++ticks % StyleEditor.updateFrequency == 0) {
5961
val polls = minOf(StyleEditor.rebuildsPerTick, rebuildQueue.size)
6062

@@ -64,8 +66,8 @@ class ChunkedESP private constructor(
6466
}
6567
}
6668

67-
owner.listen<RenderEvent.Upload> {
68-
if (uploadQueue.isEmpty()) return@listen
69+
owner.onStaticRender {
70+
if (uploadQueue.isEmpty()) return@onStaticRender
6971

7072
val polls = minOf(StyleEditor.uploadsPerTick, uploadQueue.size)
7173

@@ -98,19 +100,15 @@ class ChunkedESP private constructor(
98100
}
99101
}
100102

101-
fun rebuild() {
102-
renderer = Treed(static = true)
103-
104-
chunkIterator { owner.update(builder, chunk.world, it) }
105-
106-
owner.uploadQueue.add { renderer.upload() }
107-
}
103+
suspend fun rebuild() {
104+
renderer = awaitMainThread { Treed(static = true) }
108105

109-
inline fun chunkIterator(crossinline block: (FastVector) -> Unit) {
110106
for (x in chunk.pos.startX..chunk.pos.endX)
111107
for (z in chunk.pos.startZ..chunk.pos.endZ)
112108
for (y in chunk.bottomY..chunk.height)
113-
block(fastVectorOf(x, y, z))
109+
owner.update(builder, chunk.world, fastVectorOf(x, y, z))
110+
111+
owner.uploadQueue.add { renderer.upload() }
114112
}
115113
}
116114
}

src/main/kotlin/com/lambda/module/modules/render/BlockESP.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
package com.lambda.module.modules.render
1919

2020
import com.lambda.Lambda.mc
21+
import com.lambda.context.SafeContext
22+
import com.lambda.event.events.TickEvent
23+
import com.lambda.event.listener.SafeListener.Companion.listen
2124
import com.lambda.graphics.pipeline.VertexBuilder
2225
import com.lambda.graphics.renderer.esp.ChunkedESP.Companion.newChunkedESP
2326
import com.lambda.graphics.renderer.esp.DirectionMask
@@ -26,9 +29,12 @@ import com.lambda.graphics.renderer.esp.ShapeBuilder
2629
import com.lambda.module.Module
2730
import com.lambda.module.tag.ModuleTag
2831
import com.lambda.threading.runSafe
32+
import com.lambda.util.Communication.info
2933
import com.lambda.util.extension.blockColor
3034
import com.lambda.util.extension.getBlockState
3135
import com.lambda.util.extension.outlineShape
36+
import com.lambda.util.world.blockSearch
37+
import com.lambda.util.world.distSq
3238
import com.lambda.util.world.toBlockPos
3339
import net.minecraft.block.BlockState
3440
import net.minecraft.block.Blocks
@@ -41,17 +47,17 @@ object BlockESP : Module(
4147
description = "Render block ESP",
4248
tag = ModuleTag.RENDER,
4349
) {
44-
private var drawFaces: Boolean by setting("Draw Faces", true, "Draw faces of blocks").onValueSet(::rebuildMesh).onValueSet { _, to -> if (!to) drawOutlines = true }
45-
private var drawOutlines: Boolean by setting("Draw Outlines", true, "Draw outlines of blocks").onValueSet(::rebuildMesh).onValueSet { _, to -> if (!to) drawFaces = true }
46-
private val mesh by setting("Mesh", true, "Connect similar adjacent blocks").onValueSet(::rebuildMesh)
50+
private var drawFaces: Boolean by setting("Draw Faces", true, "Draw faces of blocks").onValueChange(::rebuildMesh).onValueChange { _, to -> if (!to) drawOutlines = true }
51+
private var drawOutlines: Boolean by setting("Draw Outlines", true, "Draw outlines of blocks").onValueChange(::rebuildMesh).onValueChange { _, to -> if (!to) drawFaces = true }
52+
private val mesh by setting("Mesh", true, "Connect similar adjacent blocks").onValueChange(::rebuildMesh)
4753

48-
private val useBlockColor by setting("Use Block Color", false, "Use the color of the block instead").onValueSet(::rebuildMesh)
49-
private val faceColor by setting("Face Color", Color(100, 150, 255, 51), "Color of the surfaces") { drawFaces && !useBlockColor }.onValueSet(::rebuildMesh)
50-
private val outlineColor by setting("Outline Color", Color(100, 150, 255, 128), "Color of the outlines") { drawOutlines && !useBlockColor }.onValueSet(::rebuildMesh)
54+
private val useBlockColor by setting("Use Block Color", false, "Use the color of the block instead").onValueChange(::rebuildMesh)
55+
private val faceColor by setting("Face Color", Color(100, 150, 255, 51), "Color of the surfaces") { drawFaces && !useBlockColor }.onValueChange(::rebuildMesh)
56+
private val outlineColor by setting("Outline Color", Color(100, 150, 255, 128), "Color of the outlines") { drawOutlines && !useBlockColor }.onValueChange(::rebuildMesh)
5157

52-
private val outlineMode by setting("Outline Mode", DirectionMask.OutlineMode.AND, "Outline mode").onValueSet(::rebuildMesh)
58+
private val outlineMode by setting("Outline Mode", DirectionMask.OutlineMode.AND, "Outline mode").onValueChange(::rebuildMesh)
5359

54-
private val blocks by setting("Blocks", setOf(Blocks.BEDROCK), setOf(Blocks.BEDROCK), "Render blocks").onValueSet(::rebuildMesh)
60+
private val blocks by setting("Blocks", setOf(Blocks.BEDROCK), setOf(Blocks.BEDROCK), "Render blocks").onValueChange(::rebuildMesh)
5561

5662
@JvmStatic
5763
val barrier by setting("Solid Barrier Block", true, "Render barrier blocks")
@@ -63,12 +69,6 @@ object BlockESP : Module(
6369
@JvmStatic
6470
val model: BlockStateModel get() = mc.bakedModelManager.missingModel
6571

66-
init {
67-
onToggle {
68-
if (barrier) mc.worldRenderer.reload()
69-
}
70-
}
71-
7272
private val esp = newChunkedESP { world, position ->
7373
val state = world.getBlockState(position)
7474
if (state.block !in blocks) return@newChunkedESP
@@ -94,5 +94,5 @@ object BlockESP : Module(
9494
if (drawOutlines) outline(shape, if (useBlockColor) blockColor else outlineColor, sides, outlineMode)
9595
}
9696

97-
private fun rebuildMesh(from: Any, to: Any): Unit = esp.rebuild()
97+
private fun rebuildMesh(ctx: SafeContext, from: Any, to: Any): Unit = esp.rebuild()
9898
}

src/main/kotlin/com/lambda/module/modules/render/StorageESP.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ object StorageESP : Module(
5858
private val distance by setting("Distance", 64.0, 10.0..256.0, 1.0, "Maximum distance for rendering").group(Group.General)
5959

6060
/* Render settings */
61-
private var drawFaces: Boolean by setting("Draw Faces", true, "Draw faces of blocks").onValueSet { _, to -> if (!to) drawEdges = true }.group(Group.Render)
62-
private var drawEdges: Boolean by setting("Draw Edges", true, "Draw edges of blocks").onValueSet { _, to -> if (!to) drawFaces = true }.group(Group.Render)
61+
private var drawFaces: Boolean by setting("Draw Faces", true, "Draw faces of blocks").onValueChange { _, to -> drawEdges = !to && !drawFaces }.group(Group.Render)
62+
private var drawEdges: Boolean by setting("Draw Edges", true, "Draw edges of blocks").onValueChange { _, to -> drawFaces = !to && !drawEdges }.group(Group.Render)
6363
private val mode by setting("Outline Mode", DirectionMask.OutlineMode.AND, "Outline mode").group(Group.Render)
6464
private val mesh by setting("Mesh", true, "Connect similar adjacent blocks").group(Group.Render)
6565

src/main/kotlin/com/lambda/threading/Threading.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ inline fun runSafeConcurrent(crossinline block: suspend SafeContext.() -> Unit)
9797
*
9898
* @param block The task to be executed on the game's main thread.
9999
*/
100-
inline fun recordRenderCall(crossinline block: () -> Unit) =
100+
inline fun recordRenderCall(crossinline block: () -> Unit) {
101101
mc.renderTaskQueue.add { block() }
102+
}
102103

103104
/**
104105
* Executes a given task on the game's main thread.

0 commit comments

Comments
 (0)