Skip to content

Commit

Permalink
Fix lag spike when enabling block esp (MeteorDevelopment#5001)
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog authored Nov 6, 2024
1 parent e599dd5 commit 49aa4f4
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
import meteordevelopment.meteorclient.events.render.Render3DEvent;
import meteordevelopment.meteorclient.events.world.BlockUpdateEvent;
import meteordevelopment.meteorclient.events.world.ChunkDataEvent;
Expand All @@ -16,8 +17,6 @@
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.UnorderedArrayList;
import meteordevelopment.meteorclient.utils.network.MeteorExecutor;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import meteordevelopment.meteorclient.utils.render.color.RainbowColors;
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
Expand All @@ -31,6 +30,9 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class BlockESP extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();
Expand Down Expand Up @@ -78,7 +80,8 @@ public class BlockESP extends Module {
private final BlockPos.Mutable blockPos = new BlockPos.Mutable();

private final Long2ObjectMap<ESPChunk> chunks = new Long2ObjectOpenHashMap<>();
private final List<ESPGroup> groups = new UnorderedArrayList<>();
private final Set<ESPGroup> groups = new ReferenceOpenHashSet<>();
private final ExecutorService workerThread = Executors.newSingleThreadExecutor();

private Dimension lastDimension;

Expand Down Expand Up @@ -157,7 +160,7 @@ private void onChunkData(ChunkDataEvent event) {
}

private void searchChunk(Chunk chunk) {
MeteorExecutor.execute(() -> {
workerThread.submit(() -> {
if (!isActive()) return;
ESPChunk schunk = ESPChunk.searchChunk(chunk, blocks.get());

Expand Down Expand Up @@ -191,7 +194,7 @@ private void onBlockUpdate(BlockUpdateEvent event) {
boolean removed = !added && !blocks.get().contains(event.newState.getBlock()) && blocks.get().contains(event.oldState.getBlock());

if (added || removed) {
MeteorExecutor.execute(() -> {
workerThread.submit(() -> {
synchronized (chunks) {
ESPChunk chunk = chunks.get(key);

Expand Down Expand Up @@ -238,7 +241,7 @@ private void onRender(Render3DEvent event) {
ESPChunk chunk = it.next();

if (chunk.shouldBeDeleted()) {
MeteorExecutor.execute(() -> {
workerThread.submit(() -> {
for (ESPBlock block : chunk.blocks.values()) {
block.group.remove(block, false);
block.loaded = false;
Expand All @@ -251,13 +254,15 @@ private void onRender(Render3DEvent event) {
}

if (tracers.get()) {
for (Iterator<ESPGroup> it = groups.iterator(); it.hasNext();) {
ESPGroup group = it.next();

if (group.blocks.isEmpty()) it.remove();
else group.render(event);
for (ESPGroup group : groups) {
group.render(event);
}
}
}
}

@Override
public String getInfoString() {
return "%s groups".formatted(groups.size());
}
}

0 comments on commit 49aa4f4

Please sign in to comment.