From 02636de71e68ed4f191440f677f0ea85b987cd7b Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Thu, 18 Jul 2024 01:31:13 -0700 Subject: [PATCH] improve no texture highlight draw perf at low zooms --- .../xaeroplus/feature/render/DrawManager.java | 19 +++++++------------ .../ChunkHighlightBaseCacheHandler.java | 19 +------------------ .../xaeroplus/mixin/client/MixinGuiMap.java | 8 ++++---- .../module/impl/PaletteNewChunks.java | 10 ++++++---- 4 files changed, 18 insertions(+), 38 deletions(-) diff --git a/common/src/main/java/xaeroplus/feature/render/DrawManager.java b/common/src/main/java/xaeroplus/feature/render/DrawManager.java index a44847a7..3ca3d0c8 100644 --- a/common/src/main/java/xaeroplus/feature/render/DrawManager.java +++ b/common/src/main/java/xaeroplus/feature/render/DrawManager.java @@ -5,8 +5,9 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import it.unimi.dsi.fastutil.longs.LongArrayList; -import it.unimi.dsi.fastutil.longs.LongArraySet; import it.unimi.dsi.fastutil.longs.LongList; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; import it.unimi.dsi.fastutil.objects.Reference2ObjectMap; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import net.lenni0451.lambdaevents.EventHandler; @@ -21,7 +22,7 @@ public class DrawManager { private final Reference2ObjectMap, DrawFeature> chunkHighlightDrawFeatures = new Reference2ObjectOpenHashMap<>(); - final LongArraySet regionBuf = new LongArraySet(8); + private final LongSet regionBuf = new LongOpenHashSet(8); public DrawManager() { XaeroPlus.EVENT_BUS.register(this); @@ -93,7 +94,7 @@ public synchronized void drawMinimapFeatures( final PoseStack matrixStack, final VertexConsumer overlayBufferBuilder, MinimapRendererHelper helper - ) { + ) { if (chunkHighlightDrawFeatures.isEmpty()) return; regionBuf.clear(); for (int i = minViewX; i <= maxViewX; i++) { @@ -135,13 +136,7 @@ public synchronized void drawWorldMapFeatures( regionBuf.clear(); for (int x = minRegX; x <= maxRegX; x++) { for (int z = minRegZ; z <= maxRegZ; z++) { - final int mx = x + level; - final int mz = z + level; - for (int regX = x; regX < mx; ++regX) { - for (int regZ = z; regZ < mz; ++regZ) { - regionBuf.add(ChunkUtils.chunkPosToLong(regX, regZ)); - } - } + regionBuf.add(ChunkUtils.chunkPosToLong(x, z)); } } @@ -188,7 +183,7 @@ public synchronized void drawWorldMapFeaturesSection( } private void drawMinimapChunkHighlights(final DrawFeature feature, - final LongArraySet regions, + final LongSet regions, int chunkX, int chunkZ, int tileX, @@ -229,7 +224,7 @@ private void drawMinimapChunkHighlights(final DrawFeature feature, } private void drawWorldMapChunkHighlights(final DrawFeature feature, - final LongArraySet regions, + final LongSet regions, final int flooredCameraX, final int flooredCameraZ, final PoseStack matrixStack, diff --git a/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightBaseCacheHandler.java b/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightBaseCacheHandler.java index 08d90361..0a016692 100644 --- a/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightBaseCacheHandler.java +++ b/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightBaseCacheHandler.java @@ -52,30 +52,13 @@ public boolean isHighlighted(final int x, final int z, ResourceKey dimens public boolean isHighlighted(final long chunkPos) { try { - if (lock.readLock().tryLock()) { - boolean containsKey = chunks.containsKey(chunkPos); - lock.readLock().unlock(); - return containsKey; - } + return chunks.containsKey(chunkPos); } catch (final Exception e) { XaeroPlus.LOGGER.error("Error checking if chunk is highlighted: {}, {}", ChunkUtils.longToChunkX(chunkPos), ChunkUtils.longToChunkZ(chunkPos), e); } return false; } - public boolean isHighlightedWithWait(final long chunkPos) { - try { - if (lock.readLock().tryLock(1, TimeUnit.SECONDS)) { - boolean containsKey = chunks.containsKey(chunkPos); - lock.readLock().unlock(); - return containsKey; - } - } catch (final Exception e) { - XaeroPlus.LOGGER.error("Error checking if chunk is highlighted", e); - } - return false; - } - public Long2LongMap getHighlightsState() { return chunks; } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java b/common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java index 96485410..74bb67d5 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java @@ -299,10 +299,10 @@ public void drawWorldMapFeatures(final GuiGraphics guiGraphics, final int scaled final int minZ = minRegZ * leveledSideInRegions; final int maxZ = maxRegZ * leveledSideInRegions; Globals.drawManager.drawWorldMapFeatures( - minX, - maxX, - minZ, - maxZ, + minX - 1, + maxX + 1, + minZ - 1, + maxZ + 1, leveledSideInRegions, flooredCameraX, flooredCameraZ, diff --git a/common/src/main/java/xaeroplus/module/impl/PaletteNewChunks.java b/common/src/main/java/xaeroplus/module/impl/PaletteNewChunks.java index e57dd5ec..df6fdab2 100644 --- a/common/src/main/java/xaeroplus/module/impl/PaletteNewChunks.java +++ b/common/src/main/java/xaeroplus/module/impl/PaletteNewChunks.java @@ -76,19 +76,21 @@ public void setNewChunksCache(final boolean disk) { public void onChunkData(ChunkDataEvent event) { if (event.seenChunk()) return; // never will be newchunk if we've already cached it var currentDim = ChunkUtils.getActualDimension(); + var x = event.chunk().getPos().x; + var z = event.chunk().getPos().z; try { - var x = event.chunk().getPos().x; - var z = event.chunk().getPos().z; + if (newChunksCache.isHighlighted(x, z, currentDim)) return; + if (newChunksInverseCache.isHighlighted(x, z, currentDim)) return; if (currentDim == OVERWORLD || currentDim == NETHER) { if (checkNewChunkOverworldOrNether(event.chunk())) { newChunksCache.addHighlight(x, z); - } else if (!newChunksCache.isHighlighted(x, z, currentDim)) { + } else { newChunksInverseCache.addHighlight(x, z); } } else if (currentDim == END) { if (checkNewChunkEnd(event.chunk())) { newChunksCache.addHighlight(x, z); - } else if (!newChunksCache.isHighlighted(x, z, currentDim)) { + } else { newChunksInverseCache.addHighlight(x, z); } }