Skip to content

Commit 4ffc9af

Browse files
committed
fixed esp, still has caching issues
1 parent 38330d1 commit 4ffc9af

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ package com.lambda.graphics.renderer.esp
2020
import com.lambda.event.events.RenderEvent
2121
import com.lambda.event.events.TickEvent
2222
import com.lambda.event.events.WorldEvent
23-
import com.lambda.event.events.onStaticRender
2423
import com.lambda.event.listener.SafeListener.Companion.listen
2524
import com.lambda.event.listener.SafeListener.Companion.listenConcurrently
2625
import com.lambda.module.Module
2726
import com.lambda.module.modules.client.StyleEditor
2827
import com.lambda.threading.awaitMainThread
2928
import com.lambda.util.world.FastVector
3029
import com.lambda.util.world.fastVectorOf
31-
import net.minecraft.util.math.ChunkPos
3230
import net.minecraft.world.World
3331
import net.minecraft.world.chunk.WorldChunk
3432
import java.util.concurrent.ConcurrentHashMap
@@ -53,36 +51,30 @@ class ChunkedESP private constructor(
5351
}
5452

5553
init {
56-
//listen<WorldEvent.BlockUpdate.Client> { rebuildQueue.add(rendererMap[ChunkPos.toLong(it.pos)] ?: return@listen) }
57-
listen<WorldEvent.ChunkEvent.Load> {
58-
if (!owner.isEnabled) return@listen
59-
it.chunk.renderer.notifyChunks()
54+
listen<WorldEvent.BlockUpdate.Client> { event ->
55+
world.getWorldChunk(event.pos).renderer.notifyChunks()
6056
}
6157

62-
listen<WorldEvent.ChunkEvent.Unload> {
63-
if (!owner.isEnabled) return@listen
64-
rendererMap.remove(it.chunk.pos.toLong())?.notifyChunks()
58+
listen<WorldEvent.ChunkEvent.Load> { event ->
59+
event.chunk.renderer.notifyChunks()
6560
}
6661

67-
listenConcurrently<TickEvent.Post> {
68-
if (!owner.isEnabled) return@listenConcurrently
69-
if (++ticks % StyleEditor.updateFrequency == 0) {
70-
val polls = minOf(StyleEditor.rebuildsPerTick, rebuildQueue.size)
71-
72-
repeat(polls) { rebuildQueue.poll()?.rebuild() }
62+
listen<WorldEvent.ChunkEvent.Unload> {
63+
val pos = it.chunk.pos.toLong()
64+
rendererMap.remove(pos)?.notifyChunks()
65+
}
7366

74-
ticks = 0
75-
}
67+
owner.listenConcurrently<TickEvent.Pre> {
68+
val polls = minOf(StyleEditor.rebuildsPerTick, rebuildQueue.size)
69+
repeat(polls) { rebuildQueue.poll()?.rebuild() }
7670
}
7771

78-
owner.onStaticRender {
79-
if (!owner.isEnabled || uploadQueue.isEmpty()) return@onStaticRender
72+
owner.listen<TickEvent.Pre> {
8073
val polls = minOf(StyleEditor.uploadsPerTick, uploadQueue.size)
8174
repeat(polls) { uploadQueue.poll()?.invoke() }
8275
}
8376

8477
owner.listen<RenderEvent.Render> {
85-
if (!owner.isEnabled) return@listen
8678
rendererMap.values.forEach { it.renderer.render() }
8779
}
8880
}
@@ -98,19 +90,18 @@ class ChunkedESP private constructor(
9890
private val builder: ShapeBuilder
9991
get() = ShapeBuilder(renderer.faceBuilder, renderer.edgeBuilder)
10092

101-
val neighbors = listOf(1 to 0, 0 to 1, -1 to 0, 0 to -1)
102-
.map { ChunkPos(chunk.pos.x + it.first, chunk.pos.z + it.second) }
93+
/*val neighbors = listOf(1 to 0, 0 to 1, -1 to 0, 0 to -1)
94+
.map { ChunkPos(chunk.pos.x + it.first, chunk.pos.z + it.second) }*/
10395

10496
fun notifyChunks() {
105-
neighbors.forEach { chunkPos ->
106-
owner.rendererMap[chunkPos.toLong()]?.let {
107-
if (!owner.rebuildQueue.contains(it))
108-
owner.rebuildQueue.add(it)
109-
}
97+
owner.rendererMap[chunk.pos.toLong()]?.let {
98+
if (!owner.rebuildQueue.contains(it))
99+
owner.rebuildQueue.add(it)
110100
}
111101
}
112102

113103
suspend fun rebuild() {
104+
renderer.clear()
114105
renderer = awaitMainThread { Treed(static = true) }
115106

116107
for (x in chunk.pos.startX..chunk.pos.endX)

0 commit comments

Comments
 (0)