From b655f9de78c2f42014c4dd4ff93aeb8905fbda67 Mon Sep 17 00:00:00 2001 From: TechLord22 <37029404+techlord22@users.noreply.github.com> Date: Sat, 28 Sep 2024 17:33:23 -0400 Subject: [PATCH 1/4] improve preview renderFilter performance --- .../renderer/scene/WorldSceneRenderer.java | 65 +++++++------------ .../MultiblockInfoRecipeWrapper.java | 5 +- 2 files changed, 27 insertions(+), 43 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java b/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java index d5947edf46d..ecce4133259 100644 --- a/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java +++ b/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java @@ -5,6 +5,8 @@ import gregtech.api.util.Size; import gregtech.client.utils.RenderUtil; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; + import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -33,8 +35,6 @@ import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; import java.util.function.Consumer; import javax.vecmath.Vector3f; @@ -61,7 +61,7 @@ public abstract class WorldSceneRenderer { .order(ByteOrder.nativeOrder()).asFloatBuffer(); public final World world; - public final Map, ISceneRenderHook> renderedBlocksMap; + public final Collection renderedBlocks = new ObjectOpenHashSet<>(); private Consumer beforeRender; private Consumer afterRender; private Consumer onLookingAt; @@ -73,7 +73,6 @@ public abstract class WorldSceneRenderer { public WorldSceneRenderer(World world) { this.world = world; - renderedBlocksMap = new LinkedHashMap<>(); } public WorldSceneRenderer setBeforeWorldRender(Consumer callback) { @@ -88,7 +87,7 @@ public WorldSceneRenderer setAfterWorldRender(Consumer callb public WorldSceneRenderer addRenderedBlocks(Collection blocks, ISceneRenderHook renderHook) { if (blocks != null) { - this.renderedBlocksMap.put(blocks, renderHook); + this.renderedBlocks.addAll(blocks); } return this; } @@ -240,31 +239,24 @@ protected void drawWorld() { for (BlockRenderLayer layer : BlockRenderLayer.values()) { ForgeHooksClient.setRenderLayer(layer); int pass = layer == BlockRenderLayer.TRANSLUCENT ? 1 : 0; + setDefaultPassRenderState(pass); - renderedBlocksMap.forEach((renderedBlocks, hook) -> { - if (hook != null) { - hook.apply(false, pass, layer); - } else { - setDefaultPassRenderState(pass); - } + BufferBuilder buffer = Tessellator.getInstance().getBuffer(); + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + BlockRendererDispatcher blockrendererdispatcher = mc.getBlockRendererDispatcher(); - BufferBuilder buffer = Tessellator.getInstance().getBuffer(); - buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); - BlockRendererDispatcher blockrendererdispatcher = mc.getBlockRendererDispatcher(); - - for (BlockPos pos : renderedBlocks) { - IBlockState state = world.getBlockState(pos); - Block block = state.getBlock(); - if (block == Blocks.AIR) continue; - state = state.getActualState(world, pos); - if (block.canRenderInLayer(state, layer)) { - blockrendererdispatcher.renderBlock(state, pos, world, buffer); - } + for (BlockPos pos : renderedBlocks) { + IBlockState state = world.getBlockState(pos); + Block block = state.getBlock(); + if (block == Blocks.AIR) continue; + state = state.getActualState(world, pos); + if (block.canRenderInLayer(state, layer)) { + blockrendererdispatcher.renderBlock(state, pos, world, buffer); } + } - Tessellator.getInstance().draw(); - Tessellator.getInstance().getBuffer().setTranslation(0, 0, 0); - }); + Tessellator.getInstance().draw(); + Tessellator.getInstance().getBuffer().setTranslation(0, 0, 0); } } finally { ForgeHooksClient.setRenderLayer(oldRenderLayer); @@ -276,22 +268,15 @@ protected void drawWorld() { // render TESR for (int pass = 0; pass < 2; pass++) { ForgeHooksClient.setRenderPass(pass); - int finalPass = pass; - renderedBlocksMap.forEach((renderedBlocks, hook) -> { - if (hook != null) { - hook.apply(true, finalPass, null); - } else { - setDefaultPassRenderState(finalPass); - } - for (BlockPos pos : renderedBlocks) { - TileEntity tile = world.getTileEntity(pos); - if (tile != null) { - if (tile.shouldRenderInPass(finalPass)) { - TileEntityRendererDispatcher.instance.render(tile, pos.getX(), pos.getY(), pos.getZ(), 0); - } + setDefaultPassRenderState(pass); + for (BlockPos pos : renderedBlocks) { + TileEntity tile = world.getTileEntity(pos); + if (tile != null) { + if (tile.shouldRenderInPass(pass)) { + TileEntityRendererDispatcher.instance.render(tile, pos.getX(), pos.getY(), pos.getZ(), 0); } } - }); + } } ForgeHooksClient.setRenderPass(-1); GlStateManager.enableDepth(); diff --git a/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java b/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java index b746f67a2cd..cf4ca50fc95 100644 --- a/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java +++ b/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java @@ -217,7 +217,7 @@ private void setNextLayer(int newLayer) { if (renderer != null) { TrackedDummyWorld world = ((TrackedDummyWorld) renderer.world); resetCenter(world); - renderer.renderedBlocksMap.clear(); + renderer.renderedBlocks.clear(); int minY = (int) world.getMinPos().getY(); Collection renderBlocks; if (newLayer == -1) { @@ -607,8 +607,7 @@ private MBPattern initializePattern(@NotNull MultiblockShapeInfo shapeInfo, @Not renderBlockOverLay(selected, 255, 0, 0); }); world.updateEntities(); - world.setRenderFilter( - pos -> worldSceneRenderer.renderedBlocksMap.keySet().stream().anyMatch(c -> c.contains(pos))); + world.setRenderFilter(worldSceneRenderer.renderedBlocks::contains); Map predicateMap = new HashMap<>(); if (controllerBase != null) { From 2e2c02b1a750e75b93149902a4dd53faa0759ec2 Mon Sep 17 00:00:00 2001 From: TechLord22 <37029404+techlord22@users.noreply.github.com> Date: Sat, 28 Sep 2024 17:34:08 -0400 Subject: [PATCH 2/4] remove ISceneRenderHook --- .../gui/widgets/MachineSceneWidget.java | 4 ++-- .../client/renderer/scene/ISceneRenderHook.java | 17 ----------------- .../renderer/scene/WorldSceneRenderer.java | 3 ++- .../AdvancedMonitorPluginBehavior.java | 2 +- .../multiblockhelper/MachineBuilderWidget.java | 2 +- .../multiblock/MultiblockInfoRecipeWrapper.java | 4 ++-- 6 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 src/main/java/gregtech/client/renderer/scene/ISceneRenderHook.java diff --git a/src/main/java/gregtech/api/terminal/gui/widgets/MachineSceneWidget.java b/src/main/java/gregtech/api/terminal/gui/widgets/MachineSceneWidget.java index 43fceb358f9..23e31372ba0 100644 --- a/src/main/java/gregtech/api/terminal/gui/widgets/MachineSceneWidget.java +++ b/src/main/java/gregtech/api/terminal/gui/widgets/MachineSceneWidget.java @@ -247,8 +247,8 @@ private void updateScene() { } center = new Vector3f(pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f); } - worldSceneRenderer.addRenderedBlocks(cores, null); - worldSceneRenderer.addRenderedBlocks(around, this::aroundBlocksRenderHook); + worldSceneRenderer.addRenderedBlocks(cores); + worldSceneRenderer.addRenderedBlocks(around); worldSceneRenderer.setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw)); } diff --git a/src/main/java/gregtech/client/renderer/scene/ISceneRenderHook.java b/src/main/java/gregtech/client/renderer/scene/ISceneRenderHook.java deleted file mode 100644 index e6674c9b4d2..00000000000 --- a/src/main/java/gregtech/client/renderer/scene/ISceneRenderHook.java +++ /dev/null @@ -1,17 +0,0 @@ -package gregtech.client.renderer.scene; - -import net.minecraft.util.BlockRenderLayer; - -/** - * Created with IntelliJ IDEA. - * - * @Author: KilaBash - * @Date: 2021/08/25 - * @Description: Scene Render State hooks. - * This is where you decide whether or not this group of pos should be rendered. What other requirements - * do you have for rendering. - */ -public interface ISceneRenderHook { - - void apply(boolean isTESR, int pass, BlockRenderLayer layer); -} diff --git a/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java b/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java index ecce4133259..a9cf8ccbf2b 100644 --- a/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java +++ b/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java @@ -27,6 +27,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import codechicken.lib.vec.Vector3; +import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL11; import org.lwjgl.util.glu.GLU; @@ -85,7 +86,7 @@ public WorldSceneRenderer setAfterWorldRender(Consumer callb return this; } - public WorldSceneRenderer addRenderedBlocks(Collection blocks, ISceneRenderHook renderHook) { + public WorldSceneRenderer addRenderedBlocks(@Nullable Collection blocks) { if (blocks != null) { this.renderedBlocks.addAll(blocks); } diff --git a/src/main/java/gregtech/common/items/behaviors/monitorplugin/AdvancedMonitorPluginBehavior.java b/src/main/java/gregtech/common/items/behaviors/monitorplugin/AdvancedMonitorPluginBehavior.java index 7c3da2f0166..694dcc04f5e 100644 --- a/src/main/java/gregtech/common/items/behaviors/monitorplugin/AdvancedMonitorPluginBehavior.java +++ b/src/main/java/gregtech/common/items/behaviors/monitorplugin/AdvancedMonitorPluginBehavior.java @@ -104,7 +104,7 @@ private void createWorldScene() { TrackedDummyWorld dummyWorld = new TrackedDummyWorld(world); dummyWorld.setRenderFilter(pos -> validPos.contains(pos)); worldSceneRenderer = new FBOWorldSceneRenderer(dummyWorld, FBO); - worldSceneRenderer.addRenderedBlocks(validPos, null); + worldSceneRenderer.addRenderedBlocks(validPos); center = new Vector3f((minX + maxX) / 2f + 0.5f, (minY + maxY) / 2f + 0.5f, (minZ + maxZ) / 2f + 0.5f); worldSceneRenderer.setCameraLookAt(center, 10 / scale, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw)); diff --git a/src/main/java/gregtech/common/terminal/app/multiblockhelper/MachineBuilderWidget.java b/src/main/java/gregtech/common/terminal/app/multiblockhelper/MachineBuilderWidget.java index 899e1dc9d37..6e4c27cf820 100644 --- a/src/main/java/gregtech/common/terminal/app/multiblockhelper/MachineBuilderWidget.java +++ b/src/main/java/gregtech/common/terminal/app/multiblockhelper/MachineBuilderWidget.java @@ -154,7 +154,7 @@ public void drawInBackground(int mouseX, int mouseY, float partialTicks, IRender public void setSceneWidget(MachineSceneWidget sceneWidget) { this.sceneWidget = sceneWidget; this.highLightBlocks = new HashSet<>(); - MachineSceneWidget.getWorldSceneRenderer().addRenderedBlocks(highLightBlocks, this::highLightRender); + MachineSceneWidget.getWorldSceneRenderer().addRenderedBlocks(highLightBlocks); sceneWidget.setOnSelected(this::setFocus); sceneWidget.getAround().clear(); Set cores = sceneWidget.getCores(); diff --git a/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java b/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java index cf4ca50fc95..1e5dd465b99 100644 --- a/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java +++ b/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java @@ -226,7 +226,7 @@ private void setNextLayer(int newLayer) { renderBlocks = world.renderedBlocks.stream().filter(pos -> pos.getY() - minY == newLayer) .collect(Collectors.toSet()); } - renderer.addRenderedBlocks(renderBlocks, null); + renderer.addRenderedBlocks(renderBlocks); } } @@ -593,7 +593,7 @@ private MBPattern initializePattern(@NotNull MultiblockShapeInfo shapeInfo, @Not Vector3f minPos = world.getMinPos(); center = new Vector3f(minPos.x + size.x / 2, minPos.y + size.y / 2, minPos.z + size.z / 2); - worldSceneRenderer.addRenderedBlocks(world.renderedBlocks, null); + worldSceneRenderer.addRenderedBlocks(world.renderedBlocks); worldSceneRenderer.setOnLookingAt(ray -> {}); worldSceneRenderer.setAfterWorldRender(renderer -> { From 69e2251f09566bdc97079f87b1b4ef1c618be317 Mon Sep 17 00:00:00 2001 From: TechLord22 <37029404+techlord22@users.noreply.github.com> Date: Sat, 28 Sep 2024 18:27:00 -0400 Subject: [PATCH 3/4] spotless --- .../gregtech/client/renderer/scene/WorldSceneRenderer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java b/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java index a9cf8ccbf2b..cb0dacd1c63 100644 --- a/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java +++ b/src/main/java/gregtech/client/renderer/scene/WorldSceneRenderer.java @@ -5,8 +5,6 @@ import gregtech.api.util.Size; import gregtech.client.utils.RenderUtil; -import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; - import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -27,6 +25,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import codechicken.lib.vec.Vector3; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL11; import org.lwjgl.util.glu.GLU; From 840f5eecf194ee9e715c07a5057efd661e91a5a5 Mon Sep 17 00:00:00 2001 From: bruberu <80226372+bruberu@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:28:22 -0500 Subject: [PATCH 4/4] fix: empty files --- .../gregtech/api/terminal/gui/widgets/MachineSceneWidget.java | 0 .../terminal/app/multiblockhelper/MachineBuilderWidget.java | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/main/java/gregtech/api/terminal/gui/widgets/MachineSceneWidget.java delete mode 100644 src/main/java/gregtech/common/terminal/app/multiblockhelper/MachineBuilderWidget.java diff --git a/src/main/java/gregtech/api/terminal/gui/widgets/MachineSceneWidget.java b/src/main/java/gregtech/api/terminal/gui/widgets/MachineSceneWidget.java deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/main/java/gregtech/common/terminal/app/multiblockhelper/MachineBuilderWidget.java b/src/main/java/gregtech/common/terminal/app/multiblockhelper/MachineBuilderWidget.java deleted file mode 100644 index e69de29bb2d..00000000000