Skip to content

Commit

Permalink
share buffer to reduce allocs
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jul 9, 2024
1 parent 29f7f5c commit 819e4dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
43 changes: 7 additions & 36 deletions common/src/main/java/xaeroplus/feature/render/DrawManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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

public DrawManager() {
XaeroPlus.EVENT_BUS.register(this);
Expand Down Expand Up @@ -93,18 +94,18 @@ public synchronized void drawMinimapFeatures(
final VertexConsumer overlayBufferBuilder,
MinimapRendererHelper helper
) {
final LongArraySet regions = new LongArraySet(4);
regionBuf.clear();
for (int i = minViewX; i <= maxViewX; i++) {
for (int j = minViewZ; j <= maxViewZ; j++) {
int regX = i >> 3;
int regZ = j >> 3;
regions.add(ChunkUtils.chunkPosToLong(regX, regZ));
regionBuf.add(ChunkUtils.chunkPosToLong(regX, regZ));
}
}
for (DrawFeature feature : chunkHighlightDrawFeatures.values()) {
drawMinimapChunkHighlights(
feature,
regions,
regionBuf,
chunkX,
chunkZ,
tileX,
Expand All @@ -119,35 +120,6 @@ public synchronized void drawMinimapFeatures(
}

public synchronized void drawWorldMapFeatures(
final int leafRegionX,
final int leafRegionZ,
final int level,
final int flooredCameraX,
final int flooredCameraZ,
final PoseStack matrixStack,
final VertexConsumer overlayBuffer
) {
final int mx = leafRegionX + level;
final int mz = leafRegionZ + level;
final LongArraySet regions = new LongArraySet(1);
for (int regX = leafRegionX; regX < mx; ++regX) {
for (int regZ = leafRegionZ; regZ < mz; ++regZ) {
regions.add(ChunkUtils.chunkPosToLong(regX, regZ));
}
}
for (DrawFeature feature : chunkHighlightDrawFeatures.values()) {
drawWorldMapChunkHighlights(
feature,
regions,
flooredCameraX,
flooredCameraZ,
matrixStack,
overlayBuffer
);
}
}

public synchronized void drawWorldMapFeaturesNew(
final int minRegX,
final int maxRegX,
final int minRegZ,
Expand All @@ -158,15 +130,14 @@ public synchronized void drawWorldMapFeaturesNew(
final PoseStack matrixStack,
final VertexConsumer overlayBuffer
) {
final LongArraySet regions = new LongArraySet(8);

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) {
regions.add(ChunkUtils.chunkPosToLong(regX, regZ));
regionBuf.add(ChunkUtils.chunkPosToLong(regX, regZ));
}
}
}
Expand All @@ -175,7 +146,7 @@ public synchronized void drawWorldMapFeaturesNew(
for (DrawFeature feature : chunkHighlightDrawFeatures.values()) {
drawWorldMapChunkHighlights(
feature,
regions,
regionBuf,
flooredCameraX,
flooredCameraZ,
matrixStack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void drawWorldMapFeatures(final GuiGraphics guiGraphics, final int scaled
final int maxX = maxRegX * leveledSideInRegions;
final int minZ = minRegZ * leveledSideInRegions;
final int maxZ = maxRegZ * leveledSideInRegions;
Globals.drawManager.drawWorldMapFeaturesNew(
Globals.drawManager.drawWorldMapFeatures(
minX,
maxX,
minZ,
Expand Down

0 comments on commit 819e4dc

Please sign in to comment.