From 02db3f5a2c0f86e8a78968b537a8b0b6cf2fc666 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 17 Feb 2021 13:58:24 -0800 Subject: [PATCH] fix some problematic code. creating matrix stacks is expensive, apparently --- .../foundation/render/SuperByteBuffer.java | 4 ++-- .../render/backend/FastRenderDispatcher.java | 22 ++++++------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index 94d03f781..d85977d8e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -25,7 +25,7 @@ public class SuperByteBuffer extends TemplateBuffer { } // Vertex Position - private MatrixStack transforms; + private final MatrixStack transforms; // Vertex Texture Coords private SpriteShiftFunc spriteShiftFunc; @@ -152,7 +152,7 @@ public class SuperByteBuffer extends TemplateBuffer { .endVertex(); } - transforms = new MatrixStack(); + while (!transforms.isEmpty()) transforms.pop(); spriteShiftFunc = null; shouldColor = false; shouldLight = false; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java index 07e7e91bf..4e7955e85 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java @@ -45,7 +45,13 @@ public class FastRenderDispatcher { CreateClient.kineticRenderer.tick(); - runQueue(queuedUpdates.get(world), CreateClient.kineticRenderer::update); + ConcurrentHashMap.KeySetView map = queuedUpdates.get(world); + map + .forEach(te -> { + map.remove(te); + + CreateClient.kineticRenderer.update(te); + }); } public static boolean available() { @@ -64,20 +70,6 @@ public class FastRenderDispatcher { RenderWork.enqueue(Minecraft.getInstance().worldRenderer::loadRenderers); } - private static void runQueue(@Nullable ConcurrentHashMap.KeySetView changed, Consumer action) { - if (changed == null) return; - - if (available()) { - // because of potential concurrency issues, we make a copy of what's in the set at the time we get here - ArrayList tiles = new ArrayList<>(changed); - - tiles.forEach(action); - changed.removeAll(tiles); - } else { - changed.clear(); - } - } - public static void renderLayer(RenderType layer, Matrix4f viewProjection, double cameraX, double cameraY, double cameraZ) { if (!Backend.canUseInstancing()) return;