@@ -26,27 +26,22 @@ class ChunkedESP private constructor(
2626 private val uploadQueue = ConcurrentLinkedDeque < () -> Unit > ()
2727 private val rebuildQueue = ConcurrentLinkedDeque <EspChunk >()
2828
29- // i completely dont like to listen to enable events
30-
3129 fun rebuild () {
3230 rebuildQueue.clear()
3331 rebuildQueue.addAll(rendererMap.values)
3432 }
3533
3634 init {
3735 concurrentListener<WorldEvent .BlockUpdate > { event ->
38- world.getWorldChunk(event.pos).renderer.apply {
39- queueRebuild()
40- notifyNeighbors()
41- }
36+ world.getWorldChunk(event.pos).renderer.notify()
4237 }
4338
4439 concurrentListener<WorldEvent .ChunkEvent .Load > { event ->
45- event.chunk.renderer.notifyNeighbors ()
40+ event.chunk.renderer.notify ()
4641 }
4742
4843 concurrentListener<WorldEvent .ChunkEvent .Unload > { event ->
49- rendererMap.remove(event.chunk.pos.toLong())?.notifyNeighbors ()
44+ rendererMap.remove(event.chunk.pos.toLong())?.notify ()
5045 }
5146
5247 owner.concurrentListener<TickEvent .Pre > {
@@ -90,18 +85,14 @@ class ChunkedESP private constructor(
9085 val neighbors = chunkOffsets.map {
9186 ChunkPos (chunk.pos.x + it.first, chunk.pos.z + it.second)
9287 }.toTypedArray()
93- val neighborsLoaded get() = neighbors.all { it.isLoaded() }
94-
95- fun ChunkPos.isLoaded () = chunk.world.chunkManager.isChunkLoaded(x, z)
9688
97- fun queueRebuild () {
98- if (owner.rebuildQueue.contains(this )) return
99- owner.rebuildQueue.add(this )
100- }
101-
102- fun notifyNeighbors () {
89+ fun notify () {
10390 neighbors.forEach {
104- owner.rendererMap[it.toLong()]?.queueRebuild()
91+ owner.rendererMap[it.toLong()]?.let {
92+ owner.rebuildQueue.apply {
93+ if (! contains(it)) add(it)
94+ }
95+ }
10596 }
10697 }
10798
@@ -114,22 +105,10 @@ class ChunkedESP private constructor(
114105 owner.update(newRenderer, chunk.world, x, y, z)
115106 }
116107
117- val upload = {
108+ owner.uploadQueue.add {
118109 newRenderer.upload()
119- renderer?.clear()
120110 renderer = newRenderer
121111 }
122-
123- when (RenderSettings .uploadScheduler) {
124- RenderSettings .UploadScheduler .Instant -> {
125- runGameBlocking {
126- upload()
127- }
128- }
129- RenderSettings .UploadScheduler .Delayed -> {
130- owner.uploadQueue.add(upload)
131- }
132- }
133112 }
134113
135114 private fun iterateChunk (block : (Int , Int , Int ) -> Unit ) = chunk.apply {
0 commit comments