Skip to content

Commit

Permalink
improve no texture highlight draw perf at low zooms
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jul 18, 2024
1 parent c5236c6 commit 02636de
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 38 deletions.
19 changes: 7 additions & 12 deletions common/src/main/java/xaeroplus/feature/render/DrawManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,7 @@

public class DrawManager {
private final Reference2ObjectMap<Class<?>, DrawFeature> chunkHighlightDrawFeatures = new Reference2ObjectOpenHashMap<>();
final LongArraySet regionBuf = new LongArraySet(8);
private final LongSet regionBuf = new LongOpenHashSet(8);

public DrawManager() {
XaeroPlus.EVENT_BUS.register(this);
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,13 @@ public boolean isHighlighted(final int x, final int z, ResourceKey<Level> 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;
}
Expand Down
8 changes: 4 additions & 4 deletions common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions common/src/main/java/xaeroplus/module/impl/PaletteNewChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 02636de

Please sign in to comment.