From 0e96125db3f91890657d1026feb0879bbf761dc7 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 10 Apr 2021 14:28:46 +0800 Subject: BatchEntryRenderer -> BatchedEntryRenderer Signed-off-by: shedaniel --- api/build.gradle | 2 +- .../client/entry/renderer/BatchEntryRenderer.java | 62 --------- .../entry/renderer/BatchedEntryRenderer.java | 88 +++++++++++++ .../api/client/entry/renderer/EntryRenderer.java | 7 + build.gradle | 4 +- gradle.properties | 1 + runtime/build.gradle | 2 +- .../client/config/entries/FilteringScreen.java | 4 +- .../gui/widget/BatchEntryRendererManager.java | 143 -------------------- .../gui/widget/BatchedEntryRendererManager.java | 144 +++++++++++++++++++++ .../impl/client/gui/widget/EntryListWidget.java | 4 +- .../client/gui/widget/FavoritesListWidget.java | 2 +- .../OverlaySearchFieldSyntaxHighlighter.java | 4 +- .../shedaniel/rei/impl/client/search/IntRange.java | 38 ++++++ .../rei/impl/client/search/argument/Argument.java | 2 +- .../search/result/ArgumentApplicableResult.java | 2 +- .../rei/impl/common/entry/AbstractEntryStack.java | 2 +- .../plugin/client/entry/ItemEntryDefinition.java | 6 +- 18 files changed, 296 insertions(+), 221 deletions(-) delete mode 100644 api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchEntryRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/BatchEntryRendererManager.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/BatchedEntryRendererManager.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/IntRange.java diff --git a/api/build.gradle b/api/build.gradle index 3a332c299..44fe15010 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -5,7 +5,7 @@ dependencies { } architectury { - common() + common(forgeEnabled.toBoolean()) } remapJar { diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchEntryRenderer.java deleted file mode 100644 index ba7e5d150..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchEntryRenderer.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.client.entry.renderer; - -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.common.entry.EntryStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.MultiBufferSource; - -public interface BatchEntryRenderer extends EntryRenderer { - static int getBatchIdFrom(EntryStack entry) { - EntryRenderer renderer = entry.getRenderer(); - if (renderer instanceof BatchEntryRenderer) return ((BatchEntryRenderer) renderer).getBatchId(entry); - return renderer.getClass().hashCode(); - } - - default int getBatchId(EntryStack entry) { - return getClass().hashCode(); - } - - void startBatch(EntryStack entry, PoseStack matrices, float delta); - - void renderBase(EntryStack entry, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); - - void renderOverlay(EntryStack entry, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); - - void endBatch(EntryStack entry, PoseStack matrices, float delta); - - @Deprecated - @Override - default void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { - startBatch(entry, matrices, delta); - MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); - renderBase(entry, matrices, immediate, bounds, mouseX, mouseY, delta); - immediate.endBatch(); - renderOverlay(entry, matrices, immediate, bounds, mouseX, mouseY, delta); - immediate.endBatch(); - endBatch(entry, matrices, delta); - } -} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java new file mode 100644 index 000000000..400ef727c --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java @@ -0,0 +1,88 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.client.entry.renderer; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.common.entry.EntryStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.MultiBufferSource; + +public interface BatchedEntryRenderer extends EntryRenderer { + /** + * Returns a batch identifier, stacks with the same batch identifier will be grouped together + * into a batch. + * + * @param entry the stack + * @param bounds the bounds of the entry + * @return the batch identifier + */ + default int getBatchIdentifier(EntryStack entry, Rectangle bounds) { + return getClass().hashCode(); + } + + /** + * Modifies the {@link PoseStack} passed tp various batch rendering methods. + * + * @param matrices the matrix stack + * @return the modified matrix stack, could be an entirely different stack + */ + default PoseStack batchModifyMatrices(PoseStack matrices) { + return matrices; + } + + /** + * Starts the batch rendering, used to setup states, only called once with every batch. + * + * @param entry the first entry in the batch + * @param matrices the matrix stack + * @param delta the tick delta + */ + void startBatch(EntryStack entry, PoseStack matrices, float delta); + + void renderBase(EntryStack entry, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); + + void renderOverlay(EntryStack entry, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); + + /** + * Ends the batch rendering, used to setup states, only called once with every batch. + * + * @param entry the first entry in the batch + * @param matrices the matrix stack + * @param delta the tick delta + */ + void endBatch(EntryStack entry, PoseStack matrices, float delta); + + @Override + default void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { + matrices = batchModifyMatrices(matrices); + startBatch(entry, matrices, delta); + MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); + renderBase(entry, matrices, immediate, bounds, mouseX, mouseY, delta); + immediate.endBatch(); + renderOverlay(entry, matrices, immediate, bounds, mouseX, mouseY, delta); + immediate.endBatch(); + endBatch(entry, matrices, delta); + } +} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java index 9ee60c5f8..e5b78b788 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java @@ -34,6 +34,13 @@ import net.fabricmc.api.Environment; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +/** + * A renderer to render a {@link EntryStack}. + * Use {@link me.shedaniel.rei.api.client.util.ClientEntryStacks#setRenderer} to change the {@link EntryRenderer} for a {@link EntryStack}. + * + * @param the entry type + * @see BatchedEntryRenderer + */ public interface EntryRenderer { static EntryRenderer empty() { return ClientInternals.getEmptyEntryRenderer(); diff --git a/build.gradle b/build.gradle index b82f547f9..4cbfbd082 100755 --- a/build.gradle +++ b/build.gradle @@ -148,7 +148,9 @@ task releaseOnCf { } proc.waitFor() releaseChangelog = changes.toString() - dependsOn project("forge").tasks.getByName("curseforge") + if (subprojects.any { it.name == "forge" }) { + dependsOn project("forge").tasks.getByName("curseforge") + } } /*project { diff --git a/gradle.properties b/gradle.properties index 4e9ed76c7..50ac8bcac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,7 @@ base_version=6.0.0 unstable=true supported_version=1.16.2/3/4/5 minecraft_version=1.16.5 +forgeEnabled=true forge_version=36.0.43 fabricloader_version=0.11.1 cloth_config_version=4.11.18 diff --git a/runtime/build.gradle b/runtime/build.gradle index 53c1100d7..3048fb3b7 100644 --- a/runtime/build.gradle +++ b/runtime/build.gradle @@ -1,5 +1,5 @@ architectury { - common() + common(forgeEnabled.toBoolean()) } repositories { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java index 7a6e9f32d..9717f1cf1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java @@ -46,7 +46,7 @@ import me.shedaniel.rei.api.client.search.SearchFilter; import me.shedaniel.rei.api.client.search.SearchProvider; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.impl.client.gui.ContainerScreenOverlay; -import me.shedaniel.rei.impl.client.gui.widget.BatchEntryRendererManager; +import me.shedaniel.rei.impl.client.gui.widget.BatchedEntryRendererManager; import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; import net.minecraft.client.Minecraft; @@ -222,7 +222,7 @@ public class FilteringScreen extends Screen { int skip = Math.max(0, Mth.floor(scrolling.scrollAmount / (float) entrySize())); int nextIndex = skip * innerBounds.width / entrySize(); int i = nextIndex; - BatchEntryRendererManager manager = new BatchEntryRendererManager(); + BatchedEntryRendererManager manager = new BatchedEntryRendererManager(); for (; i < entryStacks.size(); i++) { EntryStack stack = entryStacks.get(i); EntryListEntry entry = entries.get(nextIndex); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/BatchEntryRendererManager.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/BatchEntryRendererManager.java deleted file mode 100644 index 6cafecb90..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/BatchEntryRendererManager.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.impl.client.gui.widget; - -import com.google.common.collect.Iterables; -import com.mojang.blaze3d.vertex.PoseStack; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import me.shedaniel.rei.api.client.config.ConfigObject; -import me.shedaniel.rei.api.client.entry.renderer.BatchEntryRenderer; -import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; -import me.shedaniel.rei.api.common.entry.EntryStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.MultiBufferSource; -import org.apache.commons.lang3.mutable.MutableInt; -import org.apache.commons.lang3.mutable.MutableLong; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class BatchEntryRendererManager { - private boolean fastEntryRendering = ConfigObject.getInstance().doesFastEntryRendering(); - private Int2ObjectMap> grouping = new Int2ObjectOpenHashMap<>(); - private List toRender = new ArrayList<>(); - - public BatchEntryRendererManager() { - } - - public BatchEntryRendererManager(Collection widgets) { - addAll(widgets); - } - - public void addAll(Collection widgets) { - if (fastEntryRendering) { - for (EntryWidget widget : widgets) { - add(widget); - } - } else { - toRender.addAll(widgets); - } - } - - public void add(EntryWidget widget) { - if (fastEntryRendering) { - EntryStack currentEntry = widget.getCurrentEntry(); - EntryRenderer renderer = currentEntry.getRenderer(); - if (renderer instanceof BatchEntryRenderer) { - int hash = ((BatchEntryRenderer) renderer).getBatchId(currentEntry.cast()); - List entries = grouping.get(hash); - if (entries == null) { - grouping.put(hash, entries = new ArrayList<>()); - } - entries.add(widget); - return; - } - } - toRender.add(widget); - } - - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - render(false, null, null, matrices, mouseX, mouseY, delta); - } - - public void render(boolean debugTime, MutableInt size, MutableLong time, PoseStack matrices, int mouseX, int mouseY, float delta) { - if (fastEntryRendering) { - for (List entries : grouping.values()) { - renderEntries(debugTime, size, time, fastEntryRendering, matrices, mouseX, mouseY, delta, entries); - } - } - if (!toRender.isEmpty()) { - renderEntries(debugTime, size, time, fastEntryRendering, matrices, mouseX, mouseY, delta, toRender); - } - } - - - public static void renderEntries(boolean debugTime, MutableInt size, MutableLong time, boolean fastEntryRendering, PoseStack matrices, int mouseX, int mouseY, float delta, Iterable entries) { - T firstWidget = Iterables.getFirst(entries, null); - if (firstWidget == null) return; - @SuppressWarnings("rawtypes") - EntryStack first = firstWidget.getCurrentEntry(); - EntryRenderer renderer = first.getRenderer(); - if (fastEntryRendering && renderer instanceof BatchEntryRenderer) { - BatchEntryRenderer firstRenderer = (BatchEntryRenderer) renderer; - firstRenderer.startBatch(first, matrices, delta); - long l = debugTime ? System.nanoTime() : 0; - MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); - for (T listEntry : entries) { - @SuppressWarnings("rawtypes") - EntryStack currentEntry = listEntry.getCurrentEntry(); - currentEntry.setZ(100); - listEntry.drawBackground(matrices, mouseX, mouseY, delta); - firstRenderer.renderBase(currentEntry, matrices, immediate, listEntry.getInnerBounds(), mouseX, mouseY, delta); - if (debugTime && !currentEntry.isEmpty()) size.increment(); - } - immediate.endBatch(); - for (T listEntry : entries) { - @SuppressWarnings("rawtypes") - EntryStack currentEntry = listEntry.getCurrentEntry(); - firstRenderer.renderOverlay(currentEntry, matrices, immediate, listEntry.getInnerBounds(), mouseX, mouseY, delta); - if (listEntry.containsMouse(mouseX, mouseY)) { - listEntry.queueTooltip(matrices, mouseX, mouseY, delta); - listEntry.drawHighlighted(matrices, mouseX, mouseY, delta); - } - } - immediate.endBatch(); - if (debugTime) time.add(System.nanoTime() - l); - firstRenderer.endBatch(first, matrices, delta); - } else { - for (T entry : entries) { - if (entry.getCurrentEntry().isEmpty()) - continue; - if (debugTime) { - size.increment(); - long l = System.nanoTime(); - entry.render(matrices, mouseX, mouseY, delta); - time.add(System.nanoTime() - l); - } else entry.render(matrices, mouseX, mouseY, delta); - } - } - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/BatchedEntryRendererManager.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/BatchedEntryRendererManager.java new file mode 100644 index 000000000..a410a24a3 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/BatchedEntryRendererManager.java @@ -0,0 +1,144 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.gui.widget; + +import com.google.common.collect.Iterables; +import com.mojang.blaze3d.vertex.PoseStack; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.entry.renderer.BatchedEntryRenderer; +import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; +import me.shedaniel.rei.api.common.entry.EntryStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.MultiBufferSource; +import org.apache.commons.lang3.mutable.MutableInt; +import org.apache.commons.lang3.mutable.MutableLong; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class BatchedEntryRendererManager { + private boolean fastEntryRendering = ConfigObject.getInstance().doesFastEntryRendering(); + private Int2ObjectMap> grouping = new Int2ObjectOpenHashMap<>(); + private List toRender = new ArrayList<>(); + + public BatchedEntryRendererManager() { + } + + public BatchedEntryRendererManager(Collection widgets) { + addAll(widgets); + } + + public void addAll(Collection widgets) { + if (fastEntryRendering) { + for (EntryWidget widget : widgets) { + add(widget); + } + } else { + toRender.addAll(widgets); + } + } + + public void add(EntryWidget widget) { + if (fastEntryRendering) { + EntryStack currentEntry = widget.getCurrentEntry(); + EntryRenderer renderer = currentEntry.getRenderer(); + if (renderer instanceof BatchedEntryRenderer) { + int hash = ((BatchedEntryRenderer) renderer).getBatchIdentifier(currentEntry.cast(), widget.getBounds()); + List entries = grouping.get(hash); + if (entries == null) { + grouping.put(hash, entries = new ArrayList<>()); + } + entries.add(widget); + return; + } + } + toRender.add(widget); + } + + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { + render(false, null, null, matrices, mouseX, mouseY, delta); + } + + public void render(boolean debugTime, MutableInt size, MutableLong time, PoseStack matrices, int mouseX, int mouseY, float delta) { + if (fastEntryRendering) { + for (List entries : grouping.values()) { + renderEntries(debugTime, size, time, fastEntryRendering, matrices, mouseX, mouseY, delta, entries); + } + } + if (!toRender.isEmpty()) { + renderEntries(debugTime, size, time, fastEntryRendering, matrices, mouseX, mouseY, delta, toRender); + } + } + + + public static void renderEntries(boolean debugTime, MutableInt size, MutableLong time, boolean fastEntryRendering, PoseStack matrices, int mouseX, int mouseY, float delta, Iterable entries) { + T firstWidget = Iterables.getFirst(entries, null); + if (firstWidget == null) return; + @SuppressWarnings("rawtypes") + EntryStack first = firstWidget.getCurrentEntry(); + EntryRenderer renderer = first.getRenderer(); + if (fastEntryRendering && renderer instanceof BatchedEntryRenderer) { + BatchedEntryRenderer firstRenderer = (BatchedEntryRenderer) renderer; + matrices = firstRenderer.batchModifyMatrices(matrices); + firstRenderer.startBatch(first, matrices, delta); + long l = debugTime ? System.nanoTime() : 0; + MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); + for (T listEntry : entries) { + @SuppressWarnings("rawtypes") + EntryStack currentEntry = listEntry.getCurrentEntry(); + currentEntry.setZ(100); + listEntry.drawBackground(matrices, mouseX, mouseY, delta); + firstRenderer.renderBase(currentEntry, matrices, immediate, listEntry.getInnerBounds(), mouseX, mouseY, delta); + if (debugTime && !currentEntry.isEmpty()) size.increment(); + } + immediate.endBatch(); + for (T listEntry : entries) { + @SuppressWarnings("rawtypes") + EntryStack currentEntry = listEntry.getCurrentEntry(); + firstRenderer.renderOverlay(currentEntry, matrices, immediate, listEntry.getInnerBounds(), mouseX, mouseY, delta); + if (listEntry.containsMouse(mouseX, mouseY)) { + listEntry.queueTooltip(matrices, mouseX, mouseY, delta); + listEntry.drawHighlighted(matrices, mouseX, mouseY, delta); + } + } + immediate.endBatch(); + if (debugTime) time.add(System.nanoTime() - l); + firstRenderer.endBatch(first, matrices, delta); + } else { + for (T entry : entries) { + if (entry.getCurrentEntry().isEmpty()) + continue; + if (debugTime) { + size.increment(); + long l = System.nanoTime(); + entry.render(matrices, mouseX, mouseY, delta); + time.add(System.nanoTime() - l); + } else entry.render(matrices, mouseX, mouseY, delta); + } + } + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListWidget.java index ec57bf1d1..44e0589d9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListWidget.java @@ -220,7 +220,7 @@ public class EntryListWidget extends WidgetWithBounds { int skip = Math.max(0, Mth.floor(scrolling.scrollAmount / (float) entrySize())); int nextIndex = skip * innerBounds.width / entrySize(); this.blockedCount = 0; - BatchEntryRendererManager helper = new BatchEntryRendererManager(); + BatchedEntryRendererManager helper = new BatchedEntryRendererManager(); int i = nextIndex; for (int cont = nextIndex; cont < entries.size(); cont++) { @@ -253,7 +253,7 @@ public class EntryListWidget extends WidgetWithBounds { for (Widget widget : renders) { widget.render(matrices, mouseX, mouseY, delta); } - new BatchEntryRendererManager(entries).render(debugTime, size, time, matrices, mouseX, mouseY, delta); + new BatchedEntryRendererManager(entries).render(debugTime, size, time, matrices, mouseX, mouseY, delta); } if (debugTime) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java index 57ccd0b6a..1433c65de 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java @@ -251,7 +251,7 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt Stream entryStream = this.entriesList.stream() .filter(entry -> entry.getBounds().getMaxY() >= this.currentBounds.getY() && entry.getBounds().y <= this.currentBounds.getMaxY()); - new BatchEntryRendererManager(entryStream.collect(Collectors.toList())) + new BatchedEntryRendererManager(entryStream.collect(Collectors.toList())) .render(matrices, mouseX, mouseY, delta); updatePosition(delta); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/search/OverlaySearchFieldSyntaxHighlighter.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/search/OverlaySearchFieldSyntaxHighlighter.java index 42308f678..0af21de72 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/search/OverlaySearchFieldSyntaxHighlighter.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/search/OverlaySearchFieldSyntaxHighlighter.java @@ -23,9 +23,9 @@ package me.shedaniel.rei.impl.client.gui.widget.search; +import me.shedaniel.rei.impl.client.search.IntRange; import me.shedaniel.rei.impl.client.search.argument.Argument; import me.shedaniel.rei.impl.client.search.argument.type.ArgumentTypesRegistry; -import net.minecraft.util.IntRange; import org.jetbrains.annotations.ApiStatus; import java.util.Collection; @@ -63,7 +63,7 @@ public class OverlaySearchFieldSyntaxHighlighter implements Consumer { highlighted[i] = (byte) argIndex; } for (IntRange grammarRange : grammarRanges) { - for (int i = grammarRange.getMinInclusive(); i <= grammarRange.getMaxInclusive(); i++) { + for (int i = grammarRange.min(); i <= grammarRange.max(); i++) { highlighted[i + index] = (byte) (argIndex + 1); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/IntRange.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/IntRange.java new file mode 100644 index 000000000..05c5e1ca4 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/IntRange.java @@ -0,0 +1,38 @@ +package me.shedaniel.rei.impl.client.search; + +import java.util.Objects; + +public class IntRange { + private final int min; + private final int max; + + private IntRange(int min, int max) { + this.min = min; + this.max = max; + } + + public static IntRange of(int min, int max) { + return new IntRange(min, max); + } + + public int min() { + return min; + } + + public int max() { + return max; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + IntRange intRange = (IntRange) o; + return min == intRange.min && max == intRange.max; + } + + @Override + public int hashCode() { + return Objects.hash(min, max); + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java index 67520b666..dcabfbdf2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java @@ -27,13 +27,13 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.Lists; import me.shedaniel.rei.api.client.gui.config.SearchMode; import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.impl.client.search.IntRange; import me.shedaniel.rei.impl.client.search.argument.type.AlwaysMatchingArgumentType; import me.shedaniel.rei.impl.client.search.argument.type.ArgumentType; import me.shedaniel.rei.impl.client.search.argument.type.ArgumentTypesRegistry; import me.shedaniel.rei.impl.client.search.result.ArgumentApplicableResult; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.util.IntRange; import net.minecraft.util.Unit; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.mutable.Mutable; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/result/ArgumentApplicableResult.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/result/ArgumentApplicableResult.java index e25b89326..3014c9771 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/result/ArgumentApplicableResult.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/result/ArgumentApplicableResult.java @@ -23,8 +23,8 @@ package me.shedaniel.rei.impl.client.search.result; +import me.shedaniel.rei.impl.client.search.IntRange; import me.shedaniel.rei.impl.client.search.argument.type.MatchType; -import net.minecraft.util.IntRange; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java index 618674152..3cbf8d511 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java @@ -154,7 +154,7 @@ public abstract class AbstractEntryStack extends AbstractRenderer implements @Override @Nullable public Tooltip getTooltip(Point mouse, boolean appendModName) { - Mutable tooltip = new MutableObject<>(this.get(Settings.RENDER).apply(this).cast().getTooltip(this, mouse)); + Mutable tooltip = new MutableObject<>(this.get(Settings.RENDERER).apply(this).cast().getTooltip(this, mouse)); if (tooltip.getValue() == null) return null; tooltip.getValue().getText().addAll(get(EntryStack.Settings.TOOLTIP_APPEND_EXTRA).apply(this)); tooltip.setValue(get(Settings.TOOLTIP_PROCESSOR).apply(this, tooltip.getValue())); diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java index 453df00c3..a6a102ea8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java @@ -33,7 +33,7 @@ import it.unimi.dsi.fastutil.objects.ReferenceSet; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.entry.renderer.AbstractEntryRenderer; -import me.shedaniel.rei.api.client.entry.renderer.BatchEntryRenderer; +import me.shedaniel.rei.api.client.entry.renderer.BatchedEntryRenderer; import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.common.entry.EntrySerializer; @@ -185,9 +185,9 @@ public class ItemEntryDefinition implements EntryDefinition, EntrySer } @SuppressWarnings("deprecation") - public class ItemEntryRenderer extends AbstractEntryRenderer implements BatchEntryRenderer { + public class ItemEntryRenderer extends AbstractEntryRenderer implements BatchedEntryRenderer { @Override - public int getBatchId(EntryStack entry) { + public int getBatchIdentifier(EntryStack entry, Rectangle bounds) { return 1738923 + (getModelFromStack(entry.getValue()).usesBlockLight() ? 1 : 0); } -- cgit From 5bfc72d5037b6e1c9a0e3adac15f7ebbeffd2a93 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 10 Apr 2021 14:29:01 +0800 Subject: Apply license to IntRange Signed-off-by: shedaniel --- .../shedaniel/rei/impl/client/search/IntRange.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/IntRange.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/IntRange.java index 05c5e1ca4..28b3720a0 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/IntRange.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/IntRange.java @@ -1,3 +1,26 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package me.shedaniel.rei.impl.client.search; import java.util.Objects; -- cgit From 6d7690b3410e6aa837089987c08598cb9ecbe45a Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 10 Apr 2021 14:30:41 +0800 Subject: Change how EntryStack.Settings is exposed Signed-off-by: shedaniel --- .../rei/api/client/util/ClientEntryStacks.java | 28 ++++++++++++++++++ .../shedaniel/rei/api/common/entry/EntryStack.java | 34 +++++++++++++--------- .../rei/impl/common/entry/AbstractEntryStack.java | 2 +- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java b/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java index 537a658f2..7409f1150 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java @@ -23,10 +23,16 @@ package me.shedaniel.rei.api.client.util; +import me.shedaniel.architectury.fluid.FluidStack; +import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; import me.shedaniel.rei.api.client.entry.type.BuiltinClientEntryTypes; import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.common.entry.EntryStack; +import java.util.function.BiFunction; +import java.util.function.Function; + public final class ClientEntryStacks { private ClientEntryStacks() {} @@ -37,4 +43,26 @@ public final class ClientEntryStacks { return EntryStack.of(BuiltinClientEntryTypes.RENDERING, renderer); } + + public static EntryStack setNotRenderer(EntryStack stack) { + return setRenderer(stack, EntryRenderer.empty()); + } + + public static EntryStack setRenderer(EntryStack stack, EntryRenderer renderer) { + return stack.setting(EntryStack.Settings.RENDERER, s -> renderer); + } + + @SuppressWarnings("rawtypes") + public static EntryStack setRenderer(EntryStack stack, Function, EntryRenderer> rendererProvider) { + return stack.setting(EntryStack.Settings.RENDERER, (Function) rendererProvider); + } + + @SuppressWarnings("rawtypes") + public static EntryStack setTooltipProcessor(EntryStack stack, BiFunction, Tooltip, Tooltip> processor) { + return stack.setting(EntryStack.Settings.TOOLTIP_PROCESSOR, (BiFunction) processor); + } + + public static EntryStack setFluidRenderRatio(EntryStack stack, float ratio) { + return stack.setting(EntryStack.Settings.FLUID_RENDER_RATIO, ratio); + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java index 660605f32..3b0f6b454 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java @@ -23,6 +23,8 @@ package me.shedaniel.rei.api.common.entry; +import me.shedaniel.architectury.utils.Env; +import me.shedaniel.architectury.utils.EnvExecutor; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; @@ -103,7 +105,7 @@ public interface EntryStack extends TextRepresentable, Renderer { @Environment(EnvType.CLIENT) default EntryRenderer getRenderer() { - EntryRenderer renderer = get(Settings.RENDER).apply(this); + EntryRenderer renderer = get(Settings.RENDERER).apply(this); return renderer == null ? EntryRenderer.empty() : renderer.cast(); } @@ -138,39 +140,43 @@ public interface EntryStack extends TextRepresentable, Renderer { R get(Settings settings); + @Environment(EnvType.CLIENT) default EntryStack tooltip(Component... tooltips) { return tooltip(Arrays.asList(tooltips)); } + @Environment(EnvType.CLIENT) default EntryStack tooltip(List tooltips) { return tooltip(stack -> tooltips); } + @Environment(EnvType.CLIENT) default EntryStack tooltip(Function, List> tooltipProvider) { return setting(Settings.TOOLTIP_APPEND_EXTRA, tooltipProvider); } + @Deprecated class Settings { @ApiStatus.Internal private static final List> SETTINGS = new ArrayList<>(); - public static final Supplier TRUE = () -> true; - public static final Supplier FALSE = () -> false; @Environment(EnvType.CLIENT) - public static final Function, EntryRenderer> DEFAULT_RENDERER = stack -> stack.getDefinition().getRenderer(); + public static Settings, EntryRenderer>> RENDERER; @Environment(EnvType.CLIENT) - public static final Function, EntryRenderer> EMPTY_RENDERER = stack -> EntryRenderer.empty(); - public static final BiFunction, Tooltip, Tooltip> DEFAULT_TOOLTIP_PROCESSOR = (stack, tooltip) -> tooltip; + public static Settings, Tooltip, Tooltip>> TOOLTIP_PROCESSOR; @Environment(EnvType.CLIENT) - public static final Settings, EntryRenderer>> RENDER = new Settings<>(DEFAULT_RENDERER); - @Deprecated - public static final Settings, Tooltip, Tooltip>> TOOLTIP_PROCESSOR = new Settings<>(DEFAULT_TOOLTIP_PROCESSOR); - @Deprecated - public static final Settings, List>> TOOLTIP_APPEND_EXTRA = new Settings<>(stack -> Collections.emptyList()); + public static Settings, List>> TOOLTIP_APPEND_EXTRA; @Environment(EnvType.CLIENT) - public static final Float DEFAULT_RENDER_RATIO = 1.0F; - @Environment(EnvType.CLIENT) - public static final Settings FLUID_RENDER_RATIO = new Settings<>(DEFAULT_RENDER_RATIO); + public static Settings FLUID_RENDER_RATIO; + + static { + EnvExecutor.runInEnv(Env.CLIENT, () -> () -> { + RENDERER = new Settings<>(stack -> stack.getDefinition().getRenderer()); + TOOLTIP_PROCESSOR = new Settings<>((stack, tooltip) -> tooltip); + TOOLTIP_APPEND_EXTRA = new Settings<>(stack -> Collections.emptyList()); + FLUID_RENDER_RATIO = new Settings<>(1.0F); + }); + } private R defaultValue; private short id; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java index 3cbf8d511..e272a8d70 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java @@ -154,7 +154,7 @@ public abstract class AbstractEntryStack extends AbstractRenderer implements @Override @Nullable public Tooltip getTooltip(Point mouse, boolean appendModName) { - Mutable tooltip = new MutableObject<>(this.get(Settings.RENDERER).apply(this).cast().getTooltip(this, mouse)); + Mutable tooltip = new MutableObject<>(getRenderer().cast().getTooltip(this, mouse)); if (tooltip.getValue() == null) return null; tooltip.getValue().getText().addAll(get(EntryStack.Settings.TOOLTIP_APPEND_EXTRA).apply(this)); tooltip.setValue(get(Settings.TOOLTIP_PROCESSOR).apply(this, tooltip.getValue())); -- cgit